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;
        LoadStrings(ci);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        //Set UserRights
        UserRights();
        // focus to first control
        txtType.Focus();
        if (!IsPostBack)
        {
            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");
        }
        else
        {
            //   
        }
    }
    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("'", "''"));
        DataSet ds = new DataSet();
        TypeEventData Cat = new TypeEventData();
        bool IsFlexible = false;
        if (rbtnFlexibleYes.Checked == true)
        {
            IsFlexible = true;
        }
        ds = Cat.CheckDuplicate("I", TypeName, TypeID);
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                //lblError.Text = "Employee Type Already Exists";
                // base.Message("Employee Type already exists");
                //base.Message(rm.GetString("Alert_EmployeeTypealreadyexists", ci));
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_EmployeeTypealreadyexists", ci) + "');", true);
            }
            else
            {
                Cat.InsertUpdate("I", txtType.Text.Trim().Replace("'", "''"), Convert.ToString(Session["EmpAutoID"]), TypeID, IsFlexible);
                // string str = "alert('Employee Type saved successfully');location.replace('TA_UI_Master_EmployeeTypelist.aspx')";
                //string str = "alert('" + rm.GetString("Alert_EmployeeTypesavedsuccessfully", ci) + "');location.replace('TA_UI_Master_EmployeeTypelist.aspx')";
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                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)
    {
        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);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_EmployeeTypelist.aspx");
    }
}
