using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Threading;
using System.Resources;

public partial class Transactions_PopUp_ShiftRequisitionadd : System.Web.UI.Page
{

    #region Global Variable Decalration
    ResourceManager rm;
    CultureInfo ci;
    int LevelID, loginEmployeeId;
    DataSet ds = new DataSet();
    bool checkRecordExists;
    bool checkLevel;
    ShiftAllocationEvendata obj = new ShiftAllocationEvendata();
    GetReports ObjectShift = new GetReports();
    EmployeeEventData objEmployee = new EmployeeEventData();
    #endregion
    #region Page Load Event
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            btn_done1.Visible = false;
            BindingEmployeeCategoryandType();
            Session["EmpCategoryShift"] = 0;
            Session["EmpTypeShift"] = 0;
            BindingReligion();
        }
        checkRecordExists = true;
        loadcss();
        if (Session["Session_ActiveLanguage"] == null)
        {
            string str = "<script language=\"javascript\">";
            str = str + "opener.focus();";
            str = str + "opener.location.href = opener.location + '?fl=1&sid=" + Session.SessionID + "';";
            str = str + "self.close();";
            str = str + "</script>";
            Response.Write(str);
        }
        else
        {
            string source_Language;
            loginEmployeeId = Convert.ToInt32(Session["EmpAutoID"]);
            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);
            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 + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }


    }



    #endregion
    public void shiftDataBind()
    {
        LevelID = Convert.ToInt32(Session["currentSession"]);
        string strEmpCodeID = "";
        strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
        {
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
            lblError.Text = "";
        }
        else
        {
            grv_Shift.DataBind();
            Div1.Visible = false;
            btn_done1.Visible = false;
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_Selectallorganizationlevels", ci) + "');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message", strMsg);
            checkLevel = true;
            checkRecordExists = false;
            return;
        }
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Convert.ToString(Session["PopShiftEmpId"]);
        }
        ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]),
            Level, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId,
            LevelID, txtEmployeeName.Text, Convert.ToInt32(Session["EmpCategoryShift"]), Convert.ToInt32(Session["EmpTypeShift"]),
            Convert.ToInt32(ddlReligion.SelectedValue));
        //txt_StartDate.Text = "2023-05-01";
        //txt_ToDate.Text = "2023-05-31";

        //ds = ObjectShift.SelectShiftAllocationReport(txt_StartDate.Text, txt_ToDate.Text, txtEmployeeName.Text,LevelID.ToString(), strPopShiftEmployeeId,
        //   Convert.ToInt32(Session["EmpCategoryShift"]), Convert.ToInt32(Session["EmpTypeShift"]), Convert.ToString(Session["UserGroupName"]),
        //   Convert.ToString(Session["GradeLevel"]), "", LevelID, 0, "Both", Convert.ToInt32(ddlReligion.SelectedValue), 0);
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                grv_Shift.DataSource = ds.Tables[0];
                grv_Shift.DataBind();
                Session["TotalEmployees"] = ds.Tables[0].Rows.Count;
                ViewState["Employees"] = ds;
                Div1.Visible = true;
                btn_done1.Visible = true;
            }
            else
            {
                btn_done1.Visible = false;
                checkRecordExists = false;
            }
        }
        else
        {
            checkRecordExists = false;
        }
        if (checkRecordExists == true)
        {
            CheckBox chkSelect = new CheckBox();
            chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
            chkSelect.Checked = Convert.ToBoolean(Session["SelectAllStatus"]);
        }
    }
    public void CheckEmployeeId_CheckBox()
    {
        string strEmpId = "";
        strEmpId = (string)Session["EmployeeIds"];
        int intEmployeeIdsLength = strEmpId.Length;
        char[] Delimit = { ',' };
        string[] Empid = strEmpId.Split(Delimit);
        CheckBox deleteChkBxItem = new CheckBox();
        foreach (GridViewRow gr in grv_Shift.Rows)
        {
            string empId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
            foreach (string str in Empid)
            {
                if (str == empId)
                {
                    deleteChkBxItem = (CheckBox)gr.Cells[0].FindControl("deletethis");
                    deleteChkBxItem.Checked = true;
                    int intLength = empId.Length;
                    if (intEmployeeIdsLength > intLength)
                    {
                        int intIndex = strEmpId.IndexOf("," + str + ",");
                        if (intIndex != -1)
                        {
                            strEmpId = strEmpId.Remove(intIndex, (intLength + 1));
                        }
                        else
                        {
                            if (strEmpId.IndexOf(str + ",") != -1 && strEmpId.IndexOf(str + ",") == 0)
                            {
                                strEmpId = strEmpId.Remove(0, (intLength + 1));
                            }
                            else if (strEmpId.IndexOf("," + str) != -1 && (strEmpId.IndexOf("," + str) + intLength + 1) == intEmployeeIdsLength)
                            {
                                strEmpId = strEmpId.Substring(0, (intEmployeeIdsLength - (intLength + 1)));
                            }
                        }
                    }
                    else
                    {
                        strEmpId = strEmpId.Replace(empId, "");
                    }
                    intEmployeeIdsLength = strEmpId.Length;
                    Session["EmployeeIds"] = strEmpId;
                    goto D;
                }
            }
            D:;
        }
    }
    protected void grv_Shift_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_Shift.EnableViewState = true;
        string ChkBoxIDs = "";
        CheckBox deleteChkBxItem = new CheckBox();
        foreach (GridViewRow i in grv_Shift.Rows)
        {
            deleteChkBxItem = (CheckBox)i.Cells[0].FindControl("deletethis");
            if (deleteChkBxItem.Checked)
            {
                if (ChkBoxIDs == "")
                {
                    ChkBoxIDs = ((Label)i.FindControl("lbl_EmpId")).Text.ToString();
                }
                else
                {
                    ChkBoxIDs = ChkBoxIDs + "," + ((Label)i.FindControl("lbl_EmpId")).Text.ToString();
                }
            }
        }
        if (Convert.ToString(Session["EmployeeIds"]) == "")
        {
            Session["EmployeeIds"] = ChkBoxIDs;
        }
        else
        {
            if (ChkBoxIDs != "")
            {
                Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
            }
        }
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        Session["SelectAllStatus"] = chkSelect.Checked;
        grv_Shift.PageIndex = e.NewPageIndex;
        shiftDataBind();
        CheckEmployeeId_CheckBox();
    }
    protected void btn_done1_Click(object sender, EventArgs e)
    {
        if (Session["currentSession"] != null && Session["currentSession"] != string.Empty)
        {
            org_levelsEventData getOrg = new org_levelsEventData();
            getOrg.GetOrgParentLevels_FromID(Convert.ToInt32(Session["currentSession"]));
            DataSet ds_getOrg = new DataSet();
            ds_getOrg = getOrg.GetOrgParentLevels();
            if (ds_getOrg != null)
            {
                if (ds_getOrg.Tables[0].Rows.Count > 0)
                {
                    int companyId = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"]);
                    if (Session["DataAddedby"] == "IsSingle")
                    {
                        int gintUserId = Convert.ToInt32(Session["EmpAutoID"]);
                        obj.DeleteEmpShiftDetails(gintUserId);
                        Session["DataAddedby"] = "IsMultiple";
                    }
                    if (Convert.ToInt32(Session["previousCompanyId"]) == companyId)
                    {
                        InsertEmployeeDetails();
                        Session["CheckRecordsAddInPopUP"] = "TEst";
                        Session["ISSingleorMultiple"] = "IsMultiple";
                    }
                    else
                    {
                        int gintUserId = Convert.ToInt32(Session["EmpAutoID"]);
                        obj.DeleteEmpShiftDetails(gintUserId);
                        InsertEmployeeDetails();
                        Session["CheckRecordsAddInPopUP"] = "TEst";
                        Session["ISSingleorMultiple"] = "IsMultiple";
                    }
                }
            }
        }
        else
        {
        }
        DataSet ds = new DataSet();
        ds = obj.SelectEmployeeDetails(loginEmployeeId);
        Session["EmpDetails"] = ds;
        string str = "<script language=\"javascript\">";
        str = str + "window.top.location.href = window.top.location.href + '?fl=1&sid=" + Session.SessionID + "';";
        str = str + "parent.$('#myModal').modal('hide');";
        str = str + "</script>";
        Response.Write(str);
    }
    protected void InsertEmployeeDetails()
    {
        int intEmployeeId = 0;
        int intLoopCounter = 0;
        string strEmployeeCode = string.Empty;
        string strEmployeeName = string.Empty;
        string strEmployeeIds = Convert.ToString(Session["EmployeeIds"]);
        char[] Delimit = { ',' };
        string[] EmployeeIds = strEmployeeIds.Split(Delimit);
        LevelID = Convert.ToInt32(Session["currentSession"]);
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
        string strEmpCodeID = "";
        strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Convert.ToString(Session["PopShiftEmpId"]);
        }
        if (ViewState["Employees"] != null)
        {
            ds = (DataSet)ViewState["Employees"];
        }
        else
        {
            ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]), Level,
                Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]),
                strPopShiftEmployeeId, LevelID, txtEmployeeName.Text, Convert.ToInt32(Session["EmpCategoryShift"]),
                Convert.ToInt32(Session["EmpTypeShift"]), Convert.ToInt32(ddlReligion.SelectedValue));
        }
        int intCount = ds.Tables[0].Rows.Count;
        CheckBox chkSelect = new CheckBox();
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        if (chkSelectAll.Checked)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                intEmployeeId = Convert.ToInt32(dr["Employee_Id"]);
                strEmployeeCode = Convert.ToString(dr["Employee_Code_Id"]);
                strEmployeeName = Convert.ToString(dr["Employee Name"]);
                obj.InsertEmpDetails(intEmployeeId, strEmployeeCode, strEmployeeName.Replace("'", "''"), loginEmployeeId);
            }
        }
        else
        {
            foreach (GridViewRow gr in grv_Shift.Rows)
            {
                chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
                if (chkSelect.Checked)
                {
                    string strEmpCodeId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
                    for (intLoopCounter = 0; intLoopCounter < intCount; intLoopCounter++)
                    {
                        if (ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString() == strEmpCodeId)
                        {
                            intEmployeeId = Convert.ToInt32(ds.Tables[0].Rows[intLoopCounter]["Employee_Id"].ToString());
                            strEmployeeCode = ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString();
                            strEmployeeName = ds.Tables[0].Rows[intLoopCounter]["Employee Name"].ToString();
                            obj.InsertEmpDetails(intEmployeeId, strEmployeeCode, strEmployeeName.Replace("'", "''"), loginEmployeeId);
                        }
                    }
                }
            }
            foreach (string EmpCId in EmployeeIds)
            {
                for (intLoopCounter = 0; intLoopCounter < intCount; intLoopCounter++)
                {
                    if (ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString() == EmpCId)
                    {
                        intEmployeeId = Convert.ToInt32(ds.Tables[0].Rows[intLoopCounter]["Employee_Id"].ToString());
                        strEmployeeCode = ds.Tables[0].Rows[intLoopCounter]["Employee_Code_Id"].ToString();
                        strEmployeeName = ds.Tables[0].Rows[intLoopCounter]["Employee Name"].ToString();
                        obj.InsertEmpDetails(intEmployeeId, strEmployeeCode, strEmployeeName.Replace("'", "''"), loginEmployeeId);
                    }
                }
            }
        }
    }
    protected void butGo_Click(object sender, EventArgs e)
    {
        Session["SelectAllStatus"] = "False";
        Session["EmployeeIds"] = "";
        Session["currentSession"] = Session["parentLevelId"];
        Session["parentLevelId"] = null;
        if (txtEmpCodeID.Text.Trim() != string.Empty)
        {
            Session["PopShiftEmpId"] = txtEmpCodeID.Text.Trim();
        }
        else
        {
            Session["PopShiftEmpId"] = null;
        }
        shiftDataBind();
        if (checkLevel == true)
        {
            return;
        }
        if (checkRecordExists == true)
        {
            btn_done1.Visible = true;
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "$('html, body').animate({scrollTop: 800}, 'slow');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message ShiftAllocationAdd", strMsg);
        }
        else
        {
            btn_done1.Visible = false;
            string strMsg;
            strMsg = "<script language='javascript'>";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_Thereisnorecord", ci) + "');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("Display Message ShiftAllocationAdd", strMsg);
            Div1.Visible = false;
            return;
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {

        butGo.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Go", ci);
        btn_done1.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Ok", ci);
        grv_Shift.Columns[1].HeaderText = rm.GetString("email_EmployeeId", ci);
        grv_Shift.Columns[2].HeaderText = rm.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        lblReligion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        //CustomValidator1.ErrorMessage = rm.GetString("Validator_ShiftAllocation_ScheduleFrom", ci);
        //CustomValidator3.ErrorMessage = rm.GetString("Validator_ShiftAllocation_ScheduleTo", ci);
    }
    private void BindingEmployeeCategoryandType()
    {
        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);
            }
        }
        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);
            }
        }
    }
    protected void grv_CheckAll_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        string ChkBoxIDs = string.Empty;
        if (chkSelect.Checked)
        {
            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
            if (Session["EmployeeIds"].ToString() == "")
            {
                Session["EmployeeIds"] = ChkBoxIDs;
            }
            else
            {
                if (ChkBoxIDs != "")
                {
                    Session["EmployeeIds"] = Session["EmployeeIds"] + "," + ChkBoxIDs;
                }
            }
        }
        else
        {
            Session["EmployeeIds"] = string.Empty;
        }
        foreach (GridViewRow gr in grv_Shift.Rows)
        {
            chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
            chkSelect.Checked = ((CheckBox)sender).Checked;
        }
    }
    protected void grv_Check_CheckedChanged(object sender, EventArgs e)
    {
        string ChkBoxIDs = string.Empty;
        int intCount = 0;
        int intGridPageSize = grv_Shift.PageSize;
        int intGridTotalPages = grv_Shift.PageCount;
        bool boolAllChecked = false;
        CheckBox chkSelect = new CheckBox();
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)grv_Shift.HeaderRow.Cells[0].FindControl("checkall");
        if (((CheckBox)sender).Checked == false)
        {
            chkSelectAll.Checked = false;
        }
        else
        {
            foreach (GridViewRow gr in grv_Shift.Rows)
            {
                chkSelect = (CheckBox)gr.Cells[0].FindControl("deletethis");
                if (chkSelect.Checked)
                    intCount = intCount + 1;
            }
            if (Convert.ToInt32(Session["TotalEmployees"].ToString()) == intCount)
            {
                chkSelectAll.Checked = true;
            }
            else if (intCount > 0 && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intCount && Convert.ToInt32(Session["TotalEmployees"].ToString()) > intGridPageSize)
            {
                if (intCount == intGridPageSize)
                {
                    if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                    {
                        ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                        char[] Delimit = { ',' };
                        string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                        string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                        Array.Sort(SessionEmployeeIds);
                        Array.Sort(ChedkedEmployeeIds);
                        if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                        {
                            for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                            {
                                if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                {
                                    boolAllChecked = false;
                                    break;
                                }
                            }
                            boolAllChecked = true;
                        }
                        if (boolAllChecked == true)
                        {
                            chkSelectAll.Checked = true;
                        }
                    }
                }
                else if (grv_Shift.PageIndex == intGridTotalPages - 1)
                {
                    int intLastPageCount = Convert.ToInt32(Session["TotalEmployees"].ToString()) - (intGridPageSize * (intGridTotalPages - 1));
                    if (intCount == intLastPageCount)
                    {
                        if (Session["EmployeeIds"] != null || Session["EmployeeIds"].ToString() != string.Empty)
                        {
                            ChkBoxIDs = GetEmployeeIdsInOtherPagesOfGrid();
                            char[] Delimit = { ',' };
                            string[] SessionEmployeeIds = Session["EmployeeIds"].ToString().Split(Delimit);
                            string[] ChedkedEmployeeIds = ChkBoxIDs.Split(Delimit);
                            Array.Sort(SessionEmployeeIds);
                            Array.Sort(ChedkedEmployeeIds);
                            if (SessionEmployeeIds.Length == ChedkedEmployeeIds.Length)
                            {
                                for (int iLoop = 0; iLoop < ChedkedEmployeeIds.Length; iLoop++)
                                {
                                    if (SessionEmployeeIds[iLoop] != ChedkedEmployeeIds[iLoop])
                                    {
                                        boolAllChecked = false;
                                        break;
                                    }
                                }
                                boolAllChecked = true;
                            }
                            if (boolAllChecked == true)
                            {
                                chkSelectAll.Checked = true;
                            }
                        }
                    }
                }
            }
        }
    }
    protected string GetEmployeeIdsInOtherPagesOfGrid()
    {
        LevelID = Convert.ToInt32(Session["currentSession"]);
        Rpt_Common rptcommon = new Rpt_Common();
        string Level = "";
        if (LevelID != 0)
            Level = rptcommon.getNodes(LevelID, Convert.ToString(Session["LevelRights"]));
        string strEmpCodeID = "";
        strEmpCodeID = Convert.ToString(txtEmpCodeID.Text).Replace("'", "''");
        string strPopShiftEmployeeId = null;
        if (Session["PopShiftEmpId"] != null)
        {
            strPopShiftEmployeeId = Session["PopShiftEmpId"].ToString();
        }
        if (ViewState["Employees"] != null)
        {
            ds = (DataSet)ViewState["Employees"];
        }
        else
        {
            ds = obj.SelectEmployeeForShiftAlloc(Convert.ToInt32(Session["EmpAutoId"]), Level, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strPopShiftEmployeeId, LevelID, txtEmployeeName.Text, Convert.ToInt32(Session["EmpCategoryShift"]), Convert.ToInt32(Session["EmpTypeShift"]), Convert.ToInt32(ddlReligion.SelectedValue));
        }
        string strEmpId = string.Empty;
        string ChkBoxIDs = string.Empty;
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            foreach (GridViewRow gr in grv_Shift.Rows)
            {
                strEmpId = ((Label)gr.FindControl("lbl_EmpId")).Text.ToString();
                if (strEmpId == dr["employee_id"].ToString())
                {
                    goto A;
                }
            }
            if (ChkBoxIDs == "")
            {
                ChkBoxIDs = dr["Employee_Code_Id"].ToString();
            }
            else
            {
                ChkBoxIDs = ChkBoxIDs + "," + dr["Employee_Code_Id"].ToString();
            }
            A:;
        }
        return ChkBoxIDs;
    }
    protected void grv_Shift_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    }
    protected void ddlEmpCatagory_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["EmpCategoryShift"] = ddlEmpCatagory.SelectedValue;
    }
    protected void ddlEmpType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["EmpTypeShift"] = ddlEmpType.SelectedValue;
    }
    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;
        htmlShiftAllocation.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";
            styleselect2.Href = "../plugins/select2/select2.min-rtl.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew-rtl.css";
        }
        else
        {
            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";
            styleselect2.Href = "../plugins/select2/select2.min.css";
            stylefonts.Href = "../dist/css/fonts.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew.css";
        }
    }
}