using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Masters_TA_UI_Master_OverTimeTypeModify : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    string strSetAlert;
    #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"]);
        LoadStrings(ci);
        //Set UserRights
        UserRights();
        ddlCompany.Focus();
        if (!IsPostBack)
        {
            btn_add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;";
            int iOtID = 0;
            if (Request.QueryString["Id"] != null)
            {
                iOtID = Convert.ToInt32(Request.QueryString["Id"]);
            }
            CompanyBinding();
            OverTimeCodeEventData objClass = new OverTimeCodeEventData();
            DataSet ds = new DataSet();
            ds = objClass.SelectOtTypeByID(iOtID, "No", "", "", Convert.ToInt16(Session["parentLevelId"]));
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["OtType"] != DBNull.Value)
                {
                    txt_OverTimeType.Text = Convert.ToString(ds.Tables[0].Rows[0]["OtType"]);
                }
                if (ds.Tables[0].Rows[0]["CompanyID"] != DBNull.Value && Convert.ToInt32(ds.Tables[0].Rows[0]["CompanyID"]) != 0)
                {
                    ddlCompany.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["CompanyID"]);
                }
                if (ds.Tables[0].Rows[0]["OtValue"] != DBNull.Value)
                {
                    ddlOt.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["OtValue"]).Trim();
                }
            }
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objCommon.menu("Others", "100");
        }
    }
    #endregion
    #region UserDefinedFunctions
    private void CompanyBinding()
    {
        ShiftEvenData objShift = new ShiftEvenData();
        string gstrUserGroupName = string.Empty;
        DataSet dsCompany = new DataSet();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                ddlCompany.DataSource = dsCompany;
                ddlCompany.DataTextField = "CompanyName";
                ddlCompany.DataValueField = "CompanyId";
                ddlCompany.DataBind();
            }
        }
        foreach (ListItem item in ddlCompany.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_OtCat.Text = rm.GetString("OverTimeCategory", ci);
        lbl_OverTimeType.Text = rm.GetString("OverTimeType", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_Header.Text = rm.GetString("OverTimeType", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        ddlCompany.Items[0].Text = rm.GetString("Select", ci);
        ddlOt.Items[0].Text = rm.GetString("Select", ci);
        ddlOt.Items[1].Text = rm.GetString("OverTimeType_WorkingDay", ci);
        ddlOt.Items[2].Text = rm.GetString("ShiftSetting_WeeklyOff", ci);
        ddlOt.Items[3].Text = rm.GetString("Masters_Holidays_Holidays", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("Alert_Select_Company", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("OverTime_Type", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Alert_SelectOverTimeCategory", ci);
    }
    private void UserRights()
    {
        Cls_CheckUser objCheckUser = new Cls_CheckUser();
        DataSet ds_Checkuser = new DataSet();
        ds_Checkuser = objCheckUser.checkRights(100, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        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 iOtID = 0;
        if (Request.QueryString["Id"] != null)
        {
            iOtID = Convert.ToInt32(Request.QueryString["Id"]);
        }
        string strOtType = "";
        string strOtCat = "";
        string strOpr = "";
        int iCompanyID = 0;
        strOtType = txt_OverTimeType.Text.Trim().Replace("'", "''");
        strOtCat = Convert.ToString(ddlOt.SelectedValue).Trim();
        strOpr = "U";
        iCompanyID = Convert.ToInt32(ddlCompany.SelectedValue);
        string strScript = "";
        DataSet dsCheck = new DataSet();
        OverTimeCodeEventData objClass = new OverTimeCodeEventData();
        dsCheck = objClass.CheckOtType(strOtType, strOtCat, iCompanyID, iOtID, strOpr);
        if (dsCheck != null && dsCheck.Tables.Count > 0 && dsCheck.Tables[0].Rows.Count > 0)
        {
            if (dsCheck.Tables[0].Rows[0]["RecCount"] != DBNull.Value)
            {
                if (Convert.ToInt16(dsCheck.Tables[0].Rows[0]["RecCount"]) > 0)
                {
                    strScript = "alert('" + rm.GetString("Alert_OverTimetypealreadyexists", ci) + "');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", strScript, true);
                    return;
                }
            }
        }
        int EmpID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        objClass.UpdateOtType(iOtID, strOtType, strOtCat, iCompanyID, EmpID);
        strScript = "alert('" + rm.GetString("Alert_OverTimeTypemodifiedsuccessfully", ci) + "');location.replace('TA_UI_Master_OverTimeType.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", strScript, true);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_OverTimeType.aspx");
    }
    #endregion
}