using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
public partial class Masters_TA_UI_Master_EmployeeTypeAdd : Base.BasePage
{
    ResourceManager rm;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    cls_Common objcommon = new cls_Common();
    //get the culture info to set the language
    CultureInfo ci;
    string strSetAlert;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        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"]);
        // focus to first control
        txtType.Focus();
        if (!IsPostBack)
        {
            //Set UserRights
            UserRights();
            LoadStrings(ci);
            btn_save.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("EmployeeMaster", "95");
        }
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(95, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        int TypeID = 0;
        TypeID = Convert.ToInt32(Request.QueryString["CatID"]);
        string TypeName = Convert.ToString(txtType.Text.Trim().Replace("'", "''"));
        int MaxTargetDays = Convert.ToInt32(txt_MaxAllowedWorkingDays.Text);
        DataSet ds = new DataSet();
        TypeEventData objempType = new TypeEventData();
        bool IsFlexible = false;
        if (rbtnFlexibleYes.Checked == true)
        {
            IsFlexible = true;
        }
        ds = objempType.CheckDuplicate("I", TypeName, TypeID);
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_EmployeeTypealreadyexists", ci) + "');", true);
            }
            else
            {
                objempType.InsertUpdate("I", txtType.Text.Trim().Replace("'", "''"), Convert.ToString(Session["EmpAutoID"]), TypeID, IsFlexible, (chkboxMyprofile.Checked) ? 1 : 0, MaxTargetDays);
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_EmployeeTypesavedsuccessfully", ci) + "');";
                strScript = strScript + "location.replace('TA_UI_Master_EmployeeTypelist.aspx');";
                strScript = strScript + "</script>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        chkboxMyprofile.Text = rm.GetString("Isdisply_MyProf", ci);
        lbl_Type.Text = rm.GetString("Master_Type", ci);
        lbl_Header.Text = rm.GetString("Master_Type", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        lblFlexibleTimings.Text = rm.GetString("FlexibleTimings", ci);
        rbtnFlexibleYes.Text = rm.GetString("Yes", ci);
        rbtnFlexibleNo.Text = rm.GetString("Grid_False", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_EnterType", ci);
        lbl_MaxAllowedWorkingDays.Text = rm.GetString("Master_MaxAllowedWorkingDays", ci);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_EmployeeTypelist.aspx");
    }
}
