using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Transactions_PopUp_EmployeeOTCompOffSanction : Base.BasePage
{
    #region Variable Declaraion
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    ShiftAllocationEvendata obj = new ShiftAllocationEvendata();
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    Rpt_Common rptcommon = new Rpt_Common();
    OTEventData objOT = new OTEventData();
    DataTable dtLeaveOTDetails = new DataTable();
    DataTable dtLeaveApplicationOTHrs = new DataTable();
    int intCount;
    DataView dv;
    int loginEmployeeId, intUpOTHrs, intOTHrs;
    DataSet ds = new DataSet();
    string OTStatus;
    DataSet dsOtEmployee = new DataSet();
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        //if Standar Edition set the visibility to false
        int otApprovalExists = 0;
        loadcss();
        otApprovalExists = objCommon.CheckPageExistsInLicense(97);
        if (otApprovalExists == 0)
        {
            string strScripts = "";
            strScripts = strScripts + "<script language='javascript'>";
            strScripts = strScripts + "parent.$('#myModal').modal('hide');</script>";
            Page.RegisterStartupScript("AlertManualApproval", strScripts);
            return;
        }
        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 = Int32.Parse(Session["EmpAutoID"].ToString());
            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") + "','" + rm.GetString("Alert_SelectItemsToDelete") + "','" + rm.GetString("Alert_ConfirmDeletePermanent") + "','" + rm.GetString("Alert_Areyousuretorestore") + "','" + rm.GetString("Alert_SelectItemsToRestore") + "','" + rm.GetString("Alert_SelectItemToForwarded") + "','" + rm.GetString("Alert_SelectItemToApproved") + "');";
            strSetAlert = strSetAlert + "SetAlert('" + rm.GetString("CheckedOtCompOff") + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
        if (!IsPostBack)
        {
            string strScript = "<script language='javascript'>";
            if (Convert.ToInt32(Session["parentLevelId"]) == 0)
            {
                string strStatus = rm.GetString("Alert_SelectCompany", ci);
                dvSanction.Visible = false;
                strScript = strScript + "alert('" + strStatus + "');parent.$('#myModal').modal('hide');";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertManualApproval", strScript);
                return;
            }
            #region Not Required For Checking.
            #endregion
            CompOffAndOTEmployeeDetails();
            Session["EmployeeIds"] = "";
        }
    }
    #endregion
    #region User Defined Functions

    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
        htmlEmpOTcomp.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";
            styledatepicker3.Href = "../plugins/datepicker/datepicker3-rtl.css";
            styledaterangepicker.Href = "../plugins/daterangepicker/daterangepicker-bs3-rtl.css";
        }
        else
        {
            //htmlOTpop.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";
            //styledatepicker3.Href = "../plugins/datepicker/datepicker3-rtl.css";
            //styledaterangepicker.Href = "../plugins/daterangepicker/daterangepicker-bs3-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";
        }
    }
    protected void CompOffAndOTEmployeeDetails()
    {
        DataSet dsYearSetting = new DataSet();
        string strFromdate, strTodate, Level;
        string EmployeeID = Request.QueryString["EmpId"].ToString();
        string EmployeeName = Request.QueryString["EmpName"].ToString();
        int EmployeeCategory = Convert.ToInt32(Request.QueryString["EmpCategory"].ToString());
        int EmployeeType = Convert.ToInt32(Request.QueryString["EmpType"].ToString());
        string gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        string Fromdate = Request.QueryString["FromDate"].ToString();
        string Todate = Request.QueryString["ToDate"].ToString();
        string SanctionType = Request.QueryString["SanctionType"].ToString();
        string strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
        dsYearSetting = objYearSettingsEventData.GetActiveYearSettings();
        if (dsYearSetting.Tables[0].Rows.Count <= 0)
        {
            return;
        }
        else
        {
            strFromdate = dsYearSetting.Tables[0].Rows[0]["FromDate"].ToString();
            strTodate = dsYearSetting.Tables[0].Rows[0]["ToDate"].ToString();
        }
        Fromdate = (Fromdate == string.Empty) ? strFromdate : objCommon.DateConvertion(gstrDateFormat, Fromdate);
        Todate = (Todate == string.Empty) ? strTodate : objCommon.DateConvertion(gstrDateFormat, Todate);
        Level = rptcommon.getNodes(Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
        OTStatus = Request.QueryString["Status"].ToString();
        dsOtEmployee = objOT.SelectCompOffAndOTEmployee(Fromdate, Todate, EmployeeID, EmployeeName, Level, EmployeeCategory, EmployeeType, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), OTStatus, strSwipeCard, Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["EmpAutoID"]));
        Session["OTEmployee"] = dsOtEmployee;
        bool bCount = true;
        if (dsOtEmployee.Tables.Count > 0)
        {
            grv_EmployeeOverTimeDetails.DataSource = dsOtEmployee;
            grv_EmployeeOverTimeDetails.DataBind();
            bCount = btn_Approved.Visible = btn_Reject.Visible = !(dsOtEmployee.Tables[0].Rows.Count <= 0);
        }
        btn_Approved.Visible = (OTStatus != "Approved") && bCount;
        btn_Reject.Visible = (OTStatus != "Rejected") && bCount;
    }
    public void EmployeeSorting()
    {
        DataSet dsSort = new DataSet();
        dsSort = (DataSet)Session["OTEmployee"];
        if (ViewState["sort"] != null)
        {
            dv = new DataView(dsSort.Tables[0]);
            dv.Sort = ViewState["sort"].ToString() + " " + ViewState["sort_direction"].ToString();
        }
        else
        {
            dv = dsSort.Tables[0].DefaultView;
        }
        grv_EmployeeOverTimeDetails.DataSource = dv; ;
        grv_EmployeeOverTimeDetails.DataBind();
    }
    private void LoadStrings(CultureInfo ci)
    {
        btn_Approved.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Approved", ci) + "/" + rm.GetString("btn_Forwarded", ci);
        btn_Reject.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Reject", ci);
        grv_EmployeeOverTimeDetails.Columns[2].HeaderText = rm.GetString("Reports_Date", ci);
        grv_EmployeeOverTimeDetails.Columns[3].HeaderText = rm.GetString("email_EmployeeId", ci);
        grv_EmployeeOverTimeDetails.Columns[4].HeaderText = rm.GetString("email_EmployeeName", ci);
        grv_EmployeeOverTimeDetails.Columns[5].HeaderText = rm.GetString("LevelDetails_LevelName", ci);
        //ToDo:V1.9
        //grv_EmployeeOverTimeDetails.Columns[6].HeaderText = rm.GetString("OTSanction_ExtraHoursWorked", ci); 
        grv_EmployeeOverTimeDetails.Columns[6].HeaderText = "Actual Extra Hours Worked";
        grv_EmployeeOverTimeDetails.Columns[7].HeaderText = "Modified Extra Hours Worked";
        grv_EmployeeOverTimeDetails.Columns[8].HeaderText = rm.GetString("lbl_OT_Selection", ci);
        grv_EmployeeOverTimeDetails.Columns[9].HeaderText = rm.GetString("lbl_CompOff_Selection", ci);
        grv_EmployeeOverTimeDetails.Columns[10].HeaderText = rm.GetString("email_Status", ci);
        grv_EmployeeOverTimeDetails.Columns[11].HeaderText = "";
        lblheader.Text = rm.GetString("lblOTCompOffApproval", ci);
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    #region Not Used.
    public string GetApprovalStatus(int intCompanyId, string strModule)
    {
        int approvalSettingsPageExists = 0;
        //Checking grade module is available or not and changed the id value from 110 to 228
        approvalSettingsPageExists = objCommon.CheckPageExistsInLicense(228);
        string strStatus = string.Empty;
        if (approvalSettingsPageExists == 1)
        {
            DataSet dsApprovalSettings = new DataSet();
            ShiftEvenData objShift = new ShiftEvenData();
            dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
            if (dsApprovalSettings != null)
            {
                if (dsApprovalSettings.Tables.Count > 0)
                {
                    if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                    {
                        if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0][strModule]) == false)
                        {
                            strStatus = "ApprovalNotRequired";
                        }
                        else
                        {
                            strStatus = "ApprovalRequired";
                        }
                    }
                    else
                    {
                        strStatus = "NotDefined";
                    }
                }
            }
        }
        else
        {
            strStatus = "ApprovalRequired";
        }
        return strStatus;
    }
    public int getParentCompany(int iEmployeeLevelID)
    {
        org_levelsEventData getOrg = new org_levelsEventData();
        getOrg.GetOrgParentLevels_FromID(iEmployeeLevelID);
        DataSet ds_getOrg = new DataSet();
        ds_getOrg = getOrg.GetOrgParentLevels();
        int iCompanyID = 0;
        if (ds_getOrg != null)
        {
            if (ds_getOrg.Tables[0].Rows.Count > 0)
            {
                iCompanyID = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"].ToString());
            }
        }
        return iCompanyID;
    }
    #endregion
    #endregion
    #region Grid View Events
    protected void grv_EmployeeOverTimeDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        grv_EmployeeOverTimeDetails.EditIndex = -1;
        grv_EmployeeOverTimeDetails.DataSource = (DataSet)Session["OTEmployee"];
        grv_EmployeeOverTimeDetails.DataBind();
        ViewState["EditMode"] = "Fales";
    }
    protected void grv_EmployeeOverTimeDetails_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grv_EmployeeOverTimeDetails.EditIndex = e.NewEditIndex;
        grv_EmployeeOverTimeDetails.DataSource = (DataSet)Session["OTEmployee"];
        grv_EmployeeOverTimeDetails.DataBind();
        TextBox txtOT = (TextBox)grv_EmployeeOverTimeDetails.Rows[e.NewEditIndex].FindControl("txtHoursOT");
        Label lblOT = (Label)grv_EmployeeOverTimeDetails.Rows[e.NewEditIndex].FindControl("lblHoursOT");
        Label lblStatus = (Label)grv_EmployeeOverTimeDetails.Rows[e.NewEditIndex].FindControl("lblOTStatus");
        if (lblStatus.Text != "Approved")
        {
            //txtOT.Attributes.Add("onmouseover", "javascript:return DynamicDatePicker('" + txtOT.ClientID + "')");
            if (txtOT.Text == "00:00" && lblOT.Text == "00:00")
            {
                txtOT.Enabled = false;
                txtOT.Style.Add("background-color", "#D3DBE7");
            }
            else
            {
                txtOT.Enabled = true;
                txtOT.Style.Add("background-color", "#FFF");
            }
        }
        else
        {
            string str = "<script language=\"javascript\">";
            //str = str + "alert('Select Any Record');";
            str = str + "alert('" + rm.GetString("OT_Approved", ci) + "');";
            str = str + "</script>";
            Page.RegisterStartupScript("alert", str);
            grv_EmployeeOverTimeDetails.EditIndex = -1;
            grv_EmployeeOverTimeDetails.DataSource = (DataSet)Session["OTEmployee"];
            grv_EmployeeOverTimeDetails.DataBind();
            return;
        }
        ViewState["EditMode"] = "True";

    }
    protected void grv_EmployeeOverTimeDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int Pro_RecordID = Convert.ToInt32(((Label)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("lblProc_RecordId")).Text);
        string UpOTHours = Convert.ToString(((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Text);
        string OTHours = Convert.ToString(((Label)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("lblHoursOT")).Text);
        string OTHoursIN = Convert.ToString(((Label)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("lblHoursOT")).ToolTip);
        string[] str1;
        DataSet OTComEmp = (DataSet)Session["OTEmployee"];
        if (UpOTHours == "")
        {
            string str = "<script language=\"javascript\">";
            //str = str + "alert('Select Any Record');";
            str = str + "alert('" + rm.GetString("Alert_ModifiedMissed", ci) + "');";
            str = str + "</script>";
            Page.RegisterStartupScript("alert", str);
            ((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Focus();
            return;
        }
        // Get Modify OT Hours in integer format
        str1 = UpOTHours.Split(':');
        if (str1.Length == 2)
        {
            if (str1[0].Length == 2)
            {
                intUpOTHrs = Convert.ToInt32(str1[0]) * 60;
            }
            else
            {
                string str = "<script language=\"javascript\">";
                //str = str + "alert('Select Any Record');";
                str = str + "alert('" + rm.GetString("Alert_HoursIncorrect", ci) + "');";
                str = str + "</script>";
                Page.RegisterStartupScript("alert", str);
                ((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Focus();
                return;
            }
            if (str1[1].Length == 2)
            {
                intUpOTHrs = intUpOTHrs + Convert.ToInt32(str1[1]);
            }
            else
            {
                string str = "<script language=\"javascript\">";
                //str = str + "alert('Select Any Record');";
                str = str + "alert('" + rm.GetString("Alert_HoursIncorrect", ci) + "');";
                str = str + "</script>";
                Page.RegisterStartupScript("alert", str);
                ((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Focus();
                return;
            }
        }
        else
        {
            string str = "<script language=\"javascript\">";
            //str = str + "alert('Select Any Record');";
            str = str + "alert('" + rm.GetString("Alert_HoursIncorrect", ci) + "');";
            str = str + "</script>";
            Page.RegisterStartupScript("alert", str);
            ((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Focus();
            return;
        }
        // Get OT Hours in integer format
        str1 = OTHours.Split(':');
        if (str1.Length == 2)
        {
            intOTHrs = Convert.ToInt32(str1[0]) * 60;
            intOTHrs = intOTHrs + Convert.ToInt32(str1[1]);
        }
        if (intOTHrs < intUpOTHrs)
        {
            string str = "<script language=\"javascript\">";
            //str = str + "alert('Select Any Record');";
            str = str + "alert('" + rm.GetString("Alert_ActOTHours", ci) + "');";
            str = str + "</script>";
            Page.RegisterStartupScript("alert", str);
            ((TextBox)grv_EmployeeOverTimeDetails.Rows[e.RowIndex].FindControl("txtHoursOT")).Focus();
            return;
        }
        //ToDO: This Line used to update the dataset value using select querys.
        obj.UpdateOTHours(OTHoursIN, intOTHrs, UpOTHours, OTHours, intUpOTHrs, Pro_RecordID);
        CompOffAndOTEmployeeDetails();
        grv_EmployeeOverTimeDetails.EditIndex = -1;
        grv_EmployeeOverTimeDetails.DataSource = (DataSet)Session["OTEmployee"];
        grv_EmployeeOverTimeDetails.DataBind();
        ViewState["EditMode"] = "Fales";
    }

    protected void grv_EmployeeOverTimeDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblStatus = (Label)e.Row.FindControl("lblOTStatus");
                Label lblHoursOT = (Label)e.Row.FindControl("lblHoursOT");
                Label lblHoursOT1 = (Label)e.Row.FindControl("lblHoursOT1");
                if (lblStatus.Text == "Approved")
                {
                    lblStatus.Text = rm.GetString("btn_Approved", ci);
                }
                else if (lblStatus.Text == "Forwarded")
                {
                    lblStatus.Text = rm.GetString("btn_Forwarded", ci);
                }
                else if (lblStatus.Text == "Pending")
                {
                    lblStatus.Text = rm.GetString("btn_Pending", ci);
                }
                else if (lblStatus.Text == "Rejected")
                {
                    lblStatus.Text = rm.GetString("btn_Reject", ci);
                }
                Label lbl = (Label)e.Row.Cells[2].FindControl("lblOTDate");
                if (lbl.Text != "")
                {
                    lbl.Text = (Convert.ToDateTime(lbl.Text.ToString())).ToString(Session["MDateFormat"].ToString());
                }
                if (lblHoursOT1 != null)
                {
                    if (lblHoursOT.Text == lblHoursOT1.Text)
                    {
                        lblHoursOT1.Style.Add("color", "#333");
                    }
                    else
                    {
                        lblHoursOT1.Style.Add("color", "#F00");
                    }
                }
            }
        }
        catch (Exception Ex)
        {
        }
    }
    protected void grv_EmployeeOverTimeDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            grv_EmployeeOverTimeDetails.EnableViewState = true;
            grv_EmployeeOverTimeDetails.PageIndex = e.NewPageIndex;
            grv_EmployeeOverTimeDetails.DataSource = (DataSet)Session["OTEmployee"];
            grv_EmployeeOverTimeDetails.DataBind();
        }
        catch (Exception Ex)
        {
        }
    }
    public void grv_EmployeeOverTimeDetails_Sorting(object sender, GridViewSortEventArgs e)
    {
        try
        {
            ViewState["sort"] = e.SortExpression;
            ViewState["sort"] = e.SortExpression;
            if (ViewState["sort_direction"] == null)
            {
                ViewState["sort_direction"] = "Asc";
            }
            else if (ViewState["sort_direction"].ToString() == "Asc")
            {
                ViewState["sort_direction"] = "Desc";
            }
            else
            {
                ViewState["sort_direction"] = "Asc";
            }
            EmployeeSorting();
        }
        catch (Exception Ex)
        {
        }
    }
    #endregion
    #region Button Events
    protected void btn_Approved_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(ViewState["EditMode"]) == "True")
            {
                string str = "<script language=\"javascript\">";
                //str = str + "alert('Select Any Record');";
                str = str + "alert('Update the OT hours and then proceed with approvals');";
                str = str + "</script>";
                Page.RegisterStartupScript("alert", str);
                return;
            }
            DataSet ds = ((DataSet)Session["OTEmployee"]).Copy();
            ds.Tables[0].TableName = "ColumnValues";
            if (!(ds.Tables[0].Columns.Contains("IsUpdated"))) ds.Tables[0].Columns.Add("IsUpdated");
            int iCheckedRow = 0;
            bool bAlert = false;
            string strAlert = "Alert_SelectAnyRecord", strMsg = string.Empty;
            foreach (GridViewRow gRow in grv_EmployeeOverTimeDetails.Rows)
            {
                DataRow[] dRow = ds.Tables[0].Select("Process_Rec_ID = " + Convert.ToString(((Label)gRow.FindControl("lblProc_RecordId")).Text));
                CheckBox chkChecked = ((CheckBox)gRow.FindControl("chkChecked"));
                CheckBox chkOT = ((CheckBox)gRow.FindControl("chkOTSelection"));
                CheckBox chkCompOff = ((CheckBox)gRow.FindControl("chkCompOffSelection"));
                if (!chkChecked.Enabled) continue;
                if (chkChecked.Checked)
                {
                    dRow[0]["OTChecked"] = chkOT.Checked;
                    dRow[0]["CompOffChecked"] = (chkOT.Checked && !chkCompOff.Enabled) ? false : chkCompOff.Checked;
                    dRow[0]["IsUpdated"] = "U";
                    bAlert = (!chkOT.Checked && !chkCompOff.Checked);
                    if (bAlert)
                    {
                        strAlert = "CheckedOtCompOff";
                        break;
                    }
                    iCheckedRow++;
                }
                dRow[0]["Status"] = chkChecked.Checked ? Convert.ToString(dRow[0]["Status"]) : Convert.ToString(dRow[0]["OverTimeStatus"]);
            }
            if (iCheckedRow == 0 || bAlert)
            {
                strMsg = "<script language=\"javascript\">";
                strMsg = strMsg + "alert('" + rm.GetString(strAlert, ci) + "');";
                strMsg = strMsg + "</script>";
                Page.RegisterStartupScript("alert", strMsg);
                return;
            }
            StringWriter strWriteXML = new StringWriter();
            ds.WriteXml(strWriteXML);
            objOT.UpdateEmployeeCompOffOTStatus(strWriteXML.ToString());
            strMsg = "<script language=\"javascript\">";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');";
            //strMsg = strMsg + "opener.focus();";
            strMsg = strMsg + "window.top.location.href = window.top.location.href + '?fl=1&sid=" + Session.SessionID + "';";
            strMsg = strMsg + "parent.$('#myModal').modal('hide');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("alert", strMsg);
        }
        catch (Exception Ex)
        {
            throw;
        }
    }
    protected void btn_Reject_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(ViewState["EditMode"]) == "True")
            {
                string str = "<script language=\"javascript\">";
                //str = str + "alert('Select Any Record');";
                str = str + "alert('Update the OT hours and then proceed with rejected');";
                str = str + "</script>";
                Page.RegisterStartupScript("alert", str);
                return;
            }
            DataSet ds = ((DataSet)Session["OTEmployee"]).Copy();
            ds.Tables[0].TableName = "ColumnValues";
            if (!(ds.Tables[0].Columns.Contains("IsUpdated"))) ds.Tables[0].Columns.Add("IsUpdated");
            int iCheckedRow = 0;
            bool bAlert = false;
            string strAlert = "Alert_SelectAnyRecord", strMsg = string.Empty;
            foreach (GridViewRow gRow in grv_EmployeeOverTimeDetails.Rows)
            {
                DataRow[] dRow = ds.Tables[0].Select("Process_Rec_ID = " + Convert.ToString(((Label)gRow.FindControl("lblProc_RecordId")).Text));
                CheckBox chkChecked = ((CheckBox)gRow.FindControl("chkChecked"));
                CheckBox chkOT = ((CheckBox)gRow.FindControl("chkOTSelection"));
                CheckBox chkCompOff = ((CheckBox)gRow.FindControl("chkCompOffSelection"));
                if (!chkChecked.Enabled) continue;
                if (chkChecked.Checked)
                {
                    dRow[0]["OTChecked"] = chkOT.Checked;
                    dRow[0]["CompOffChecked"] = (chkOT.Checked && !chkCompOff.Enabled) ? false : chkCompOff.Checked;
                    dRow[0]["IsUpdated"] = "U";
                    bAlert = (!chkOT.Checked && !chkCompOff.Checked);
                    if (bAlert)
                    {
                        strAlert = "CheckedOtCompOff";
                        break;
                    }
                    iCheckedRow++;
                }
                dRow[0]["Status"] = chkChecked.Checked ? "Rejected" : Convert.ToString(dRow[0]["OverTimeStatus"]);
            }
            if (iCheckedRow == 0 || bAlert)
            {
                strMsg = "<script language=\"javascript\">";
                strMsg = strMsg + "alert('" + rm.GetString(strAlert, ci) + "');";
                strMsg = strMsg + "</script>";
                Page.RegisterStartupScript("alert", strMsg);
                return;
            }
            StringWriter strWriteXML = new StringWriter();
            ds.WriteXml(strWriteXML);
            objOT.UpdateEmployeeCompOffOTStatus(strWriteXML.ToString());
            strMsg = "<script language=\"javascript\">";
            strMsg = strMsg + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');";
            //strMsg = strMsg + "opener.focus();";
            strMsg = strMsg + "window.top.location.href = window.top.location.href + '?fl=1&sid=" + Session.SessionID + "';";
            strMsg = strMsg + "parent.$('#myModal').modal('hide');";
            strMsg = strMsg + "</script>";
            Page.RegisterStartupScript("alert", strMsg);
        }
        catch (Exception Ex)
        {
            throw;
        }
    }
    #endregion
}