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;
public partial class Transactions_ShiftAllocationView_Popup : Base.BasePage
{
    string strFromdate, gstrDateFormat, strTodate;
    cls_Common objCommon = new cls_Common();
    GetReports rptEmp = new GetReports();
    ShiftAllocationEvendata objShiftAllocation = new ShiftAllocationEvendata();
    ShiftPatternEventData objShiftPatternOverLap = new ShiftPatternEventData();
    Rpt_Common rptcommon = new Rpt_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    DataTable dtShiftShortName = new DataTable();
    DataSet dsShiftAllocation = new DataSet();
    DataSet dsTempShiftAllocation = new DataSet();
    string Shift;
    string Level = "";
    bool checkRowsExist;
    bool checkRowsExistInTemp;
    CultureInfo ci;
    ResourceManager rm;
    protected override void Page_Load(object sender, EventArgs e)
    {
        checkRowsExist = true;
        checkRowsExistInTemp = true;
        Shift = Request.QueryString["Shift"].ToString();
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
       Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
     //   Hidden1.Value = DateTime.Now.ToString(Session["MDateFormat"].ToString()); //added on Dec 23 2019
        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;
        aspnetForm.Attributes.CssStyle.Add("Direction", rm.GetString("Direction", ci));
        LoadStrings(ci);
        loadcss();
        if (!IsPostBack)
        {
            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();
            lblTemp.Visible = false;
            lblPermanent.Visible = false;
            BindingReligion();
        }
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages_DeleteRestore('" + rm.GetString("Alert_ConfirmDelete", ci) + "','" + rm.GetString("Alert_SelectItemsToDelete", ci) + "','" + rm.GetString("Alert_ConfirmDeletePermanent", ci) + "','" + rm.GetString("Alert_Areyousuretorestore", ci) + "','" + rm.GetString("Alert_SelectItemsToRestore", ci) + "','" + rm.GetString("Alert_SelectItemToForwarded") + "','" + rm.GetString("Alert_SelectItemToApproved") + "');";
        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_ValiddatemonthMMDDYYHHMMTTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterToDate", ci) + "','" + rm.GetString("Alert_EnterDate", ci) + "');";
        strSetAlert = strSetAlert + "MaxLen('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        if (Convert.ToString(Session["Demo"]) != string.Empty)
        {
            if (Convert.ToString(Session["Demo"]) == "Express")
            {
                grdTemp.Columns[35].Visible = false;
                grv_Shift.Columns[35].Visible = false;
            }
        }
    }
    /// <summary>
    /// Bindings the employee category and type.
    /// </summary>
    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
            foreach (ListItem item in ddlEmpCatagory.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        // employee type binding
        DataSet dsType = new DataSet();
        dsType = objEmployee.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();
            foreach (ListItem item in ddlEmpType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    /// <summary>
    /// Compare ToDate with FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            strTodate = txtToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            DateTime dtToDate = DateTime.Parse(strTodate);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
            {
                base.Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }
    protected void btn_View_Click(object sender, EventArgs e)
    {
        // Added by Gopinath.k on 12Aug14 for Bug No.22780
        string strScript = string.Empty;
        string strStatus = string.Empty;
        strScript = strScript + "<script language='javascript'>";
        if (Session["parentLevelId"] == null || Convert.ToInt32(Session["parentLevelId"]) == 0)
        {
            // strStatus = "Select a company";
            strStatus = rm.GetString("Alert_SelectCompany", ci);
            strScript = strScript + "alert('" + strStatus + "');";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertManualApproval", strScript);
            return;
        }
        dsShiftAllocation = fillShiftAllocationDetails();
        dsTempShiftAllocation = fillTempShiftAllocationDetails();
        if (checkRowsExist == false && checkRowsExistInTemp == false)
        {
            grv_Shift.DataSource = null; grv_Shift.DataBind();
            grdTemp.DataSource = null; grdTemp.DataBind();
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_Thereisnorecord", ci) + "');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message", strMsg);
            grv_Shift.Visible = false;
            return;
        }
        if (dsShiftAllocation.Tables.Count > 0)
        {
            if (dsShiftAllocation.Tables[0].Rows.Count > 0)
            {
                if (Shift == "Permanent")
                {
                    lblPermanent.Visible = true;
                }
                else
                {
                    lblPermanent.Visible = true;
                    lblPermanent.Text = "Temporary Shift Allocation";
                }
                Session["sessiondsShiftAllocation"] = dsShiftAllocation;
                grv_Shift.Visible = true;
                grdTemp.Visible = true;
                divGrid.Visible = true;
                if (ViewState["vsLevel"] == null)
                {
                    if (grv_Shift.EditIndex != 0)
                    {
                        grv_Shift.EditIndex = -1;
                    }
                    grv_Shift.DataSource = null;
                    grv_Shift.DataSource = dsShiftAllocation;
                    grv_Shift.DataBind();
                    ViewState["vsLevel"] = Level;
                }
                else if (ViewState["vsLevel"].ToString() != Level)
                {
                    grv_Shift.PageIndex = 0;
                    if (grv_Shift.EditIndex != 0)
                    {
                        grv_Shift.EditIndex = -1;
                    }
                    grv_Shift.DataSource = null; grv_Shift.DataBind();
                    grv_Shift.DataSource = dsShiftAllocation;
                    grv_Shift.DataBind();
                    ViewState["vsLevel"] = Level;
                }
                else
                {
                    grv_Shift.PageIndex = 0;
                    if (grv_Shift.EditIndex != 0)
                    {
                        grv_Shift.EditIndex = -1;
                    }
                    grv_Shift.DataSource = null; grv_Shift.DataBind();
                    grv_Shift.DataSource = dsShiftAllocation;
                    grv_Shift.DataBind();
                    ViewState["vsLevel"] = Level;
                }
            }
            else
            {
                if (Shift == "Permanent")
                {
                    lblPermanent.Visible = true;
                }
                else
                {
                    lblPermanent.Visible = true;
                    lblPermanent.Text = "Temporary Shift Allocation";
                }
                //  dsShiftAllocation.Tables[0].Rows.Add(dsShiftAllocation.Tables[0].NewRow());
                if (grv_Shift.EditIndex != 0)
                {
                    grv_Shift.EditIndex = -1;
                }
                grv_Shift.DataSource = null; grv_Shift.DataBind();
                grv_Shift.DataSource = dsShiftAllocation;
                grv_Shift.DataBind();
                //int columncount = grv_Shift.Rows[0].Cells.Count;
                //grv_Shift.Rows[0].Cells.Clear();
                //grv_Shift.Rows[0].Cells.Add(new TableCell());
                //grv_Shift.Rows[0].Cells[0].ColumnSpan = columncount;
                //grv_Shift.Rows[0].Cells[0].Style.Add("text-align", "Center");
                //grv_Shift.Rows[0].Cells[0].Text = "No Records Found";
            }
        }
        if (dsTempShiftAllocation.Tables.Count > 0)
        {
            if (dsTempShiftAllocation.Tables[0].Rows.Count > 0)
            {
                lblTemp.Visible = true;
                Session["sessiondsTempShiftAllocation"] = dsTempShiftAllocation;
                grdTemp.Visible = true;
                grv_Shift.Visible = true;
                divGrid.Visible = true;
                if (ViewState["vsLevel"] == null)
                {
                    if (grdTemp.EditIndex != 0)
                    {
                        grdTemp.EditIndex = -1;
                    }
                    grdTemp.DataSource = null; grdTemp.DataBind();
                    grdTemp.DataSource = dsTempShiftAllocation;
                    grdTemp.DataBind();
                    ViewState["vsLevel"] = Level;
                }
                else if (ViewState["vsLevel"].ToString() != Level)
                {
                    grdTemp.PageIndex = 0;
                    if (grdTemp.EditIndex != 0)
                    {
                        grdTemp.EditIndex = -1;
                    }
                    grdTemp.DataSource = null; grdTemp.DataBind();
                    grdTemp.DataSource = dsTempShiftAllocation;
                    grdTemp.DataBind();
                    ViewState["vsLevel"] = Level;
                }
                else
                {
                    grdTemp.PageIndex = 0;
                    if (grdTemp.EditIndex != 0)
                    {
                        grdTemp.EditIndex = -1;
                    }
                    grdTemp.DataSource = null; grdTemp.DataBind();
                    grdTemp.DataSource = dsTempShiftAllocation;
                    grdTemp.DataBind();
                    ViewState["vsLevel"] = Level;
                }
            }
            else
            {
                if (Shift == "Permanent")
                {
                    lblTemp.Visible = true;
                }
                // dsTempShiftAllocation.Tables[0].Rows.Add(dsTempShiftAllocation.Tables[0].NewRow());
                if (grdTemp.EditIndex != 0)
                {
                    grdTemp.EditIndex = -1;
                }
                grdTemp.DataSource = null; grdTemp.DataBind();
                grdTemp.DataSource = dsTempShiftAllocation;
                grdTemp.DataBind();
                //int columncount = grdTemp.Rows[0].Cells.Count;
                //grdTemp.Rows[0].Cells.Clear();
                //grdTemp.Rows[0].Cells.Add(new TableCell());
                //grdTemp.Rows[0].Cells[0].ColumnSpan = columncount;
                //grdTemp.Rows[0].Cells[0].Style.Add("text-align", "Center");
                //grdTemp.Rows[0].Cells[0].Text = "No Records Found";
            }
        }
        //if (grv_Shift.DataSource != null)
        //{
        //    divPermanentShift.Style.Add("Border", "Solid 1px Black");
        //}
        //if (grdTemp.DataSource != null)
        //{
        //    divTempShift.Style.Add("Border", "Solid 1px Black");
        //}
    }
    public DataSet fillShiftAllocationDetails()
    {
        try
        {
            if (this.Page.IsValid == true)
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                string dtFrom = "", dtTo = "";
                int employeeCategory = 0, employeeType = 0;
                if (txtFromDate.Text != "")
                {
                    strFromdate = txtFromDate.Text;
                    strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
                    dtFrom = strFromdate;
                }
                if (txtToDate.Text != "")
                {
                    strTodate = txtToDate.Text;
                    strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
                    dtTo = strTodate;
                }
                string empName = "";
                empName = txtEmployeeName.Text.Trim();
                string EmployeeId;
                EmployeeId = txtEmployeeId.Text.Trim();
                // set employee category and type
                if (Convert.ToInt32(ddlEmpCatagory.SelectedValue) != 0)
                {
                    employeeCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
                }
                else
                {
                    employeeCategory = 0;
                }
                if (Convert.ToInt32(ddlEmpType.SelectedValue) != 0)
                {
                    employeeType = Convert.ToInt32(ddlEmpType.SelectedValue);
                }
                else
                {
                    employeeType = 0;
                }
                if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                {
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                }
                //Get the Report source from the Server and load this into the report table
                string strSwipeCard = "";
                strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
                string employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                Session["dtFrom"] = dtFrom;
                Session["dtTo"] = dtTo;
                Session["employeeName"] = employeeName;
                Session["Level"] = Level;
                Session["EmpId"] = EmployeeId;
                Session["employeeCategory"] = employeeCategory;
                Session["employeeType"] = employeeType;
                Session["strSwipeCard"] = strSwipeCard;
                Session["EmpParent"] = Convert.ToInt16(Session["parentLevelId"]);
                int EmpAutoId = 0;
                if (Session["ReportsBasedOn"] != null)
                {
                    if (Session["ReportsBasedOn"].ToString() == "False")
                    {
                        EmpAutoId = 0;
                    }
                    else
                    {
                        EmpAutoId = Convert.ToInt32(Session["EmpAutoID"]);
                    }
                }
                if (Shift == "Permanent")
                {
                    //Session["dtFrom"] = dtFrom;
                    //Session["dtTo"] = dtTo;
                    //Session["employeeName"] = employeeName;
                    //Session["Level"] = Level;
                    //Session["EmpId"] = EmployeeId;
                    //Session["employeeCategory"] = employeeCategory;
                    //Session["employeeType"] = employeeType;
                    //Session["strSwipeCard"] = strSwipeCard;
                    //Session["EmpParent"] = Convert.ToInt16(Session["parentLevelId"]);
                    dsShiftAllocation = rptEmp.SelectShiftAllocationReport(dtFrom, dtTo, employeeName, Level, EmployeeId, employeeCategory, employeeType, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipeCard, Convert.ToInt16(Session["parentLevelId"]), 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue), EmpAutoId);
                }
                //else if (Shift == "Temporary")
                //{
                //    //Fill Data to Dataset dsTempShiftAllocation
                //    string levelId = Level;
                //    dsShiftAllocation = rptEmp.SelectTempShiftAllocationReport(dtFrom, dtTo, employeeName, levelId, EmployeeId, employeeCategory, employeeType, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipeCard, Convert.ToInt16(Session["parentLevelId"]), 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue));
                //}
                // Session["parentLevelId"] = null;
                DataTable dtSift = new DataTable();
                //Check the Empty table 
                if (dsShiftAllocation.Tables["Table"] == null || dsShiftAllocation.Tables["Table"].Rows.Count == 0)
                {
                    checkRowsExist = false;
                    return dsShiftAllocation;
                }
                else
                {
                    //start
                    strFromdate = txtFromDate.Text;
                    strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
                    int fromDay = DateTime.Parse(strFromdate).Day;
                    int fromMonth = DateTime.Parse(strFromdate).Month;
                    int fromYear = DateTime.Parse(strFromdate).Year;
                    strTodate = txtToDate.Text;
                    strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
                    int toMonth = DateTime.Parse(strTodate).Month;
                    int toDay = DateTime.Parse(strTodate).Day;
                    int toYear = DateTime.Parse(strTodate).Year;
                    //int chkFlag = 0;
                    // int endFlag = 0;
                    int j = 0;
                    //Following line commented due to Multidatabase usage
                    //cl.fillDT("Proc_TA_GetShiftShortName", dtShiftShortName);
                    dtShiftShortName = rptEmp.GetShiftShortName();
                    for (int k = 0; k <= dsShiftAllocation.Tables[0].Columns.Count - 4; k++)
                    {
                        if (k == 0)
                        {
                            dtSift.Columns.Add("Employee_FirstName");
                        }
                        else if (k == 1)
                        {
                            dtSift.Columns.Add("Employee_Id");
                        }
                        else if (k == 2)
                        {
                            dtSift.Columns.Add("Year");
                        }
                        else if (k == 3)
                        {
                            dtSift.Columns.Add("Month");
                        }
                        else
                        {
                            dtSift.Columns.Add("Day" + (k - 3) + "Shift".ToString());
                        }
                    }
                    foreach (DataRow dr in dsShiftAllocation.Tables[0].Rows)
                    {
                        //int checkflag = 0;
                        j = j + 1;
                        dtSift.Rows.Add();
                        for (int i = 0; i <= dsShiftAllocation.Tables[0].Columns.Count - 4; i++)
                        {
                            //if (i == 4 && checkflag == 0)
                            if (i == 4 && Convert.ToInt32(dr["Month"]) == fromMonth)
                            {
                                if (Convert.ToInt32(dr["Year"]) != fromYear)
                                {
                                }
                                else
                                {
                                    i = fromDay + 3;
                                    //chkFlag = 1;
                                    //checkflag = 1;
                                }
                            }
                            //Response.Write("i = " + i);
                            // Response.Write(dr[i].ToString() + "<br>");
                            if (i > 3)
                            {
                                foreach (DataRow dRow in dtShiftShortName.Rows)
                                {
                                    if (dr[i].ToString() == dRow["Shift_Id"].ToString())
                                    {
                                        dtSift.Rows[j - 1][i] = dRow["Shift_ShortName"];
                                    }
                                    else if (dr[i].ToString() == "-1")
                                    {
                                        dtSift.Rows[j - 1][i] = "Off";
                                    }
                                }
                            }
                            else if (i == 3)
                            {
                                DateTimeFormatInfo dtfi = new CultureInfo("en-US", true).DateTimeFormat;
                                string temp = dtfi.GetMonthName(Convert.ToInt32(dr[i].ToString()));
                                dtSift.Rows[j - 1][i] = temp;
                            }
                            else
                            {
                                dtSift.Rows[j - 1][i] = dr[i];
                            }
                            //Response.Write((toDay + 3 == i && j == dsShiftAllocation.Tables[0].Rows.Count - 1));
                            //if (toDay + 3 == i)
                            if (toDay + 3 == i && Convert.ToInt32(dr["Month"]) == toMonth && Convert.ToInt32(dr["Year"]) == toYear)
                            {
                                i = dsShiftAllocation.Tables[0].Columns.Count;
                            }
                        }
                    }
                    // dtShiftAllocation = dsShiftAllocation.Tables["Table"].Copy();
                    dsShiftAllocation.Tables.Remove("Table");
                    dsShiftAllocation.Tables.Add(dtSift);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        return dsShiftAllocation;
    }
    public DataSet fillTempShiftAllocationDetails()
    {
        try
        {
            if (this.Page.IsValid == true)
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                string dtFrom = "", dtTo = "";
                int employeeCategory = 0, employeeType = 0;
                if (txtFromDate.Text != "")
                {
                    strFromdate = txtFromDate.Text;
                    strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
                    dtFrom = strFromdate;
                }
                if (txtToDate.Text != "")
                {
                    strTodate = txtToDate.Text;
                    strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
                    dtTo = strTodate;
                }
                string empName = "";
                empName = txtEmployeeName.Text.Trim();
                string EmployeeId;
                EmployeeId = txtEmployeeId.Text.Trim();
                // set employee category and type
                if (Convert.ToInt32(ddlEmpCatagory.SelectedValue) != 0)
                {
                    employeeCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
                }
                else
                {
                    employeeCategory = 0;
                }
                if (Convert.ToInt32(ddlEmpType.SelectedValue) != 0)
                {
                    employeeType = Convert.ToInt32(ddlEmpType.SelectedValue);
                }
                else
                {
                    employeeType = 0;
                }
                if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                {
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                }
                //Get the Report source from the Server and load this into the report table
                string strSwipeCard = "";
                strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
                string employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                Session["dtFrom"] = dtFrom;
                Session["dtTo"] = dtTo;
                Session["employeeName"] = employeeName;
                Session["Level"] = Level;
                Session["EmpId"] = EmployeeId;
                Session["employeeCategory"] = employeeCategory;
                Session["employeeType"] = employeeType;
                Session["strSwipeCard"] = strSwipeCard;
                Session["EmpParent"] = Convert.ToInt16(Session["parentLevelId"]);
                string levelId = Level;
                int EmpAutoId = 0;
                if (Session["ReportsBasedOn"] != null)
                {
                    if (Session["ReportsBasedOn"].ToString() == "False")
                    {
                        EmpAutoId = 0;
                    }
                    else
                    {
                        EmpAutoId = Convert.ToInt32(Session["EmpAutoID"]);
                    }
                }
                dsTempShiftAllocation = rptEmp.SelectTempShiftAllocationReport(dtFrom, dtTo, employeeName, levelId, EmployeeId, employeeCategory, employeeType, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipeCard, Convert.ToInt16(Session["parentLevelId"]), 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue), EmpAutoId);
                //Session["parentLevelId"] = null;
                DataTable dtSift = new DataTable();
                //Check the Empty table 
                if (dsTempShiftAllocation.Tables["Table"] == null || dsTempShiftAllocation.Tables["Table"].Rows.Count == 0)
                {
                    checkRowsExistInTemp = false;
                    return dsTempShiftAllocation;
                }
                else
                {
                    //start
                    strFromdate = txtFromDate.Text;
                    strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
                    int fromDay = DateTime.Parse(strFromdate).Day;
                    int fromMonth = DateTime.Parse(strFromdate).Month;
                    int fromYear = DateTime.Parse(strFromdate).Year;
                    strTodate = txtToDate.Text;
                    strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
                    int toMonth = DateTime.Parse(strTodate).Month;
                    int toDay = DateTime.Parse(strTodate).Day;
                    int toYear = DateTime.Parse(strTodate).Year;
                    int j = 0;
                    DataTable dtShiftShortName = new DataTable();
                    dtShiftShortName = rptEmp.GetShiftShortName();
                    for (int k = 0; k <= dsTempShiftAllocation.Tables[0].Columns.Count - 4; k++)
                    {
                        if (k == 0)
                        {
                            dtSift.Columns.Add("Employee_FirstName");
                        }
                        else if (k == 1)
                        {
                            dtSift.Columns.Add("Employee_Id");
                        }
                        else if (k == 2)
                        {
                            dtSift.Columns.Add("Year");
                        }
                        else if (k == 3)
                        {
                            dtSift.Columns.Add("Month");
                        }
                        else
                        {
                            dtSift.Columns.Add("Day" + (k - 3) + "Shift".ToString());
                        }
                    }
                    foreach (DataRow dr in dsTempShiftAllocation.Tables[0].Rows)
                    {
                        //int checkflag = 0;
                        j = j + 1;
                        dtSift.Rows.Add();
                        for (int i = 0; i <= dsTempShiftAllocation.Tables[0].Columns.Count - 4; i++)
                        {
                            if (i == 4 && Convert.ToInt32(dr["Month"]) == fromMonth)
                            {
                                if (Convert.ToInt32(dr["Year"]) != fromYear)
                                {
                                }
                                else
                                {
                                    i = fromDay + 3;
                                }
                            }
                            if (i > 3)
                            {
                                foreach (DataRow dRow in dtShiftShortName.Rows)
                                {
                                    if (dr[i].ToString() == dRow["Shift_Id"].ToString())
                                    {
                                        dtSift.Rows[j - 1][i] = dRow["Shift_ShortName"];
                                    }
                                    else if (dr[i].ToString() == "-1")
                                    {
                                        dtSift.Rows[j - 1][i] = "Off";
                                    }
                                }
                            }
                            else if (i == 3)
                            {
                                DateTimeFormatInfo dtfi = new CultureInfo("en-US", true).DateTimeFormat;
                                string temp = dtfi.GetMonthName(Convert.ToInt32(dr[i].ToString()));
                                dtSift.Rows[j - 1][i] = temp;
                            }
                            else
                            {
                                dtSift.Rows[j - 1][i] = dr[i];
                            }
                            if (toDay + 3 == i && Convert.ToInt32(dr["Month"]) == toMonth && Convert.ToInt32(dr["Year"]) == toYear)
                            {
                                i = dsTempShiftAllocation.Tables[0].Columns.Count;
                            }
                        }
                    }
                    dsTempShiftAllocation.Tables.Remove("Table");
                    dsTempShiftAllocation.Tables.Add(dtSift);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        return dsTempShiftAllocation;
    }
    protected void grv_Shift_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Shift.PageIndex = e.NewPageIndex;
        dsShiftAllocation = (DataSet)Session["sessiondsShiftAllocation"];
        if (dsShiftAllocation.Tables.Count > 0)
        {
            if (dsShiftAllocation.Tables[0].Rows.Count > 0)
            {
                grv_Shift.DataSource = dsShiftAllocation;
                grv_Shift.DataBind();
                grv_Shift.Visible = true;
            }
        }
    }
    protected void grdTemp_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdTemp.PageIndex = e.NewPageIndex;
        dsTempShiftAllocation = (DataSet)Session["sessiondsTempShiftAllocation"];
        if (dsTempShiftAllocation.Tables.Count > 0)
        {
            if (dsTempShiftAllocation.Tables[0].Rows.Count > 0)
            {
                grdTemp.DataSource = dsTempShiftAllocation;
                grdTemp.DataBind();
                grdTemp.Visible = true;
                divGrid.Visible = true;
            }
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        lblTimePeriod.Text = rm.GetString("Reports_TimePeriod", ci);
        lblFrom.Text = rm.GetString("email_FromDate", ci);
        lblTo.Text = rm.GetString("email_ToDate", ci);
        grv_Shift.Columns[0].HeaderText = rm.GetString("email_EmployeeId", ci);
        grv_Shift.Columns[1].HeaderText = rm.GetString("email_EmployeeName", ci);
        grv_Shift.Columns[2].HeaderText = rm.GetString("PayrollProcess_Year", ci);
        grv_Shift.Columns[3].HeaderText = rm.GetString("PayrollProcess_Month", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        lblReligion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        cus_ComToDate.ErrorMessage = rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci);
        if (Shift == "Permanent")
        {
            lblShiftAllocationDetails.Text = rm.GetString("lblShiftAllocationDetails", ci);
        }
        else if (Shift == "Temporary")
        {
            lblShiftAllocationDetails.Text = rm.GetString("lblTemporaryShiftAllocationDetails", ci);
        }
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
    }
    protected void grv_Shift_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int Days = 0;
        dtShiftShortName = rptEmp.GetShiftShortName();
        dtShiftShortName.Rows.Add("-1", "Off");
        //dtShiftShortName.Rows.Add("0", "NON");
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblYear = (Label)e.Row.FindControl("lblYear");
            Label lblMonth = (Label)e.Row.FindControl("lblMonth");
            if (lblYear != null && lblYear.Text != string.Empty && DateTime.IsLeapYear(Convert.ToInt32(lblYear.Text)))
            {
                if (lblMonth != null)
                {
                    switch (lblMonth.Text)
                    {
                        case "January":
                            lblMonth.Text = rm.GetString("January", ci);
                            Days = 31;
                            break;
                        case "February":
                            lblMonth.Text = rm.GetString("February", ci);
                            Days = 29;
                            break;
                        case "March":
                            lblMonth.Text = rm.GetString("March", ci);
                            Days = 31;
                            break;
                        case "April":
                            lblMonth.Text = rm.GetString("April", ci);
                            Days = 30;
                            break;
                        case "May":
                            lblMonth.Text = rm.GetString("May", ci);
                            Days = 31;
                            break;
                        case "June":
                            lblMonth.Text = rm.GetString("June", ci);
                            Days = 30;
                            break;
                        case "July":
                            lblMonth.Text = rm.GetString("July", ci);
                            Days = 31;
                            break;
                        case "August":
                            lblMonth.Text = rm.GetString("August", ci);
                            Days = 31;
                            break;
                        case "September":
                            lblMonth.Text = rm.GetString("September", ci);
                            Days = 30;
                            break;
                        case "October":
                            lblMonth.Text = rm.GetString("October", ci);
                            Days = 31;
                            break;
                        case "November":
                            lblMonth.Text = rm.GetString("November", ci);
                            Days = 30;
                            break;
                        case "December":
                            lblMonth.Text = rm.GetString("December", ci);
                            Days = 31;
                            break;
                    }
                }
            }
            else
            {
                if (lblMonth != null)
                {
                    switch (lblMonth.Text)
                    {
                        case "January":
                            lblMonth.Text = rm.GetString("January", ci);
                            Days = 31;
                            break;
                        case "February":
                            lblMonth.Text = rm.GetString("February", ci);
                            Days = 28;
                            break;
                        case "March":
                            lblMonth.Text = rm.GetString("March", ci);
                            Days = 31;
                            break;
                        case "April":
                            lblMonth.Text = rm.GetString("April", ci);
                            Days = 30;
                            break;
                        case "May":
                            lblMonth.Text = rm.GetString("May", ci);
                            Days = 31;
                            break;
                        case "June":
                            lblMonth.Text = rm.GetString("June", ci);
                            Days = 30;
                            break;
                        case "July":
                            lblMonth.Text = rm.GetString("July", ci);
                            Days = 31;
                            break;
                        case "August":
                            lblMonth.Text = rm.GetString("August", ci);
                            Days = 31;
                            break;
                        case "September":
                            lblMonth.Text = rm.GetString("September", ci);
                            Days = 30;
                            break;
                        case "October":
                            lblMonth.Text = rm.GetString("October", ci);
                            Days = 31;
                            break;
                        case "November":
                            lblMonth.Text = rm.GetString("November", ci);
                            Days = 30;
                            break;
                        case "December":
                            lblMonth.Text = rm.GetString("December", ci);
                            Days = 31;
                            break;
                    }
                }
            }
            Label lblDay1Shift = (Label)e.Row.FindControl("lblDay1Shift");
            // HiddenField h1 = (HiddenField)e.Row.FindControl("lblDay1Shift");
            if (lblDay1Shift != null && lblDay1Shift.Text == "Off")
            {
                lblDay1Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay2Shift = (Label)e.Row.FindControl("lblDay2Shift");
            if (lblDay2Shift != null && lblDay2Shift.Text == "Off")
            {
                lblDay2Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay3Shift = (Label)e.Row.FindControl("lblDay3Shift");
            if (lblDay3Shift != null && lblDay3Shift.Text == "Off")
            {
                lblDay3Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay4Shift = (Label)e.Row.FindControl("lblDay4Shift");
            if (lblDay4Shift != null && lblDay4Shift.Text == "Off")
            {
                lblDay4Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay5Shift = (Label)e.Row.FindControl("lblDay5Shift");
            if (lblDay5Shift != null && lblDay5Shift.Text == "Off")
            {
                lblDay5Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay6Shift = (Label)e.Row.FindControl("lblDay6Shift");
            if (lblDay6Shift != null && lblDay6Shift.Text == "Off")
            {
                lblDay6Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay7Shift = (Label)e.Row.FindControl("lblDay7Shift");
            if (lblDay7Shift != null && lblDay7Shift.Text == "Off")
            {
                lblDay7Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay8Shift = (Label)e.Row.FindControl("lblDay8Shift");
            if (lblDay8Shift != null && lblDay8Shift.Text == "Off")
            {
                lblDay8Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay9Shift = (Label)e.Row.FindControl("lblDay9Shift");
            if (lblDay9Shift != null && lblDay9Shift.Text == "Off")
            {
                lblDay9Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay10Shift = (Label)e.Row.FindControl("lblDay10Shift");
            if (lblDay10Shift != null && lblDay10Shift.Text == "Off")
            {
                lblDay10Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay11Shift = (Label)e.Row.FindControl("lblDay11Shift");
            if (lblDay11Shift != null && lblDay11Shift.Text == "Off")
            {
                lblDay11Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay12Shift = (Label)e.Row.FindControl("lblDay12Shift");
            if (lblDay12Shift != null && lblDay12Shift.Text == "Off")
            {
                lblDay12Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay13Shift = (Label)e.Row.FindControl("lblDay13Shift");
            if (lblDay13Shift != null && lblDay13Shift.Text == "Off")
            {
                lblDay13Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay14Shift = (Label)e.Row.FindControl("lblDay14Shift");
            if (lblDay14Shift != null && lblDay14Shift.Text == "Off")
            {
                lblDay14Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay15Shift = (Label)e.Row.FindControl("lblDay15Shift");
            if (lblDay15Shift != null && lblDay15Shift.Text == "Off")
            {
                lblDay15Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay16Shift = (Label)e.Row.FindControl("lblDay16Shift");
            if (lblDay16Shift != null && lblDay16Shift.Text == "Off")
            {
                lblDay16Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay17Shift = (Label)e.Row.FindControl("lblDay17Shift");
            if (lblDay17Shift != null && lblDay17Shift.Text == "Off")
            {
                lblDay17Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay18Shift = (Label)e.Row.FindControl("lblDay18Shift");
            if (lblDay18Shift != null && lblDay18Shift.Text == "Off")
            {
                lblDay18Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay19Shift = (Label)e.Row.FindControl("lblDay19Shift");
            if (lblDay19Shift != null && lblDay19Shift.Text == "Off")
            {
                lblDay19Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay20Shift = (Label)e.Row.FindControl("lblDay20Shift");
            if (lblDay20Shift != null && lblDay20Shift.Text == "Off")
            {
                lblDay20Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay21Shift = (Label)e.Row.FindControl("lblDay21Shift");
            if (lblDay21Shift != null && lblDay21Shift.Text == "Off")
            {
                lblDay21Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay22Shift = (Label)e.Row.FindControl("lblDay22Shift");
            if (lblDay22Shift != null && lblDay22Shift.Text == "Off")
            {
                lblDay22Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay23Shift = (Label)e.Row.FindControl("lblDay23Shift");
            if (lblDay23Shift != null && lblDay23Shift.Text == "Off")
            {
                lblDay23Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay24Shift = (Label)e.Row.FindControl("lblDay24Shift");
            if (lblDay24Shift != null && lblDay24Shift.Text == "Off")
            {
                lblDay24Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay25Shift = (Label)e.Row.FindControl("lblDay25Shift");
            if (lblDay25Shift != null && lblDay25Shift.Text == "Off")
            {
                lblDay25Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay26Shift = (Label)e.Row.FindControl("lblDay26Shift");
            if (lblDay26Shift != null && lblDay26Shift.Text == "Off")
            {
                lblDay26Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay27Shift = (Label)e.Row.FindControl("lblDay27Shift");
            if (lblDay27Shift != null && lblDay27Shift.Text == "Off")
            {
                lblDay27Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay28Shift = (Label)e.Row.FindControl("lblDay28Shift");
            if (lblDay28Shift != null && lblDay28Shift.Text == "Off")
            {
                lblDay28Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay29Shift = (Label)e.Row.FindControl("lblDay29Shift");
            if (lblDay29Shift != null && lblDay29Shift.Text == "Off")
            {
                lblDay29Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay30Shift = (Label)e.Row.FindControl("lblDay30Shift");
            if (lblDay30Shift != null && lblDay30Shift.Text == "Off")
            {
                lblDay30Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay31Shift = (Label)e.Row.FindControl("lblDay31Shift");
            if (lblDay31Shift != null && lblDay31Shift.Text == "Off")
            {
                lblDay31Shift.Text = rm.GetString("lbl_Off", ci);
            }
            for (int i = 1; i <= Days; i++)
            {
                DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDay" + i + "Shift");
                if (ddlDepartment != null)
                {
                    ddlDepartment.DataSource = dtShiftShortName;
                    ddlDepartment.DataBind();
                    if ((e.Row.FindControl("lblDay" + i + "Shift") as Label).Text != string.Empty)
                    {
                        ddlDepartment.Items.FindByText((e.Row.FindControl("lblDay" + i + "Shift") as Label).Text).Selected = true;
                    }
                    else
                    {
                        ddlDepartment.Visible = false;
                        //ddlDepartment.Items.FindByValue("1").Selected = true;
                        //ddlDepartment.Items.FindByValue("1").Attributes.Add("style", "background-color:pink");
                    }
                }
            }
            if (Days != 31)
            {
                for (int j = Days + 1; j <= 31; j++)
                {
                    DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDay" + j + "Shift");
                    if (ddlDepartment != null)
                    {
                        ddlDepartment.Visible = false;
                    }
                }
            }
            //if (e.Row.RowType == DataControlRowType.EmptyDataRow)
            //{
            //    int i;
            //    for (i = 1; i <= 31; i++)
            //    {
            //        DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDay" + i + "Shift");
            //        if (ddlDepartment != null)
            //        {
            //            ddlDepartment.DataSource = dtShiftShortName;
            //            ddlDepartment.DataBind();
            //        }
            //    }
            //}    
        }
    }
    protected void grv_Shift_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grv_Shift.EditIndex = e.NewEditIndex;
        grv_Shift.DataSource = ParmanentShift();
        grv_Shift.DataBind();
    }
    protected void grv_Shift_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grv_Shift.EditIndex = -1;
        grv_Shift.DataSource = ParmanentShift();
        grv_Shift.DataBind();
    }
    protected void grv_Shift_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int Year = Convert.ToInt32(((Label)grv_Shift.Rows[e.RowIndex].FindControl("lblYear")).Text);
        string Month = Convert.ToString(((Label)grv_Shift.Rows[e.RowIndex].FindControl("lblMonth")).Text);
        string EmployeeCodeId = Convert.ToString(((Label)grv_Shift.Rows[e.RowIndex].FindControl("lbl_EmpId")).Text);
        DataSet dsEmployeeInfo = objShiftAllocation.EmployeeInformation(EmployeeCodeId);
        string Employee_Id = dsEmployeeInfo.Tables[0].Rows[0]["Employee_Id"].ToString();
        int MonthDays = CheckDays(Year, Month);
        int MonthCount = CheckMnoth(Month);
        bool chkShiftAllocationExists = false;
        string[] ShiftPattern = new string[31];
        for (int i = 1; i <= MonthDays; i++)
        {
            DropDownList ddlShift = (DropDownList)grv_Shift.Rows[e.RowIndex].FindControl("ddlDay" + i + "Shift");
            int j = i - 1;
            if (ddlShift != null)
            {
                if ((grv_Shift.Rows[e.RowIndex].FindControl("lblDay" + i + "Shift") as Label).Text != string.Empty)
                {
                    ShiftPattern[j] = (ddlShift.SelectedValue);
                }
                else
                {
                    ShiftPattern[j] = "";
                }
            }
        }
        string strFromDate = string.Empty;
        string strToDate = string.Empty;
        strFromDate = "01 -" + Month.Substring(0, 3) + "-" + Year;
        strToDate = MonthDays + "-" + Month.Substring(0, 3) + "-" + Year;
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Parse(strFromDate).ToString(gstrDateFormat, CultureInfo.InvariantCulture).ToString());
        strToDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Parse(strToDate).ToString(gstrDateFormat, CultureInfo.InvariantCulture).ToString());
        DateTime dtFromDate = DateTime.Parse(strFromDate);
        DateTime dtToDate = DateTime.Parse(strToDate);
        int PreviousDayShiftId = 0;
        int NextDayShiftId = 0;
        DateTime dtPreviousmonthlastDate = dtFromDate.AddDays(-1);
        DateTime dtNextMonthFirstDate = dtToDate.AddDays(1);
        DataSet dsPermanentTemporaryShift = new DataSet();
        string strUpdate = string.Empty;
        for (int i = 0; i < MonthDays; i++)
        {
            if ((i + 1) < MonthDays)
            {
                if (ShiftPattern[i] != string.Empty && ShiftPattern[i + 1] != string.Empty)
                {
                    DataSet dsOverLapping = objShiftPatternOverLap.CheckShiftOverLapping(Convert.ToInt32(ShiftPattern[i]), Convert.ToInt32(ShiftPattern[i + 1]));
                    if (dsOverLapping.Tables.Count > 0)
                    {
                        if (dsOverLapping.Tables[0].Rows.Count > 0)
                        {
                            int intOverLap = Convert.ToInt32(dsOverLapping.Tables[0].Rows[0]["ShiftOverLapping"]);
                            if (intOverLap > 0)
                            {
                                DropDownList ddlDepartment = (DropDownList)grv_Shift.Rows[e.RowIndex].FindControl("ddlDay" + (i + 1) + "Shift");
                                DropDownList ddlDepartment2 = (DropDownList)grv_Shift.Rows[e.RowIndex].FindControl("ddlDay" + (i + 2) + "Shift");
                                if (ddlDepartment != null && ddlDepartment2 != null)
                                {
                                    string strFirst;
                                    string strSecond;
                                    strFirst = ShiftPattern[i].ToString();
                                    strSecond = ShiftPattern[i + 1].ToString();
                                    ddlDepartment.Items.FindByValue(strFirst).Attributes.Add("style", "background-color:Red");
                                    ddlDepartment2.Items.FindByValue(strSecond).Attributes.Add("style", "background-color:Red");
                                }
                            }
                            else
                            {
                                if (strUpdate == string.Empty)
                                {
                                    strUpdate = "UPDATE TA_Tbl_PermanentShiftAllocation SET Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                                }
                                else
                                {
                                    strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                                }
                            }
                        }
                    }
                }
                else if (ShiftPattern[i] != string.Empty)
                {
                    strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                }
            }
            else if ((i + 1) == MonthDays)
            {
                if (ShiftPattern[i] != string.Empty)
                {
                    strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                }
            }
            //DropDownList ddlDepartmentPink = (DropDownList)grv_Shift.Rows[e.RowIndex].FindControl("ddlDay" + (i + 1) + "Shift");
            //if (ddlDepartmentPink != null && ddlDepartmentPink.SelectedItem != null)
            //{
            //    if (ddlDepartmentPink.SelectedItem.Text == "NOS")
            //    {
            //        ddlDepartmentPink.Items.FindByValue("1").Selected = true;
            //        ddlDepartmentPink.Items.FindByValue("1").Attributes.Add("style", "background-color:pink");
            //    }
            //}
        }
        if (strUpdate != string.Empty)
        {
            strUpdate += " WHERE EmployeeId  = ('" + Employee_Id + "') AND Year = " + Year + " AND Month = " + MonthCount + "";
        }
        objShiftAllocation.UpdateShiftAllocation(strUpdate);
        //Reprocess 
        objShiftAllocation.ReprocessEmployeeData(dtFromDate, dtToDate, EmployeeCodeId);
        //objShiftAllocation.ShiftAllocationReprocess_ClockDetails(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        //objShiftAllocation.ShiftAllocationReprocess_ManualEntry(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        //objShiftAllocation.ShiftAllocationReprocess_RawData(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        grv_Shift.EditIndex = -1;
        grv_Shift.DataSource = ParmanentShift();
        grv_Shift.DataBind();
    }
    protected void grdTemp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int Days = 0;
        dtShiftShortName = rptEmp.GetShiftShortName();
        dtShiftShortName.Rows.Add("-1", "Off");
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblYear = (Label)e.Row.FindControl("lblYear");
            Label lblMonth = (Label)e.Row.FindControl("lblMonth");
            if (lblYear != null && lblYear.Text != string.Empty && DateTime.IsLeapYear(Convert.ToInt32(lblYear.Text)))
            {
                if (lblMonth != null)
                {
                    switch (lblMonth.Text)
                    {
                        case "January":
                            lblMonth.Text = rm.GetString("January", ci);
                            Days = 31;
                            break;
                        case "February":
                            lblMonth.Text = rm.GetString("February", ci);
                            Days = 29;
                            break;
                        case "March":
                            lblMonth.Text = rm.GetString("March", ci);
                            Days = 31;
                            break;
                        case "April":
                            lblMonth.Text = rm.GetString("April", ci);
                            Days = 30;
                            break;
                        case "May":
                            lblMonth.Text = rm.GetString("May", ci);
                            Days = 31;
                            break;
                        case "June":
                            lblMonth.Text = rm.GetString("June", ci);
                            Days = 30;
                            break;
                        case "July":
                            lblMonth.Text = rm.GetString("July", ci);
                            Days = 31;
                            break;
                        case "August":
                            lblMonth.Text = rm.GetString("August", ci);
                            Days = 31;
                            break;
                        case "September":
                            lblMonth.Text = rm.GetString("September", ci);
                            Days = 30;
                            break;
                        case "October":
                            lblMonth.Text = rm.GetString("October", ci);
                            Days = 31;
                            break;
                        case "November":
                            lblMonth.Text = rm.GetString("November", ci);
                            Days = 30;
                            break;
                        case "December":
                            lblMonth.Text = rm.GetString("December", ci);
                            Days = 31;
                            break;
                    }
                }
            }
            else
            {
                if (lblMonth != null)
                {
                    switch (lblMonth.Text)
                    {
                        case "January":
                            lblMonth.Text = rm.GetString("January", ci);
                            Days = 31;
                            break;
                        case "February":
                            lblMonth.Text = rm.GetString("February", ci);
                            Days = 28;
                            break;
                        case "March":
                            lblMonth.Text = rm.GetString("March", ci);
                            Days = 31;
                            break;
                        case "April":
                            lblMonth.Text = rm.GetString("April", ci);
                            Days = 30;
                            break;
                        case "May":
                            lblMonth.Text = rm.GetString("May", ci);
                            Days = 31;
                            break;
                        case "June":
                            lblMonth.Text = rm.GetString("June", ci);
                            Days = 30;
                            break;
                        case "July":
                            lblMonth.Text = rm.GetString("July", ci);
                            Days = 31;
                            break;
                        case "August":
                            lblMonth.Text = rm.GetString("August", ci);
                            Days = 31;
                            break;
                        case "September":
                            lblMonth.Text = rm.GetString("September", ci);
                            Days = 30;
                            break;
                        case "October":
                            lblMonth.Text = rm.GetString("October", ci);
                            Days = 31;
                            break;
                        case "November":
                            lblMonth.Text = rm.GetString("November", ci);
                            Days = 30;
                            break;
                        case "December":
                            lblMonth.Text = rm.GetString("December", ci);
                            Days = 31;
                            break;
                    }
                }
            }
            Label lblDay1Shift = (Label)e.Row.FindControl("lblDay1Shift");
            if (lblDay1Shift.Text == "Off")
            {
                lblDay1Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay2Shift = (Label)e.Row.FindControl("lblDay2Shift");
            if (lblDay2Shift.Text == "Off")
            {
                lblDay2Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay3Shift = (Label)e.Row.FindControl("lblDay3Shift");
            if (lblDay3Shift.Text == "Off")
            {
                lblDay3Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay4Shift = (Label)e.Row.FindControl("lblDay4Shift");
            if (lblDay4Shift.Text == "Off")
            {
                lblDay4Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay5Shift = (Label)e.Row.FindControl("lblDay5Shift");
            if (lblDay5Shift.Text == "Off")
            {
                lblDay5Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay6Shift = (Label)e.Row.FindControl("lblDay6Shift");
            if (lblDay6Shift.Text == "Off")
            {
                lblDay6Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay7Shift = (Label)e.Row.FindControl("lblDay7Shift");
            if (lblDay7Shift.Text == "Off")
            {
                lblDay7Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay8Shift = (Label)e.Row.FindControl("lblDay8Shift");
            if (lblDay8Shift.Text == "Off")
            {
                lblDay8Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay9Shift = (Label)e.Row.FindControl("lblDay9Shift");
            if (lblDay9Shift.Text == "Off")
            {
                lblDay9Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay10Shift = (Label)e.Row.FindControl("lblDay10Shift");
            if (lblDay10Shift.Text == "Off")
            {
                lblDay10Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay11Shift = (Label)e.Row.FindControl("lblDay11Shift");
            if (lblDay11Shift.Text == "Off")
            {
                lblDay11Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay12Shift = (Label)e.Row.FindControl("lblDay12Shift");
            if (lblDay12Shift.Text == "Off")
            {
                lblDay12Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay13Shift = (Label)e.Row.FindControl("lblDay13Shift");
            if (lblDay13Shift.Text == "Off")
            {
                lblDay13Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay14Shift = (Label)e.Row.FindControl("lblDay14Shift");
            if (lblDay14Shift.Text == "Off")
            {
                lblDay14Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay15Shift = (Label)e.Row.FindControl("lblDay15Shift");
            if (lblDay15Shift.Text == "Off")
            {
                lblDay15Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay16Shift = (Label)e.Row.FindControl("lblDay16Shift");
            if (lblDay16Shift.Text == "Off")
            {
                lblDay16Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay17Shift = (Label)e.Row.FindControl("lblDay17Shift");
            if (lblDay17Shift.Text == "Off")
            {
                lblDay17Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay18Shift = (Label)e.Row.FindControl("lblDay18Shift");
            if (lblDay18Shift.Text == "Off")
            {
                lblDay18Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay19Shift = (Label)e.Row.FindControl("lblDay19Shift");
            if (lblDay19Shift.Text == "Off")
            {
                lblDay19Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay20Shift = (Label)e.Row.FindControl("lblDay20Shift");
            if (lblDay20Shift.Text == "Off")
            {
                lblDay20Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay21Shift = (Label)e.Row.FindControl("lblDay21Shift");
            if (lblDay21Shift.Text == "Off")
            {
                lblDay21Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay22Shift = (Label)e.Row.FindControl("lblDay22Shift");
            if (lblDay22Shift.Text == "Off")
            {
                lblDay22Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay23Shift = (Label)e.Row.FindControl("lblDay23Shift");
            if (lblDay23Shift.Text == "Off")
            {
                lblDay23Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay24Shift = (Label)e.Row.FindControl("lblDay24Shift");
            if (lblDay24Shift.Text == "Off")
            {
                lblDay24Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay25Shift = (Label)e.Row.FindControl("lblDay25Shift");
            if (lblDay25Shift.Text == "Off")
            {
                lblDay25Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay26Shift = (Label)e.Row.FindControl("lblDay26Shift");
            if (lblDay26Shift.Text == "Off")
            {
                lblDay26Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay27Shift = (Label)e.Row.FindControl("lblDay27Shift");
            if (lblDay27Shift.Text == "Off")
            {
                lblDay27Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay28Shift = (Label)e.Row.FindControl("lblDay28Shift");
            if (lblDay28Shift.Text == "Off")
            {
                lblDay28Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay29Shift = (Label)e.Row.FindControl("lblDay29Shift");
            if (lblDay29Shift.Text == "Off")
            {
                lblDay29Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay30Shift = (Label)e.Row.FindControl("lblDay30Shift");
            if (lblDay30Shift.Text == "Off")
            {
                lblDay30Shift.Text = rm.GetString("lbl_Off", ci);
            }
            Label lblDay31Shift = (Label)e.Row.FindControl("lblDay31Shift");
            if (lblDay31Shift.Text == "Off")
            {
                lblDay31Shift.Text = rm.GetString("lbl_Off", ci);
            }
            for (int i = 1; i <= Days; i++)
            {
                DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDay" + i + "Shift");
                if (ddlDepartment != null)
                {
                    ddlDepartment.DataSource = dtShiftShortName;
                    ddlDepartment.DataBind();
                    if ((e.Row.FindControl("lblDay" + i + "Shift") as Label).Text != string.Empty)
                    {
                        ddlDepartment.Items.FindByText((e.Row.FindControl("lblDay" + i + "Shift") as Label).Text).Selected = true;
                    }
                    else
                    {
                        ddlDepartment.Visible = false;
                        //ddlDepartment.Items.FindByValue("1").Selected = true;
                        //ddlDepartment.Items.FindByValue("1").Attributes.Add("style", "background-color:pink");
                    }
                }
            }
            if (Days != 31)
            {
                for (int j = Days + 1; j <= 31; j++)
                {
                    DropDownList ddlDepartment = (DropDownList)e.Row.FindControl("ddlDay" + j + "Shift");
                    if (ddlDepartment != null)
                    {
                        ddlDepartment.Visible = false;
                    }
                }
            }
        }
    }
    protected void grdTemp_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grdTemp.EditIndex = e.NewEditIndex;
        grdTemp.DataSource = TempShift();
        grdTemp.DataBind();
    }
    protected void grdTemp_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grdTemp.EditIndex = -1;
        grdTemp.DataSource = TempShift();
        grdTemp.DataBind();
    }
    protected void grdTemp_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int Year = Convert.ToInt32(((Label)grdTemp.Rows[e.RowIndex].FindControl("lblYear")).Text);
        string Month = Convert.ToString(((Label)grdTemp.Rows[e.RowIndex].FindControl("lblMonth")).Text);
        string EmployeeCodeId = Convert.ToString(((Label)grdTemp.Rows[e.RowIndex].FindControl("lbl_EmpId")).Text);
        DataSet dsEmployeeInfo = objShiftAllocation.EmployeeInformation(EmployeeCodeId);
        string Employee_Id = dsEmployeeInfo.Tables[0].Rows[0]["Employee_Id"].ToString();
        int MonthDays = CheckDays(Year, Month);
        int MonthCount = CheckMnoth(Month);
        bool chkShiftAllocationExists = false;
        string[] ShiftPattern = new string[31];
        for (int i = 1; i <= MonthDays; i++)
        {
            DropDownList ddlShift = (DropDownList)grdTemp.Rows[e.RowIndex].FindControl("ddlDay" + i + "Shift");
            int j = i - 1;
            if (ddlShift != null)
            {
                if ((grdTemp.Rows[e.RowIndex].FindControl("lblDay" + i + "Shift") as Label).Text != string.Empty)
                {
                    ShiftPattern[j] = (ddlShift.SelectedValue);
                }
                else
                {
                    ShiftPattern[j] = "";
                }
            }
        }
        string strFromDate = string.Empty;
        string strToDate = string.Empty;
        strFromDate = "01 -" + Month.Substring(0, 3) + "-" + Year;
        strToDate = MonthDays + "-" + Month.Substring(0, 3) + "-" + Year;
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Parse(strFromDate).ToString(gstrDateFormat, CultureInfo.InvariantCulture).ToString());
        strToDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Parse(strToDate).ToString(gstrDateFormat, CultureInfo.InvariantCulture).ToString());
        DateTime dtFromDate = DateTime.Parse(strFromDate);
        DateTime dtToDate = DateTime.Parse(strToDate);
        int PreviousDayShiftId = 0;
        int NextDayShiftId = 0;
        DateTime dtPreviousmonthlastDate = dtFromDate.AddDays(-1);
        DateTime dtNextMonthFirstDate = dtToDate.AddDays(1);
        DataSet dsPermanentTemporaryShift = new DataSet();
        string strUpdate = string.Empty;
        for (int i = 0; i < MonthDays; i++)
        {
            if ((i + 1) < MonthDays)
            {
                if (ShiftPattern[i] != string.Empty && ShiftPattern[i + 1] != string.Empty)
                {
                    DataSet dsOverLapping = objShiftPatternOverLap.CheckShiftOverLapping(Convert.ToInt32(ShiftPattern[i]), Convert.ToInt32(ShiftPattern[i + 1]));
                    if (dsOverLapping != null && dsOverLapping.Tables.Count > 0 && dsOverLapping.Tables[0].Rows.Count > 0)
                    {
                        int intOverLap = Convert.ToInt32(dsOverLapping.Tables[0].Rows[0]["ShiftOverLapping"]);
                        if (intOverLap > 0)
                        {
                            DropDownList ddlDepartment = (DropDownList)grdTemp.Rows[e.RowIndex].FindControl("ddlDay" + (i + 1) + "Shift");
                            DropDownList ddlDepartment2 = (DropDownList)grdTemp.Rows[e.RowIndex].FindControl("ddlDay" + (i + 2) + "Shift");
                            if (ddlDepartment != null && ddlDepartment2 != null)
                            {
                                string strFirst;
                                string strSecond;
                                strFirst = ShiftPattern[i].ToString();
                                strSecond = ShiftPattern[i + 1].ToString();
                                ddlDepartment.Items.FindByValue(strFirst).Attributes.Add("style", "background-color:Red");
                                ddlDepartment2.Items.FindByValue(strSecond).Attributes.Add("style", "background-color:Red");
                            }
                        }
                        else
                        {
                            if (strUpdate == string.Empty)
                            {
                                strUpdate = "UPDATE TA_Tbl_TemporaryShiftAllocation SET Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                            }
                            else
                            {
                                strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                            }
                        }
                    }
                }
                else if (ShiftPattern[i] != string.Empty)
                {
                    strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                }
            }
            else if ((i + 1) == MonthDays)
            {
                if (ShiftPattern[i] != string.Empty)
                {
                    strUpdate += ",Day" + (i + 1) + "Shift = " + ShiftPattern[i];
                }
            }
            //DropDownList ddlDepartmentPink = (DropDownList)grdTemp.Rows[e.RowIndex].FindControl("ddlDay" + (i + 1) + "Shift");
            //if (ddlDepartmentPink != null)
            //{
            //    if (ddlDepartmentPink.SelectedItem.Text == "NOS")
            //    {
            //        ddlDepartmentPink.Items.FindByValue("1").Selected = true;
            //        ddlDepartmentPink.Items.FindByValue("1").Attributes.Add("style", "background-color:pink");
            //    }
            //}
        }
        if (strUpdate != string.Empty)
        {
            strUpdate += " WHERE EmployeeId  = ('" + Employee_Id + "') AND Year = " + Year + " AND Month = " + MonthCount + "";
        }
        objShiftAllocation.UpdateShiftAllocation(strUpdate);
        //Reprocess 
        objShiftAllocation.ReprocessEmployeeData(dtFromDate, dtToDate, EmployeeCodeId);
        //objShiftAllocation.ShiftAllocationReprocess_ClockDetails(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        //objShiftAllocation.ShiftAllocationReprocess_ManualEntry(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        //objShiftAllocation.ShiftAllocationReprocess_RawData(dtFromDate, dtToDate, Session["EmpAutoID"].ToString());
        grdTemp.EditIndex = -1;
        grdTemp.DataSource = TempShift();
        grdTemp.DataBind();
    }
    public int CheckDays(int Year, string Month)
    {
        int Days = 0;
        if (Year != 0 && DateTime.IsLeapYear(Year))
        {
            if (Month != null)
            {
                switch (Month)
                {
                    case "January":
                        Days = 31;
                        break;
                    case "February":
                        Days = 29;
                        break;
                    case "March":
                        Days = 31;
                        break;
                    case "April":
                        Days = 30;
                        break;
                    case "May":
                        Days = 31;
                        break;
                    case "June":
                        Days = 30;
                        break;
                    case "July":
                        Days = 31;
                        break;
                    case "August":
                        Days = 31;
                        break;
                    case "September":
                        Days = 30;
                        break;
                    case "October":
                        Days = 31;
                        break;
                    case "November":
                        Days = 30;
                        break;
                    case "December":
                        Days = 31;
                        break;
                }
            }
        }
        else
        {
            if (Month != null)
            {
                switch (Month)
                {
                    case "January":
                        Days = 31;
                        break;
                    case "February":
                        Days = 28;
                        break;
                    case "March":
                        Days = 31;
                        break;
                    case "April":
                        Days = 30;
                        break;
                    case "May":
                        Days = 31;
                        break;
                    case "June":
                        Days = 30;
                        break;
                    case "July":
                        Days = 31;
                        break;
                    case "August":
                        Days = 31;
                        break;
                    case "September":
                        Days = 30;
                        break;
                    case "October":
                        Days = 31;
                        break;
                    case "November":
                        Days = 30;
                        break;
                    case "December":
                        Days = 31;
                        break;
                }
            }
        }
        return Days;
    }
    public int CheckMnoth(string Month)
    {
        int Monthcount = 0;
        if (Month != null)
        {
            switch (Month)
            {
                case "January":
                    Monthcount = 1;
                    break;
                case "February":
                    Monthcount = 2;
                    break;
                case "March":
                    Monthcount = 3;
                    break;
                case "April":
                    Monthcount = 4;
                    break;
                case "May":
                    Monthcount = 5;
                    break;
                case "June":
                    Monthcount = 6;
                    break;
                case "July":
                    Monthcount = 7;
                    break;
                case "August":
                    Monthcount = 8;
                    break;
                case "September":
                    Monthcount = 9;
                    break;
                case "October":
                    Monthcount = 10;
                    break;
                case "November":
                    Monthcount = 11;
                    break;
                case "December":
                    Monthcount = 12;
                    break;
            }
        }
        return Monthcount;
    }
    public DataSet ParmanentShift()
    {
        DataSet dsShiftAllocation = new DataSet();
        int EmpAutoId = 0;
        if (Session["ReportsBasedOn"] != null)
        {
            if (Session["ReportsBasedOn"].ToString() == "False")
            {
                EmpAutoId = 0;
            }
            else
            {
                EmpAutoId = Convert.ToInt32(Session["EmpAutoID"]);
            }
        }
        dsShiftAllocation = rptEmp.SelectShiftAllocationReport(Convert.ToString(Session["dtFrom"]), Convert.ToString(Session["dtTo"]),
            Convert.ToString(Session["employeeName"]), Convert.ToString(Session["Level"]),
            Convert.ToString(Session["EmpId"]), Convert.ToInt32(Session["employeeCategory"]), Convert.ToInt32(Session["employeeType"])
            , Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), Convert.ToString(Session["strSwipeCard"]),
            Convert.ToInt16(Session["EmpParent"]), 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue), EmpAutoId);
        DataTable dtSift = new DataTable();
        //Check the Empty table 
        if (dsShiftAllocation.Tables["Table"] == null || dsShiftAllocation.Tables["Table"].Rows.Count == 0)
        {
            checkRowsExist = false;
            return dsShiftAllocation;
        }
        else
        {
            //start
            strFromdate = Convert.ToString(Session["dtFrom"]);
            // strFromdate = objCommon.DateConvertion(Session["MDateFormat"].ToString(), strFromdate);
            int fromDay = DateTime.Parse(strFromdate).Day;
            int fromMonth = DateTime.Parse(strFromdate).Month;
            int fromYear = DateTime.Parse(strFromdate).Year;
            strTodate = Convert.ToString(Session["dtTo"]);
            // strTodate = objCommon.DateConvertion(Session["MDateFormat"].ToString(), Convert.ToString(Session["dtTo"]));
            int toMonth = DateTime.Parse(strTodate).Month;
            int toDay = DateTime.Parse(strTodate).Day;
            int toYear = DateTime.Parse(strTodate).Year;
            int j = 0;
            dtShiftShortName = rptEmp.GetShiftShortName();
            for (int k = 0; k <= dsShiftAllocation.Tables[0].Columns.Count - 4; k++)
            {
                if (k == 0)
                {
                    dtSift.Columns.Add("Employee_FirstName");
                }
                else if (k == 1)
                {
                    dtSift.Columns.Add("Employee_Id");
                }
                else if (k == 2)
                {
                    dtSift.Columns.Add("Year");
                }
                else if (k == 3)
                {
                    dtSift.Columns.Add("Month");
                }
                else
                {
                    dtSift.Columns.Add("Day" + (k - 3) + "Shift".ToString());
                }
            }
            foreach (DataRow dr in dsShiftAllocation.Tables[0].Rows)
            {
                //int checkflag = 0;
                j = j + 1;
                dtSift.Rows.Add();
                for (int i = 0; i <= dsShiftAllocation.Tables[0].Columns.Count - 4; i++)
                {
                    //if (i == 4 && checkflag == 0)
                    if (i == 4 && Convert.ToInt32(dr["Month"]) == fromMonth)
                    {
                        if (Convert.ToInt32(dr["Year"]) != fromYear)
                        {
                        }
                        else
                        {
                            i = fromDay + 3;
                            //chkFlag = 1;
                            //checkflag = 1;
                        }
                    }
                    //Response.Write("i = " + i);
                    // Response.Write(dr[i].ToString() + "<br>");
                    if (i > 3)
                    {
                        foreach (DataRow dRow in dtShiftShortName.Rows)
                        {
                            if (dr[i].ToString() == dRow["Shift_Id"].ToString())
                            {
                                dtSift.Rows[j - 1][i] = dRow["Shift_ShortName"];
                            }
                            else if (dr[i].ToString() == "-1")
                            {
                                dtSift.Rows[j - 1][i] = "Off";
                            }
                        }
                    }
                    else if (i == 3)
                    {
                        DateTimeFormatInfo dtfi = new CultureInfo("en-US", true).DateTimeFormat;
                        string temp = dtfi.GetMonthName(Convert.ToInt32(dr[i].ToString()));
                        dtSift.Rows[j - 1][i] = temp;
                    }
                    else
                    {
                        dtSift.Rows[j - 1][i] = dr[i];
                    }
                    //Response.Write((toDay + 3 == i && j == dsShiftAllocation.Tables[0].Rows.Count - 1));
                    //if (toDay + 3 == i)
                    if (toDay + 3 == i && Convert.ToInt32(dr["Month"]) == toMonth && Convert.ToInt32(dr["Year"]) == toYear)
                    {
                        i = dsShiftAllocation.Tables[0].Columns.Count;
                    }
                }
            }
            // dtShiftAllocation = dsShiftAllocation.Tables["Table"].Copy();
            dsShiftAllocation.Tables.Remove("Table");
            dsShiftAllocation.Tables.Add(dtSift);
        }
        return dsShiftAllocation;
    }
    public DataSet TempShift()
    {
        DataSet dsTempShiftAllocation = new DataSet();
        int EmpAutoId = 0;
        if (Session["ReportsBasedOn"] != null)
        {
            if (Session["ReportsBasedOn"].ToString() == "False")
            {
                EmpAutoId = 0;
            }
            else
            {
                EmpAutoId = Convert.ToInt32(Session["EmpAutoID"]);
            }
        }
        dsTempShiftAllocation = rptEmp.SelectTempShiftAllocationReport(Convert.ToString(Session["dtFrom"]), Convert.ToString(Session["dtTo"]),
            Convert.ToString(Session["employeeName"]), Convert.ToString(Session["Level"]),
            Convert.ToString(Session["EmpId"]), Convert.ToInt32(Session["employeeCategory"]), Convert.ToInt32(Session["employeeType"])
            , Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), Convert.ToString(Session["strSwipeCard"]),
            Convert.ToInt16(Session["EmpParent"]), 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue), EmpAutoId);
        DataTable dtSift = new DataTable();
        //Check the Empty table 
        if (dsTempShiftAllocation.Tables["Table"] == null || dsTempShiftAllocation.Tables["Table"].Rows.Count == 0)
        {
            checkRowsExistInTemp = false;
            return dsTempShiftAllocation;
        }
        else
        {
            //start
            strFromdate = Convert.ToString(Session["dtFrom"]);
            // strFromdate = objCommon.DateConvertion(Session["MDateFormat"].ToString(), strFromdate);
            int fromDay = DateTime.Parse(strFromdate).Day;
            int fromMonth = DateTime.Parse(strFromdate).Month;
            int fromYear = DateTime.Parse(strFromdate).Year;
            strTodate = Convert.ToString(Session["dtTo"]);
            // strTodate = objCommon.DateConvertion(Session["MDateFormat"].ToString(), Convert.ToString(Session["dtTo"]));
            int toMonth = DateTime.Parse(strTodate).Month;
            int toDay = DateTime.Parse(strTodate).Day;
            int toYear = DateTime.Parse(strTodate).Year;
            int j = 0;
            DataTable dtShiftShortName = new DataTable();
            dtShiftShortName = rptEmp.GetShiftShortName();
            for (int k = 0; k <= dsTempShiftAllocation.Tables[0].Columns.Count - 4; k++)
            {
                if (k == 0)
                {
                    dtSift.Columns.Add("Employee_FirstName");
                }
                else if (k == 1)
                {
                    dtSift.Columns.Add("Employee_Id");
                }
                else if (k == 2)
                {
                    dtSift.Columns.Add("Year");
                }
                else if (k == 3)
                {
                    dtSift.Columns.Add("Month");
                }
                else
                {
                    dtSift.Columns.Add("Day" + (k - 3) + "Shift".ToString());
                }
            }
            foreach (DataRow dr in dsTempShiftAllocation.Tables[0].Rows)
            {
                //int checkflag = 0;
                j = j + 1;
                dtSift.Rows.Add();
                for (int i = 0; i <= dsTempShiftAllocation.Tables[0].Columns.Count - 4; i++)
                {
                    if (i == 4 && Convert.ToInt32(dr["Month"]) == fromMonth)
                    {
                        if (Convert.ToInt32(dr["Year"]) != fromYear)
                        {
                        }
                        else
                        {
                            i = fromDay + 3;
                        }
                    }
                    if (i > 3)
                    {
                        foreach (DataRow dRow in dtShiftShortName.Rows)
                        {
                            if (dr[i].ToString() == dRow["Shift_Id"].ToString())
                            {
                                dtSift.Rows[j - 1][i] = dRow["Shift_ShortName"];
                            }
                            else if (dr[i].ToString() == "-1")
                            {
                                dtSift.Rows[j - 1][i] = "Off";
                            }
                        }
                    }
                    else if (i == 3)
                    {
                        DateTimeFormatInfo dtfi = new CultureInfo("en-US", true).DateTimeFormat;
                        string temp = dtfi.GetMonthName(Convert.ToInt32(dr[i].ToString()));
                        dtSift.Rows[j - 1][i] = temp;
                    }
                    else
                    {
                        dtSift.Rows[j - 1][i] = dr[i];
                    }
                    if (toDay + 3 == i && Convert.ToInt32(dr["Month"]) == toMonth && Convert.ToInt32(dr["Year"]) == toYear)
                    {
                        i = dsTempShiftAllocation.Tables[0].Columns.Count;
                    }
                }
            }
            dsTempShiftAllocation.Tables.Remove("Table");
            dsTempShiftAllocation.Tables.Add(dtSift);
        }
        return dsTempShiftAllocation;
    }
    private void BindingReligion()
    {
        DataSet dsReligion = new DataSet();
        dsReligion = objEmployee.SelectReligion();
        if (dsReligion != null)
        {
            if (dsReligion.Tables[0].Rows.Count > 0)
            {
                ddlReligion.DataSource = dsReligion;
                ddlReligion.DataTextField = "Name";
                ddlReligion.DataValueField = "Id";
                ddlReligion.DataBind();
            }
            dsReligion.Dispose();
        }
        foreach (ListItem item in ddlReligion.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    private void loadcss()
    {
        CultureInfo ci;
        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;
        //if Standard Demo
        htmlShiftViewPop.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
            styledatepicker3.Href = "../plugins/datepicker/datepicker3-rtl.css";
            styledaterangepicker.Href = "../plugins/daterangepicker/daterangepicker-bs3-rtl.css";
            styleProgressBar.Href = "../css/ProgressBar-rtl.css";
            styleselect2.Href = "../plugins/select2/select2.min-rtl.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew-rtl.css";
        }
        else
        {
            //htmlShiftViewPop.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            //styledatepicker3.Href = "../plugins/datepicker/datepicker3-rtl.css";
            //styledaterangepicker.Href = "../plugins/daterangepicker/daterangepicker-bs3-rtl.css";
            //styleProgressBar.Href = "../css/ProgressBar-rtl.css";
            //styleselect2.Href = "../plugins/select2/select2.min-rtl.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
            styledatepicker3.Href = "../plugins/datepicker/datepicker3.css";
            styledaterangepicker.Href = "../plugins/daterangepicker/daterangepicker-bs3.css";
            styleProgressBar.Href = "../css/ProgressBar.css";
            styleselect2.Href = "../plugins/select2/select2.min.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew.css";
        }
    }
}
