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_PopUpManualTimeEntryApproval : Base.BasePage
{
    #region Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    ManualEntryEventData objManualEntryEventData = new ManualEntryEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    cls_Common objcls_Common = new cls_Common();
    Rpt_Common rptcommon = new Rpt_Common();
    DataTable dtManualEntrySanctionView = new DataTable();
    DataSet dsYearSetting = new DataSet();
    DataSet ds_Checkuser = new DataSet();
    int vmonthValue;
    string startDate;
    bool CheckGrid = false;
    bool statusProcess = false;
    bool checkRecordExists;
    int intCount, EmployeeCategory, EmployeeType;
    string endDate, gstrDateFormat, LevelId, Status, From_Date, To_Date, StartMonth, EndMonth, StartYear, EndYear;
    string EmployeeID, EmployeeName;
    string strSwipeCard = "";
    #endregion
    #region Page Load events
    /// <summary>
    /// on page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        int manualEntryExists = 0;
        manualEntryExists = objcls_Common.CheckPageExistsInLicense(98);
        if (manualEntryExists == 0)
        {
            string strScripts = "";
            strScripts = strScripts + "<script language='javascript'>";
            strScripts = strScripts + "parent.$('#myModal').modal('hide');</script>";
            Page.RegisterStartupScript("AlertManualApproval", strScripts);
            return;
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        //aspnetForm.Attributes.CssStyle.Add("Direction", rm.GetString("Direction", ci));
        if (!IsPostBack)
        {
            UserRights();
            LoadStrings(ci);
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            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 + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
        Status = Convert.ToString(Request.QueryString["Status"]);
        From_Date = Convert.ToString(Request.QueryString["FromDate"]);
        To_Date = Convert.ToString(Request.QueryString["ToDate"]);
        EmployeeID = Convert.ToString(Request.QueryString["EmpId"]);
        EmployeeName = Convert.ToString(Request.QueryString["EmpName"]);
        EmployeeCategory = Convert.ToInt32(Request.QueryString["EmpCategory"].ToString());
        EmployeeType = Convert.ToInt32(Request.QueryString["EmpType"].ToString());
        strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
        LevelId = rptcommon.getNodes(Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        if (From_Date != string.Empty)
        {
            From_Date = objcls_Common.DateConvertion(gstrDateFormat, From_Date);
        }
        if (To_Date != string.Empty)
        {
            To_Date = objcls_Common.DateConvertion(gstrDateFormat, To_Date);
        }
        if (!IsPostBack)
        {
            int intCompanyId;
            string strStatus = string.Empty;
            string strModule = string.Empty;
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            bool blnParentExists = true;
            strModule = "ManualEntry";
            if (Session["parentLevelId"] == null)
            {
                blnParentExists = false;
            }
            else if (Convert.ToInt32(Session["parentLevelId"]) == 0)
            {
                blnParentExists = false;
            }
            if (blnParentExists == false)
            {
                Div1.Visible = false;
                strScript = strScript + "alert('" + rm.GetString("Alert_SelectCompany", ci) + "');parent.$('#myModal').modal('hide');";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertManualApproval", strScript);
                return;
            }
            intCompanyId = getParentCompany(Convert.ToInt32(Session["parentLevelId"]));
            strStatus = GetApprovalStatus(intCompanyId, strModule);
            switch (strStatus)
            {
                case "ApprovalNotRequired":
                    strStatus = rm.GetString("Alert_ApprovalNotRequiredforthiscompany", ci);
                    Div1.Visible = false;
                    strScript = strScript + "alert('" + strStatus + "');parent.$('#myModal').modal('hide');";
                    strScript = strScript + "</script>";
                    Page.RegisterStartupScript("AlertManualApproval", strScript);
                    return;
                case "ApprovalRequired":
                    break;
                case "NotDefined":
                    strStatus = rm.GetString("Alert_ApprovalSettingsnotdefinedforthiscompany", ci);
                    Div1.Visible = false;
                    strScript = strScript + "alert('" + strStatus + "');parent.$('#myModal').modal('hide');";
                    strScript = strScript + "</script>";
                    Page.RegisterStartupScript("AlertManualApproval", strScript);
                    return;
            }            
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            dsYearSetting = objYearSettingsEventData.GetActiveYearSettings();
            if (dsYearSetting.Tables[0].Rows.Count <= 0)
            {
                return;
            }
            else
            {
                StartMonth = dsYearSetting.Tables[0].Rows[0]["StartMonth"].ToString();
                StartYear = dsYearSetting.Tables[0].Rows[0]["StartYear"].ToString();
                vmonthValue = MonthValue(StartMonth);
                startDate = vmonthValue.ToString() + "/1/" + StartYear;
                EndMonth = dsYearSetting.Tables[0].Rows[0]["EndMonth"].ToString();
                EndYear = dsYearSetting.Tables[0].Rows[0]["EndYear"].ToString();
                vmonthValue = MonthValue(EndMonth);
                endDate = vmonthValue.ToString() + "/31/" + EndYear;
            }
            if (LevelId == "0")
            {
                LevelId = null;
            }
            if (Status == "-Select Status-")
            {
                Status = "All";
            }
            if (From_Date == string.Empty)
            {
                From_Date = startDate;
            }
            if (To_Date == string.Empty)
            {
                To_Date = endDate;
            }
            BindManualEntrySanctionDetails();
            switch (Status)
            {
                case "Pending":
                    btnPending.Visible = false;
                    break;
                case "Approved":
                    btnApproved.Visible = false;
                    btnForwarded.Visible = false;
                    break;
                case "Forwarded":
                    btnForwarded.Visible = false;
                    break;
                case "Rejected":
                    btnReject.Visible = false;
                    break;
            }
        }
        checkRecordExists = true;
    }
    #endregion
    #region User Defined Functions
    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;
    }
    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 = objcls_Common.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 void BindManualEntrySanctionDetails()
    {
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            dtManualEntrySanctionView = objManualEntryEventData.GetManualEntrySanctionDetailsForSuperAdmin(Convert.ToInt32(Session["EmpAutoId"]), LevelId, Status, EmployeeID, EmployeeName, EmployeeCategory, EmployeeType, From_Date, To_Date, strSwipeCard, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(Session["parentLevelId"]));
            Session["TotalEmployees"] = dtManualEntrySanctionView.Rows.Count;
            Session["DataManualEntrySanction"] = dtManualEntrySanctionView;
        }
        else
        {
            dtManualEntrySanctionView = objManualEntryEventData.GetManualEntrySanctionDetails(Convert.ToInt32(Session["EmpAutoId"]), LevelId, Status, EmployeeID, EmployeeName, EmployeeCategory, EmployeeType, Convert.ToDateTime(From_Date), Convert.ToDateTime(To_Date), strSwipeCard, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(Session["parentLevelId"]));
            Session["TotalEmployees"] = dtManualEntrySanctionView.Rows.Count;
            Session["DataManualEntrySanction"] = dtManualEntrySanctionView;
        }
        if (dtManualEntrySanctionView.Rows.Count > 0)
        {
            gdManualEntrySanctionView.DataSource = dtManualEntrySanctionView;
            gdManualEntrySanctionView.DataBind();
        }
        else
        {
            gdManualEntrySanctionView.DataSource = dtManualEntrySanctionView;
            gdManualEntrySanctionView.DataBind();
            btnApproved.Visible = false;
            btnForwarded.Visible = false;
            btnPending.Visible = false;
            btnReject.Visible = false;
            lblRemarks.Visible = false;
            txtRemarks.Visible = false;
            checkRecordExists = false;
        }
        if (checkRecordExists == true)
        {
            CheckBox chkSelect = new CheckBox();
            chkSelect = (CheckBox)gdManualEntrySanctionView.HeaderRow.Cells[0].FindControl("checkall");
            chkSelect.Checked = Convert.ToBoolean(Session["SelectAllStatus"].ToString());
        }
    }
    public int MonthValue(string monthName)
    {
        int monthValue = 0;
        switch (monthName)
        {
            case "January":
                monthValue= 1;
                break;
            case "February":
                monthValue = 2; break;
            case "March":
                monthValue = 3; break;
            case "April":
                monthValue = 4; break;
            case "May":
                monthValue = 5; break;
            case "June":
                monthValue = 6; break;
            case "July":
                monthValue = 7; break;
            case "August":
                monthValue = 8; break;
            case "September":
                monthValue = 9; break;
            case "October":
                monthValue = 10; break;
            case "November":
                monthValue = 11; break;
            case "December":
                monthValue = 12; break;
            default:
                monthValue = 0; break;
        }
        return monthValue;
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualTimeEntrySanction", ci);
        btnPending.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Pending", ci);
        btnApproved.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Approved", ci);
        btnForwarded.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Forwarded", ci);
        btnReject.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Reject", ci);
        lblRemarks.Text = rm.GetString("email_Remarks", ci);
        btn_Back.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        gdManualEntrySanctionView.Columns[2].HeaderText = rm.GetString("email_EmployeeId", ci);
        gdManualEntrySanctionView.Columns[3].HeaderText = rm.GetString("email_EmployeeName", ci);
        gdManualEntrySanctionView.Columns[4].HeaderText = rm.GetString("ManualTimeEntry_ManualTimeEntryDate", ci);
        gdManualEntrySanctionView.Columns[5].HeaderText = rm.GetString("ManualTimeEntrySanction_InEntry", ci);
        gdManualEntrySanctionView.Columns[6].HeaderText = rm.GetString("ManualTimeEntrySanction_OutEntry", ci);
        gdManualEntrySanctionView.Columns[7].HeaderText = rm.GetString("email_Reason", ci);
        gdManualEntrySanctionView.Columns[8].HeaderText = rm.GetString("email_Status", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(98, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    /// <summary>
    /// To update the manual entry status if the manual entry is not processed
    /// </summary>
    /// <param name="Status"></param>
    protected void UpdatedManualTimeEntryStatus(string Status)
    {
        string strEmployeeName = string.Empty;
        string strRemarks = string.Empty;
        DataTable dtManual = new DataTable();
        dtManual = (DataTable)Session["DataManualEntrySanction"];
        strRemarks = txtRemarks.Text.Trim();
        intCount = dtManual.Rows.Count;
        if (dtManual.Rows.Count > 0)
        {
            DataTable dtDataToBeUpdated = new DataTable();
            dtManual.DefaultView.RowFilter = "SelectedRecords=1";
            dtDataToBeUpdated = dtManual.DefaultView.ToTable();
            if (dtDataToBeUpdated.Rows.Count > 0)
            {
                CheckGrid = true;
                dtDataToBeUpdated.Columns.Remove("name");
                dtDataToBeUpdated.Columns.Remove("Employee_Code_Id");
                dtDataToBeUpdated.Columns.Remove("Employee_FirstName");
                dtDataToBeUpdated.Columns.Remove("ManualTimeEntry_Date");
                dtDataToBeUpdated.Columns.Remove("InDateTime");
                dtDataToBeUpdated.Columns.Remove("OutDateTime");
                dtDataToBeUpdated.Columns.Remove("ManualTimeEntry_Status");
                dtDataToBeUpdated.Columns.Remove("ManualTimeEntry_Reason");
                dtDataToBeUpdated.Columns.Remove("SelectedRecords");
                StringWriter strXMLData = new StringWriter();
                dtDataToBeUpdated.WriteXml(strXMLData);
                DataSet dsProcessedData = new DataSet();
                dsProcessedData = objManualEntryEventData.UpdateManualTimeEntrySanction_Group(Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]), strXMLData.ToString());
                if (dsProcessedData.Tables[0].Rows.Count > 0)
                {
                    statusProcess = true;
                    if (Convert.ToInt16(dsProcessedData.Tables[0].Rows[0]["UpdateCount"]) > 0)
                    {
                        if (Convert.ToInt16(dsProcessedData.Tables[0].Rows[0]["ProcessedDataCount"]) > 0)
                        {
                            Message(rm.GetString("Msg_TheRecordhasbeenalreadyprocessedCannotModifytheStatus", ci));
                            Session["DataManualEntrySanction"] = null;
                            string str = "<script language=\"javascript\">";
                            str = str + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');location.replace('TA_UI_Transactions_ManualTimeEntrySanction.aspx');";
                            //str = str + "opener.focus();";
                            //str = str + "opener.location.href = opener.location + '?fl=1&sid=" + Session.SessionID + "';";
                            //str = str + "self.close();";
                            str = str + "</script>";
                            Page.RegisterStartupScript("alert", str);
                        }
                        else
                        {
                            Session["DataManualEntrySanction"] = null;
                            string str = "<script language=\"javascript\">";
                            str = str + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');location.replace('TA_UI_Transactions_ManualTimeEntrySanction.aspx');";
                            str = str + "</script>";
                            Page.RegisterStartupScript("alert", str);
                        }
                    }
                    else if (Convert.ToInt16(dsProcessedData.Tables[0].Rows[0]["ProcessedDataCount"]) > 0)
                    {
                        Message2(rm.GetString("Msg_TheRecordhasbeenalreadyprocessedCannotModifytheStatus", ci));
                    }
                }
            }
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    #endregion
    #region Grid view events
    protected void gdManualEntrySanctionView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string NewTimeFormat = string.Empty;
            string TimeFormat = Convert.ToString(Session["ITimeFormat"]);
            if (TimeFormat == "%H:%M")
            {
                NewTimeFormat = "HH:mm:ss";
            }
            else
            {
                NewTimeFormat = "hh:mm:ss tt";
            }
            Label lblManualTimeEntryDate = (Label)e.Row.Cells[1].FindControl("lblManualTimeEntryDate");
            lblManualTimeEntryDate.Text = (Convert.ToDateTime(lblManualTimeEntryDate.Text.ToString())).ToString(Session["MDateFormat"].ToString());
            Label lblInEntry = (Label)e.Row.Cells[1].FindControl("lblInEntry");
            if (lblInEntry != null)
            {
                if (lblInEntry.Text != string.Empty && lblInEntry.Text != null)
                {
                    string[] PerTime = lblInEntry.Text.Split(" ".ToCharArray());
                    string timePart1 = PerTime[2].ToString() + " " + PerTime[3].ToString();
                    lblInEntry.Text = (Convert.ToDateTime(PerTime[0])).ToString(Session["MDateFormat"].ToString()) + " " + (Convert.ToDateTime(timePart1)).ToString(NewTimeFormat);
                }
            }
            Label lblOutEntry = (Label)e.Row.Cells[1].FindControl("lblOutEntry");
            if (lblOutEntry != null)
            {
                if (lblOutEntry.Text != string.Empty && lblOutEntry.Text != null)
                {
                    string[] PerTime = lblOutEntry.Text.Split(" ".ToCharArray());
                    string timePart1 = PerTime[2].ToString() + " " + PerTime[3].ToString();
                    lblOutEntry.Text = (Convert.ToDateTime(PerTime[0])).ToString(Session["MDateFormat"].ToString()) + " " + (Convert.ToDateTime(timePart1)).ToString(NewTimeFormat);
                }
            }
            Label lblStatus = (Label)e.Row.Cells[1].FindControl("lblManualTimeEntryStatus");
            if (lblStatus != null)
            {
                switch (Convert.ToString(lblStatus.Text))
                {
                    case "Approved":
                        lblStatus.Text = rm.GetString("btn_Approved", ci);
                        break;
                    case "Forwarded":
                        lblStatus.Text = rm.GetString("btn_Forwarded", ci);
                        break;
                    case "Pending":
                        lblStatus.Text = rm.GetString("btn_Pending", ci);
                        break;
                    case "Rejected":
                        lblStatus.Text = rm.GetString("btn_Reject", ci);
                        break;
                }
            }
            Label lblManualTimeEntryReason = (Label)e.Row.Cells[1].FindControl("lblManualTimeEntryReason");
            if (lblManualTimeEntryReason != null)
            {
                if (lblManualTimeEntryReason.Text.Trim() == "Discrepancy Entry")
                {
                    lblManualTimeEntryReason.Text = rm.GetString("Discrepancy_Entry", ci);
                }
            }
        }
    }
    protected void gdManualEntrySanctionView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdManualEntrySanctionView.PageIndex = e.NewPageIndex;
        DataTable dtManualEntryDatas = new DataTable();
        dtManualEntryDatas = (DataTable)Session["DataManualEntrySanction"];
        gdManualEntrySanctionView.DataSource = dtManualEntryDatas;
        gdManualEntrySanctionView.DataBind();
        CheckBox chkSelect = new CheckBox();
        chkSelect = (CheckBox)gdManualEntrySanctionView.HeaderRow.Cells[0].FindControl("checkall");
        chkSelect.Checked = Convert.ToBoolean(Session["SelectAllStatus"]);
    }
    protected void grv_Check_CheckedChanged(object sender, EventArgs e)
    {
        Label lblManualTimeEntryId = new Label();
        lblManualTimeEntryId.Text = ((Label)((CheckBox)(sender)).FindControl("lblManualTimeEntryId")).Text.ToString();
        DataTable dtManualTimeEntry = new DataTable();
        dtManualTimeEntry = (DataTable)Session["DataManualEntrySanction"];
        DataRow[] OTCheckedRow = dtManualTimeEntry.Select("ManualTimeEntry_Id = " + lblManualTimeEntryId.Text);
        if (OTCheckedRow.Length > 0)
        {
            if (((CheckBox)(sender)).Checked == true)
            {
                OTCheckedRow[0]["SelectedRecords"] = "1";
            }
            else
            {
                OTCheckedRow[0]["SelectedRecords"] = "0";
            }
        }
        dtManualTimeEntry.DefaultView.RowFilter = "SelectedRecords=0";
        int intSelectAllCount = dtManualTimeEntry.DefaultView.ToTable().Rows.Count;
        dtManualTimeEntry.DefaultView.RowFilter = string.Empty;
        CheckBox chkSelectAll = new CheckBox();
        chkSelectAll = (CheckBox)gdManualEntrySanctionView.HeaderRow.Cells[0].FindControl("checkall");
        if (intSelectAllCount == 0)
        {
            chkSelectAll.Checked = true;
        }
        else
        {
            chkSelectAll.Checked = false;
        }
        Session["SelectAllStatus"] = chkSelectAll.Checked;
        Session["DataManualEntrySanction"] = dtManualTimeEntry;
    }
    protected void grv_CheckAll_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            DataTable dtManualTimeEntryCheckAll = new DataTable();
            dtManualTimeEntryCheckAll = (DataTable)Session["DataManualEntrySanction"];
            foreach (DataRow drRow in dtManualTimeEntryCheckAll.Rows)
            {
                if (((CheckBox)(sender)).Checked == true)
                {
                    drRow["SelectedRecords"] = "1";
                }
                else
                {
                    drRow["SelectedRecords"] = "0";
                }
            }
            DataTable dt = new DataTable();
            dt = dtManualTimeEntryCheckAll.Copy();
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            gdManualEntrySanctionView.DataSource = ds.Tables[0];
            gdManualEntrySanctionView.DataBind();
            Session["DataManualEntrySanction"] = dtManualTimeEntryCheckAll;
            CheckBox chkSelect = new CheckBox();
            chkSelect = (CheckBox)gdManualEntrySanctionView.HeaderRow.Cells[0].FindControl("checkall");
            if (((CheckBox)(sender)).Checked)
            {
                chkSelect.Checked = true;
            }
            else
            {
                chkSelect.Checked = false;
            }
            Session["SelectAllStatus"] = chkSelect.Checked;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #endregion
    #region Button events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Session["DataManualEntrySanction"] = null;
        Response.Redirect("TA_UI_Transactions_ManualTimeEntrySanction.aspx");
    }
    protected void btn_Pending_Click(object sender, EventArgs e)
    {
        UpdatedManualTimeEntryStatus("Pending");
        if (CheckGrid == false)
        {
            Message(rm.GetString("Alert_SelectAnyRecord", ci));
        }       
    }
    protected void btn_Approved_Click(object sender, EventArgs e)
    {
        UpdatedManualTimeEntryStatus("Approved");
        if (CheckGrid == false)
        {
            Message(rm.GetString("Alert_SelectAnyRecord", ci));
        }        
    }
    protected void btn_Forwarded_Click(object sender, EventArgs e)
    {
        UpdatedManualTimeEntryStatus("Forwarded");
        if (CheckGrid == false)
        {
            Message(rm.GetString("Alert_SelectAnyRecord", ci));
        }
    }
    protected void btn_Reject_Click(object sender, EventArgs e)
    {
        UpdatedManualTimeEntryStatus("Rejected");
        if (CheckGrid == false)
        {
            Message(rm.GetString("Alert_SelectAnyRecord", ci));
        }        
    }
    protected void btn_Back_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transactions_ManualTimeEntrySanction.aspx");
    }
    #endregion
    #region MessageWithRedirect.
    /// <summary>
    /// Messages the with redirect.
    /// </summary>
    /// <param name="messageContent">Content of the message.</param>
    /// <param name="ToPage">To page.</param>
    private void Message(string messageContent)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + messageContent + "');";
        strScript += " </script>";
        this.RegisterStartupScript("setScript", strScript);
    }
    private void Message2(string messageContent)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + messageContent + "');";
        strScript += "var url = window.location.href;";
        strScript += "window.location.href='';";
        strScript += "window.location.href=url;";
        strScript += " </script>";
        this.RegisterStartupScript("setScript", strScript);
    }
    #endregion
    #region NotUsed
    #endregion
}
