using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 27-Sep-2007
* Module          : Punch Types                                 Last Modified : 31-Oct-2007
* Programmer      : Arun vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Master_TA_UI_Master_PunchTypes_View : Base.BasePage
{
    #region VariableDeclaration
    PunchTypesEventdata objPunchTypesEventData = new PunchTypesEventdata();
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    int gintPunchTypeID, EmployeeID;
    string gstrUserGroupName = string.Empty;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        GC.Collect();
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        //Set UserRights
        UserRights();
        loadcss();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        gintPunchTypeID = Convert.ToInt32(Request.QueryString["PunchType_Id"]);
        btn_delete.Attributes.Add("OnClick", "javascript:return confirm('" + rm.GetString("Alert_ConfirmDelete", ci) + "')");
        btn_Restore.OnClientClick = "return confirm('" + rm.GetString("Alert_Areyousuretorestore", ci) + "')";
        btn_PermanentDelete.OnClientClick = "return confirm('" + rm.GetString("Alert_AreyouwantDeleteRecordPermanently", ci) + "')";
        if (gstrUserGroupName != "SuperAdmin")
        {
            lbl_DeleteStatus_Main.Visible = false;
            lbl_DeleteStatus.Visible = false;
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        LoadDetails();
        int count = objPunchTypesEventData.CheckPunchTypes_Delete(gintPunchTypeID);
        if (count > 0)
        {
            btn_Modify.Enabled = false;
            btn_delete.Enabled = false;
            btn_PermanentDelete.Enabled = false;
        }
        if (!IsPostBack)
        {
            objCommon.menu("Device", "68");
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        int count = objPunchTypesEventData.CheckPunchTypes_Delete(gintPunchTypeID);
        if (count > 0)
        {
            base.Message(rm.GetString("Masters_PunchType_Cannot_Modified", ci));
            return;
        }
        Response.Redirect("TA_UI_Master_PunchTypes_Modify.aspx?PunchType_Id=" + gintPunchTypeID);
    }
    protected void btn_delete_Click(object sender, EventArgs e)
    {
        int count = objPunchTypesEventData.CheckPunchTypes_Delete(gintPunchTypeID);
        if (count > 0)
        {
            base.Message(rm.GetString("Masters_PunchType_Cannot_Delete", ci));
            return;
        }
        objPunchTypesEventData.DeletePunchTypes("TemporaryDelete", Convert.ToString(gintPunchTypeID), EmployeeID);
        base.MessageWithRedirect(rm.GetString("Alert_PunchTypedeletedsuccessfully", ci), "TA_UI_Master_PunchTypes_List.aspx");
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        int count = objPunchTypesEventData.CheckRestorePunchTypes(gintPunchTypeID);
        if (count > 0)
        {
            base.Message(rm.GetString("Message_Cannot_Restore", ci));
            return;
        }
        objPunchTypesEventData.DeletePunchTypes("Restore", Convert.ToString(gintPunchTypeID), EmployeeID);
        base.MessageWithRedirect(rm.GetString("Alert_PunchTyperestoredsuccessfully", ci), "TA_UI_Master_PunchTypes_List.aspx");
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        int count = objPunchTypesEventData.CheckPunchTypes_Delete(gintPunchTypeID);
        if (count > 0)
        {
            base.Message(rm.GetString("Masters_PunchType_Cannot_Delete", ci));
            return;
        }
        objPunchTypesEventData.DeletePunchTypes("PermanentDelete", Convert.ToString(gintPunchTypeID), EmployeeID);
        base.MessageWithRedirect(rm.GetString("Alert_PunchTypedeletedsuccessfully", ci), "TA_UI_Master_PunchTypes_List.aspx");
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_PunchTypes_List.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadDetails()
    {
        DataSet ds_PunchTypes = new DataSet();
        ds_PunchTypes = objPunchTypesEventData.Select_PunchTypeDetailsById(gintPunchTypeID, gstrUserGroupName);
        if (ds_PunchTypes != null)
        {
            if (ds_PunchTypes.Tables[0].Rows.Count > 0)
            {
                if (ds_PunchTypes.Tables[0].Rows[0]["Terminal_ReaderID"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Terminal_ReaderID"]) != string.Empty)
                    {
                        lbl_TerminalId.Text = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Terminal_ReaderID"]);
                    }
                }
                if (ds_PunchTypes.Tables[0].Rows[0]["PunchType"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) != string.Empty)
                    {
                        ViewState["PunchType"] = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]);
                        if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "In")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_In", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Out")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_Out", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Shift In")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_ShiftIn", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Shift Out")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_ShiftOut", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Break In")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_BreakIn", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Break Out")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_BreakOut", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Lunch In")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_LunchIn", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Lunch Out")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_LunchOut", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "In Duty")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_InDuty", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Out Duty")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_OutDuty", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Official In")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_OfficialIn", ci);
                        }
                        else if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) == "Official Out")
                        {
                            lbl_PunchType.Text = rm.GetString("PunchType_OfficialOut", ci);
                        }
                    }
                }
                if (ds_PunchTypes.Tables[0].Rows[0]["Value"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Value"]) != string.Empty)
                    {
                        lbl_Value.Text = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Value"]);
                    }
                }
                if (ds_PunchTypes.Tables[0].Rows[0]["IsDeleted"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["IsDeleted"]) != string.Empty)
                    {
                        lbl_DeleteStatus.Text = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["IsDeleted"]);
                        if (lbl_DeleteStatus.Text == "True" || lbl_DeleteStatus.Text == rm.GetString("Grid_True", ci))
                        {
                            btn_delete.Visible = false;
                        }
                        else if (lbl_DeleteStatus.Text == "False" || lbl_DeleteStatus.Text == rm.GetString("Grid_False", ci))
                        {
                            btn_Restore.Visible = false;
                        }
                        if (lbl_DeleteStatus.Text == "True")
                        {
                            lbl_DeleteStatus.Text = rm.GetString("Grid_True", ci);
                        }
                        else if (lbl_DeleteStatus.Text == "False")
                        {
                            lbl_DeleteStatus.Text = rm.GetString("Grid_False", ci);
                        }
                    }
                }
            }
            ds_PunchTypes.Dispose();
        }
    }
    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("PunchTypes_PunchTypesHeader", ci);
        lbl_TerminalId_Main.Text = rm.GetString("TerminalMaster_Terminal_Id", ci);
        lbl_PunchType_Main.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        lbl_Value_Main.Text = rm.GetString("PunchTypes_Value", ci);
        lbl_DeleteStatus_Main.Text = rm.GetString("DeleteStatus", ci);
        btn_Modify.Text = " " + rm.GetString("btn_Modify", ci);
        btn_delete.Text = " " + rm.GetString("btn_Delete", ci);
        btn_cancel.Text = " " + rm.GetString("btn_Back", ci);
        btn_Restore.Text = " " + rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = " " + rm.GetString("btn_PermanentDelete", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(68, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Master_PunchTypes_List.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Modify.Visible = true;
            }
            else
            {
                this.btn_Modify.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_delete.Visible = true;
                this.btn_PermanentDelete.Visible = true;
                this.btn_Restore.Visible = true;
            }
            else
            {
                this.btn_delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    private void loadcss()
    {
        CultureInfo ci;
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        htmlPunchType.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            //htmlPunchType.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }
    #endregion
}