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          : 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_Add : Base.BasePage
{
    #region VariableDeclaration
    PunchTypesEventdata objPunchTypesEventData = new PunchTypesEventdata();
    TerminalEventData objTerminal = new TerminalEventData();
    string strSetAlert;
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int EmployeeID;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // 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"]);
        if (!IsPostBack)
        {
            UserRights();
            LoadStrings(ci);
            ddl_TerminalId.Focus();
            FillTerminalsDropdown();
            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");
        }
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        GC.Collect();
        btn_add.Focus();
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        popupProgress.Show();
        int count = objPunchTypesEventData.Update_PunchTypeDetails('I', 0, int.Parse(ddl_TerminalId.SelectedValue), ddl_PunchTypes.SelectedValue, txt_Value.Text.Trim().Replace("'", "''"), EmployeeID);
        if (count == 0)
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_PunchTypesavedsuccessfully", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_Master_PunchTypes_List.aspx');";
            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);
        }
        popupProgress.Hide();
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_PunchTypes_List.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    // 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"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    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);
        }
    }
    #endregion
}