using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
using System.IO;
using System.Text;
/****************************************************************************************************************************
* Project Name    : TimeCheck                            Started Date  : 14-Aug-2007
* Module          : Temporary Shift Allocation           Last Modified : 04-May-2011
* Programmer      : Kumuthini.L
* Modified by     : Sashma
****************************************************************************************************************************/
public partial class Transactions_TA_UI_Transaction_TemporaryShiftAllocationadd : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    //ShiftPatternEventData objShiftPattern = new ShiftPatternEventData();
    ShiftAllocationEvendata objShiftAllocation = new ShiftAllocationEvendata();
    //ShiftRoasterEventData objShiftRoaster = new ShiftRoasterEventData();
    cls_Common objcls_Common = new cls_Common();
    ShiftPatternEventData objShiftPatternOverLap = new ShiftPatternEventData();
    //RetrunNumberofDays obj_NumberofDays = new RetrunNumberofDays(); 
    //DateTime dtFromdate, dtTodate;
    DataSet dsOverLapping = new DataSet();
    DataSet ds_Empdetails = new DataSet();
    DataSet ds_ShiftPattern = new DataSet();
    DataSet ds_ShiftAllocdetails = new DataSet();
    DataSet ds = new DataSet();
    DataTable dtEmpDetails = new DataTable();
    DataTable dtMonthYear = new DataTable();
    Hashtable hs_PatternId = new Hashtable();
    Hashtable hs_year = new Hashtable();
    //string strOverLappedEmployeeIds = string.Empty;
    StringBuilder strOverLappedEmployeeIds = new StringBuilder();
    string gstrIsValid = "T";
    string gstrDateFormat;
    string gstrUserGroupName = string.Empty;
    string strToDate = string.Empty;
    string strStartDate = string.Empty;
    bool IsUnOverlappedEmployeeExists = false;
    bool chkShiftAllocationExists;
    int PatternDaysCount = 0;
    int gintCompanyId;
    int gintUserId;
    string strAlert = string.Empty;
    //int hskey;
    //int[] months = new int[36]; 
    #endregion
    #region Page Load events
    /// <summary>
    /// on page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);            
        }
        //get the culture info to set the language        
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        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") + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectShiftPattern", ci) + "','" + rm.GetString("Alert_SelectStartday", 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 + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        gintUserId = Int32.Parse(Session["EmpAutoID"].ToString());
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        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 = "(3 No.)";
        }
        else
        {
            divMultiple.Style.Add("display", "none");
            divSingle.Style.Add("display", "block");
            lblcount.Text = "(4 No.)";
        }
        if (!IsPostBack)
        {
            objcls_Common.menu("ShiftTransaction", "29");
            if (Session["CheckRecordsAddInPopUP"] != null)
            {
                Session["CheckRecordsAddInPopUP"] = null;
            }
            else
            {
                objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
                Session["EmpDetails"] = null;
                Session["currentSession"] = null;
            }
            fillEmployee();
            //grv_Employees.DataSourceID = ObjectDataSource1.ID; 
            // here Session["currentSession"] refers parent levelid
            if (Session["currentSession"] != null && Session["currentSession"].ToString() != string.Empty)
            {
                org_levelsEventData getOrg = new org_levelsEventData();
                getOrg.GetOrgParentLevels_FromID(Convert.ToInt32(Session["currentSession"]));
                DataSet ds_getOrg = new DataSet();
                ds_getOrg = getOrg.GetOrgParentLevels();
                if (ds_getOrg != null)
                {
                    if (ds_getOrg.Tables[0].Rows.Count > 0)
                    {
                        int companyId = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"].ToString());
                        gintCompanyId = companyId;
                        fillPatternddl(companyId);
                        //getEmployeeIDs();
                        //Fill shift Details
                        fillShiftddl(companyId);
                    }
                }
            }
            // Alert Message 28-1-2011
        }
        btn_Add.Attributes.Add("onclick", "javascript:return confirm('" + rm.GetString("Alert_AreyousuretoSaveShiftAllocation", ci) + "')");
        //Fill ShiftRoasterDropdown
        //fillShiftRoasterddl();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        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 (shiftPatternExists == 0)
        {
            rbtnShifts.Checked = true;
            rbtnShiftPattern.Style.Add("display", "none");
        }
        if (shiftRosterExists == 0)
        {
            rbtnShifts.Checked = true;
            rbtnShiftRoaster.Style.Add("display", "none");
        }
        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)
                            {
                                //Hide shift pattern
                                rbtnShifts.Checked = true;
                                rbtnShiftPattern.Style.Add("display", "none");
                            }
                            if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["Roster"]) == false)
                            {
                                //Hide shift roster
                                rbtnShifts.Checked = true;
                                rbtnShiftRoaster.Style.Add("display", "none");
                            }
                        }
                        else
                        {
                            base.Message(rm.GetString("Msg_ApprovalSettings", ci));
                            return;
                        }
                    }
                }
            }
        }
        //if (Session["Edition"].ToString() == "1")
        //{
        //    ShiftOnly();
        //}
        //else if (Session["Edition"].ToString() == "0" || Session["Edition"].ToString() == "3")
        //{
        //    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]["PatternRoster"]) == false)
        //                    {
        //                        //Display Shift Only
        //                        ShiftOnly();
        //                    }
        //                    else
        //                    {
        //                        //Display All
        //                    }
        //                }
        //                else
        //                {
        //                    base.Message(rm.GetString ("Msg_ApprovalSettings",ci));
        //                    return;
        //                }
        //            }
        //        }
        //    }
        //}
            string strScript = "<script language='javascript' type='text/javascript'>";
            strScript += "showPattern();";
            strScript += " </script>";
            this.RegisterStartupScript("StatusTypeLoad", strScript);
    }
    #endregion
    #region User Defined Functions
    //private void ShiftOnly()
    //{
    //    rbtnShifts.Checked = true;
    //    rbtnShiftPattern.Style.Add("display", "none");
    //    string strScript = "<script language='javascript' type='text/javascript'>";
    //    strScript += "showPattern();";
    //    strScript += " </script>";
    //    this.RegisterStartupScript("StatusTypeLoad", strScript);
    //}
    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
        {
            grv_Employees.DataSource = ds;
            grv_Employees.DataBind();
        }
    }
    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);
        }
    }
    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;
    }
    private int getStartDay(DateTime dtFromDate)
    {
        string strWeekDayName;
        //DateTime dtFromDate = DateTime.Parse(txt_StartDate.Text.Trim());
        strWeekDayName = dtFromDate.DayOfWeek.ToString();
        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);
    }
    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);
        }
    }
    private void fillStartDayddl(int PatternID)
    {
        ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(PatternID);
        foreach (DataRow drRow in ds_ShiftAllocdetails.Tables[0].Rows)
        {
            switch (drRow["name"].ToString())
            {
                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);
        //ddl_StartDay.Items.Insert(0, "-Select-");
        for (int i = 1; i <= Days; i++)
        {
            ddl_StartDay.Items.Add(i.ToString());
        }
        string Pattern = string.Empty;
        DataTable dt_Pattern = new DataTable();
        dt_Pattern = ds_ShiftAllocdetails.Tables[0];
        foreach (DataRow dr_Pattern in dt_Pattern.Rows)
        {
            Pattern += " " + dr_Pattern["name"].ToString();
        }
        lbl_Pattern.Text = Pattern;
    }
    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_TemporaryShiftAllocation_ScheduleFrom", ci) + "')";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strAlert, true);
                        //base.Message(rm.GetString("Validator_TemporaryShiftAllocation_ScheduleFrom", ci));
                        e.IsValid = false;
                    }
                }
                else
                {
                    e.IsValid = true;
                }
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    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 = "";
                    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);
                        //base.Message(rm.GetString("Validator_ShiftAllocation_ScheduleTo", ci));
                        e.IsValid = false;
                    }
                }
                else
                {
                    e.IsValid = true;
                }
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    /// <summary>
    /// shift pattern allocation
    /// </summary>
    private void ShiftpatternAllocation()
    {
        try
        {
            lblError.Text = string.Empty;
            //string strEmployeeIds = string.Empty;
            if (grv_Employees.Rows.Count == 0)
            {
                lblError.Text = rm.GetString("Alert_ClickAddButtontoselectEmployeesforShiftAllocation", ci);
                btn_Add.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_StartDate.Text == string.Empty)
            {
                lblError.Text = rm.GetString("Alert_ScheduleFromcannotbeEmpty", ci);
                txt_StartDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_ToDate.Text == string.Empty)
            {
                lblError.Text = rm.GetString("Msg_ScheduleTocannotbeEmpty", ci);
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_StartDate.Text.Length < 10)
            {
                lblError.Text = rm.GetString("Alert_InvalidScheduleFromDate", ci);
                txt_StartDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_ToDate.Text.Length < 10)
            {
                lblError.Text = rm.GetString("Alert_InvalidScheduleToDate", ci);
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strStartDate = objcls_Common.DateConvertion(gstrDateFormat, txt_StartDate.Text);
            strToDate = objcls_Common.DateConvertion(gstrDateFormat, txt_ToDate.Text);
            DateTime dtmStartDate = DateTime.Parse(strStartDate);
            DateTime dtmToDate = DateTime.Parse(strToDate);
            int Days = dtmToDate.CompareTo(dtmStartDate);
            //int intStartDay = int.Parse(ddl_StartDay.SelectedItem.Text);
            int intStartDay = int.Parse(ddl_StartDay.SelectedValue);
            if (Days < 0)
            {
                strAlert = string.Empty;
                strAlert = "alert('" + rm.GetString("Msg_ScheduleFromDateshouldbelesserthantheScheduleToDate", ci) + "')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strAlert, true);
                //lblError.Text = "Schedule From Date should be lesser than the Schedule To Date";
                //base.Message(rm.GetString("Msg_ScheduleFromDateshouldbelesserthantheScheduleToDate", ci));
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            // check for demo version or not
            DemoVersion objDemoVersion = new DemoVersion();
            string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
            int arrCount = fileArr.Length;
            if (arrCount > 0)
            {
                // continue with license file
                string licenseFileName = fileArr[arrCount - 1].ToString();
                //File Stream pointing to License File,if exist
                FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                //Stream Reader pointing to License  File
                StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                // read license request file information from .lrf file
                string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                //Close the Streams
                licenseFileStreamReader.Close();
                licenseFileStream.Close();
                try
                {
                    string decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
                }
                catch
                {
                    string strScriptAlert1 = "<script language='javascript' type='text/javascript'>";
                    strScriptAlert1 += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                    strScriptAlert1 += "location.href='../Index.aspx';";
                    strScriptAlert1 += " </script>";
                    this.RegisterStartupScript(rm.GetString("Alert_AlertLicInfoNotCorrect", ci), strScriptAlert1);
                    return;
                }
            }
            else
            {
                // continue as demo version
                bool demoContinue = false;
                demoContinue = objDemoVersion.CheckDVShiftAllocation(strStartDate, strToDate);
                if (demoContinue == true)
                {
                    // demo continue
                }
                else
                {
                    //string strScriptAlert = "<script language='javascript' type='text/javascript'>";
                    //strScriptAlert += "alert('This is Demo Version!, Cannot create shift allocation for those periods.');";
                    //strScriptAlert += " </script>";
                    //this.RegisterStartupScript("setScript", strScriptAlert);
                    //return;
                }
            }
            ds = objShiftAllocation.SelectEmployeeDetails(gintUserId);
            dtEmpDetails = ds.Tables[0];
            int[] Pattern = OverLappedValidationShiftPattern(dtmStartDate, dtmToDate, intStartDay);
            dtEmpDetails.DefaultView.RowFilter = "OverLapped=false";
            if (dtEmpDetails.DefaultView.ToTable().Rows.Count > 0)
            {
                IsUnOverlappedEmployeeExists = true;
            }
            //for (int i = 0; i < dtEmpDetails.Rows.Count; i++)
            //{
            //    if (strEmployeeIds == "")
            //    {
            //        if (Convert.ToBoolean(dtEmpDetails.Rows[i]["OverLapped"]) == false)
            //        {
            //            strEmployeeIds = dtEmpDetails.Rows[i]["EmpID"].ToString();
            //        }
            //    }
            //    else
            //    {
            //        if (Convert.ToBoolean(dtEmpDetails.Rows[i]["OverLapped"]) == false)
            //        {
            //            strEmployeeIds = strEmployeeIds + "," + dtEmpDetails.Rows[i]["EmpID"].ToString();
            //        }
            //    }
            //}
            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.ToInt16(drRow["Month"]) + "/1/" + Convert.ToInt16(drRow["Year"]);
                    objShiftAllocation.InsertTempShiftAllocation_Bulk(Convert.ToInt16(drRow["Year"]), Convert.ToInt16(drRow["Month"]), gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift, strWriteXML.ToString());
                }
                //foreach (DataRow drEmpDetails in dtEmpDetails.Rows)
                //{
                //    int intMonth = 0, intYear = 0;
                //    if (Convert.ToBoolean(drEmpDetails["OverLapped"]) == false)
                //    {
                //    for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
                //    {
                //        if ((intMonth != j.Month) || (intYear != j.Year))
                //        {
                //            string strDateShift = j.Month + "/1/" + j.Year;
                //            //// Check for Duplicate
                //            //intCount = objShiftAllocation.CheckTempShiftAllocation(int.Parse(drEmpDetails["EmpID"].ToString()), j.Year, j.Month);
                //            //if (intCount == 0)
                //            //{
                //                objShiftAllocation.InsertTempShiftAllocation(int.Parse(drEmpDetails["EmpID"].ToString()), j.Year, j.Month, gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift);
                //            //}
                //        }
                //        intMonth = j.Month;
                //        intYear = j.Year;
                //    }
                //    ////updating Clock Process Flag in Raw Data Table
                //    //objShiftAllocation.UpdateClockProcess(Convert.ToInt32(drEmpDetails["EmpID"]), dtmStartDate, dtmToDate);
                //    // Shift Allocation Re-Process
                //    //objShiftAllocation.ShiftAllocationReprocess(dtmStartDate, dtmToDate, Convert.ToInt32(drEmpDetails["EmpID"]));
                //  }
                //}
                //objShiftAllocation.ShiftAllocationReprocess(dtmStartDate, dtmToDate, strEmployeeIds);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            try
            {
                //if (strEmployeeIds != string.Empty)
                if (IsUnOverlappedEmployeeExists == true)
                {
                    //DataTable dtShiftIDs = new DataTable();
                    //ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(int.Parse(ddl_Pattern.SelectedValue));
                    //dtShiftIDs = ds_ShiftAllocdetails.Tables[0];
                    //int PatternDaysCount = dtShiftIDs.Rows.Count;
                    //int[] Pattern1 = new int[31];
                    //for (int i = 0; i < PatternDaysCount; i++)
                    //{
                    //    Pattern[i] = int.Parse(dtShiftIDs.Rows[i]["id"].ToString());
                    //}
                    int intMonth = 0, intYear = 0;
                    int p = intStartDay - 1;
                    string strUpdate = "UPDATE TA_Tbl_TemporaryShiftAllocation 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=" + Session["EmpAutoID"].ToString() + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                                //Response.Write("<br>" + strUpdate);
                                objShiftAllocation.UpdateShiftAllocation(strUpdate);
                                strUpdate = "UPDATE TA_Tbl_TemporaryShiftAllocation SET ";
                            }
                        }
                        intMonth = j.Month;
                        intYear = j.Year;
                        if (strUpdate == "UPDATE TA_Tbl_TemporaryShiftAllocation 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=" + Session["EmpAutoID"].ToString() + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                        }
                        if (p < (PatternDaysCount - 1))
                        {
                            p += 1;
                        }
                        else if (p >= (PatternDaysCount - 1))
                        {
                            p = 0;
                        }
                    }
                    //Response.Write("<br>" + strUpdate);
                    objShiftAllocation.UpdateShiftAllocation(strUpdate);
                    //Reprocess 
                    objShiftAllocation.ShiftAllocationReprocess_ProcessedData(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_ClockDetails(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_ManualEntry(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_RawData(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
            Session["EmpDetails"] = null;
            //txt_StartDate.Text = "";
            //txt_ToDate.Text = "";
            //ddl_Pattern.Items.Clear();
            //ddl_StartDay.Items.Clear();
            //Response.Redirect("TA_UI_Transaction_TemporaryShiftAllocationadd.aspx");
            // Response.Write("<script>alert('Shift Allocated Successfully');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');</script>");
            string strScript = "<script language='javascript' type='text/javascript'>";
            //if (strOverLappedEmployeeIds != string.Empty && strEmployeeIds == string.Empty)
            if (strOverLappedEmployeeIds.ToString() != string.Empty && IsUnOverlappedEmployeeExists == false)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftnotallocatedforemployeewithShiftOverLapping", ci) + " " + strOverLappedEmployeeIds + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //else if (strOverLappedEmployeeIds != string.Empty && strEmployeeIds != string.Empty)
            else if (strOverLappedEmployeeIds.ToString() != string.Empty && IsUnOverlappedEmployeeExists == true)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftAllocatedSuccessfullyExceptEmployeewithShiftOverLapping", ci) + " " + strOverLappedEmployeeIds + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //else if (strOverLappedEmployeeIds == string.Empty && strEmployeeIds != string.Empty)
            else if (strOverLappedEmployeeIds.ToString() == string.Empty && IsUnOverlappedEmployeeExists == true)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftAllocatedSuccessfully", ci) + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //strScript += "alert('Shift Allocated Successfully');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            strScript += " </script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            //this.RegisterStartupScript("setScript", strScript);
        }
        catch
        {
            //
        }
    }
    /// <summary>
    /// Shift allocation
    /// </summary>
    private void SimpleShiftAllocation()
    {
        try
        {
            lblError.Text = string.Empty;
            //string strEmployeeIds = string.Empty;
            if (grv_Employees.Rows.Count == 0)
            {
                lblError.Text = rm.GetString("Alert_ClickAddButtontoselectEmployeesforShiftAllocation", ci);
                btn_Add.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_StartDate.Text == string.Empty)
            {
                lblError.Text = rm.GetString("Alert_ScheduleFromcannotbeEmpty", ci);
                txt_StartDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_ToDate.Text == string.Empty)
            {
                lblError.Text = rm.GetString("Msg_ScheduleTocannotbeEmpty", ci);
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_StartDate.Text.Length < 10)
            {
                lblError.Text = rm.GetString("Alert_InvalidScheduleFromDate", ci);
                txt_StartDate.Focus();
                gstrIsValid = "F";
                return;
            }
            else if (txt_ToDate.Text.Length < 10)
            {
                lblError.Text = rm.GetString("Alert_InvalidScheduleToDate", ci);
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strStartDate = objcls_Common.DateConvertion(gstrDateFormat, txt_StartDate.Text);
            strToDate = objcls_Common.DateConvertion(gstrDateFormat, txt_ToDate.Text);
            DateTime dtmStartDate = DateTime.Parse(strStartDate);
            DateTime dtmToDate = DateTime.Parse(strToDate);
            int Days = dtmToDate.CompareTo(dtmStartDate);
            int intStartDay = getStartDay(dtmStartDate);
            if (Days < 0)
            {
                strAlert = string.Empty;
                strAlert = "alert('" + rm.GetString("Msg_ScheduleFromDateshouldbelesserthantheScheduleToDate", ci) + "')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strAlert, true);
                //lblError.Text = "Schedule From Date should be lesser than the Schedule To Date";
                //base.Message(rm.GetString("Msg_ScheduleFromDateshouldbelesserthantheScheduleToDate", ci));
                txt_ToDate.Focus();
                gstrIsValid = "F";
                return;
            }
            // check for demo version or not
            DemoVersion objDemoVersion = new DemoVersion();
            string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
            int arrCount = fileArr.Length;
            if (arrCount > 0)
            {
                // continue with license file
                string licenseFileName = fileArr[arrCount - 1].ToString();
                //File Stream pointing to License File,if exist
                FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                //Stream Reader pointing to License  File
                StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                // read license request file information from .lrf file
                string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                //Close the Streams
                licenseFileStreamReader.Close();
                licenseFileStream.Close();
                try
                {
                    string decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
                }
                catch
                {
                    string strScriptAlert1 = "<script language='javascript' type='text/javascript'>";
                    strScriptAlert1 += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                    strScriptAlert1 += "location.href='../Index.aspx';";
                    strScriptAlert1 += " </script>";
                    this.RegisterStartupScript("AlertLicInfoNotCorrect", strScriptAlert1);
                    return;
                }
            }
            else
            {
                // continue as demo version
                bool demoContinue = false;
                demoContinue = objDemoVersion.CheckDVShiftAllocation(strStartDate, strToDate);
                if (demoContinue == true)
                {
                    // demo continue
                }
                else
                {
                    string strScriptAlert = "<script language='javascript' type='text/javascript'>";
                    strScriptAlert += "alert('" + rm.GetString("Alert_ThisisDemoVersionCannotcreateshiftallocationforthoseperiods", ci) + "');";
                    strScriptAlert += " </script>";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScriptAlert, false);
                    //this.RegisterStartupScript("setScript", strScriptAlert);
                    return;
                }
            }
            ds = objShiftAllocation.SelectEmployeeDetails(gintUserId);
            dtEmpDetails = ds.Tables[0];
            int[] Pattern = OverLappedValidationShiftPattern(dtmStartDate, dtmToDate, intStartDay);
            dtEmpDetails.DefaultView.RowFilter = "OverLapped=false";
            if (dtEmpDetails.DefaultView.ToTable().Rows.Count > 0)
            {
                IsUnOverlappedEmployeeExists = true;
            }
            //for (int i = 0; i < dtEmpDetails.Rows.Count; i++)
            //{
            //    if (strEmployeeIds == "")
            //    {
            //        if (Convert.ToBoolean(dtEmpDetails.Rows[i]["OverLapped"]) == false)
            //        {
            //            strEmployeeIds = dtEmpDetails.Rows[i]["EmpID"].ToString();
            //        }
            //    }
            //    else
            //    {
            //        if (Convert.ToBoolean(dtEmpDetails.Rows[i]["OverLapped"]) == false)
            //        {
            //            strEmployeeIds = strEmployeeIds + "," + dtEmpDetails.Rows[i]["EmpID"].ToString();
            //        }
            //    }
            //}
            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.ToInt16(drRow["Month"]) + "/1/" + Convert.ToInt16(drRow["Year"]);
                    objShiftAllocation.InsertTempShiftAllocation_Bulk(Convert.ToInt16(drRow["Year"]), Convert.ToInt16(drRow["Month"]), gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift, strWriteXML.ToString());
                }
                //foreach (DataRow drEmpDetails in dtEmpDetails.Rows)
                //{
                //    int intMonth = 0, intYear = 0;
                //    if (Convert.ToBoolean(drEmpDetails["OverLapped"]) == false)
                //    {
                //        for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
                //        {
                //            if ((intMonth != j.Month) || (intYear != j.Year))
                //            {
                //                string strDateShift = j.Month + "/1/" + j.Year;
                //                //// Check for Duplicate
                //                //intCount = objShiftAllocation.CheckTempShiftAllocation(int.Parse(drEmpDetails["EmpID"].ToString()), j.Year, j.Month);
                //                //if (intCount == 0)
                //                //{
                //                    objShiftAllocation.InsertTempShiftAllocation(int.Parse(drEmpDetails["EmpID"].ToString()), j.Year, j.Month, gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift);
                //                //}
                //            }
                //            intMonth = j.Month;
                //            intYear = j.Year;
                //        }
                //        ////updating Clock Process Flag in Raw Data Table
                //        //objShiftAllocation.UpdateClockProcess(Convert.ToInt32(drEmpDetails["EmpID"]), dtmStartDate, dtmToDate);
                //        // Shift Allocation Re-Process
                //       // objShiftAllocation.ShiftAllocationReprocess(dtmStartDate, dtmToDate, Convert.ToInt32(drEmpDetails["EmpID"]));
                //    }
                //}
                //objShiftAllocation.ShiftAllocationReprocess(dtmStartDate, dtmToDate, strEmployeeIds);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            try
            {
                //if (strEmployeeIds != string.Empty)
                if (IsUnOverlappedEmployeeExists == true)
                {
                    //DataTable dtShiftIDs = new DataTable();
                    //int[] Pattern = new int[31];
                    PatternDaysCount = 7;
                    //ds_ShiftAllocdetails = objShiftAllocation.SelectShiftPattern_ShiftAllocDetails(int.Parse(ddl_Pattern.SelectedValue));
                    //dtShiftIDs = ds_ShiftAllocdetails.Tables[0];
                    //int PatternDaysCount = dtShiftIDs.Rows.Count;
                    //int[] Pattern = new int[31];
                    //for (int i = 0; i < PatternDaysCount; i++)
                    //{
                    //    Pattern[i] = int.Parse(dtShiftIDs.Rows[i]["id"].ToString());
                    //}
                    //Pattern = ShiftPatternSequence(); 
                    int intMonth = 0, intYear = 0;
                    int p = intStartDay - 1;
                    string strUpdate = "UPDATE TA_Tbl_TemporaryShiftAllocation 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 (" + strEmployeeIds + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                                strUpdate += " WHERE EmployeeId in (select EmpID from TA_Tbl_TempShiftAllocation where EmployeeId not in ('" + strOverLappedEmployeeIds + "') and LoginEmployeeId=" + Session["EmpAutoID"].ToString() + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                                //Response.Write("<br>" + strUpdate);
                                objShiftAllocation.UpdateShiftAllocation(strUpdate);
                                strUpdate = "UPDATE TA_Tbl_TemporaryShiftAllocation SET ";
                            }
                        }
                        intMonth = j.Month;
                        intYear = j.Year;
                        if (strUpdate == "UPDATE TA_Tbl_TemporaryShiftAllocation SET ")
                        {
                            strUpdate += "Day" + j.Day + "Shift = " + Pattern[p];
                        }
                        else
                        {
                            strUpdate += ",Day" + j.Day + "Shift = " + Pattern[p];
                        }
                        if (j == dtmToDate)
                        {
                            //strUpdate += " WHERE EmployeeId in (" + strEmployeeIds + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                            strUpdate += " WHERE EmployeeId in (select EmpID from TA_Tbl_TempShiftAllocation where EmployeeId not in ('" + strOverLappedEmployeeIds + "') and LoginEmployeeId=" + Session["EmpAutoID"].ToString() + ") AND Year = " + intYear + " AND Month = " + intMonth + "";
                        }
                        if (p < (PatternDaysCount - 1))
                        {
                            p += 1;
                        }
                        else if (p >= (PatternDaysCount - 1))
                        {
                            p = 0;
                        }
                    }
                    //Response.Write("<br>" + strUpdate);
                    objShiftAllocation.UpdateShiftAllocation(strUpdate);
                    //Reprocess 
                    objShiftAllocation.ShiftAllocationReprocess_ProcessedData(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_ClockDetails(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_ManualEntry(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                    objShiftAllocation.ShiftAllocationReprocess_RawData(dtmStartDate, dtmToDate, Session["EmpAutoID"].ToString());
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
            Session["EmpDetails"] = null;
            //txt_StartDate.Text = "";
            //txt_ToDate.Text = "";
            //ddl_Pattern.Items.Clear();
            //ddl_StartDay.Items.Clear();
            //Response.Redirect("TA_UI_Transaction_TemporaryShiftAllocationadd.aspx");
            // Response.Write("<script>alert('Shift Allocated Successfully');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');</script>");
            string strScript = "<script language='javascript' type='text/javascript'>";
            //if (strOverLappedEmployeeIds != string.Empty && strEmployeeIds == string.Empty)
            if (strOverLappedEmployeeIds.ToString() != string.Empty && IsUnOverlappedEmployeeExists == false)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftnotallocatedforemployeewithShiftOverLapping", ci) + " " + strOverLappedEmployeeIds + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //else if (strOverLappedEmployeeIds != string.Empty && strEmployeeIds != string.Empty)
            else if (strOverLappedEmployeeIds.ToString() != string.Empty && IsUnOverlappedEmployeeExists == true)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftAllocatedSuccessfullyExceptEmployeewithShiftOverLapping", ci) + " " + strOverLappedEmployeeIds + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //else if (strOverLappedEmployeeIds == string.Empty && strEmployeeIds != string.Empty)
            else if (strOverLappedEmployeeIds.ToString() == string.Empty && IsUnOverlappedEmployeeExists == true)
            {
                strScript += "alert('" + rm.GetString("Alert_ShiftAllocatedSuccessfully", ci) + "');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            }
            //strScript += "alert('Shift Allocated Successfully');location.replace('TA_UI_Transaction_TemporaryShiftAllocationadd.aspx');";
            strScript += " </script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
        }
        catch
        {
            //
        }
    }
    /// <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;
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_TemporaryShiftAllocation", ci);
        lbl_ActualPattern.Text = rm.GetString("ShiftAllocation_ActualPattern", ci);
        lbl_ScheduleFrom.Text = rm.GetString("ShiftAllocation_ScheduleFrom", ci);
        lbl_ScheduleTo.Text = rm.GetString("ShiftAllocation_ScheduleTo", ci);
        lbl_SelectedEmployees.Text = rm.GetString("ShiftAllocation_SelectedEmployees", ci);
        lbl_ShiftPattern.Text = rm.GetString("Masters_ShiftPattern", ci);
        lbl_StartDay.Text = rm.GetString("ShiftAllocation_StartDay", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        CustomValidator1.ErrorMessage = rm.GetString("Validator_TemporaryShiftAllocation_ScheduleFrom", ci);
        CustomValidator3.ErrorMessage = rm.GetString("Validator_ShiftAllocation_ScheduleTo", ci);
        lblDataView.Text = rm.GetString("lblDataView", ci);
        //rfvShiftPattern.ErrorMessage = rm.GetString("Alert_SelectShiftPattern", ci);
        //rfvStartDay.ErrorMessage = rm.GetString("Validator_ShiftAllocation_StartDay", ci);
        lblShiftRoaster.Text = rm.GetString("UserGroups_ShiftRoaster", ci);
        grv_Employees.Columns[2].HeaderText = rm.GetString("email_EmployeeId", ci);
        grv_Employees.Columns[3].HeaderText = rm.GetString("email_EmployeeName", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_ShiftAllocationView.Text = "&nbsp;&nbsp;" + rm.GetString("btn_ShiftAllocationView", ci);
        rbtnShiftPattern.Text = rm.GetString("Masters_ShiftPattern", ci);
        rbtnShifts.Text = rm.GetString("Menu_Reports_Shift", ci);
        lblShifts.Text = rm.GetString("ShiftTiming_ShiftName", ci);
        lblWeeklyOffDays.Text = rm.GetString("ShiftAllocationWeeklyOffDays", ci);
        lstWeeklyOffDays.Items[0].Text = rm.GetString("Monday", ci);
        lstWeeklyOffDays.Items[1].Text = rm.GetString("Tuesday", ci);
        lstWeeklyOffDays.Items[2].Text = rm.GetString("Wednesday", ci);
        lstWeeklyOffDays.Items[3].Text = rm.GetString("Thursday", ci);
        lstWeeklyOffDays.Items[4].Text = rm.GetString("Friday", ci);
        lstWeeklyOffDays.Items[5].Text = rm.GetString("Saturday", ci);
        lstWeeklyOffDays.Items[6].Text = rm.GetString("Sunday", ci);
        ddlShifts.Items[0].Text = rm.GetString("Select", ci);
        ddl_Pattern.Items[0].Text = rm.GetString("Select", ci);
        ddl_StartDay.Items[0].Text = rm.GetString("Select", ci);
        ddlShiftRoaster.Items[0].Text = rm.GetString("Select", ci);
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        lblSelectEmployee.Text = rm.GetString("Shift_SelectEmployee", 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);
    }
    public int[] OverLappedValidationShiftPattern(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);
        DataTable dtShiftIDs = new DataTable();
        //int[] Pattern = new int[31];
        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(dtShiftIDs.Rows[i]["id"].ToString());
            }
        }
        else if (rbtnShifts.Checked == true)
        {
            Pattern = ShiftPatternSequence();
        }
        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;
            }
        }
        //Each employee check overlapping
        foreach (DataRow dRow in ds.Tables[0].Rows)
        {
            intOverLapped = ConstructTemporaryShiftAllocation(Convert.ToInt32(dRow["EmpID"]), dtmStartDate, dtmToDate, intStartDay, StartDateShiftId, EndDateShiftId);
            if (intOverLapped > 0)
            {
                dRow["OverLapped"] = "True";
                if (strOverLappedEmployeeIds.ToString() == string.Empty)
                {
                    //strOverLappedEmployeeIds = dRow["EmployeeId"].ToString();
                    strOverLappedEmployeeIds.Append(dRow["EmployeeId"].ToString());
                }
                else
                {
                    //strOverLappedEmployeeIds = strOverLappedEmployeeIds + "," + dRow["EmployeeId"].ToString();
                    strOverLappedEmployeeIds.Append("," + dRow["EmployeeId"].ToString());
                }
            }
            else
            {
                dRow["OverLapped"] = "False";
            }
        }
        return Pattern;
        //Employee loop end here
    }
    public int ConstructTemporaryShiftAllocation(int EmployeeId, DateTime dtmStartDate, DateTime dtmToDate, int intStartDay, int StartDateShiftId, int EndDateShiftId)
    {
        chkShiftAllocationExists = false;
        int PreviousDayShiftId = 0;
        int NextDayShiftId = 0;
        //DataTable dtShiftIDs = new DataTable();
        //DataTable dtTemporaryShift = new DataTable();
        //dtTemporaryShift.TableName = "TemporaryShiftTable";
        //DataColumn dcEmployeeId = new DataColumn("EmployeeId");
        //DataColumn dcShiftDate = new DataColumn("ShiftDate", System.Type.GetType("System.DateTime"));
        //DataColumn dcShiftId = new DataColumn("ShiftId");
        //DataRow dRow;
        //dtTemporaryShift.Columns.Add(dcEmployeeId);
        //dtTemporaryShift.Columns.Add(dcShiftDate);
        //dtTemporaryShift.Columns.Add(dcShiftId);
        //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(dtShiftIDs.Rows[i]["id"].ToString());
        //    }
        //}
        //else if (rbtnShifts.Checked == true)
        //{
        //    Pattern = ShiftPatternSequence();
        //}
        //int p = intStartDay - 1;
        //for (DateTime j = dtmStartDate; j <= dtmToDate; j = j.AddDays(1))
        //{
        //    dRow = dtTemporaryShift.NewRow();
        //    dRow["EmployeeId"] = EmployeeId;
        //    dRow["ShiftDate"] = j.ToShortDateString();
        //    dRow["ShiftId"] = Pattern[p];
        //    dRow.EndEdit();
        //    dtTemporaryShift.Rows.Add(dRow);
        //    if (p < (PatternDaysCount - 1))
        //    {
        //        p += 1;
        //    }
        //    else if (p >= (PatternDaysCount - 1))
        //    {
        //        p = 0;
        //    }
        //}
        dtmStartDate = dtmStartDate.AddDays(-1);
        dtmToDate = dtmToDate.AddDays(1);
        DataSet dsPermanentTemporaryShift = new DataSet();
        //To get Previous Date shift to Start Date and Next Day shift to End Date.
        dsPermanentTemporaryShift = objShiftAllocation.SelectPermanentTemporaryShiftDates(dtmStartDate, dtmToDate, EmployeeId.ToString());
        if (dsPermanentTemporaryShift.Tables[0].Rows.Count > 0)
        {
            //Temporary shift allocation based on from date
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"] != null && dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"].ToString() != string.Empty)
            {
                chkShiftAllocationExists = true;
                PreviousDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_FromShiftId"]);
            }
            //Permanent shift allocation based on from date
            else if (dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"] != null && dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"].ToString() != string.Empty)
            {
                chkShiftAllocationExists = true;
                PreviousDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_FromShiftId"]);
            }
            //Temporary shift allocation based on to date
            if (dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"] != null && dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"].ToString() != string.Empty)
            {
                chkShiftAllocationExists = true;
                NextDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["T_ToShiftId"]);
            }
            //Permanent shift allocation based on to date
            else if (dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"] != null && dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"].ToString() != string.Empty)
            {
                chkShiftAllocationExists = true;
                NextDayShiftId = Convert.ToInt32(dsPermanentTemporaryShift.Tables[0].Rows[0]["P_ToShiftId"]);
            }
        }
        //Check shift Time Overlapping 
        if (chkShiftAllocationExists == true)
        {
            int intOverLap = 0;
            //int ShiftCount = dtPermanentShift.Rows.Count;
            //for (int i = 0; i < ShiftCount - 1; i++)
            //{
            //int ShiftId1 = Convert.ToInt32(dtPermanentShift.Rows[i]["ShiftId"]);
            //int ShiftId2 = Convert.ToInt32(dtPermanentShift.Rows[i + 1]["ShiftId"]);
            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;
        ////Add Previous Date shift to Start Date and Next Day shift to End Date and EmployeeId in PermanentShiftTable
        //DataSet dsTemporaryShiftAllocation = new DataSet();
        //dsTemporaryShiftAllocation = objShiftAllocation.SelectTemporaryShiftForDate(dtmStartDate, EmployeeId.ToString());
        //if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //{
        //    chkShiftAllocationExists = true;
        //}
        //if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //{
        //    dRow = dtTemporaryShift.NewRow();
        //    dRow["EmployeeId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["EmployeeId"].ToString();
        //    dRow["ShiftDate"] = Convert.ToDateTime(dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftDate"]);
        //    dRow["ShiftId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftId"].ToString();
        //    dRow.EndEdit();
        //    dtTemporaryShift.Rows.Add(dRow);
        //}
        //else
        //{
        //    dsTemporaryShiftAllocation = objShiftAllocation.SelectPermanentShiftForDate(dtmStartDate, EmployeeId.ToString());
        //    if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //    {
        //        chkShiftAllocationExists = true;
        //    }
        //    if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //    {
        //        dRow = dtTemporaryShift.NewRow();
        //        dRow["EmployeeId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["EmployeeId"].ToString();
        //        dRow["ShiftDate"] = Convert.ToDateTime(dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftDate"]);
        //        dRow["ShiftId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftId"].ToString();
        //        dRow.EndEdit();
        //        dtTemporaryShift.Rows.Add(dRow);
        //    }
        //    else
        //    {
        //        dRow = dtTemporaryShift.NewRow();
        //        dRow["EmployeeId"] = EmployeeId;
        //        dRow["ShiftDate"] = dtmStartDate.ToShortDateString();
        //        dRow["ShiftId"] = "0";
        //        dRow.EndEdit();
        //        dtTemporaryShift.Rows.Add(dRow);
        //    }
        //}
        //dsTemporaryShiftAllocation = objShiftAllocation.SelectTemporaryShiftForDate(dtmToDate, EmployeeId.ToString());
        //if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //{
        //    chkShiftAllocationExists = true;
        //}
        //if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //{
        //    dRow = dtTemporaryShift.NewRow();
        //    dRow["EmployeeId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["EmployeeId"].ToString();
        //    dRow["ShiftDate"] = Convert.ToDateTime(dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftDate"]);
        //    dRow["ShiftId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftId"].ToString();
        //    dRow.EndEdit();
        //    dtTemporaryShift.Rows.Add(dRow);
        //}
        //else
        //{
        //    dsTemporaryShiftAllocation = objShiftAllocation.SelectPermanentShiftForDate(dtmToDate, EmployeeId.ToString());
        //    if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //    {
        //        chkShiftAllocationExists = true;
        //    }
        //    if (dsTemporaryShiftAllocation.Tables[0].Rows.Count > 0)
        //    {
        //        dRow = dtTemporaryShift.NewRow();
        //        dRow["EmployeeId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["EmployeeId"].ToString();
        //        dRow["ShiftDate"] = Convert.ToDateTime(dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftDate"]);
        //        dRow["ShiftId"] = dsTemporaryShiftAllocation.Tables[0].Rows[0]["ShiftId"].ToString();
        //        dRow.EndEdit();
        //        dtTemporaryShift.Rows.Add(dRow);
        //    }
        //    else
        //    {
        //        dRow = dtTemporaryShift.NewRow();
        //        dRow["EmployeeId"] = EmployeeId;
        //        dRow["ShiftDate"] = dtmToDate.ToShortDateString();
        //        dRow["ShiftId"] = "0";
        //        dRow.EndEdit();
        //        dtTemporaryShift.Rows.Add(dRow);
        //    }
        //}
        //DataView dView = new DataView();
        //dView = (DataView)dtTemporaryShift.DefaultView;
        //dView.Sort = "ShiftDate";
        //dtTemporaryShift = dView.ToTable();
        ////Get Permanent Shift Allocation table data from Database using (Previous Date shift to Start Date and Next Day shift to End Date and EmployeeId)  
        //DataSet dsPermanentShiftAllocation = new DataSet();
        //dsPermanentShiftAllocation = objShiftAllocation.SelectPermanentShiftAllocationForDates(dtmStartDate, dtmToDate, EmployeeId.ToString());
        //if (dsPermanentShiftAllocation.Tables[0].Rows.Count > 0)
        //{
        //    chkShiftAllocationExists = true;
        //}
        //DataTable dtPermanentShiftAllocation = new DataTable();
        //if (dsPermanentShiftAllocation.Tables.Count > 0)
        //{
        //    dtPermanentShiftAllocation = dsPermanentShiftAllocation.Tables[0];
        //}
        ////Overwrite PermanentshiftTable using Temporaray Shift Allocation Table Based on Employee Id and ShiftIds
        //if (dtPermanentShiftAllocation != null)
        //{
        //    foreach (DataRow dRowTempShift in dtTemporaryShift.Rows)
        //    {
        //        foreach (DataRow dRowPermanentShift in dtPermanentShiftAllocation.Rows)
        //        {
        //            if (dRowTempShift["EmployeeId"].ToString() == dRowPermanentShift["EmployeeId"].ToString() && Convert.ToDateTime(dRowTempShift["ShiftDate"]).ToString() == Convert.ToDateTime(dRowPermanentShift["ShiftDate"]).ToString())
        //            {
        //                if (dRowTempShift["ShiftId"].ToString() == "0" || dRowTempShift["ShiftId"].ToString() == "")
        //                {
        //                }
        //                else
        //                {
        //                    dRowPermanentShift["ShiftId"] = dRowTempShift["ShiftId"];
        //                }
        //            }
        //        }
        //    }
        //}
        //else
        //{
        //    dtPermanentShiftAllocation = dtTemporaryShift;
        //}
        //if (chkShiftAllocationExists == true)
        //{
        //    //Check shift Time Overlapping 
        //    ShiftPatternEventData objShiftPatternOverLap = new ShiftPatternEventData();
        //    DataSet dsOverLapping = new DataSet();
        //    int intOverLap = 0;
        //    int ShiftCount = dtPermanentShiftAllocation.Rows.Count;
        //    for (int i = 0; i < ShiftCount - 1; i++)
        //    {
        //        int ShiftId1 = Convert.ToInt32(dtPermanentShiftAllocation.Rows[i]["ShiftId"]);
        //        int ShiftId2 = Convert.ToInt32(dtPermanentShiftAllocation.Rows[i + 1]["ShiftId"]);
        //        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;
    }
    #endregion
    #region Button Events
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if (rbtnShiftPattern.Checked == true)
        {
            if (Page.IsValid)
            {
                ShiftpatternAllocation();
                if (gstrIsValid == "F")
                {
                    return;
                }
            }
        }
        else if (rbtnShifts.Checked == true)
        {
            if (Page.IsValid)
            {
                //CheckLicense();
                //ts = DateTime.Parse(strToDate).Subtract(DateTime.Parse(strStartDate));
                //if (ts.Days > 730)
                //{
                //    base.Message("Shift cannot be allocated for more than 2 years");
                //    return;
                //}
                SimpleShiftAllocation();
                if (gstrIsValid == "F")
                {
                    return;
                }
            }
        }
        if (rbtnMultiple.Checked == true)
        {
            Session["ISSingleorMultiple"] = "IsMultiple";
        }
        else
        {
            Session["ISSingleorMultiple"] = "IsSingle";
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        objShiftAllocation.DeleteEmpShiftDetails(gintUserId);
        Session["EmpDetails"] = null;
        Response.Redirect("TA_UI_Transaction_TemporaryShiftAllocationadd.aspx");
    }
    #endregion
    #region Grid events
    protected void grv_Employees_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Employees.PageIndex = e.NewPageIndex;
        fillEmployee();
    }
    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();
    }
    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;
        }
    }
    #endregion
    #region Dropdown events
    protected void ddl_Pattern_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_Pattern.SelectedValue != "-Select-")
        {
            int index = Convert.ToInt32(ddl_Pattern.SelectedValue);
            fillStartDayddl(index);
        }
        else
        {
            ddl_StartDay.Items.Clear();
            ListItem liSelect = new ListItem();
            liSelect.Value = "-Select-";
            liSelect.Text = rm.GetString("Select", ci);
            ddl_StartDay.Items.Insert(0, liSelect);
            //ddl_StartDay.Items.Insert(0, "-Select-");
            lbl_Pattern.Text = string.Empty;
        }
    }
    #endregion
    #region Not used
    //private void getEmployeeIDs()
    //{
    //    ds_Empdetails = (DataSet)Session["EmpDetails"];
    //    if (ds_Empdetails != null)
    //    {
    //        int count = ds_Empdetails.Tables[0].Rows.Count;
    //        for (int i = 0; i < count; i++)
    //        {
    //            if (IDs == "")
    //            {
    //                IDs = ds_Empdetails.Tables[0].Rows[i]["EmployeeId"].ToString();
    //            }
    //            else
    //            {
    //                IDs = IDs + "," + ds_Empdetails.Tables[0].Rows[i]["EmployeeId"].ToString();
    //            }
    //        }
    //    }
    //}
    //private void ShiftroasterAllocation()
    //{
    //    try
    //    {
    //        // Dataset ds_Empdetails stores the selected employee details
    //        ds_Empdetails = GetEmployeeDetails();
    //        // For each Employee Insert shiftPattern Details
    //        InsertandUpdateEmployeeDetails(ds_Empdetails);
    //    }
    //    catch
    //    {
    //        //
    //    }
    //}
    /// <summary>
    /// Fetch Employee Details
    /// </summary>
    /// <returns></returns>
    //private DataSet GetEmployeeDetails()
    //{
    //    DataSet ds_Employee = new DataSet();
    //    try
    //    {
    //        ds_Employee = objShiftAllocation.SelectEmployeeDetails(gintUserId);
    //    }
    //    catch
    //    {
    //        //
    //    }
    //    return ds_Employee;
    //}
    //private void InsertandUpdateEmployeeDetails(DataSet ds)
    //{
    //    try
    //    {
    //        string strStartDate = "", strToDate = "";
    //        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
    //        strStartDate = objcls_Common.DateConvertion(gstrDateFormat, txt_StartDate.Text);
    //        strToDate = objcls_Common.DateConvertion(gstrDateFormat, txt_ToDate.Text);
    //        dtFromdate = Convert.ToDateTime(strStartDate);
    //        dtTodate = Convert.ToDateTime(strToDate);
    //        foreach (DataRow drEmpDetails in ds.Tables[0].Rows)
    //        {
    //            //int fromMonth = 0, tomonth = 0;
    //            int intMonth = 0, intYear = 0, Count;
    //            for (DateTime jd = dtFromdate; jd <= dtTodate; jd = jd.AddDays(1))
    //            {
    //                if ((intMonth != jd.Month) || (intYear != jd.Year))
    //                {
    //                    //Gernerate Current year in Date Time Format
    //                    string strDateShift = dtFromdate.Month + "/1/" + dtFromdate.Year;
    //                    //Checking for duplicate
    //                    Count = objShiftAllocation.CheckTempShiftAllocation(int.Parse(drEmpDetails["EmpID"].ToString()), jd.Year, jd.Month);
    //                    if (Count == 0)
    //                    {
    //                        objShiftAllocation.InsertTempShiftAllocation(Convert.ToInt16(drEmpDetails["EmpID"].ToString()), jd.Year, jd.Month, gintUserId, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"), strDateShift);
    //                    }
    //                    //month = dtTodate.Month;
    //                    //year = dtTodate.Year;
    //                }
    //                intMonth = jd.Month;
    //                intYear = jd.Year;
    //            }
    //        }
    //        int j = 0;
    //        // Fetching Shift Roaster Details and Insert ShiftPatternId in Hash Table
    //        DataSet ds_ShiftRoaster = objShiftRoaster.SelectShiftRoasterById(Convert.ToInt16(ddlShiftRoaster.SelectedValue));
    //        hs_PatternId.Clear();
    //        for (int i = 1; i <= 10; i++)
    //        {
    //            string str = "Pattern" + i.ToString().Trim();
    //            // If the patternId is 0 then Skip insert ShiftId in Hash Table
    //            if (Convert.ToInt16(ds_ShiftRoaster.Tables[0].Rows[0][str]) != 0)
    //            {
    //                hs_PatternId.Add(j, Convert.ToInt16(ds_ShiftRoaster.Tables[0].Rows[0][str]));
    //                j = j + 1;
    //            }
    //        }
    //        // Update Permanent Shift Allocation
    //        //int frmmonth, tmonth;
    //        //tmonth = 1;
    //        int count;
    //        int p = 0, q = 0, c = 0;
    //        for (DateTime dt1 = dtFromdate; dt1 <= dtTodate; dt1 = dt1.AddDays(1))
    //        {
    //            if ((p != dt1.Month) || (q != dt1.Year))
    //            {
    //                months[c] = dt1.Month;
    //                hs_year.Add(c, dt1.Year);
    //                c++;
    //            }
    //            p = dt1.Month;
    //            q = dt1.Year;
    //        }
    //        /*for (p = 0, q = dtFromdate.Month; q <= dtTodate.Month; q++)
    //        {
    //            months[p] = q;
    //            hs_year.Add(q, "");
    //            p++;
    //        }
    //        count = p;*/
    //        count = c;
    //        //For each Employee
    //        foreach (DataRow drEmpDetails in ds.Tables[0].Rows)
    //        {
    //            int haskey = 0, ptId = 1;
    //            bool MonthStatus = false;
    //            for (int x = 0; x < count; x++)
    //            {
    //                int Nodays = 0, f = 0;
    //                Nodays = obj_NumberofDays.NumberofDays(Convert.ToInt16(months[x]), Convert.ToInt16(hs_year[x]));
    //                int infrom = 0, into = 0;
    //                //both starting month and end month are same then from date is start day of the month and end date is 
    //                //total number of days of that month
    //                if (x == 0)
    //                {
    //                    if (dtFromdate.Month == dtTodate.Month)
    //                    {
    //                        infrom = dtFromdate.Day;
    //                        into = dtTodate.Day;
    //                    }
    //                    else
    //                    {
    //                        infrom = dtFromdate.Day;
    //                        into = Nodays;
    //                    }
    //                }
    //                else if (x == count - 1)
    //                {
    //                    infrom = 1;
    //                    into = dtTodate.Day;
    //                }
    //                else
    //                {
    //                    infrom = 1;
    //                    into = Nodays;
    //                }
    //                string[] ShiftId = new string[32] { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
    //                                              "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
    //                //int flag = 0;
    //                for (hskey = haskey; hskey < hs_PatternId.Count; hskey++)
    //                {
    //                    //int month1 = 0;
    //                    ds_ShiftPattern = objShiftAllocation.Shiftpattern(Convert.ToInt16(hs_PatternId[hskey].ToString()));
    //                    //if (fromMonth != dtTodate.Month)
    //                    //{
    //                    for (f = infrom; f <= into; f++)
    //                    {
    //                        string strcol = "Day" + ptId.ToString() + "_Shift".Trim(); ;
    //                        ShiftId[f] = ds_ShiftPattern.Tables[0].Rows[0][strcol].ToString();
    //                        //if the value of patternid is 0 then control transfer to the next pattern  
    //                        if (Convert.ToInt16(ShiftId[f]) == 0)
    //                        {
    //                            infrom = f;
    //                            ptId = 1;
    //                            break;
    //                        }
    //                        //if the value of f Reaches number of days then Update the permanent shift allocation table
    //                        if (into == f)
    //                        {
    //                            objShiftRoaster.UpdateTempShiftAllocation_AfterInsert(Convert.ToInt16(drEmpDetails["EmpID"].ToString()), Convert.ToInt16(hs_year[x]), Convert.ToInt16(months[x]), Convert.ToInt16(ShiftId[1]), Convert.ToInt16(ShiftId[2]), Convert.ToInt16(ShiftId[3]), Convert.ToInt16(ShiftId[4]), Convert.ToInt16(ShiftId[5]), Convert.ToInt16(ShiftId[6]), Convert.ToInt16(ShiftId[7]), Convert.ToInt16(ShiftId[8]), Convert.ToInt16(ShiftId[9]), Convert.ToInt16(ShiftId[10]), Convert.ToInt16(ShiftId[11]), Convert.ToInt16(ShiftId[12]), Convert.ToInt16(ShiftId[13]), Convert.ToInt16(ShiftId[14]), Convert.ToInt16(ShiftId[15]), Convert.ToInt16(ShiftId[16]), Convert.ToInt16(ShiftId[17]), Convert.ToInt16(ShiftId[18]), Convert.ToInt16(ShiftId[19]), Convert.ToInt16(ShiftId[20]), Convert.ToInt16(ShiftId[21]), Convert.ToInt16(ShiftId[22]), Convert.ToInt16(ShiftId[23]), Convert.ToInt16(ShiftId[24]), Convert.ToInt16(ShiftId[25]), Convert.ToInt16(ShiftId[26]), Convert.ToInt16(ShiftId[27]), Convert.ToInt16(ShiftId[28]), Convert.ToInt16(ShiftId[29]), Convert.ToInt16(ShiftId[30]), Convert.ToInt16(ShiftId[31]));
    //                            MonthStatus = true;
    //                            haskey = hskey;
    //                            ptId = ptId + 1;
    //                            break;
    //                        }
    //                        ptId = ptId + 1;
    //                    }
    //                    //Rotates the Shiftroaster   
    //                    if (hskey == hs_PatternId.Count - 1)
    //                    {
    //                        hskey = -1;
    //                        infrom = f;
    //                    }
    //                    if (MonthStatus == true && f == into && Convert.ToInt16(ShiftId[f]) != 0)
    //                    {
    //                        break;
    //                    }
    //                    //Rotates the Shiftroaster   
    //                    if (hskey == hs_PatternId.Count - 1 && f != Nodays)
    //                    {
    //                        hskey = -1;
    //                        infrom = f;
    //                    }
    //                }
    //                //objShiftRoaster.UpdateShiftRoaster_AfterInsert(dtFromdate.Year, fromMonth, Convert.ToInt16(ShiftId[1]), Convert.ToInt16(ShiftId[2]), Convert.ToInt16(ShiftId[3]), Convert.ToInt16(ShiftId[4]), Convert.ToInt16(ShiftId[5]), Convert.ToInt16(ShiftId[6]), Convert.ToInt16(ShiftId[7]), Convert.ToInt16(ShiftId[8]), Convert.ToInt16(ShiftId[9]), Convert.ToInt16(ShiftId[10]), Convert.ToInt16(ShiftId[11]), Convert.ToInt16(ShiftId[12]), Convert.ToInt16(ShiftId[13]), Convert.ToInt16(ShiftId[14]), Convert.ToInt16(ShiftId[15]), Convert.ToInt16(ShiftId[16]), Convert.ToInt16(ShiftId[17]), Convert.ToInt16(ShiftId[18]), Convert.ToInt16(ShiftId[19]), Convert.ToInt16(ShiftId[20]), Convert.ToInt16(ShiftId[21]), Convert.ToInt16(ShiftId[22]), Convert.ToInt16(ShiftId[23]), Convert.ToInt16(ShiftId[24]), Convert.ToInt16(ShiftId[25]), Convert.ToInt16(ShiftId[26]), Convert.ToInt16(ShiftId[27]), Convert.ToInt16(ShiftId[28]), Convert.ToInt16(ShiftId[29]), Convert.ToInt16(ShiftId[30]), Convert.ToInt16(ShiftId[31]));
    //            }
    //        }
    //    }
    //    catch
    //    {
    //        //
    //    }
    //}
    ///// <summary>
    ///// Fill ShiftRoaster dropdown
    ///// </summary>
    //private void fillShiftRoasterddl()
    //{
    //    DataSet ds_ShiftRoaster = new DataSet();
    //    try
    //    {
    //        ds_ShiftRoaster = objShiftRoaster.SelectShiftRoaster(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), Convert.ToInt16(Session["parentLevelId"]));
    //        ddlShiftRoaster.DataTextField = "ShiftRoaster_Name";
    //        ddlShiftRoaster.DataValueField = "ShiftRoaster_Id";
    //        ddlShiftRoaster.DataSource = ds_ShiftRoaster;
    //        ddlShiftRoaster.DataBind();
    //        ds_ShiftRoaster.Dispose();
    //    }
    //    catch
    //    {
    //        //
    //    }
    //}
    //Getting Information from resource file and display it in label
    #endregion
}
