using System;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Text;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Transactions_TA_UI_Transaction_ShiftRequisitionAdd : System.Web.UI.Page
{
    //protected void Page_Load(object sender, EventArgs e)
    //{

    //}
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ShiftEvenData objShift = new ShiftEvenData();
    int LevelID, loginEmployeeId;
    ShiftAllocationEvendata obj = new ShiftAllocationEvendata();
    FileStream aFile;
    ShiftRoasterEventData objShiftRoaster = new ShiftRoasterEventData();
    ShiftAllocationEvendata objShiftAllocation = new ShiftAllocationEvendata();
    cls_Common objcls_Common = new cls_Common();
    ShiftPatternEventData objShiftPatternOverLap = new ShiftPatternEventData();
    DataSet dsOverLapping = new DataSet();
    DataSet ds_Empdetails = new DataSet();
    DataSet ds_ShiftAllocdetails = new DataSet();
    DataSet ds = new DataSet();
    DataSet ds_ShiftPattern = new DataSet();
    DataTable dtEmpDetails = new DataTable();
    DataTable dtMonthYear = new DataTable();
    StringBuilder strOverLappedEmployeeIds = new StringBuilder();
    Int32 gintUserId;
    string gstrIsValid = "T";
    string gstrDateFormat;
    string gstrUserGroupName = string.Empty;
    bool chkShiftAllocationExists;
    string strToDate = string.Empty;
    string strStartDate = string.Empty;
    int gintCompanyId;
    bool IsUnOverlappedEmployeeExists = false;
    string strAlert = string.Empty;
    int PatternDaysCount = 0;
    cls_Common objClassCommon = new cls_Common();
    DataSet dsYear = new DataSet();
    string strYearStartDate = string.Empty;
    string strYearEndDate = string.Empty;
    #endregion
    #region PageLoad events
    protected  void Page_Load(object sender, EventArgs e)
    {
        //String SS;
        
        //txt_StartDate.TextChanged += new EventHandler(txt_StartDate_TextChanged);
        //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);
        fillLocation();
        gintUserId = Convert.ToInt32(Session["EmpAutoID"]);
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        dsYear = objClassCommon.GetYearsetting();
        grvImportDetails.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);

        
        if (dsYear.Tables[0].Rows.Count > 0)
        {
            strYearStartDate = (DateTime.Parse(dsYear.Tables[0].Rows[0]["FromDate"].ToString())).ToString(Session["MDateFormat"].ToString());
            strYearEndDate = (DateTime.Parse(dsYear.Tables[0].Rows[0]["ToDate"].ToString())).ToString(Session["MDateFormat"].ToString());
            dsYear.Dispose();
        }
        if (Convert.ToString(Session["ISSingleorMultiple"]) == "IsMultiple")
        {
            rbtnMultiple.Checked = true;
            rbtnSingle.Checked = false;
            Session["ISSingleorMultiple"] = "";
        }
        else if (Convert.ToString(Session["ISSingleorMultiple"]) == "IsSingle")
        {
            rbtnSingle.Checked = true;
            rbtnMultiple.Checked = false;
            Session["ISSingleorMultiple"] = "";
        }
        if (rbtnMultiple.Checked == true)
        {
            divMultiple.Style.Add("display", "block");
            divSingle.Style.Add("display", "none");
            lblcount.Text = "(1 No.)";
        }
        else
        {
            divMultiple.Style.Add("display", "none");
            divSingle.Style.Add("display", "block");
            lblcount.Text = "(2 No.)";
        }
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        if (!Page.IsPostBack)
        {
            objcls_Common.menu("ShiftTransaction", "28");


            if (Session["CheckRecordsAddInPopUP"] != null)
            {
                Session["CheckRecordsAddInPopUP"] = null;
            }
            else
            {
                objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
                Session["EmpDetails"] = null;
                Session["currentSession"] = null;
            }
            fillEmployee();
            ShiftMonthLoad();
            grv_Employees.Visible = true;
            grv_Employees.DataSource = null;
            grv_Employeess.Visible = false;
            btn_Save.Visible = false;
            btn_Cancel.Visible = false;

        }
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectShiftPattern", ci) + "','" + rm.GetString("Alert_SelectStartday", ci) + "','" + rm.GetString("Alert_SelectShiftRoaster", ci) + "','" + rm.GetString("Alert_SelectShift", ci) + "','" + rm.GetString("Alert_SelectSheduleFrom", ci) + "','" + rm.GetString("Alert_SelectSheduleTo", ci) + "','" + rm.GetString("Alert_Are_you_sure_to_Save", ci) + "','" + rm.GetString("Alert_ClickAddButton", ci) + "','" + rm.GetString("Alert_EntertheEmployeeID", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        lbl_Info.Text = string.Empty;
        
        int shiftPatternExists = 0;
        int shiftRosterExists = 0;
        int approvalSettingsPageExists = 0;
        shiftPatternExists = objcls_Common.CheckPageExistsInLicense(20);
        shiftRosterExists = objcls_Common.CheckPageExistsInLicense(69);
        //Checking grade module is available or not and changed the id value from 110 to 228
        approvalSettingsPageExists = objcls_Common.CheckPageExistsInLicense(228);
        
        if (approvalSettingsPageExists == 1)
        {
            ShiftEvenData objShift = new ShiftEvenData();
            DataSet dsApprovalSettings = new DataSet();
            if (gintCompanyId > 0)
            {
                dsApprovalSettings = objShift.SelectApprovalSettings(gintCompanyId);
                if (dsApprovalSettings != null)
                {
                    if (dsApprovalSettings.Tables.Count > 0)
                    {
                        if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                        {
                            //if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Pattern"]) == false)
                            //{
                            //    rbtnShifts.Checked = true;
                            //    rbtnShiftPattern.Style.Add("display", "none");
                            //}
                            //if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Roster"]) == false)
                            //{
                            //    rbtnShifts.Checked = true;
                            //    rbtnShiftRoaster.Style.Add("display", "none");
                            //}
                        }
                        else
                        {
                            //base.Message(rm.GetString("Msg_ApprovalSettings", ci));
                            string strScripts = "<script language='javascript' type='text/javascript'>";
                            strScripts += "showPattern();";
                            strScripts += " </script>";
                            this.RegisterStartupScript("StatusTypeLoad", strScripts);
                            return;
                        }
                    }
                }
            }
        }
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "showPattern();";
        strScript += " </script>";
        this.RegisterStartupScript("StatusTypeLoad", strScript);
        //
        // TODO: Insert location value validation package Id
        //
        if (Convert.ToString(Session["packageID"]) != "")
            if (Convert.ToInt32(Session["packageID"]) >= 158) /*Hotel Surguru -TimecheckV2.7*/
            {
                divShiftLocation.Style.Add("display", "");
                divShiftLocation.Style.Add("display", "block");
            }
            else
            {
                divShiftLocation.Style.Add("display", "");
                divShiftLocation.Style.Add("display", "none");
            }
        GRidLoad();

        if(gstrUserGroupName == "IndividualUsers")
        {
            //rbtnSingle.Checked = true;
            //rbtnMultiple.Visible = false;
            txt_EmployeeId.Text = "";

            //txt_EmployeeId.Enabled = false;
        }
        else
        {

        }

    }
    #endregion
    #region User Procedures
    /// <summary>
    /// License checking
    /// </summary>
    private void CheckLicense()
    {
        DemoVersion objDemoVersion = new DemoVersion();
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = Convert.ToString(fileArr[arrCount - 1]);
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            try
            {
                string decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                this.RegisterStartupScript(rm.GetString("Alert_AlertLicInfoNotCorrect", ci), strScript);
                return;
            }
        }
        else
        {
            bool demoContinue = false;
            demoContinue = objDemoVersion.CheckDVShiftAllocation(strStartDate, strToDate);
            if (demoContinue == true)
            {
            }
            else
            {
            }
        }
    }
    /// <summary>
    /// To fill selected employees in the pop up to the grid.
    /// </summary>
    private void fillEmployee()
    {
        Session["previousCompanyId"] = Session["currentSession"];
        ds = objShiftAllocation.SelectEmployeeDetails(gintUserId);
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            grv_Employees.DataSource = ds;
            grv_Employees.DataBind();
        }
        else
        {
            if(gstrUserGroupName == "IndividualUsers")
            {
                int gintUserIds = Convert.ToInt32(Session["EmpAutoID"]);
                ShiftAllocationEvendata objShiftAllocations = new ShiftAllocationEvendata();
                objShiftAllocations.InsertShiftAllocationindi(gintUserIds);
                ds = objShiftAllocation.SelectEmployeeDetails(gintUserId);
                grv_Employees.DataSource = ds;
                grv_Employees.DataBind();
                lblAllocationType.Visible = false;
                rbtnMultiple.Visible = false;
                rbtnSingle.Visible = false;
                lbl_SelectedEmployees.Visible = false;
                btn_Add.Visible = false;
                txt_EmployeeId.Visible = false;

            }
            else
            {
                grv_Employees.DataSource = ds;
                grv_Employees.DataBind();
            }

            ///grv_Employees.DataSource = ds;
            //grv_Employees.DataBind();
        }
    }
    /// <summary>
    /// TO fill the shift patterns in the drop down based on the company selected.
    /// </summary>
    /// <param name="companyId"></param>
    private void fillPatternddl(int companyId)
    {
        //DataSet ds_Pattern = new DataSet();
        //string usergroupname = string.Empty;
        //ds_Pattern = objShiftAllocation.SelectShiftPatternForShiftAllocation(companyId);
        //if (ds_Pattern.Tables[0].Rows.Count > 0)
        //{
        //    ddl_Pattern.DataSource = ds_Pattern;
        //    ddl_Pattern.DataTextField = "Pattern_Name";
        //    ddl_Pattern.DataValueField = "ShiftPattern_Id";
        //    ddl_Pattern.DataBind();
        //}
        //ds_Pattern.Dispose();
        //foreach (ListItem item in ddl_Pattern.Items)
        //{
        //    item.Attributes.Add("title", item.Text);
        //}
    }
    /// <summary>
    /// To fill the various shifts in the drop down based on the company selected.
    /// </summary>
    /// <param name="companyId"></param>
    private void fillShiftddl(int companyId)
    {
        ShiftEvenData objShift = new ShiftEvenData();
        DataSet ds = new DataSet();
        ds = objShift.SelectShiftByCompany(companyId);
        //if (ds.Tables[0].Rows.Count > 0)
        //{
        //    ddlShifts.DataSource = ds;
        //    ddlShifts.DataTextField = "Shift_ShortName";
        //    ddlShifts.DataValueField = "Shift_Id";
        //    ddlShifts.DataBind();
        //}
        //ddlShifts.Dispose();
        //foreach (ListItem item in ddlShifts.Items)
        //{
        //    item.Attributes.Add("title", item.Text);
        //}
    }
    /// <summary>
    /// To fill the various shifts in the drop down based on the company selected.
    /// </summary>
    /// <param name="companyId"></param>
    private void fillLocation()
    {
        ShiftEvenData objShift = new ShiftEvenData();
        DataSet ds = new DataSet();
        ds = objShift.SelectLocation();
        if (ds.Tables[0].Rows.Count > 0)
        {
            ddlLocation.DataSource = ds;
            ddlLocation.DataTextField = "LocationName";
            ddlLocation.DataValueField = "LocationId";
            ddlLocation.DataBind();
        }
        ddlLocation.Dispose();
        foreach (ListItem item in ddlLocation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    /// <summary>
    /// To fill the start day in the drop down and show the pattern in the label 
    /// based on the shift pattern selected.
    /// </summary>
    /// <param name="PatternID"></param>
    private void fillStartDayddl(int PatternID)
    {
        ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(PatternID);
        foreach (DataRow drRow in ds_ShiftAllocdetails.Tables[0].Rows)
        {
            switch (Convert.ToString(drRow["name"]))
            {
                case "Off":
                    drRow["name"] = rm.GetString("lbl_Off", ci);
                    break;
            }
        }
        int Days = ds_ShiftAllocdetails.Tables[0].Rows.Count;
        //ddl_StartDay.Items.Clear();
        ListItem liSelect = new ListItem();
        liSelect.Value = "-Select-";
        liSelect.Text = rm.GetString("Select", ci);
        //ddl_StartDay.Items.Insert(0, liSelect);
        for (int i = 1; i <= Days; i++)
        {
           // ddl_StartDay.Items.Add(Convert.ToString(i));
        }
        string Pattern = string.Empty;
        DataTable dt_Pattern = new DataTable();
        dt_Pattern = ds_ShiftAllocdetails.Tables[0];
        foreach (DataRow dr_Pattern in dt_Pattern.Rows)
        {
            Pattern += " " + Convert.ToString(dr_Pattern["name"]);
        }
        //lbl_Pattern.Text = Pattern;
    }
    /// <summary>
    /// To get the pattern for simple shift allocation.
    /// </summary>
    /// <returns></returns>
    private int[] ShiftPatternSequence()
    {
        int[] Pattern = new int[31];
        for (int i = 0; i < 7; i++)
        {
            //if (lstWeeklyOffDays.Items[i].Selected)
            //{
            //    Pattern[i] = -1;
            //}
            //else
            //{
            //    Pattern[i] = Convert.ToInt32(ddlShifts.SelectedValue);
            //}
        }
        return Pattern;
    }
    /// <summary>
    /// To get the start day based on the shift start date selected.
    /// </summary>
    /// <returns></returns>
    //private int getStartDay()
    //{
    //    string strWeekDayName;
    //    string strStartDate = objcls_Common.DateConvertion(gstrDateFormat, txt_StartDate.Text.Trim());
    //    DateTime dtFromDate = DateTime.Parse(strStartDate);
    //    strWeekDayName = Convert.ToString(dtFromDate.DayOfWeek);
    //    int intWeekDay = 0;
    //    switch (strWeekDayName)
    //    {
    //        case "Monday":
    //            intWeekDay = 1;
    //            break;
    //        case "Tuesday":
    //            intWeekDay = 2;
    //            break;
    //        case "Wednesday":
    //            intWeekDay = 3;
    //            break;
    //        case "Thursday":
    //            intWeekDay = 4;
    //            break;
    //        case "Friday":
    //            intWeekDay = 5;
    //            break;
    //        case "Saturday":
    //            intWeekDay = 6;
    //            break;
    //        case "Sunday":
    //            intWeekDay = 7;
    //            break;
    //    }
    //    return (intWeekDay);
    //}
    /// <summary>
    /// To validate start data and To restrict users other than super admin or 
    /// user having special rights to allocate shift for back date
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    //public void CheckStartDate(object s, ServerValidateEventArgs e)
    //{
    //    if (gstrUserGroupName == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
    //    {
    //        e.IsValid = true;
    //    }
    //    else
    //    {
    //        if (txt_StartDate.Text != string.Empty)
    //        {
    //            if (txt_StartDate.Text.Length >= 10)
    //            {
    //                string strStartDate = string.Empty;
    //                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
    //                strStartDate = objcls_Common.DateConvertion(gstrDateFormat, txt_StartDate.Text);
    //                DateTime dtCurrent = DateTime.Now;
    //                DateTime dtStartDate = DateTime.Parse(strStartDate);
    //                TimeSpan diff = dtCurrent.Subtract(dtStartDate);
    //                int day = diff.Days;
    //                if (day <= 0)
    //                    e.IsValid = true;
    //                else
    //                {
    //                    strAlert = string.Empty;
    //                    strAlert = "alert('" + rm.GetString("Validator_ShiftAllocation_ScheduleFrom", ci) + "')";
    //                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strAlert, true);
    //                    e.IsValid = false;
    //                }
    //            }
    //            else
    //            {
    //                e.IsValid = true;
    //            }
    //        }
    //        else
    //        {
    //            e.IsValid = true;
    //        }
    //    }
    //}
    /// <summary>
    /// To validate end data and To restrict users other than super admin or 
    /// user having special rights to allocate shift for back date
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CheckToDate(object s, ServerValidateEventArgs e)
    {
        //if (gstrUserGroupName == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        //{
        //    e.IsValid = true;
        //}
        //else
        //{
        //    if (txt_ToDate.Text != string.Empty)
        //    {
        //        if (txt_ToDate.Text.Length >= 10)
        //        {
        //            string strToDate = string.Empty;
        //            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        //            //strToDate = objcls_Common.DateConvertion(gstrDateFormat, txt_ToDate.Text);
        //            DateTime dtCurrent = DateTime.Now;
        //            DateTime dtToDate = DateTime.Parse(strToDate);
        //            TimeSpan diff = dtCurrent.Subtract(dtToDate);
        //            int day = diff.Days;
        //            if (day <= 0)
        //                e.IsValid = true;
        //            else
        //            {
        //                strAlert = string.Empty;
        //                strAlert = "alert('" + rm.GetString("Validator_ShiftAllocation_ScheduleTo", ci) + "')";
        //                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strAlert, true);
        //                e.IsValid = false;
        //            }
        //        }
        //        else
        //        {
        //            e.IsValid = true;
        //        }
        //    }
        //    else
        //    {
        //        e.IsValid = true;
        //    }
        //}
    }
    private DataSet ImportShiftData(FileInfo fileInfo)
    {
        string strLine;
        string strScript = String.Empty;
        string[] strArray;
        char[] charArray = new char[] { ',' };
        string[] strColumnName = { "Employee_Code_Id", "Employee_Name", "Company_Name", "Year", "Mon", "Day1", "Day2", "Day3", "Day4", "Day5", "Day6", "Day7", "Day8", "Day9", "Day10", "Day11", "Day12", "Day13", "Day14", "Day15", "Day16", "Day17", "Day18", "Day19", "Day20", "Day21", "Day22", "Day23", "Day24", "Day25", "Day26", "Day27", "Day28", "Day29", "Day30", "Day31" };
        DataSet dsShift = new DataSet("Dst_ShiftAlloc");
        DataTable dtShift = dsShift.Tables.Add("Tbl_ShiftAlloc");
        foreach (string str in strColumnName)
        {
            dtShift.Columns.Add(str);
        }
        aFile = new FileStream(fileInfo.FullName.ToString(), FileMode.Open);
        StreamReader sr = new StreamReader(aFile);
        strLine = sr.ReadLine();
        strArray = strLine.Split(charArray);
        if (strArray.Length != dtShift.Columns.Count)
        {
            strScript = "<script language='javascript'>";
            strScript = strScript + "ModeOfAllocation();";
            strScript = strScript + "alert('" + rm.GetString("Alert_ErrorinShiftImporting", ci) + "');";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("Alert", strScript);
            return null;
        }
        strLine = sr.ReadLine();
        strArray = null;
        while (strLine != null)
        {
            strArray = strLine.Split(charArray);
            dtShift.Rows.Add(strArray);
            strLine = sr.ReadLine();
        }
        string strWeekOff = string.Empty;
        //for (int i = 0; i < lstWeeklyOffDays.Items.Count; i++)
        //{
        //    strWeekOff = (lstWeeklyOffDays.Items[i].Selected ? ((strWeekOff.Trim() == string.Empty) ? lstWeeklyOffDays.Items[i].Value : strWeekOff + "," + lstWeeklyOffDays.Items[i].Value) : strWeekOff);
        //    lstWeeklyOffDays.Items[i].Selected = false;
        //}
        if (ChbMonday.Checked)
            strWeekOff = strWeekOff + "2,";
        if (ChbTuesday.Checked)
            strWeekOff = strWeekOff + "3,";
        if (ChbWednesday.Checked)
            strWeekOff = strWeekOff + "4,";
        if (ChbThuday.Checked)
            strWeekOff = strWeekOff + "5,";
        if (ChbFriday.Checked)
            strWeekOff = strWeekOff + "6,";
        if (ChbSaturday.Checked)
            strWeekOff = strWeekOff + "7,";
        if (ChbSunday.Checked)
            strWeekOff = strWeekOff + "1";
        StringWriter strShiftAlloc = new StringWriter();
        dsShift.WriteXml(strShiftAlloc);
        string strAlloc = Convert.ToString(strShiftAlloc);
        aFile.Dispose();
        return objShiftAllocation.EmployeeShiftAllcationImport(strAlloc, strWeekOff, (chkSkip.Checked));
    }
    /// <summary>
    /// Shift allocation based on the pattern
    /// Inserts and update the shift details in the shift allocation table.
    /// Reprocesses the datas for the duration selected from processed data,clockdetails,raw data and manual time entry
    /// </summary>
    /// <param name="pattern"></param>
    /// <param name="dtmStartDate"></param>
    /// <param name="dtmToDate"></param>
    /// <param name="intStartDay"></param>
    /// <param name="PatternDaysCount"></param>
    private void ShiftAllocation(int[] pattern, DateTime dtmStartDate, DateTime dtmToDate, int intStartDay, int PatternDaysCount)
    {
        try
        {
            StringWriter strWriteXML = new StringWriter();
            dtEmpDetails.DefaultView.RowFilter = "OverLapped=false";
            dtEmpDetails.DefaultView.ToTable().WriteXml(strWriteXML);
            dtMonthYear.TableName = "Table";
            dtMonthYear.Columns.Add("Month", typeof(int));
            dtMonthYear.Columns.Add("Year", typeof(int));
            if (dtmStartDate.Year == dtmToDate.Year)
            {
                FillMonthYearForShiftAllocation(dtmStartDate.Month, dtmToDate.Month, dtmStartDate.Year);
            }
            else
            {
                int startYear = dtmStartDate.Year;
                int endYear = dtmToDate.Year;
                int Year = 0;
                for (Year = startYear; Year <= endYear; Year++)
                {
                    if (Year == startYear)
                    {
                        FillMonthYearForShiftAllocation(dtmStartDate.Month, 12, Year);
                    }
                    else if (Year == endYear)
                    {
                        FillMonthYearForShiftAllocation(1, dtmToDate.Month, Year);
                    }
                    else
                    {
                        FillMonthYearForShiftAllocation(1, 12, Year);
                    }
                }
            }
            foreach (DataRow drRow in dtMonthYear.Rows)
            {
                string strDateShift = Convert.ToInt32(drRow["Month"]) + "/1/" + Convert.ToInt32(drRow["Year"]);
                objShiftAllocation.InsertShiftAllocation(Convert.ToInt32(drRow["Year"]), Convert.ToInt32(drRow["Month"]), gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift, strWriteXML.ToString());
            }
        }
        catch (Exception ex)
        {
            //Message(ex.ToString());
        }
        try
        {
            if (IsUnOverlappedEmployeeExists == true)
            {
                DataTable dtShiftIDs = new DataTable();
                int intMonth = 0, intYear = 0;
                int p = 0;
                //if (rbtnShiftRoaster.Checked == true)
                //{
                //    p = 0;
                //}
                //else
                //{
                //    p = intStartDay - 1;
                //}
                string strUpdate = "UPDATE TA_Tbl_PermanentShiftAllocation SET ";
                for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
                {
                    if ((intMonth != j.Month) || (intYear != j.Year))
                    {
                        if ((intMonth != 0) || (intYear != 0))
                        {
                            strUpdate += " WHERE EmployeeId in (select EmpID from TA_Tbl_TempShiftAllocation where EmployeeId not in ('" + strOverLappedEmployeeIds + "') and LoginEmployeeId=" + Convert.ToString(Session["EmpAutoID"]) + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                            objShiftAllocation.UpdateShiftAllocation(strUpdate);
                            strUpdate = "UPDATE TA_Tbl_PermanentShiftAllocation SET ";
                        }
                    }
                    intMonth = j.Month;
                    intYear = j.Year;
                    if (strUpdate == "UPDATE TA_Tbl_PermanentShiftAllocation SET ")
                    {
                        strUpdate += "Day" + j.Day + "Shift = " + pattern[p];
                    }
                    else
                    {
                        strUpdate += ",Day" + j.Day + "Shift = " + pattern[p];
                    }
                    if (j == dtmToDate)
                    {
                        strUpdate += " WHERE EmployeeId in (select EmpID from TA_Tbl_TempShiftAllocation where EmployeeId not in ('" + strOverLappedEmployeeIds + "') and LoginEmployeeId=" + Convert.ToString(Session["EmpAutoID"]) + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                    }
                    if (p < (PatternDaysCount - 1))
                    {
                        p += 1;
                    }
                    else if (p >= (PatternDaysCount - 1))
                    {
                        p = 0;
                    }
                }
                objShiftAllocation.UpdateShiftAllocation(strUpdate);
                objShiftAllocation.ShiftAllocationReprocess_ProcessedData(dtmStartDate, dtmToDate, Convert.ToString(Session["EmpAutoID"]));
                objShiftAllocation.ShiftAllocationReprocess_ClockDetails(dtmStartDate, dtmToDate, Convert.ToString(Session["EmpAutoID"]));
                objShiftAllocation.ShiftAllocationReprocess_ManualEntry(dtmStartDate, dtmToDate, Convert.ToString(Session["EmpAutoID"]));
                objShiftAllocation.ShiftAllocationReprocess_RawData(dtmStartDate, dtmToDate, Convert.ToString(Session["EmpAutoID"]));
            }
        }
        catch (Exception ex)
        {
           // Message(ex.ToString());
        }
        //location detail update hotel surguru
        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToInt32(Session["packageID"]) >= 158) /*Hotel Surguru -TimecheckV2.7*/
            {
                try
                {
                    if (ddlLocation.SelectedValue != "-Select-")
                    {
                        int LocationId = 0;
                        LocationId = Convert.ToInt32(ddlLocation.SelectedValue);
                        DateTime Fromdate = dtmStartDate;
                        DateTime ToDate = dtmToDate;
                        while (Fromdate <= ToDate)
                        {
                            objShiftAllocation.UpdateShiftAddLocation(LocationId, Fromdate, gintUserId);
                            Fromdate = Fromdate.AddDays(1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Message(ex.ToString());
                }
            }
        }
        objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
        Session["EmpDetails"] = null;
    }
    /// <summary>
    /// To fill the month and year in the datatable for shift allocation
    /// </summary>
    /// <param name="StartMonth"></param>
    /// <param name="EndMonth"></param>
    /// <param name="Year"></param>
    private void FillMonthYearForShiftAllocation(int StartMonth, int EndMonth, int Year)
    {
        int exitLoop = 1;
        while (exitLoop == 1)
        {
            DataRow drData;
            drData = dtMonthYear.NewRow();
            drData["Month"] = StartMonth;
            drData["Year"] = Year;
            dtMonthYear.Rows.Add(drData);
            StartMonth = StartMonth + 1;
            if (StartMonth > EndMonth)
            {
                exitLoop = 0;
            }
        }
    }
    /// <summary>
    /// To fill the shift roasters in the drop down based on the company.
    /// </summary>
    /// <param name="companyId"></param>
    private void fillShiftRoasterddl(int companyId)
    {
        
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);
        lbl_Header.Text = rm.GetString("Menu_Transactions_ShiftRequisition", ci);
        lblEmployeeCode.Text = rm.GetString("email_EmployeeId", ci);
        //lbl_ActualPattern.Text = rm.GetString("ShiftAllocation_ActualPattern", ci);
        lbl_ScheduleFrom.Text = rm.GetString("ShiftAllocation_ScheduleFrom", ci);
        
        lbl_SelectedEmployees.Text = rm.GetString("ShiftAllocation_SelectedEmployees", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        
        grv_Employees.Columns[2].HeaderText = rm.GetString("email_EmployeeId", ci);
        grv_Employees.Columns[3].HeaderText = rm.GetString("email_EmployeeName", ci);
        
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        lblDataView.Text = rm.GetString("lblDataView", ci);
        lbl_Mandatory.Text = rm.GetString("IndicatesMandatoryFields", ci);
        //lbl_Mandatory1.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblSelectEmployee.Text = rm.GetString("Shift_SelectEmployee", ci);
        btn_Upload.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Upload", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_Template.Text = "&nbsp;&nbsp;" + rm.GetString("strDownloadTemplate", ci);
        //lblWeeklyOffDays.Text = rm.GetString("ShiftAllocationWeeklyOffDays", ci);
        lblImportFilePath.Text = rm.GetString("SelectFileImport", ci);
       
        ChbMonday.Text = rm.GetString("Monday", ci);
        ChbTuesday.Text = rm.GetString("Tuesday", ci);
        ChbWednesday.Text = rm.GetString("Wednesday", ci);
        ChbThuday.Text = rm.GetString("Thursday", ci);
        ChbFriday.Text = rm.GetString("Friday", ci);
        ChbSaturday.Text = rm.GetString("Saturday", ci);
        ChbSunday.Text = rm.GetString("Sunday", ci);
        lblUnProcess.Text = rm.GetString("lbl_UnProcessedRecord", ci);
        grvImportDetails.Columns[0].Caption = rm.GetString("email_EmployeeId", ci);
        grvImportDetails.Columns[1].Caption = rm.GetString("PayrollProcess_Year", ci);
        grvImportDetails.Columns[2].Caption = rm.GetString("PayrollProcess_Month", ci);
        grvImportDetails.Columns[3].Caption = rm.GetString("TerminalDataType_RawDataFormat", ci);
        lblAllocationType.Text = rm.GetString("lbl_EmpSelectMode", ci);
        rbtnSingle.Text = rm.GetString("rbtn_EmployeeMaster_Single", ci);
        rbtnMultiple.Text = rm.GetString("rpt_Multiple", ci);
        lblEmployeeCode.Text = rm.GetString("email_EmployeeId", ci);
    }
    /// <summary>
    /// To get the previous date adn next date shift Id from both permament and temporary shift allocation table
    /// TO check whether overlap occurs based on the start data and end date.
    /// </summary>
    /// <param name="EmployeeId"></param>
    /// <param name="dtmStartDate"></param>
    /// <param name="dtmToDate"></param>
    /// <param name="StartDateShiftId"></param>
    /// <param name="EndDateShiftId"></param>
    /// <returns></returns>
    public int ConstructPermanentShiftAllocation(int EmployeeId, DateTime dtmStartDate, DateTime dtmToDate, int StartDateShiftId, int EndDateShiftId)
    {
        chkShiftAllocationExists = false;
        int PreviousDayShiftId = 0;
        int NextDayShiftId = 0;
        dtmStartDate = dtmStartDate.AddDays(-1);
        dtmToDate = dtmToDate.AddDays(1);
        DataSet dsPermanentTemporaryShift = new DataSet();
        dsPermanentTemporaryShift = objShiftAllocation.SelectPermanentTemporaryShiftDates(dtmStartDate, dtmToDate, Convert.ToString(EmployeeId));
        if (dsPermanentTemporaryShift.Tables[0].Rows.Count > 0)
        {
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"] != null && Convert.ToString(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"]) != string.Empty)
            {
                chkShiftAllocationExists = true;
                PreviousDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"]);
            }
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"] != null && Convert.ToString(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"]) != string.Empty)
            {
                chkShiftAllocationExists = true;
                NextDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"]);
            }
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"] != null && Convert.ToString(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"]) != string.Empty)
            {
                chkShiftAllocationExists = true;
                PreviousDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"]);
            }
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"] != null && Convert.ToString(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"]) != string.Empty)
            {
                chkShiftAllocationExists = true;
                NextDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"]);
            }
        }
        if (chkShiftAllocationExists == true)
        {
            int intOverLap = 0;
            int ShiftId1 = PreviousDayShiftId;
            int ShiftId2 = StartDateShiftId;
            dsOverLapping = objShiftPatternOverLap.CheckShiftOverLapping(ShiftId1, ShiftId2);
            if (dsOverLapping.Tables.Count > 0)
            {
                if (dsOverLapping.Tables[0].Rows.Count > 0)
                {
                    intOverLap = Convert.ToInt32(dsOverLapping.Tables[0].Rows[0]["ShiftOverLapping"]);
                }
            }
            if (intOverLap > 0)
            {
                return intOverLap;
            }
            dsOverLapping.Tables.Clear();
            ShiftId1 = EndDateShiftId;
            ShiftId2 = NextDayShiftId;
            dsOverLapping = objShiftPatternOverLap.CheckShiftOverLapping(ShiftId1, ShiftId2);
            if (dsOverLapping.Tables.Count > 0)
            {
                if (dsOverLapping.Tables[0].Rows.Count > 0)
                {
                    intOverLap = Convert.ToInt32(dsOverLapping.Tables[0].Rows[0]["ShiftOverLapping"]);
                }
            }
            if (intOverLap > 0)
            {
                return intOverLap;
            }
        }
        return 0;
    }
    /// <summary>
    /// check whether any shift overlapping occures
    /// </summary>
    /// <param name="dtmStartDate"></param>
    /// <param name="dtmToDate"></param>
    /// <param name="intStartDay"></param>
    /// <returns></returns>
    //public int[] OverLappedValidation(DateTime dtmStartDate, DateTime dtmToDate, int intStartDay)
    //{
    //    //int StartDateShiftId = 0;
    //    //int EndDateShiftId = 0;
    //    //int p = 0;
    //    //int[] Pattern = new int[310];
    //    //int intOverLapped = 0;
    //    //DataColumn dcEmployeeId = new DataColumn("OverLapped", System.Type.GetType("System.Boolean"));
    //    //dtEmpDetails.Columns.Add(dcEmployeeId);
    //    //if (rbtnShiftPattern.Checked == true || rbtnShifts.Checked == true)
    //    //{
    //    //    DataTable dtShiftIDs = new DataTable();
    //    //    PatternDaysCount = 7;
    //    //    if (rbtnShiftPattern.Checked == true)
    //    //    {
    //    //        ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(int.Parse(ddl_Pattern.SelectedValue));
    //    //        dtShiftIDs = ds_ShiftAllocdetails.Tables[0];
    //    //        PatternDaysCount = dtShiftIDs.Rows.Count;
    //    //        for (int i = 0; i < PatternDaysCount; i++)
    //    //        {
    //    //            Pattern[i] = int.Parse(Convert.ToString(dtShiftIDs.Rows[i]["id"]));
    //    //        }
    //    //    }
    //    //    else if (rbtnShifts.Checked == true)
    //    //    {
    //    //        Pattern = ShiftPatternSequence();
    //    //    }
    //    //    p = intStartDay - 1;
    //    //}
    //    //else if (rbtnShiftRoaster.Checked == true)
    //    //{
    //    //    int l = 0;
    //    //    // Fetching ShiftRoaster Details, Pattern Details and getting ShiftIDs in an array
    //    //    DataSet ds_ShiftRoaster = objShiftRoaster.SelectShiftRoasterById(Convert.ToInt32(ddlShiftRoaster.SelectedValue));
    //    //    foreach (DataRow drShiftRoster in ds_ShiftRoaster.Tables[0].Rows)
    //    //    {
    //    //        int intNoOfPatterns = int.Parse(Convert.ToString(drShiftRoster["NumberOfPatterns"]));
    //    //        string strPatternName = string.Empty;
    //    //        for (int m = 1; m <= intNoOfPatterns; m++)
    //    //        {
    //    //            strPatternName = "Pattern" + m;
    //    //            ds_ShiftPattern = objShiftAllocation.Shiftpattern(Convert.ToInt32(drShiftRoster[strPatternName]));
    //    //            foreach (DataRow drShiftPattern in ds_ShiftPattern.Tables[0].Rows)
    //    //            {
    //    //                int intPatternDays = int.Parse(Convert.ToString(drShiftPattern["Shift_days"]));
    //    //                string strShiftName = string.Empty;
    //    //                PatternDaysCount = PatternDaysCount + intPatternDays;
    //    //                for (int n = 1; n <= intPatternDays; n++)
    //    //                {
    //    //                    strShiftName = "Day" + n + "_Shift";
    //    //                    Pattern[l] = Convert.ToInt32(drShiftPattern[strShiftName]);
    //    //                    if ((l + 1) != PatternDaysCount)
    //    //                    {
    //    //                        l = l + 1;
    //    //                    }
    //    //                }
    //    //            }
    //    //            l = l + 1;
    //    //        }
    //    //    }
    //    //}
    //    //for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
    //    //{
    //    //    if (j == dtmStartDate)
    //    //    {
    //    //        StartDateShiftId = Pattern[p];
    //    //    }
    //    //    if (j == dtmToDate)
    //    //    {
    //    //        EndDateShiftId = Pattern[p];
    //    //    }
    //    //    if (p < (PatternDaysCount - 1))
    //    //    {
    //    //        p += 1;
    //    //    }
    //    //    else if (p >= (PatternDaysCount - 1))
    //    //    {
    //    //        p = 0;
    //    //    }
    //    //}
    //    ////Each employee check overlapping
    //    //foreach (DataRow dRow in dtEmpDetails.Rows)
    //    //{
    //    //    intOverLapped = ConstructPermanentShiftAllocation(Convert.ToInt32(dRow["EmpID"]), dtmStartDate, dtmToDate, StartDateShiftId, EndDateShiftId);
    //    //    if (intOverLapped > 0)
    //    //    {
    //    //        dRow["OverLapped"] = "True";
    //    //        if (Convert.ToString(strOverLappedEmployeeIds) == string.Empty)
    //    //        {
    //    //            strOverLappedEmployeeIds.Append(Convert.ToString(dRow["EmployeeId"]));
    //    //        }
    //    //        else
    //    //        {
    //    //            strOverLappedEmployeeIds.Append("," + Convert.ToString(dRow["EmployeeId"]));
    //    //        }
    //    //    }
    //    //    else
    //    //    {
    //    //        dRow["OverLapped"] = "False";
    //    //    }
    //    //}
    //    //return Pattern;
    //}
    #endregion
    #region button events
    /// <summary>
    /// To validate and save the shift allocation details
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Save_Click(object sender, EventArgs e)
      {
          DataSet dsApprovalSettings = new DataSet();
        int CompanyID = Convert.ToInt32(Session["currentSession"]),ShiftapprovalGetID =0;
        String Status = "";

        DataSet dtDlls = new DataSet();
        ShiftAllocationEvendata dsDLLShifts = new ShiftAllocationEvendata();
        dtDlls = dsDLLShifts.SelectShiftRequisitionParentID(gintUserId);
        int ComID = Convert.ToInt32(dtDlls.Tables[0].Rows[0]["CompanyID"].ToString());
        if(CompanyID==0)
        {
            dsApprovalSettings = objShift.SelectApprovalSettings(ComID);
        }
        else
        {
            dsApprovalSettings = objShift.SelectApprovalSettings(CompanyID);
        }

        //dsApprovalSettings = objShift.SelectApprovalSettings(CompanyID);
        if (dsApprovalSettings != null)
        {
            if(grv_Employees.Rows.Count != 0)
            {
                if (dsApprovalSettings.Tables[0].Rows[0]["ShiftRequisition"] != "")
                {
                    if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ShiftRequisition"]) == true)
                    {
                        ShiftapprovalGetID = 1;
                        Status = "Pending";
                    }
                    else
                    {
                        ShiftapprovalGetID = 0;
                        Status = "Approved";
                    }


                    if (ShiftapprovalGetID == 1)
                    {
                        ShiftEvenData objshiftInsert = new ShiftEvenData();



                        for (int i = 0; i < grv_Employeess.Rows.Count; i++)
                        {

                            string EMPAutoID = (grv_Employeess.Rows[i].FindControl("lbl_EmpAutoId") as Label).Text;
                            string lbl_LoginEmployeeId = (grv_Employeess.Rows[i].FindControl("lbl_LoginEmployeeId") as Label).Text;
                            string lbl_EmpId = (grv_Employeess.Rows[i].FindControl("lbl_EmpId") as Label).Text;
                            string lbl_EmpName = (grv_Employeess.Rows[i].FindControl("lbl_EmpName") as Label).Text;

                            //string ss = Session["SS"].ToString();
                            String ss = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName") as DropDownList).SelectedValue.ToString();
                            string SS2 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName2") as DropDownList).SelectedValue.ToString();
                            string SS3 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName3") as DropDownList).SelectedValue.ToString();
                            string SS4 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName4") as DropDownList).SelectedValue.ToString();
                            string SS5 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName5") as DropDownList).SelectedValue.ToString();
                            string SS6 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName6") as DropDownList).SelectedValue.ToString();
                            string SS7 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName7") as DropDownList).SelectedValue.ToString();
                            string SS8 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName8") as DropDownList).SelectedValue.ToString();
                            string SS9 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName9") as DropDownList).SelectedValue.ToString();
                            string SS10 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName10") as DropDownList).SelectedValue.ToString();
                            string SS11 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName11") as DropDownList).SelectedValue.ToString();
                            string SS12 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName12") as DropDownList).SelectedValue.ToString();
                            string SS13 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName13") as DropDownList).SelectedValue.ToString();
                            string SS14 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName14") as DropDownList).SelectedValue.ToString();
                            string SS15 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName15") as DropDownList).SelectedValue.ToString();
                            string SS16 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName16") as DropDownList).SelectedValue.ToString();
                            string SS17 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName17") as DropDownList).SelectedValue.ToString();
                            string SS18 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName18") as DropDownList).SelectedValue.ToString();
                            string SS19 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName19") as DropDownList).SelectedValue.ToString();
                            string SS20 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName20") as DropDownList).SelectedValue.ToString();
                            string SS21 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName21") as DropDownList).SelectedValue.ToString();
                            string SS22 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName22") as DropDownList).SelectedValue.ToString();
                            string SS23 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName23") as DropDownList).SelectedValue.ToString();
                            string SS24 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName24") as DropDownList).SelectedValue.ToString();
                            string SS25 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName25") as DropDownList).SelectedValue.ToString();
                            string SS26 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName26") as DropDownList).SelectedValue.ToString();
                            string SS27 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName27") as DropDownList).SelectedValue.ToString();
                            string SS28 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName28") as DropDownList).SelectedValue.ToString();
                            string SS29 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName29") as DropDownList).SelectedValue.ToString();
                            string SS30 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName30") as DropDownList).SelectedValue.ToString();
                            string SS31 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName31") as DropDownList).SelectedValue.ToString();
                            if (ss == "1" || ss == "-Select-")
                            {
                                ss = " ";
                            }
                            if (SS2 == "1" || SS2 == "-Select-")
                            {
                                SS2 = " ";
                            }
                            if (SS3 == "1" || SS3 == "-Select-")
                            {
                                SS3 = " ";
                            }
                            if (SS4 == "1" || SS4 == "-Select-")
                            {
                                SS4 = " ";
                            }
                            if (SS5 == "1" || SS5 == "-Select-")
                            {
                                SS5 = " ";
                            }
                            if (SS6 == "1" || SS6 == "-Select-")
                            {
                                SS6 = " ";
                            }
                            if (SS7 == "1" || SS7 == "-Select-")
                            {
                                SS7 = " ";
                            }
                            if (SS8 == "1" || SS8 == "-Select-")
                            {
                                SS8 = " ";
                            }
                            if (SS9 == "1" || SS9 == "-Select-")
                            {
                                SS9 = " ";
                            }
                            if (SS10 == "1" || SS10 == "-Select-")
                            {
                                SS10 = " ";
                            }
                            if (SS11 == "1" || SS11 == "-Select-")
                            {
                                SS11 = " ";
                            }
                            if (SS12 == "1" || SS12 == "-Select-")
                            {
                                SS12 = " ";
                            }
                            if (SS13 == "1" || SS13 == "-Select-")
                            {
                                SS13 = " ";
                            }
                            if (SS14 == "1" || SS14 == "-Select-")
                            {
                                SS14 = " ";
                            }
                            if (SS15 == "1" || SS15 == "-Select-")
                            {
                                SS15 = " ";
                            }
                            if (SS16 == "1" || SS16 == "-Select-")
                            {
                                SS16 = " ";
                            }
                            if (SS17 == "1" || SS17 == "-Select-")
                            {
                                SS17 = " ";
                            }
                            if (SS18 == "1" || SS18 == "-Select-")
                            {
                                SS18 = " ";
                            }
                            if (SS19 == "1" || SS19 == "-Select-")
                            {
                                SS19 = " ";
                            }
                            if (SS20 == "1" || SS20 == "-Select-")
                            {
                                SS20 = " ";
                            }
                            if (SS21 == "1" || SS21 == "-Select-")
                            {
                                SS21 = " ";
                            }
                            if (SS22 == "1" || SS22 == "-Select-")
                            {
                                SS22 = " ";
                            }
                            if (SS23 == "1" || SS23 == "-Select-")
                            {
                                SS23 = " ";
                            }
                            if (SS24 == "1" || SS24 == "-Select-")
                            {
                                SS24 = " ";
                            }
                            if (SS25 == "1" || SS25 == "-Select-")
                            {
                                SS25 = " ";
                            }
                            if (SS26 == "1" || SS26 == "-Select-")
                            {
                                SS26 = " ";
                            }
                            if (SS27 == "1" || SS27 == "-Select-")
                            {
                                SS27 = " ";
                            }
                            if (SS28 == "1" || SS28 == "-Select-")
                            {
                                SS28 = " ";
                            }
                            if (SS29 == "1" || SS29 == "-Select-")
                            {
                                SS29 = " ";
                            }
                            if (SS30 == "1" || SS30 == "-Select-")
                            {
                                SS30 = " ";
                            }
                            if (SS31 == "1" || SS31 == "-Select-")
                            {
                                SS31 = " ";
                            }





                            string Date = "1-" + ddl_Month.SelectedItem.ToString();
                            string autoid = Session["EmpAutoId"].ToString();
                            int CompanyIDs = Convert.ToInt32(Session["currentSession"]);

                            try
                            {
                                Hashtable htable = new Hashtable();
                                htable.Add("@EmployeeID", EMPAutoID);
                                htable.Add("@RequisitionDate", Date);
                                htable.Add("@Status", Status);
                                htable.Add("@EMP_ID", autoid);
                                htable.Add("@Timestamp", DateTime.Today);
                                htable.Add("@DAY1 ", ss);
                                htable.Add("@DAY2 ", SS2);
                                htable.Add("@DAY3 ", SS3);
                                htable.Add("@DAY4 ", SS4);
                                htable.Add("@DAY5 ", SS5);
                                htable.Add("@DAY6 ", SS6);
                                htable.Add("@DAY7 ", SS7);
                                htable.Add("@DAY8 ", SS8);
                                htable.Add("@DAY9 ", SS9);
                                htable.Add("@DAY10", SS10);
                                htable.Add("@DAY11", SS11);
                                htable.Add("@DAY12", SS12);
                                htable.Add("@DAY13", SS13);
                                htable.Add("@DAY14", SS14);
                                htable.Add("@DAY15", SS15);
                                htable.Add("@DAY16", SS16);
                                htable.Add("@DAY17", SS17);
                                htable.Add("@DAY18", SS18);
                                htable.Add("@DAY19", SS19);
                                htable.Add("@DAY20", SS20);
                                htable.Add("@DAY21", SS21);
                                htable.Add("@DAY22", SS22);
                                htable.Add("@DAY23", SS23);
                                htable.Add("@DAY24", SS24);
                                htable.Add("@DAY25", SS25);
                                htable.Add("@DAY26", SS26);
                                htable.Add("@DAY27", SS27);
                                htable.Add("@DAY28", SS28);
                                htable.Add("@DAY29", SS29);
                                htable.Add("@DAY30", SS30);
                                htable.Add("@DAY31", SS31);
                                htable.Add("@Tag", 1);
                                htable.Add("@ShiftRequisitionID", 0);
                                htable.Add("@CompanyID", CompanyIDs);
                                DataSet ds = new DataSet();

                                ds = objshiftInsert.InsertUpdateShiftRequisition(htable);

                            }
                            catch (Exception ex)
                            {

                            }

                        }
                        string strScript;
                        strScript = "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_Shift_Requisition_Save", ci) + "');";
                        strScript = strScript + "</script>";
                        Page.RegisterStartupScript("Alert", strScript);

                        grv_Employees.DataSource = null;
                        grv_Employees.DataBind();
                        grv_Employees.Visible = false;
                        grv_Employeess.Visible = false;
                        btn_Save.Visible = false;
                        Page_Load(sender, e);
                        GRidLoad();

                        //EmployeeID,RequisitionDate,Status,Timestamp,EMP_ID,DAY1,DAY2, DAY3, DAY4, DAY5, DAY6, DAY7,
                        //DAY8, DAY9, DAY10, DAY11, DAY12, DAY13, DAY14, DAY15, DAY16, DAY17, DAY18, DAY19, 
                        //             DAY20, DAY21, DAY22, DAY23, DAY24, DAY25, DAY26, DAY27, DAY28, DAY29, DAY30, DAY31
                    }
                    else
                    {
                        ShiftEvenData objshiftInsert = new ShiftEvenData();

                        int Count = 0;

                        for (int i = 0; i < grv_Employeess.Rows.Count; i++)
                        {
                            Count = Count + 1;
                            string EMPAutoID = (grv_Employeess.Rows[i].FindControl("lbl_EmpAutoId") as Label).Text;
                            string lbl_LoginEmployeeId = (grv_Employeess.Rows[i].FindControl("lbl_LoginEmployeeId") as Label).Text;
                            string lbl_EmpId = (grv_Employeess.Rows[i].FindControl("lbl_EmpId") as Label).Text;
                            string lbl_EmpName = (grv_Employeess.Rows[i].FindControl("lbl_EmpName") as Label).Text;

                            //string ss = Session["SS"].ToString();
                            String ss = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName") as DropDownList).SelectedValue.ToString();
                            string SS2 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName2") as DropDownList).SelectedValue.ToString();
                            string SS3 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName3") as DropDownList).SelectedValue.ToString();
                            string SS4 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName4") as DropDownList).SelectedValue.ToString();
                            string SS5 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName5") as DropDownList).SelectedValue.ToString();
                            string SS6 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName6") as DropDownList).SelectedValue.ToString();
                            string SS7 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName7") as DropDownList).SelectedValue.ToString();
                            string SS8 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName8") as DropDownList).SelectedValue.ToString();
                            string SS9 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName9") as DropDownList).SelectedValue.ToString();
                            string SS10 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName10") as DropDownList).SelectedValue.ToString();
                            string SS11 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName11") as DropDownList).SelectedValue.ToString();
                            string SS12 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName12") as DropDownList).SelectedValue.ToString();
                            string SS13 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName13") as DropDownList).SelectedValue.ToString();
                            string SS14 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName14") as DropDownList).SelectedValue.ToString();
                            string SS15 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName15") as DropDownList).SelectedValue.ToString();
                            string SS16 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName16") as DropDownList).SelectedValue.ToString();
                            string SS17 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName17") as DropDownList).SelectedValue.ToString();
                            string SS18 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName18") as DropDownList).SelectedValue.ToString();
                            string SS19 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName19") as DropDownList).SelectedValue.ToString();
                            string SS20 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName20") as DropDownList).SelectedValue.ToString();
                            string SS21 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName21") as DropDownList).SelectedValue.ToString();
                            string SS22 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName22") as DropDownList).SelectedValue.ToString();
                            string SS23 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName23") as DropDownList).SelectedValue.ToString();
                            string SS24 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName24") as DropDownList).SelectedValue.ToString();
                            string SS25 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName25") as DropDownList).SelectedValue.ToString();
                            string SS26 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName26") as DropDownList).SelectedValue.ToString();
                            string SS27 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName27") as DropDownList).SelectedValue.ToString();
                            string SS28 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName28") as DropDownList).SelectedValue.ToString();
                            string SS29 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName29") as DropDownList).SelectedValue.ToString();
                            string SS30 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName30") as DropDownList).SelectedValue.ToString();
                            string SS31 = (grv_Employeess.Rows[i].FindControl("ddlShiftShortName31") as DropDownList).SelectedValue.ToString();
                            if (ss == "1" || ss == "-Select-")
                            {
                                ss = " ";
                            }
                            if (SS2 == "1" || ss == "-Select-")
                            {
                                SS2 = " ";
                            }
                            if (SS3 == "1" || ss == "-Select-")
                            {
                                SS3 = " ";
                            }
                            if (SS4 == "1" || ss == "-Select-")
                            {
                                SS4 = " ";
                            }
                            if (SS5 == "1" || ss == "-Select-")
                            {
                                SS5 = " ";
                            }
                            if (SS6 == "1" || ss == "-Select-")
                            {
                                SS6 = " ";
                            }
                            if (SS7 == "1" || ss == "-Select-")
                            {
                                SS7 = " ";
                            }
                            if (SS8 == "1" || ss == "-Select-")
                            {
                                SS8 = " ";
                            }
                            if (SS9 == "1" || ss == "-Select-")
                            {
                                SS9 = " ";
                            }
                            if (SS10 == "1" || ss == "-Select-")
                            {
                                SS10 = " ";
                            }
                            if (SS11 == "1" || ss == "-Select-")
                            {
                                SS11 = " ";
                            }
                            if (SS12 == "1" || ss == "-Select-")
                            {
                                SS12 = " ";
                            }
                            if (SS13 == "1" || ss == "-Select-")
                            {
                                SS13 = " ";
                            }
                            if (SS14 == "1" || ss == "-Select-")
                            {
                                SS14 = " ";
                            }
                            if (SS15 == "1" || ss == "-Select-")
                            {
                                SS15 = " ";
                            }
                            if (SS16 == "1" || ss == "-Select-")
                            {
                                SS16 = " ";
                            }
                            if (SS17 == "1" || ss == "-Select-")
                            {
                                SS17 = " ";
                            }
                            if (SS18 == "1" || ss == "-Select-")
                            {
                                SS18 = " ";
                            }
                            if (SS19 == "1" || ss == "-Select-")
                            {
                                SS19 = " ";
                            }
                            if (SS20 == "1" || ss == "-Select-")
                            {
                                SS20 = " ";
                            }
                            if (SS21 == "1" || ss == "-Select-")
                            {
                                SS21 = " ";
                            }
                            if (SS22 == "1" || ss == "-Select-")
                            {
                                SS22 = " ";
                            }
                            if (SS23 == "1" || ss == "-Select-")
                            {
                                SS23 = " ";
                            }
                            if (SS24 == "1" || ss == "-Select-")
                            {
                                SS24 = " ";
                            }
                            if (SS25 == "1" || ss == "-Select-")
                            {
                                SS25 = " ";
                            }
                            if (SS26 == "1" || ss == "-Select-")
                            {
                                SS26 = " ";
                            }
                            if (SS27 == "1" || ss == "-Select-")
                            {
                                SS27 = " ";
                            }
                            if (SS28 == "1" || ss == "-Select-")
                            {
                                SS28 = " ";
                            }
                            if (SS29 == "1" || ss == "-Select-")
                            {
                                SS29 = " ";
                            }
                            if (SS30 == "1" || ss == "-Select-")
                            {
                                SS30 = " ";
                            }
                            if (SS31 == "1" || ss == "-Select-")
                            {
                                SS31 = " ";
                            }





                            string Date = "1-" + ddl_Month.SelectedItem.ToString();
                            string autoid = Session["EmpAutoId"].ToString();
                            int CompanyIDs = Convert.ToInt32(Session["currentSession"]);

                            try
                            {
                                Hashtable htable = new Hashtable();
                                htable.Add("@EmployeeID", EMPAutoID);
                                htable.Add("@RequisitionDate", Date);
                                htable.Add("@Status", Status);
                                htable.Add("@EMP_ID", autoid);
                                htable.Add("@Timestamp", DateTime.Today);
                                htable.Add("@DAY1 ", ss);
                                htable.Add("@DAY2 ", SS2);
                                htable.Add("@DAY3 ", SS3);
                                htable.Add("@DAY4 ", SS4);
                                htable.Add("@DAY5 ", SS5);
                                htable.Add("@DAY6 ", SS6);
                                htable.Add("@DAY7 ", SS7);
                                htable.Add("@DAY8 ", SS8);
                                htable.Add("@DAY9 ", SS9);
                                htable.Add("@DAY10", SS10);
                                htable.Add("@DAY11", SS11);
                                htable.Add("@DAY12", SS12);
                                htable.Add("@DAY13", SS13);
                                htable.Add("@DAY14", SS14);
                                htable.Add("@DAY15", SS15);
                                htable.Add("@DAY16", SS16);
                                htable.Add("@DAY17", SS17);
                                htable.Add("@DAY18", SS18);
                                htable.Add("@DAY19", SS19);
                                htable.Add("@DAY20", SS20);
                                htable.Add("@DAY21", SS21);
                                htable.Add("@DAY22", SS22);
                                htable.Add("@DAY23", SS23);
                                htable.Add("@DAY24", SS24);
                                htable.Add("@DAY25", SS25);
                                htable.Add("@DAY26", SS26);
                                htable.Add("@DAY27", SS27);
                                htable.Add("@DAY28", SS28);
                                htable.Add("@DAY29", SS29);
                                htable.Add("@DAY30", SS30);
                                htable.Add("@DAY31", SS31);
                                htable.Add("@Tag", 1);
                                htable.Add("@ShiftRequisitionID", 0);
                                htable.Add("@CompanyID", CompanyIDs);
                                DataSet ds = new DataSet();

                                ds = objshiftInsert.InsertUpdateShiftRequisition(htable);

                            }
                            catch (Exception ex)
                            {

                            }

                        }
                        string strScript;
                        strScript = "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_Shift_Requisition_Save", ci) + "');";
                        strScript = strScript + "</script>";
                        Page.RegisterStartupScript("Alert", strScript);

                        grv_Employees.DataSource = null;
                        grv_Employees.DataBind();
                        grv_Employees.Visible = false;
                        grv_Employeess.Visible = false;
                        btn_Save.Visible = false;
                        Page_Load(sender, e);
                        GRidLoad();
                        ShiftDerectApprovaltoUpdate(Count);
                        // 



                    }
                }
            }
            else
            {
                string strScript;
                strScript = "<script language='javascript'>";
                strScript = strScript + "Select Employee";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("Alert", strScript);
            }
            
        }
        
       

    }

    private void ShiftDerectApprovaltoUpdate(int Count)
    {
        ManualEntryEventData objShiftRequisition = new ManualEntryEventData();
        ShiftAllocationEvendata dsGridLoad = new ShiftAllocationEvendata();
        DataSet dtGrid = new DataSet();
        Count = Count - 1;
        int ComID = Convert.ToInt32(Session["currentSession"]);
        string gintUsrId = Convert.ToString(Session["EmpAutoID"]);
        dtGrid = dsGridLoad.SelectShiftRequisitionGridLoad(ComID, gintUsrId);
        for (int i =0;Count == dtGrid.Tables[0].Rows.Count; i++ )
        {
            int ShiftRequisitionID = Convert.ToInt16( dtGrid.Tables[0].Rows[i]["ShiftRequisitionID"].ToString());
            String MonthDate = dtGrid.Tables[0].Rows[i]["RequisitionDate"].ToString();
           objShiftRequisition.UpdateShiftRequisitionApprovalgrid(ShiftRequisitionID, "Approved", MonthDate, 1);
        }
        

    }

    protected string GetEmployeeIdsInOtherPagesOfGrid()
    {
        LevelID = Convert.ToInt32(Session["currentSession"]);
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
        string strEmpCodeID = "";
        //strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Session["PopShiftEmpId"].ToString();
        }
        if (ViewState["Employees"] != null)
        {
            ds = (DataSet)ViewState["Employees"];
        }
        else
        {
            //ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]), Level, Convert.ToString(Session["UserGroupName"]),
            //    Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId, LevelID,
            //    txtEmployeeName.Text, Convert.ToInt32(Session["EmpCategoryShift"]), Convert.ToInt32(Session["EmpTypeShift"]),
            //    Convert.ToInt32(ddlReligion.SelectedValue));
        }
        string strEmpId = string.Empty;
        string ChkBoxIDs = string.Empty;
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            foreach (GridViewRow gr in grv_Employees.Rows)
            {
                strEmpId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
                if (strEmpId == dr["Employee_Code_Id"].ToString())
                {
                    goto A;
                }
            }
            if (ChkBoxIDs == "")
            {
                ChkBoxIDs = dr["Employee_Code_Id"].ToString();
            }
            else
            {
                ChkBoxIDs = ChkBoxIDs + "," + dr["Employee_Code_Id"].ToString();
            }
            A:;
        }
        return ChkBoxIDs;
    }
    protected void grv_Check_CheckedChanged(object sender, EventArgs e)
    {
        string ChkBoxIDs = string.Empty;
        int intCount = 0;
        int intGridPageSize = grv_Employees.PageSize;
        int intGridTotalPages = grv_Employees.PageCount;
        bool boolAllChecked = false;
        CheckBox chkSelect = new CheckBox();
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)grv_Employees.HeaderRow.Cells[0].FindControl("checkall");
        if (((CheckBox)sender).Checked == false)
        {
            chkSelectAll.Checked = false;
        }
        else
        {
            foreach (GridViewRow gr in grv_Employees.Rows)
            {
                chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
                if (chkSelect.Checked)
                    intCount = intCount + 1;
            }
            if (Convert.ToInt32(Session["TotalEmployees"].ToString()) == intCount)
            {
                chkSelectAll.Checked = true;
            }
            else if (intCount > 0 && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intCount && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intGridPageSize)
            {
                if (intCount == intGridPageSize)
                {
                    if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                    {
                        ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                        char[] Delimit = { ',' };
                        string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                        string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                        Array.Sort(SessionEmployeeIds);
                        Array.Sort(ChedkedEmployeeIds);
                        if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                        {
                            for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                            {
                                if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                {
                                    boolAllChecked = false;
                                    break;
                                }
                            }
                            boolAllChecked = true;
                        }
                        if (boolAllChecked == true)
                        {
                            chkSelectAll.Checked = true;
                        }
                    }
                }
                else if (grv_Employees.PageIndex == intGridTotalPages - 1)
                {
                    int intLastPageCount = Convert.ToInt32(Session["TotalEmployees"].ToString()) - (intGridPageSize * (intGridTotalPages - 1));
                    if (intCount == intLastPageCount)
                    {
                        if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                        {
                            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                            char[] Delimit = { ',' };
                            string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                            string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                            Array.Sort(SessionEmployeeIds);
                            Array.Sort(ChedkedEmployeeIds);
                            if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                            {
                                for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                                {
                                    if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                    {
                                        boolAllChecked = false;
                                        break;
                                    }
                                }
                                boolAllChecked = true;
                            }
                            if (boolAllChecked == true)
                            {
                                chkSelectAll.Checked = true;
                            }
                        }
                    }
                }
            }
        }
    }
    protected void grv_CheckAll_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Employees.HeaderRow.Cells[0].FindControl("checkall");
        string ChkBoxIDs = string.Empty;
        if (chkSelect.Checked)
        {
            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
            if (Session["EmployeeIds"].ToString() == "")
            {
                Session["EmployeeIds"] = ChkBoxIDs;
            }
            else
            {
                if (ChkBoxIDs != "")
                {
                    Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
                }
            }
        }
        else
        {
            Session["EmployeeIds"] = string.Empty;
        }
        foreach (GridViewRow gr in grv_Employees.Rows)
        {
            chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
            chkSelect.Checked = ((CheckBox)sender).Checked;
        }
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
    }
    protected void btnTemplate_Click(object sender, EventArgs e)
    {
        try
        {
            string strPath = Server.MapPath("Templates/Shift_Allocation_Import_Template.csv");
            if (File.Exists(strPath))
            {
                byte[] data = System.IO.File.ReadAllBytes(strPath);
                Response.Clear();
                Response.AddHeader("Content-Type", "application/Excel");
                Response.AddHeader("Content-Disposition", "attachment;filename=Shift_Allocation_Import.csv");
                Response.BinaryWrite(data);
                Response.End();
            }
            else
            {
                //base.Message("Template file is not available in the source file");
                return;
            }
        }
        catch (Exception Ex)
        {
            //Message(Ex.ToString());
        }
    }
    protected void btn_btn_Upload(object sender, EventArgs e)
    {
        string strScript = string.Empty;
        try
        {
            if (fup_ShiftImport.HasFile)
            {
                string filename = fup_ShiftImport.FileName.Substring(fup_ShiftImport.FileName.LastIndexOf("\\") + 1);
                string fileType = System.IO.Path.GetExtension(filename);
                if (fileType == ".csv")
                {
                    string strFilePath = Server.MapPath("Uploads");
                    FileInfo fileInfo = new System.IO.FileInfo(strFilePath + "\\" + fup_ShiftImport.FileName);
                    fup_ShiftImport.SaveAs(strFilePath + "\\" + fup_ShiftImport.FileName);
                    if (fup_ShiftImport.PostedFile.ContentLength == fileInfo.Length)
                    {
                        DataSet dstShiftAlloc = ImportShiftData(fileInfo);
                        if (dstShiftAlloc.Tables.Count > 0)
                        {
                            if (dstShiftAlloc.Tables[0].Columns.Contains("Employee_Id"))
                            {
                                divImport.Style.Add("display", "block");
                                divManual.Style.Add("display", "none");
                                Session["ShiftAllocaData"] = dstShiftAlloc;
                                grvImportDetails.DataSource = dstShiftAlloc;
                                grvImportDetails.DataBind();
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "ModeOfAllocation();";
                                strScript = strScript + "alert('" + rm.GetString("Alert_ImportNotSuccessed", ci) + "');";
                                strScript = strScript + "</script>";
                                Page.RegisterStartupScript("Alert", strScript);
                            }
                            else
                            {
                                divImport.Style.Add("display", "block");
                                divManual.Style.Add("display", "none");
                                grvImportDetails.DataSource = null;
                                grvImportDetails.DataBind();
                                string strMsg = Convert.ToString(dstShiftAlloc.Tables[0].Rows[0]["Message"]);
                                strScript = "<script language='javascript'>";
                                strScript = strScript + "ModeOfAllocation();";
                                strScript = strScript + "alert('" + rm.GetString(strMsg.Contains("Msg:") ? "Alert_ImportSuccessed" : "Alert_ImportNotSuccessed", ci) + "');";
                                strScript = strScript + "</script>";
                                Page.RegisterStartupScript("Alert", strScript);
                            }
                        }
                    }
                    else
                    {
                        divImport.Style.Add("display", "block");
                        divManual.Style.Add("display", "none");
                        strScript = "<script language='javascript'>";
                        strScript = strScript + "ModeOfAllocation();";
                        strScript = strScript + "alert('" + rm.GetString("Alert_ErrorinShiftImporting", ci) + "');";
                        strScript = strScript + "</script>";
                        Page.RegisterStartupScript("Alert", strScript);
                    }
                }
                else
                {
                    divImport.Style.Add("display", "block");
                    divManual.Style.Add("display", "none");
                    strScript = "<script language='javascript'>";
                    strScript = strScript + "ModeOfAllocation();";
                    strScript = strScript + "alert('" + rm.GetString("Alert_TheUploadedfileisnotCsvfile", ci) + "');";
                    strScript = strScript + "</script>";
                    Page.RegisterStartupScript("Alert", strScript);
                }
            }
            else
            {
                divImport.Style.Add("display", "block");
                divManual.Style.Add("display", "none");
                strScript = "<script language='javascript'>";
                strScript = strScript + "ModeOfAllocation();";
                strScript = strScript + "alert('" + rm.GetString("Alert_Youhavenotspecifiedafile", ci) + "');";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("Alert", strScript);
            }
        }
        catch (Exception ex)
        {
            divImport.Style.Add("display", "block");
            divManual.Style.Add("display", "none");
            string strErr = Convert.ToString(ex.Message);
            strScript = "<script language='javascript' type='text/javascript'>";
            strScript = strScript + "ModeOfAllocation();";
            strScript = strScript + "alert('" + strErr.Replace("\r", "").Replace("\n", "") + "');";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("Alert", strScript);
            if (aFile != null) aFile.Dispose();
        }
        finally
        {
            try
            {
                if (fup_ShiftImport.HasFile)
                {
                    string StrFilePath = Convert.ToString(Server.MapPath("Uploads")) + "\\" + fup_ShiftImport.FileName;
                    System.IO.File.Delete(StrFilePath);
                }
            }
            catch (Exception Ex)
            {
            }
            if (aFile != null) aFile.Dispose();
        }
    }
    /// <summary>
    /// Cancel shift allocation
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
        Session["EmpDetails"] = null;
        Response.Redirect("TA_UI_Transaction_ShiftAllocation.aspx");
    }
    #endregion
   
   
    #region gridview events
    /// <summary>
    /// On page index changing, to load employee in the grid
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_Employees_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Employees.PageIndex = e.NewPageIndex;
        fillEmployee();
    }
    protected void grv_Employeess_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Employees.PageIndex = e.NewPageIndex;
        fillEmployee();
    }
    /// <summary>
    /// To delete the employee from the grid.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_Employees_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblEmpAutoId = (Label)grv_Employees.Rows[e.RowIndex].FindControl("lbl_EmpAutoId");
        Label lblLoginEmployeeId = (Label)grv_Employees.Rows[e.RowIndex].FindControl("lbl_LoginEmployeeId");
        objShiftAllocation.DeleteEmpDetails(Convert.ToInt32(lblEmpAutoId.Text), Convert.ToInt32(lblLoginEmployeeId.Text));
        fillEmployee();
    }
    /// <summary>
    /// To change the name of the link button(delete) based on the language.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_Employees_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lbDelete = new LinkButton();
            lbDelete = (LinkButton)e.Row.Cells[0].Controls[0];
            e.Row.Cells[0].BorderColor = System.Drawing.Color.White;
            if (lbDelete.Text == "Delete")
            {
                lbDelete.Text = rm.GetString("btn_Delete", ci);
            }
        }
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].BorderColor = System.Drawing.Color.White;
        }

      
    }
   
    protected void grv_Employeess_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].BorderColor = System.Drawing.Color.White;

        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Find the DropDownList in the Row.
            DropDownList ddlShiftShortName = (e.Row.FindControl("ddlShiftShortName") as DropDownList);
            DropDownList ddlShiftShortName2 = (e.Row.FindControl("ddlShiftShortName2") as DropDownList);
            DropDownList ddlShiftShortName3 = (e.Row.FindControl("ddlShiftShortName3") as DropDownList);
            DropDownList ddlShiftShortName4 = (e.Row.FindControl("ddlShiftShortName4") as DropDownList);
            DropDownList ddlShiftShortName5 = (e.Row.FindControl("ddlShiftShortName5") as DropDownList);
            DropDownList ddlShiftShortName6 = (e.Row.FindControl("ddlShiftShortName6") as DropDownList);
            DropDownList ddlShiftShortName7 = (e.Row.FindControl("ddlShiftShortName7") as DropDownList);
            DropDownList ddlShiftShortName8 = (e.Row.FindControl("ddlShiftShortName8") as DropDownList);
            DropDownList ddlShiftShortName9 = (e.Row.FindControl("ddlShiftShortName9") as DropDownList);
            DropDownList ddlShiftShortName10 = (e.Row.FindControl("ddlShiftShortName10") as DropDownList);
            DropDownList ddlShiftShortName11 = (e.Row.FindControl("ddlShiftShortName11") as DropDownList);
            DropDownList ddlShiftShortName12 = (e.Row.FindControl("ddlShiftShortName12") as DropDownList);
            DropDownList ddlShiftShortName13 = (e.Row.FindControl("ddlShiftShortName13") as DropDownList);
            DropDownList ddlShiftShortName14 = (e.Row.FindControl("ddlShiftShortName14") as DropDownList);
            DropDownList ddlShiftShortName15 = (e.Row.FindControl("ddlShiftShortName15") as DropDownList);
            DropDownList ddlShiftShortName16 = (e.Row.FindControl("ddlShiftShortName16") as DropDownList);
            DropDownList ddlShiftShortName17 = (e.Row.FindControl("ddlShiftShortName17") as DropDownList);
            DropDownList ddlShiftShortName18 = (e.Row.FindControl("ddlShiftShortName18") as DropDownList);
            DropDownList ddlShiftShortName19 = (e.Row.FindControl("ddlShiftShortName19") as DropDownList);
            DropDownList ddlShiftShortName20 = (e.Row.FindControl("ddlShiftShortName20") as DropDownList);
            DropDownList ddlShiftShortName21 = (e.Row.FindControl("ddlShiftShortName21") as DropDownList);
            DropDownList ddlShiftShortName22 = (e.Row.FindControl("ddlShiftShortName22") as DropDownList);
            DropDownList ddlShiftShortName23 = (e.Row.FindControl("ddlShiftShortName23") as DropDownList);
            DropDownList ddlShiftShortName24 = (e.Row.FindControl("ddlShiftShortName24") as DropDownList);
            DropDownList ddlShiftShortName25 = (e.Row.FindControl("ddlShiftShortName25") as DropDownList);
            DropDownList ddlShiftShortName26 = (e.Row.FindControl("ddlShiftShortName26") as DropDownList);
            DropDownList ddlShiftShortName27 = (e.Row.FindControl("ddlShiftShortName27") as DropDownList);
            DropDownList ddlShiftShortName28 = (e.Row.FindControl("ddlShiftShortName28") as DropDownList);
            DropDownList ddlShiftShortName29 = (e.Row.FindControl("ddlShiftShortName29") as DropDownList);
            DropDownList ddlShiftShortName30 = (e.Row.FindControl("ddlShiftShortName30") as DropDownList);
            DropDownList ddlShiftShortName31 = (e.Row.FindControl("ddlShiftShortName31") as DropDownList);

            int CompanyID = Convert.ToInt32(Session["currentSession"]);
            ShiftAllocationEvendata dsDLLShift = new ShiftAllocationEvendata();
            ShiftAllocationEvendata dsDLLShifts = new ShiftAllocationEvendata();
            DataSet dtDll = new DataSet();
            DataSet dtDlls = new DataSet();


            if (CompanyID==0)
            {
                dtDlls = dsDLLShifts.SelectShiftRequisitionParentID(gintUserId);
                int ComID=Convert.ToInt32( dtDlls.Tables[0].Rows[0]["CompanyID"].ToString());
                dtDll = dsDLLShift.SelectShiftRequisitionGridViewDll(ComID);
            }
            else
            {
                dtDll = dsDLLShift.SelectShiftRequisitionGridViewDll(CompanyID);
            }         
            
            //Add Default Item in the DropDownList.
            //ddlShiftShortName.Items.Insert(0, new ListItem("Please select"));
            //Select the Shift Short name in DropDownList.
            string SS = (e.Row.FindControl("lblShift") as Label).Text;
            if(SS != "-1")
            {
                if (SS != "0")
                {
                    
                    ddlShiftShortName.DataSource = dtDll;
                    ddlShiftShortName.DataTextField = "Shift_ShortName";
                    ddlShiftShortName.DataValueField = "Shift_Id";
                    ddlShiftShortName.DataBind();
                    //ddlShiftShortName.Items.FindByValue("-Select-").Selected = true;
                    if (SS == "1")
                    {
                        ddlShiftShortName.Items.Add("-Select-");
                        ddlShiftShortName.SelectedItem.Text = "-Select-";
                        ddlShiftShortName.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    
                        ddlShiftShortName.DataSource = null;
                        ddlShiftShortName.Items.Insert(0, new ListItem("NA"));
                        ddlShiftShortName.Text = "NA";
                        ddlShiftShortName.Enabled = false;

                    

                }
                
            }
            else
            {
                ddlShiftShortName.DataSource = null;
                ddlShiftShortName.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName.SelectedValue = "Off";
                //ddlShiftShortName.Enabled = false;
                

            }
            

            
            string SS2 = (e.Row.FindControl("lblShift2") as Label).Text;
            if (SS2 != "-1")
            {
                if (SS2 != "0")
                {
                    ddlShiftShortName2.DataSource = dtDll;
                    ddlShiftShortName2.DataTextField = "Shift_ShortName";
                    ddlShiftShortName2.DataValueField = "Shift_Id";
                    ddlShiftShortName2.DataBind();
                    //ddlShiftShortName2.Items.FindByValue(SS2).Selected = true;
                    if (SS2 == "1")
                    {
                        ddlShiftShortName2.Items.Add("-Select-");
                        ddlShiftShortName2.SelectedItem.Text = "-Select-";
                        ddlShiftShortName2.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift2") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName2.DataSource = null;
                    ddlShiftShortName2.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName2.Text = "NA";
                    ddlShiftShortName2.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName2.DataSource = null;
                ddlShiftShortName2.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName2.SelectedValue = "Off";
                //ddlShiftShortName2.Enabled = false;
                
            }

           

           
            string SS3 = (e.Row.FindControl("lblShift3") as Label).Text;
            if (SS3 != "-1")
            {
                if (SS3 != "0")
                {
                    ddlShiftShortName3.DataSource = dtDll;
                    ddlShiftShortName3.DataTextField = "Shift_ShortName";
                    ddlShiftShortName3.DataValueField = "Shift_Id";
                    ddlShiftShortName3.DataBind();
                    //.Items.FindByValue(SS3).Selected = true;
                    if (SS3 == "1")
                    {
                        ddlShiftShortName3.Items.Add("-Select-");
                        ddlShiftShortName3.SelectedItem.Text = "-Select-";
                        ddlShiftShortName3.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift3") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName3.DataSource = null;
                    ddlShiftShortName3.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName3.Text = "NA";
                    ddlShiftShortName3.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName3.DataSource = null;
                ddlShiftShortName3.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName3.SelectedValue = "Off";
                //ddlShiftShortName3.Enabled = false;
                
                
            }
            

            
            string SS4 = (e.Row.FindControl("lblShift4") as Label).Text;
            if (SS4 != "-1")
            {
                if (SS4 != "0")
                {
                    ddlShiftShortName4.DataSource = dtDll;
                    ddlShiftShortName4.DataTextField = "Shift_ShortName";
                    ddlShiftShortName4.DataValueField = "Shift_Id";
                    ddlShiftShortName4.DataBind();
                    //ddlShiftShortName4.Items.FindByValue(SS4).Selected = true;
                    if (SS4 == "1")
                    {
                        ddlShiftShortName4.Items.Add("-Select-");
                        ddlShiftShortName4.SelectedItem.Text = "-Select-";
                        ddlShiftShortName4.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift4") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName4.DataSource = null;
                    ddlShiftShortName4.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName4.Text = "NA";
                    ddlShiftShortName4.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName4.DataSource = null;
                ddlShiftShortName4.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName4.SelectedValue = "Off";
                //ddlShiftShortName4.Enabled = false;
                
            }
            

            
            string SS5 = (e.Row.FindControl("lblShift5") as Label).Text;
            if (SS5 != "-1")
            {
                if (SS5 != "0")
                {
                    ddlShiftShortName5.DataSource = dtDll;
                    ddlShiftShortName5.DataTextField = "Shift_ShortName";
                    ddlShiftShortName5.DataValueField = "Shift_Id";
                    ddlShiftShortName5.DataBind();
                    //ddlShiftShortName5.Items.FindByValue(SS5).Selected = true;
                    if (SS5 == "1")
                    {
                        ddlShiftShortName5.Items.Add("-Select-");
                        ddlShiftShortName5.SelectedItem.Text = "-Select-";
                        ddlShiftShortName5.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift5") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName5.DataSource = null;
                    ddlShiftShortName5.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName5.Text = "NA";
                    ddlShiftShortName5.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName5.DataSource = null;
                ddlShiftShortName5.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName5.Text = "Off";
                //ddlShiftShortName5.Enabled = false;
            }

            
            string SS6 = (e.Row.FindControl("lblShift6") as Label).Text;
            if (SS6 != "-1")
            {
                if (SS6 != "0")
                {
                    ddlShiftShortName6.DataSource = dtDll;
                    ddlShiftShortName6.DataTextField = "Shift_ShortName";
                    ddlShiftShortName6.DataValueField = "Shift_Id";
                    ddlShiftShortName6.DataBind();
                    //ddlShiftShortName6.Items.FindByValue(SS6).Selected = true;
                    if (SS6 == "1")
                    {
                        ddlShiftShortName6.Items.Add("-Select-");
                        ddlShiftShortName6.SelectedItem.Text = "-Select-";
                        ddlShiftShortName6.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift6") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName6.DataSource = null;
                    ddlShiftShortName6.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName6.Text = "NA";
                    ddlShiftShortName6.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName6.DataSource = null;
                ddlShiftShortName6.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName6.Text = "Off";
                //ddlShiftShortName6.Enabled = false;
            }
            

            
            string SS7 = (e.Row.FindControl("lblShift7") as Label).Text;
            if (SS7 != "-1")
            {
                if (SS7 != "0")
                {
                    ddlShiftShortName7.DataSource = dtDll;
                    ddlShiftShortName7.DataTextField = "Shift_ShortName";
                    ddlShiftShortName7.DataValueField = "Shift_Id";
                    ddlShiftShortName7.DataBind();
                    //ddlShiftShortName7.Items.FindByValue(SS7).Selected = true;
                    if (SS7 == "1")
                    {
                        ddlShiftShortName7.Items.Add("-Select-");
                        ddlShiftShortName7.SelectedItem.Text = "-Select-";
                        ddlShiftShortName7.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift7") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName7.DataSource = null;
                    ddlShiftShortName7.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName7.Text = "NA";
                    ddlShiftShortName7.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName7.DataSource = null;
                ddlShiftShortName7.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName7.Text = "Off";
                //ddlShiftShortName7.Enabled = false;
            }
            

           
            string SS8 = (e.Row.FindControl("lblShift8") as Label).Text;
            if (SS8 != "-1")
            {
                if (SS8 != "0")
                {
                    ddlShiftShortName8.DataSource = dtDll;
                    ddlShiftShortName8.DataTextField = "Shift_ShortName";
                    ddlShiftShortName8.DataValueField = "Shift_Id";
                    ddlShiftShortName8.DataBind();
                    //ddlShiftShortName8.Items.FindByValue(SS8).Selected = true;

                    if (SS8 == "1")
                    {
                        ddlShiftShortName8.Items.Add("-Select-");
                        ddlShiftShortName8.SelectedItem.Text = "-Select-";
                        ddlShiftShortName8.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift8") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName8.DataSource = null;
                    ddlShiftShortName8.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName8.Text = "NA";
                    ddlShiftShortName8.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName8.DataSource = null;
                ddlShiftShortName8.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName8.Text = "Off";
                //ddlShiftShortName8.Enabled = false;
            }
            

            
            string SS9 = (e.Row.FindControl("lblShift9") as Label).Text;
            if (SS9 != "-1")
            {
                if (SS9 != "0")
                {
                    ddlShiftShortName9.DataSource = dtDll;
                    ddlShiftShortName9.DataTextField = "Shift_ShortName";
                    ddlShiftShortName9.DataValueField = "Shift_Id";
                    ddlShiftShortName9.DataBind();
                    //ddlShiftShortName9.Items.FindByValue(SS9).Selected = true;
                    if (SS9 == "1")
                    {
                        ddlShiftShortName9.Items.Add("-Select-");
                        ddlShiftShortName9.SelectedItem.Text = "-Select-";
                        ddlShiftShortName9.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift9") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName9.DataSource = null;
                    ddlShiftShortName9.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName9.Text = "NA";
                    ddlShiftShortName9.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName9.DataSource = null;
                ddlShiftShortName9.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName9.Text = "Off";
                //ddlShiftShortName9.Enabled = false;
            }
            

            string SS10 = (e.Row.FindControl("lblShift10") as Label).Text;
            if (SS10 != "-1")
            {
                if (SS10 != "0")
                {

                    ddlShiftShortName10.DataSource = dtDll;
                    ddlShiftShortName10.DataTextField = "Shift_ShortName";
                    ddlShiftShortName10.DataValueField = "Shift_Id";
                    ddlShiftShortName10.DataBind();
                    //ddlShiftShortName10.Items.FindByValue(SS10).Selected = true;
                    if (SS10 == "1")
                    {
                        ddlShiftShortName10.Items.Add("-Select-");
                        ddlShiftShortName10.SelectedItem.Text = "-Select-";
                        ddlShiftShortName10.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift10") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName10.DataSource = null;
                    ddlShiftShortName10.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName10.Text = "NA";
                    ddlShiftShortName10.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName10.DataSource = null;
                ddlShiftShortName10.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName10.Text = "Off";
                //ddlShiftShortName10.Enabled = false;
            }
            

            
            string SS11 = (e.Row.FindControl("lblShift11") as Label).Text;
            if (SS11 != "-1")
            {
                if (SS11 != "0")
                {
                    ddlShiftShortName11.DataSource = dtDll;
                    ddlShiftShortName11.DataTextField = "Shift_ShortName";
                    ddlShiftShortName11.DataValueField = "Shift_Id";
                    ddlShiftShortName11.DataBind();
                    //ddlShiftShortName11.Items.FindByValue(SS11).Selected = true;
                    if (SS11 == "1")
                    {
                        ddlShiftShortName11.Items.Add("-Select-");
                        ddlShiftShortName11.SelectedItem.Text = "-Select-";
                        ddlShiftShortName11.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift11") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName11.DataSource = null;
                    ddlShiftShortName11.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName11.Text = "NA";
                    ddlShiftShortName11.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName11.DataSource = null;
                ddlShiftShortName11.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName11.Text = "Off";
                //ddlShiftShortName11.Enabled = false;
            }
            

            
            string SS12 = (e.Row.FindControl("lblShift12") as Label).Text;
            if (SS12 != "-1")
            {
                if (SS12 != "0")
                {
                    ddlShiftShortName12.DataSource = dtDll;
                    ddlShiftShortName12.DataTextField = "Shift_ShortName";
                    ddlShiftShortName12.DataValueField = "Shift_Id";
                    ddlShiftShortName12.DataBind();
                    //ddlShiftShortName12.Items.FindByValue(SS12).Selected = true;
                    if (SS12 == "1")
                    {
                        ddlShiftShortName12.Items.Add("-Select-");
                        ddlShiftShortName12.SelectedItem.Text = "-Select-";
                        ddlShiftShortName12.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift12") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName12.DataSource = null;
                    ddlShiftShortName12.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName12.Text = "NA";
                    ddlShiftShortName12.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName12.DataSource = null;
                ddlShiftShortName12.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName12.Text = "Off";
                //ddlShiftShortName12.Enabled = false;
            }
            

            
            string SS13 = (e.Row.FindControl("lblShift13") as Label).Text;
            if (SS13 != "-1")
            {
                if (SS13 != "0")
                {
                    ddlShiftShortName13.DataSource = dtDll;
                    ddlShiftShortName13.DataTextField = "Shift_ShortName";
                    ddlShiftShortName13.DataValueField = "Shift_Id";
                    ddlShiftShortName13.DataBind();
                    //ddlShiftShortName13.Items.FindByValue(SS13).Selected = true;
                    if (SS13 == "1")
                    {
                        ddlShiftShortName13.Items.Add("-Select-");
                        ddlShiftShortName13.SelectedItem.Text = "-Select-";
                        ddlShiftShortName13.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift13") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName13.DataSource = null;
                    ddlShiftShortName13.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName13.Text = "NA";
                    ddlShiftShortName13.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName13.DataSource = null;
                ddlShiftShortName13.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName13.Text = "Off";
                //ddlShiftShortName13.Enabled = false;
            }
            

            
            string SS14 = (e.Row.FindControl("lblShift14") as Label).Text;
            if (SS14 != "-1")
            {
                if (SS14 != "0")
                {
                    ddlShiftShortName14.DataSource = dtDll;
                    ddlShiftShortName14.DataTextField = "Shift_ShortName";
                    ddlShiftShortName14.DataValueField = "Shift_Id";
                    ddlShiftShortName14.DataBind();
                    //ddlShiftShortName14.Items.FindByValue(SS14).Selected = true;
                    if (SS14 == "1")
                    {
                        ddlShiftShortName14.Items.Add("-Select-");
                        ddlShiftShortName14.SelectedItem.Text = "-Select-";
                        ddlShiftShortName14.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift14") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName14.DataSource = null;
                    ddlShiftShortName14.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName14.Text = "NA";
                    ddlShiftShortName14.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName14.DataSource = null;
                ddlShiftShortName14.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName14.Text = "Off";
               // ddlShiftShortName14.Enabled = false;
            }
            

            
            string SS15 = (e.Row.FindControl("lblShift15") as Label).Text;
            if (SS15 != "-1")
            {
                if (SS15 != "0")
                {
                    ddlShiftShortName15.DataSource = dtDll;
                    ddlShiftShortName15.DataTextField = "Shift_ShortName";
                    ddlShiftShortName15.DataValueField = "Shift_Id";
                    ddlShiftShortName15.DataBind();
                    //ddlShiftShortName15.Items.FindByValue(SS15).Selected = true;
                    if (SS15 == "1")
                    {
                        ddlShiftShortName15.Items.Add("-Select-");
                        ddlShiftShortName15.SelectedItem.Text = "-Select-";
                        ddlShiftShortName15.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift15") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName15.DataSource = null;
                    ddlShiftShortName15.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName15.Text = "NA";
                    ddlShiftShortName15.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName15.DataSource = null;
                ddlShiftShortName15.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName15.Text = "Off";
                //ddlShiftShortName15.Enabled = false;
            }
            

            
            string SS16 = (e.Row.FindControl("lblShift16") as Label).Text;
            if (SS16 != "-1")
            {
                if (SS16 != "0")
                {
                    ddlShiftShortName16.DataSource = dtDll;
                    ddlShiftShortName16.DataTextField = "Shift_ShortName";
                    ddlShiftShortName16.DataValueField = "Shift_Id";
                    ddlShiftShortName16.DataBind();
                    //ddlShiftShortName16.Items.FindByValue(SS16).Selected = true;
                    if (SS16 == "1")
                    {
                        ddlShiftShortName16.Items.Add("-Select-");
                        ddlShiftShortName16.SelectedItem.Text = "-Select-";
                        ddlShiftShortName16.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift16") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName16.DataSource = null;
                    ddlShiftShortName16.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName16.Text = "NS";
                    ddlShiftShortName16.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName16.DataSource = null;
                ddlShiftShortName16.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName16.Text = "Off";
                //ddlShiftShortName16.Enabled = false;
            }
           

            
            string SS17 = (e.Row.FindControl("lblShift17") as Label).Text;
            if (SS17 != "-1")
            {
                if (SS17 != "0")
                {
                    ddlShiftShortName17.DataSource = dtDll;
                    ddlShiftShortName17.DataTextField = "Shift_ShortName";
                    ddlShiftShortName17.DataValueField = "Shift_Id";
                    ddlShiftShortName17.DataBind();
                    //ddlShiftShortName17.Items.FindByValue(SS17).Selected = true;
                    if (SS17 == "1")
                    {
                        ddlShiftShortName17.Items.Add("-Select-");
                        ddlShiftShortName17.SelectedItem.Text = "-Select-";
                        ddlShiftShortName17.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift17") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName17.DataSource = null;
                    ddlShiftShortName17.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName17.Text = "NA";
                    ddlShiftShortName17.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName17.DataSource = null;
                ddlShiftShortName17.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName17.Text = "Off";
               // ddlShiftShortName17.Enabled = false;
            }
            

            
            string SS18 = (e.Row.FindControl("lblShift18") as Label).Text;
            if (SS18 != "-1")
            {
                if (SS18 != "0")
                {
                    ddlShiftShortName18.DataSource = dtDll;
                    ddlShiftShortName18.DataTextField = "Shift_ShortName";
                    ddlShiftShortName18.DataValueField = "Shift_Id";
                    ddlShiftShortName18.DataBind();
                    //ddlShiftShortName18.Items.FindByValue(SS18).Selected = true;
                    if (SS18 == "1")
                    {
                        ddlShiftShortName18.Items.Add("-Select-");
                        ddlShiftShortName18.SelectedItem.Text = "-Select-";
                        ddlShiftShortName18.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift18") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                   
                    ddlShiftShortName18.DataSource = null;
                    ddlShiftShortName18.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName18.Text = "NA";
                    ddlShiftShortName18.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName18.DataSource = null;
                ddlShiftShortName18.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName18.Text = "Off";
                //ddlShiftShortName18.Enabled = false;
            }
            

            
            string SS19 = (e.Row.FindControl("lblShift19") as Label).Text;
            if (SS19 != "-1")
            {
                if (SS19 != "0")
                {
                    ddlShiftShortName19.DataSource = dtDll;
                    ddlShiftShortName19.DataTextField = "Shift_ShortName";
                    ddlShiftShortName19.DataValueField = "Shift_Id";
                    ddlShiftShortName19.DataBind();
                    //ddlShiftShortName19.Items.FindByValue(SS19).Selected = true;
                    if (SS19 == "1")
                    {
                        ddlShiftShortName19.Items.Add("-Select-");
                        ddlShiftShortName19.SelectedItem.Text = "-Select-";
                        ddlShiftShortName19.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift19") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName19.DataSource = null;
                    ddlShiftShortName19.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName19.Text = "NA";
                    ddlShiftShortName19.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName19.DataSource = null;
                ddlShiftShortName19.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName19.Text = "Off";
                //ddlShiftShortName19.Enabled = false;
            }
            

            
            string SS20 = (e.Row.FindControl("lblShift20") as Label).Text;
            if (SS20 != "-1")
            {
                if (SS20 != "0")
                {
                    ddlShiftShortName20.DataSource = dtDll;
                    ddlShiftShortName20.DataTextField = "Shift_ShortName";
                    ddlShiftShortName20.DataValueField = "Shift_Id";
                    ddlShiftShortName20.DataBind();
                    //ddlShiftShortName20.Items.FindByValue(SS20).Selected = true;
                    if (SS20 == "1")
                    {
                        ddlShiftShortName20.Items.Add("-Select-");
                        ddlShiftShortName20.SelectedItem.Text = "-Select-";
                        ddlShiftShortName20.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift20") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName20.DataSource = null;
                    ddlShiftShortName20.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName20.Text = "NA";
                    ddlShiftShortName20.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName20.DataSource = null;
                ddlShiftShortName20.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName20.Text = "Off";
                //ddlShiftShortName20.Enabled = false;
            }
            

            string SS21 = (e.Row.FindControl("lblShift21") as Label).Text;
            if (SS21 != "-1")
            {
                if (SS21 != "0")
                {

                    ddlShiftShortName21.DataSource = dtDll;
                    ddlShiftShortName21.DataTextField = "Shift_ShortName";
                    ddlShiftShortName21.DataValueField = "Shift_Id";
                    ddlShiftShortName21.DataBind();
                    //ddlShiftShortName21.Items.FindByValue(SS21).Selected = true;
                    if (SS21 == "1")
                    {
                        ddlShiftShortName21.Items.Add("-Select-");
                        ddlShiftShortName21.SelectedItem.Text = "-Select-";
                        ddlShiftShortName21.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift21") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName21.DataSource = null;
                    ddlShiftShortName21.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName21.Text = "NA";
                    ddlShiftShortName21.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName21.DataSource = null;
                ddlShiftShortName21.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName21.Text = "Off";
                //ddlShiftShortName21.Enabled = false;
            }
            

            
            string SS22 = (e.Row.FindControl("lblShift22") as Label).Text;
            if (SS22 != "-1")
            {
                if (SS22 != "0")
                {
                    ddlShiftShortName22.DataSource = dtDll;
                    ddlShiftShortName22.DataTextField = "Shift_ShortName";
                    ddlShiftShortName22.DataValueField = "Shift_Id";
                    ddlShiftShortName22.DataBind();
                    //ddlShiftShortName22.Items.FindByValue(SS22).Selected = true;
                    if (SS22 == "1")
                    {
                        ddlShiftShortName22.Items.Add("-Select-");
                        ddlShiftShortName22.SelectedItem.Text = "-Select-";
                        ddlShiftShortName22.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift22") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName22.DataSource = null;
                    ddlShiftShortName22.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName22.Text = "NA";
                    ddlShiftShortName22.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName22.DataSource = null;
                ddlShiftShortName22.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName22.Text = "Off";
                //ddlShiftShortName22.Enabled = false;
            }
            

            
            string SS23 = (e.Row.FindControl("lblShift23") as Label).Text;
            if (SS23 != "-1")
            {
                if (SS23 != "0")
                {
                    ddlShiftShortName23.DataSource = dtDll;
                    ddlShiftShortName23.DataTextField = "Shift_ShortName";
                    ddlShiftShortName23.DataValueField = "Shift_Id";
                    ddlShiftShortName23.DataBind();
                    //ddlShiftShortName23.Items.FindByValue(SS23).Selected = true;
                    if (SS23 == "1")
                    {
                        ddlShiftShortName23.Items.Add("-Select-");
                        ddlShiftShortName23.SelectedItem.Text = "-Select-";
                        ddlShiftShortName23.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift23") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName23.DataSource = null;
                    ddlShiftShortName23.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName23.Text = "NA";
                    ddlShiftShortName23.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName23.DataSource = null;
                ddlShiftShortName23.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName23.Text = "Off";
                //ddlShiftShortName23.Enabled = false;
            }
            

            
            string SS24 = (e.Row.FindControl("lblShift24") as Label).Text;
            if (SS24 != "-1")
            {
                if (SS24 != "0")
                {
                    ddlShiftShortName24.DataSource = dtDll;
                    ddlShiftShortName24.DataTextField = "Shift_ShortName";
                    ddlShiftShortName24.DataValueField = "Shift_Id";
                    ddlShiftShortName24.DataBind();
                    //ddlShiftShortName24.Items.FindByValue(SS24).Selected = true;
                    if (SS24 == "1")
                    {
                        ddlShiftShortName24.Items.Add("-Select-");
                        ddlShiftShortName24.SelectedItem.Text = "-Select-";
                        ddlShiftShortName24.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift24") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName24.DataSource = null;
                    ddlShiftShortName24.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName24.Text = "NA";
                    ddlShiftShortName24.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName24.DataSource = null;
                ddlShiftShortName24.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName24.Text = "Off";
               // ddlShiftShortName24.Enabled = false;
            }
            

            
            string SS25 = (e.Row.FindControl("lblShift25") as Label).Text;
            if (SS25 != "-1")
            {
                if (SS25 != "0")
                {
                    ddlShiftShortName25.DataSource = dtDll;
                    ddlShiftShortName25.DataTextField = "Shift_ShortName";
                    ddlShiftShortName25.DataValueField = "Shift_Id";
                    ddlShiftShortName25.DataBind();
                    //ddlShiftShortName25.Items.FindByValue(SS25).Selected = true;
                    if (SS25 == "1")
                    {
                        ddlShiftShortName25.Items.Add("-Select-");
                        ddlShiftShortName25.SelectedItem.Text = "-Select-";
                        ddlShiftShortName25.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift25") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName25.DataSource = null;
                    ddlShiftShortName25.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName25.Text = "NA";
                    ddlShiftShortName25.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName25.DataSource = null;
                ddlShiftShortName25.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName25.Text = "Off";
                //ddlShiftShortName25.Enabled = false;
            }
            

            
            string SS26 = (e.Row.FindControl("lblShift26") as Label).Text;
            if (SS26 != "-1")
            {
                if (SS26 != "0")
                {
                    ddlShiftShortName26.DataSource = dtDll;
                    ddlShiftShortName26.DataTextField = "Shift_ShortName";
                    ddlShiftShortName26.DataValueField = "Shift_Id";
                    ddlShiftShortName26.DataBind();
                    //ddlShiftShortName26.Items.FindByValue(SS26).Selected = true;
                    if (SS26 == "1")
                    {
                        ddlShiftShortName26.Items.Add("-Select-");
                        ddlShiftShortName26.SelectedItem.Text = "-Select-";
                        ddlShiftShortName26.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift26") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName26.DataSource = null;
                    ddlShiftShortName26.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName26.Text = "NA";
                    ddlShiftShortName26.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName26.DataSource = null;
                ddlShiftShortName26.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName26.Text = "Off";
                //ddlShiftShortName26.Enabled = false;
            }
            

            
            string SS27 = (e.Row.FindControl("lblShift27") as Label).Text;
            if (SS27 != "-1")
            {
                if (SS27 != "0")
                {
                    ddlShiftShortName27.DataSource = dtDll;
                    ddlShiftShortName27.DataTextField = "Shift_ShortName";
                    ddlShiftShortName27.DataValueField = "Shift_Id";
                    ddlShiftShortName27.DataBind();
                    //ddlShiftShortName27.Items.FindByValue(SS27).Selected = true;
                    if (SS27 == "1")
                    {
                        ddlShiftShortName27.Items.Add("-Select-");
                        ddlShiftShortName27.SelectedItem.Text = "-Select-";
                        ddlShiftShortName27.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift27") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName27.DataSource = null;
                    ddlShiftShortName27.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName27.Text = "NA";
                    ddlShiftShortName27.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName27.DataSource = null;
                ddlShiftShortName27.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName27.Text = "Off";
               // ddlShiftShortName27.Enabled = false;
            }
            

            
            string SS28 = (e.Row.FindControl("lblShift28") as Label).Text;
            if (SS28 != "-1")
            {
                if (SS28 != "0")
                {
                    ddlShiftShortName28.DataSource = dtDll;
                    ddlShiftShortName28.DataTextField = "Shift_ShortName";
                    ddlShiftShortName28.DataValueField = "Shift_Id";
                    ddlShiftShortName28.DataBind();
                    //ddlShiftShortName28.Items.FindByValue(SS28).Selected = true;
                    if (SS28 == "1")
                    {
                        ddlShiftShortName28.Items.Add("-Select-");
                        ddlShiftShortName28.SelectedItem.Text = "-Select-";
                        ddlShiftShortName28.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift28") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName28.DataSource = null;
                    ddlShiftShortName28.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName28.Text = "NA";
                    ddlShiftShortName28.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName28.DataSource = null;
                ddlShiftShortName28.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName28.Text = "Off";
               // ddlShiftShortName28.Enabled = false;
            }
            

           
            string SS29 = (e.Row.FindControl("lblShift29") as Label).Text;
            if (SS29 != "-1")
            {
                if(SS29 != "0")
                {
                    ddlShiftShortName29.DataSource = dtDll;
                    ddlShiftShortName29.DataTextField = "Shift_ShortName";
                    ddlShiftShortName29.DataValueField = "Shift_Id";
                    ddlShiftShortName29.DataBind();
                    //ddlShiftShortName29.Items.FindByValue(SS29).Selected = true;
                    if (SS29 == "1")
                    {
                        ddlShiftShortName29.Items.Add("-Select-");
                        ddlShiftShortName29.SelectedItem.Text = "-Select-";
                        ddlShiftShortName29.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift29") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName29.DataSource = null;
                    ddlShiftShortName29.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName29.Text = "NA";
                    ddlShiftShortName29.Enabled = false;

                }
                
            }
            else
            {
                ddlShiftShortName29.DataSource = null;
                ddlShiftShortName29.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName29.Text = "Off";
               // ddlShiftShortName29.Enabled = false;
            }
            

            
            string SS30 = (e.Row.FindControl("lblShift30") as Label).Text;
            if (SS30 != "-1")
            {
                if (SS30 != "0")
                {
                    ddlShiftShortName30.DataSource = dtDll;
                    ddlShiftShortName30.DataTextField = "Shift_ShortName";
                    ddlShiftShortName30.DataValueField = "Shift_Id";
                    ddlShiftShortName30.DataBind();
                    //ddlShiftShortName30.Items.FindByValue(SS30).Selected = true;
                    if (SS30 == "1")
                    {
                        ddlShiftShortName30.Items.Add("-Select-");
                        ddlShiftShortName30.SelectedItem.Text = "-Select-";
                        ddlShiftShortName30.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift30") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName30.DataSource = null;
                    ddlShiftShortName30.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName30.Text = "NA";
                    ddlShiftShortName30.Enabled = false;
                }
                
            }
            else
            {
                ddlShiftShortName30.DataSource = null;
                ddlShiftShortName30.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName30.Text = "Off";
                //ddlShiftShortName30.Enabled = false;
            }
            

            
            string SS31 = (e.Row.FindControl("lblShift31") as Label).Text;
            if (SS31 != "-1")
            {
                if (SS31 != "0")
                {
                    ddlShiftShortName31.DataSource = dtDll;
                    ddlShiftShortName31.DataTextField = "Shift_ShortName";
                    ddlShiftShortName31.DataValueField = "Shift_Id";
                    ddlShiftShortName31.DataBind();
                    //ddlShiftShortName31.Items.FindByValue(SS31).Selected = true;
                    if (SS31 == "1")
                    {
                        ddlShiftShortName31.Items.Add("-Select-");
                        ddlShiftShortName31.SelectedItem.Text = "-Select-";
                        ddlShiftShortName31.SelectedValue = "-Select-";
                        (e.Row.FindControl("lblShift31") as Label).Text = "-Select-";
                        
                    }
                }
                else
                {
                    ddlShiftShortName31.DataSource = null;
                    ddlShiftShortName31.Items.Insert(0, new ListItem("NA"));
                    ddlShiftShortName31.Text = "NA";
                    ddlShiftShortName31.Enabled = false;
                }
               
            }
            else
            {
                ddlShiftShortName31.DataSource = null;
                ddlShiftShortName31.Items.Insert(0, new ListItem("Off"));
                ddlShiftShortName31.Text = "Off";
               // ddlShiftShortName31.Enabled = false;
            }
            



        }







    }
    #endregion
    #region NotUSed
    /// <summary>
    /// Allocating Shift Based on Shift Pattern
    /// </summary>
    private void ShiftpatternAllocation()
    {
        if (Page.IsValid)
        {
        }
    }
    private void SimpleShiftAllocation()
    {
        if (Page.IsValid)
        {
        }
    }
    /// <summary>
    /// Shift Roaster Allocation
    /// </summary>
    /// 
    private void ShiftroasterAllocation()
    {
        ds_Empdetails = objShiftAllocation.SelectEmployeeDetails(gintUserId);
        AllocateRoster(ds_Empdetails);
    }
    /// <summary>
    /// Fill ShiftRoaster dropdown
    /// </summary>   
    /// 
    public void OverLappedValidationShiftPattern(DateTime dtmStartDate, DateTime dtmToDate, int intStartDay)
    {
        int intOverLapped = 0;
        int StartDateShiftId = 0;
        int EndDateShiftId = 0;
        DataColumn dcEmployeeId = new DataColumn("OverLapped", System.Type.GetType("System.Boolean"));
        dtEmpDetails.Columns.Add(dcEmployeeId);
        DataTable dtShiftIDs = new DataTable();
        int[] Pattern = new int[31];
        int PatternDaysCount = 7;
        //if (rbtnShiftPattern.Checked == true)
        //{
            /////////////////////////////ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(int.Parse(ddl_Pattern.SelectedValue));
            dtShiftIDs = ds_ShiftAllocdetails.Tables[0];
            PatternDaysCount = dtShiftIDs.Rows.Count;
            for (int i = 0; i < PatternDaysCount; i++)
            {
                Pattern[i] = int.Parse(Convert.ToString(dtShiftIDs.Rows[i]["id"]));
            }
        //}
        //else if (rbtnShifts.Checked == true)
        //{
            Pattern = ShiftPatternSequence();
        //}
        int p = intStartDay - 1;
        for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
        {
            if (j == dtmStartDate)
            {
                StartDateShiftId = Pattern[p];
            }
            if (j == dtmToDate)
            {
                EndDateShiftId = Pattern[p];
            }
            if (p < (PatternDaysCount - 1))
            {
                p += 1;
            }
            else if (p >= (PatternDaysCount - 1))
            {
                p = 0;
            }
        }
        foreach (DataRow dRow in ds.Tables[0].Rows)
        {
            intOverLapped = ConstructPermanentShiftAllocation(Convert.ToInt32(dRow["EmpID"]), dtmStartDate, dtmToDate, StartDateShiftId, EndDateShiftId);
            if (intOverLapped > 0)
            {
                dRow["OverLapped"] = "True";
                if (Convert.ToString(strOverLappedEmployeeIds) == string.Empty)
                {
                    strOverLappedEmployeeIds.Append(Convert.ToString(dRow["EmployeeId"]));
                }
                else
                {
                    strOverLappedEmployeeIds.Append("," + Convert.ToString(dRow["EmployeeId"]));
                }
            }
            else
            {
                dRow["OverLapped"] = "False";
            }
        }
    }
    private void AllocateRoster(DataSet dsEmployee)
    {
    }
    public void OverLappedValidationRoster(DateTime dtmStartDate, DateTime dtmToDate)
    {
        int intOverLapped = 0;
        int[] Pattern = new int[310];
        int intTotalPatternDays = 0;
        int l = 0;
        DataColumn dcEmployeeId = new DataColumn("OverLapped", System.Type.GetType("System.Boolean"));
        dtEmpDetails.Columns.Add(dcEmployeeId);
        // Fetching ShiftRoaster Details, Pattern Details and getting ShiftIDs in an array
        // DataSet ds_ShiftRoaster = objShiftRoaster.SelectShiftRoasterById(Convert.ToInt32(ddlShiftRoaster.SelectedValue));
        DataSet ds_ShiftRoaster = new DataSet();
        foreach (DataRow drShiftRoster in ds_ShiftRoaster.Tables[0].Rows)
        {
            int intNoOfPatterns = int.Parse(Convert.ToString(drShiftRoster["NumberOfPatterns"]));
            string strPatternName = string.Empty;
            for (int m = 1; m <= intNoOfPatterns; m++)
            {
                strPatternName = "Pattern" + m;
                ds_ShiftPattern = objShiftAllocation.Shiftpattern(Convert.ToInt32(drShiftRoster[strPatternName]));
                foreach (DataRow drShiftPattern in ds_ShiftPattern.Tables[0].Rows)
                {
                    int intPatternDays = int.Parse(Convert.ToString(drShiftPattern["Shift_days"]));
                    string strShiftName = string.Empty;
                    intTotalPatternDays = intTotalPatternDays + intPatternDays;
                    for (int n = 1; n <= intPatternDays; n++)
                    {
                        strShiftName = "Day" + n + "_Shift";
                        Pattern[l] = Convert.ToInt32(drShiftPattern[strShiftName]);
                        if ((l + 1) != intTotalPatternDays)
                        {
                            l = l + 1;
                        }
                    }
                }
                l = l + 1;
            }
        }
        int p = 0;
        int StartDateShiftId = 0;
        int EndDateShiftId = 0;
        for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
        {
            if (j == dtmStartDate)
            {
                StartDateShiftId = Pattern[p];
            }
            if (j == dtmToDate)
            {
                EndDateShiftId = Pattern[p];
            }
            if (p < (intTotalPatternDays - 1))
            {
                p += 1;
            }
            else if (p >= (intTotalPatternDays - 1))
            {
                p = 0;
            }
        }
        foreach (DataRow dRow in ds_Empdetails.Tables[0].Rows)
        {
            intOverLapped = ConstructPermanentShiftAllocation(Convert.ToInt32(dRow["EmpID"]), dtmStartDate, dtmToDate, StartDateShiftId, EndDateShiftId);
            if (intOverLapped > 0)
            {
                dRow["OverLapped"] = "True";
                if (Convert.ToString(strOverLappedEmployeeIds) == string.Empty)
                {
                    strOverLappedEmployeeIds.Append(Convert.ToString(dRow["EmployeeId"]));
                }
                else
                {
                    strOverLappedEmployeeIds.Append("," + Convert.ToString(dRow["EmployeeId"]));
                }
            }
            else
            {
                dRow["OverLapped"] = "False";
            }
        }
    }
    #endregion

    protected void grv_Employees_CheckAll_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Employees.HeaderRow.Cells[0].FindControl("checkall");
        string ChkBoxIDs = string.Empty;
        if (chkSelect.Checked)
        {
            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
            if (Session["EmployeeIds"].ToString() == "")
            {
                Session["EmployeeIds"] = ChkBoxIDs;
            }
            else
            {
                if (ChkBoxIDs != "")
                {
                    Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
                }
            }
        }
        else
        {
            Session["EmployeeIds"] = string.Empty;
        }
        foreach (GridViewRow gr in grv_Employees.Rows)
        {
            chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
            chkSelect.Checked = ((CheckBox)sender).Checked;
        }
    }
    protected void grv_Employees_Check_CheckedChanged(object sender, EventArgs e)
    {
        string ChkBoxIDs = string.Empty;
        int intCount = 0;
        int intGridPageSize = grv_Employees.PageSize;
        int intGridTotalPages = grv_Employees.PageCount;
        bool boolAllChecked = false;
        CheckBox chkSelect = new CheckBox();
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)grv_Employees.HeaderRow.Cells[0].FindControl("checkall");
        if (((CheckBox)sender).Checked == false)
        {
            chkSelectAll.Checked = false;
        }
        else
        {
            foreach (GridViewRow gr in grv_Employees.Rows)
            {
                chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
                if (chkSelect.Checked)
                    intCount = intCount + 1;
            }
            if (Convert.ToInt32(Session["TotalEmployees"].ToString()) == intCount)
            {
                chkSelectAll.Checked = true;
            }
            else if (intCount > 0 && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intCount && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intGridPageSize)
            {
                if (intCount == intGridPageSize)
                {
                    if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                    {
                        ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                        char[] Delimit = { ',' };
                        string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                        string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                        Array.Sort(SessionEmployeeIds);
                        Array.Sort(ChedkedEmployeeIds);
                        if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                        {
                            for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                            {
                                if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                {
                                    boolAllChecked = false;
                                    break;
                                }
                            }
                            boolAllChecked = true;
                        }
                        if (boolAllChecked == true)
                        {
                            chkSelectAll.Checked = true;
                        }
                    }
                }
                else if (grv_Employees.PageIndex == intGridTotalPages - 1)
                {
                    int intLastPageCount = Convert.ToInt32(Session["TotalEmployees"].ToString()) - (intGridPageSize * (intGridTotalPages - 1));
                    if (intCount == intLastPageCount)
                    {
                        if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                        {
                            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                            char[] Delimit = { ',' };
                            string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                            string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                            Array.Sort(SessionEmployeeIds);
                            Array.Sort(ChedkedEmployeeIds);
                            if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                            {
                                for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                                {
                                    if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                    {
                                        boolAllChecked = false;
                                        break;
                                    }
                                }
                                boolAllChecked = true;
                            }
                            if (boolAllChecked == true)
                            {
                                chkSelectAll.Checked = true;
                            }
                        }
                    }
                }
            }
        }
    }




    protected void ddl_NoDays_SelectedIndexChanged(object sender, EventArgs e)
    {
        grv_Employeess.Visible = true;
        grv_Employees.Visible = false;
        ShiftAllocationEvendata dsGrideLoad = new ShiftAllocationEvendata();
        int CompanyID = Convert.ToInt32(Session["currentSession"]);
        var MonthName = ((ddl_Month).SelectedItem.Text);
        grv_Employeess.DataSource = dsGrideLoad.SelectShiftRequisitionGridView(MonthName, CompanyID);
        grv_Employeess.DataBind();
        btn_Save.Visible = true;

        
        
    }
    protected void ddl_shiftShortNames(object sender, EventArgs e)
    {
        //DropDownList ddlShiftShortName = sender as DropDownList;
        //Session["SS"]= Convert.ToString(ddlShiftShortName.SelectedValue);
        //string ss1 = Session["SS"].ToString();
        //String SS= Session["SS"].ToString();
        //btn_Save.Visible = true;
        //int CompanyID = Convert.ToInt32(Session["currentSession"]);
        //ShiftAllocationEvendata dsDLLShift = new ShiftAllocationEvendata();
        //DataSet dtDll = new DataSet();
        //dtDll = dsDLLShift.SelectShiftRequisitionGridViewDll(CompanyID);
        

        //if (SS != "-1")
        //{
        //    if (SS != "0")
        //    {

        //        ddlShiftShortName.DataSource = dtDll;
        //        ddlShiftShortName.DataTextField = "Shift_ShortName";
        //        ddlShiftShortName.DataValueField = "Shift_Id";
        //        ddlShiftShortName.DataBind();
        //        //ddlShiftShortName.Items.FindByValue(SS).Selected = true;
        //        if (SS == "1")
        //        {
        //            ddlShiftShortName.Items.Add("-Select-");
        //            ddlShiftShortName.SelectedItem.Text = "-Select-";
        //            //(e.Row.FindControl("lblShift") as Label).Text = "-Select-";

        //        }
        //    }
        //    else
        //    {

        //        ddlShiftShortName.DataSource = null;
        //        ddlShiftShortName.Items.Insert(0, new ListItem("NA"));
        //        ddlShiftShortName.Text = "NA";
        //        ddlShiftShortName.Enabled = false;



        //    }

        //}
        //else
        //{
        //    ddlShiftShortName.DataSource = null;
        //    ddlShiftShortName.Items.Insert(0, new ListItem("Off"));
        //    ddlShiftShortName.SelectedValue = "Off";
        //    //ddlShiftShortName.Enabled = false;


        //}
        

    }

    private void GRidLoad()
    {
        ShiftAllocationEvendata dsGridLoad = new ShiftAllocationEvendata();
        DataSet dtGrid = new DataSet();
        int ComID = Convert.ToInt32(Session["currentSession"]);
        string gintUsrId = Convert.ToString(Session["EmpAutoID"]);
        dtGrid = dsGridLoad.SelectShiftRequisitionGridLoad(ComID, gintUsrId);
        GridView3.DataSource = dtGrid;
        GridView3.DataBind();
    }

    private void ShiftMonthLoad()
     {
        ShiftAllocationEvendata ObjMonth = new ShiftAllocationEvendata();
        DataSet dtDllMonth = new DataSet();
        //ddl_Month.SelectedItem.Text = "-Select-";
        dtDllMonth = ObjMonth.SelectShiftRequisitionMonth();
        ddl_Month.DataSource = dtDllMonth;
        ddl_Month.DataTextField = "MonYear"; 
        ddl_Month.DataValueField = "ROWID";
        ddl_Month.DataBind();
        ddl_Month.Items.Add("-Select-");
        ddl_Month.SelectedValue = "-Select-";
       
    }
}