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_EmployeeCategoryModify_Angler : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objcls_Common = new cls_Common();
    string strSetAlert;
    DataSet ds_Checkuser = new DataSet();
    int payrollConfig = 0;
    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"]);
        LoadStrings(ci);
        //Set UserRights
        UserRights();
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        payrollConfig = objcls_Common.CheckPageExistsInLicense(185);
        /*Below parameter is used for Angler*/
        if (payrollConfig == 0)
        {
            divSatWorkHrs.Style.Add("display", "none");
            divArmisHrs.Style.Add("display", "none");
            lbl_IndicatesMandatoryFields.Text = lbl_IndicatesMandatoryFields.Text + " (3 No.)";
            lbl_MonToSatWorkHrs.Text = rm.GetString("Master_Category_MondayToSaturday", ci);
            txt_SatWorkHrs.Text = "0";
            txt_ArmisHrs.Text = "48";
        }
        else
        {
            lbl_IndicatesMandatoryFields.Text = lbl_IndicatesMandatoryFields.Text + " (5 No.)";
            lbl_MonToSatWorkHrs.Text = rm.GetString("Master_Category_MondayToSaturday_Angler", ci);
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["CatID"] != null)
            {
                int CategoryID;
                CategoryID = Convert.ToInt32(Request.QueryString["CatID"]);
                CategoryEventData Cat = new CategoryEventData();
                DataSet ds = new DataSet();
                ds = Cat.SelectCategory(CategoryID);
                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["CategoryName"] != DBNull.Value)
                            {
                                txtCategory.Text = Convert.ToString(ds.Tables[0].Rows[0]["CategoryName"]);
                                txt_MonToSatWorkHrs.Text = Convert.ToString(ds.Tables[0].Rows[0]["MonToSat_WorkHrs"]);
                                txt_WeekdayWorkHrs.Text = Convert.ToString(ds.Tables[0].Rows[0]["WeekDay_WorkHrs"]);
                                txt_SatWorkHrs.Text = Convert.ToString(ds.Tables[0].Rows[0]["Sat_WorkHrs"]);
                                txt_ArmisHrs.Text = Convert.ToString(ds.Tables[0].Rows[0]["ARMIS_WorkHrs"]);
                                if (Convert.ToBoolean(ds.Tables[0].Rows[0]["IsFlexible"]))
                                {
                                    rbtnFlexibleYes.Checked = true;
                                }
                                else
                                {
                                    rbtnFlexibleNo.Checked = true;
                                }
                                string selectScript = objcls_Common.SelectAll(txtCategory);
                                RegisterStartupScript("SelectScript", selectScript);
                            }
                        }
                    }
                }
            }
            // focus to first control
            txtCategory.Focus();
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objcls_Common.menu("EmployeeMaster", "94");
        }
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(94, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["CatID"] != null)
        {
            int CategoryID;
            CategoryID = Convert.ToInt32(Request.QueryString["CatID"]);
            string CategoryName = Convert.ToString(txtCategory.Text.Trim().Replace("'", "''"));
            bool IsFlexible = false;
            string dMonToSatWorkHrs = Convert.ToString(txt_MonToSatWorkHrs.Text.Trim());
            string dWeekDayWorkHrs = Convert.ToString(txt_WeekdayWorkHrs.Text.Trim());
            string[] str1;
            decimal DcmTotWeekHours = Convert.ToDecimal(dMonToSatWorkHrs.Replace(':', '.'));
            decimal DcmWeekDayHours = Convert.ToDecimal(dWeekDayWorkHrs.Replace(':', '.'));
            decimal dSatWorkHrs = Convert.ToDecimal(txt_SatWorkHrs.Text.Trim());
            decimal dARMISWorkHrs = Convert.ToDecimal(txt_ArmisHrs.Text.Trim());
            if (DcmTotWeekHours <= 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Minimum Mandatory Cumulative Work Hrs Per Week should not be Lesser than 0');", true);
                return;
            }
            if (DcmTotWeekHours > 168)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Minimum Mandatory Cumulative Work Hrs Per Week should be Lesser than 168 Hrs');", true);
                return;
            }
            str1 = Convert.ToString(txt_WeekdayWorkHrs.Text.Trim()).Split(':');
            //if (DcmWeekDayHours <= 0)
            //{
            //    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Working Hours should not be Lesser than 0');", true);
            //    return;
            //}
            if (DcmWeekDayHours > 24)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Daily Minimum Working Hrs should be lesser than 24 Hrs');", true);
                return;
            }
            if (rbtnFlexibleYes.Checked == true)
            {
                IsFlexible = true;
            }
            DataSet ds = new DataSet();
            CategoryEventData Cat = new CategoryEventData();
            ds = Cat.CheckDuplicate("U", CategoryName, CategoryID);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //lblError.Text = "Employee Category Already Exists"; '" + rm.GetString("Alert_EmployeeCategorydeletedsuccessfully", ci) + "')
                    //base.Message(rm.GetString("Alert_EmployeeCategoryalreadyexists",ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_EmployeeCategoryalreadyexists", ci) + "');", true);
                }
                else
                {
                    Cat.InsertUpdate_Angler("U", txtCategory.Text.Trim().Replace("'", "''"), Convert.ToString(Session["EmpAutoID"]), CategoryID, IsFlexible, DcmTotWeekHours, dSatWorkHrs, DcmWeekDayHours, dARMISWorkHrs);
                    //string str = "alert('" + rm.GetString("Alert_EmployeeCategorysavedsuccessfully", ci) + "');location.replace('TA_UI_Master_EmployeeCategorylist.aspx')";
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                    string strScript = "";
                    strScript = strScript + "<script language='javascript'>";
                    strScript = strScript + "alert('" + rm.GetString("Alert_EmployeeCategorysavedsuccessfully", ci) + "');";
                    strScript = strScript + "location.replace('TA_UI_Master_EmployeeCategorylist.aspx');";
                    strScript = strScript + "</script>";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                }
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Category.Text = rm.GetString("Master_Category", ci);
        lbl_WeekdayWorkHrs.Text = rm.GetString("Master_Category_WeekDay", ci);
        lbl_Header.Text = rm.GetString("Master_Category", 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);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_EnterCategory", ci);
        lblFlexibleTimings.Text = rm.GetString("FlexibleTimings", ci);
        rbtnFlexibleYes.Text = rm.GetString("Yes", ci);
        rbtnFlexibleNo.Text = rm.GetString("Grid_False", ci);
        lbl_SatWorkHrs.Text = rm.GetString("Master_Category_Saturday", ci);
        lblArmisHrs.Text = rm.GetString("Master_Category_ArmisMinWorkHrs", ci);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_EmployeeCategorylist.aspx");
    }
}
