using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 27-Sep-2007
* Module          : InOut settings                              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_Modify : Base.BasePage
{
    #region VariableDeclaration
    PunchTypesEventdata objPunchTypesEventData = new PunchTypesEventdata();
    TerminalEventData objTerminal = new TerminalEventData();
    cls_Common objCommon = new cls_Common();
    string strSetAlert;
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        //Set UserRights
        UserRights();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        gintPunchTypeID = Convert.ToInt32(Request.QueryString["PunchType_Id"]);
        if (!IsPostBack)
        {
            ddl_TerminalId.Focus();
            FillTerminalsDropdown();
            LoadDetails();
            btn_add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;"; ;
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objCommon.menu("Device", "68");
        }
    }
    #endregion
    #region UserDefinedFunctions
    public void FillTerminalsDropdown()
    {
        DataSet ds_Terminal = new DataSet();
        ds_Terminal = objTerminal.SelectTerminalDetails(string.Empty);
        if (ds_Terminal.Tables[0].Rows.Count > 0)
        {
            ddl_TerminalId.DataSource = ds_Terminal;
            ddl_TerminalId.DataTextField = "Terminal_ReaderID";
            ddl_TerminalId.DataValueField = "Terminal_Id";
            ddl_TerminalId.DataBind();
        }
        ds_Terminal.Dispose();
        foreach (ListItem item in ddl_TerminalId.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    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_Id"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Terminal_Id"]) != "")
                    {
                        ddl_TerminalId.SelectedValue = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Terminal_Id"]);
                    }
                }
                if (ds_PunchTypes.Tables[0].Rows[0]["PunchType"] != DBNull.Value)
                {
                    if (Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]) != "")
                    {
                        ddl_PunchTypes.SelectedValue = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["PunchType"]);
                    }
                }
                if (ds_PunchTypes.Tables[0].Rows[0]["Value"] != DBNull.Value)
                {
                    txt_Value.Text = Convert.ToString(ds_PunchTypes.Tables[0].Rows[0]["Value"]);
                }
            }
            ds_PunchTypes.Dispose();
        }
    }
    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_man.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_Header.Text = rm.GetString("PunchTypes_PunchTypesHeader", ci);
        lbl_TerminalId.Text = rm.GetString("TerminalMaster_Terminal_Id", ci);
        lbl_PunchTypes.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        lbl_Value.Text = rm.GetString("PunchTypes_Value", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_Terminal_Punch", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("ReqField_PunchType", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("ReqField_PunchTypeValue", ci);
        ddl_PunchTypes.Items[0].Text = rm.GetString("Select", ci);
        ddl_PunchTypes.Items[1].Text = rm.GetString("PunchType_In", ci);
        ddl_PunchTypes.Items[2].Text = rm.GetString("PunchType_Out", ci);
        ddl_PunchTypes.Items[3].Text = rm.GetString("PunchType_ShiftIn", ci);
        ddl_PunchTypes.Items[4].Text = rm.GetString("PunchType_ShiftOut", ci);
        ddl_PunchTypes.Items[5].Text = rm.GetString("PunchType_BreakIn", ci);
        ddl_PunchTypes.Items[6].Text = rm.GetString("PunchType_BreakOut", ci);
        ddl_PunchTypes.Items[7].Text = rm.GetString("PunchType_LunchIn", ci);
        ddl_PunchTypes.Items[8].Text = rm.GetString("PunchType_LunchOut", ci);
        ddl_PunchTypes.Items[9].Text = rm.GetString("PunchType_InDuty", ci);
        ddl_PunchTypes.Items[10].Text = rm.GetString("PunchType_OutDuty", ci);
        ddl_PunchTypes.Items[11].Text = rm.GetString("PunchType_OfficialIn", ci);
        ddl_PunchTypes.Items[12].Text = rm.GetString("PunchType_OfficialOut", ci);
        ddl_TerminalId.Items[0].Text = rm.GetString("Select", ci);
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(68, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        int count = objPunchTypesEventData.Update_PunchTypeDetails('U', gintPunchTypeID, int.Parse(ddl_TerminalId.SelectedValue), ddl_PunchTypes.SelectedValue, txt_Value.Text.Trim().Replace("'", "''"), EmployeeID);
        if (count == 0)
        {
            string strScript = "";
            string strRedirectPage = "TA_UI_Master_PunchTypes_List.aspx";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("PunchType_modified", ci) + "');";
            strScript = strScript + "location.replace('" + strRedirectPage + "');";
            strScript = strScript + "</script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("PunchTypes_Duplicates", ci) + "');", true);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_PunchTypes_List.aspx");
    }
    #endregion
}