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.Resources;
using System.Globalization;
using System.Threading;
using System.Net.Mail;
using System.Net;
using DevExpress.Web;
using System.Text;
using System.IO;
public partial class Transactions_TA_UI_Transactions_OnDutySanctionViewForBulkApproval : Base.BasePage
{
    #region Variable Declaration
    string source_Language;
    SMSNotification objsms = new SMSNotification();
    bool blnCheckSMS = true;
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    CCGroupEventData_Angler objCCGroup = new CCGroupEventData_Angler();
    DataSet ds_Checkuser = new DataSet();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    ManualEntryEventData objManualEntryEventData = new ManualEntryEventData();
    DataSet dsOnDutyConversation = new DataSet();
    cls_Common objcls_Common = new cls_Common();
    Rpt_Common rptcommon = new Rpt_Common();
    DataTable dtLeaveTransactionView = new DataTable();
    DataSet dsYearSetting = new DataSet();
    int vmonthValue;
    string startDate;
    bool checkRecordExists, Isprocessedrecord;
    string endDate, gstrDateFormat, LevelId, Status, From_Date, To_Date, StartMonth, EndMonth, StartYear, EndYear;
    string strSwipeCardNo = string.Empty;
    string strEmployeeName = string.Empty;
    string strEmployeeCodeId = string.Empty;
    Int64 gintManualTimeEntryId, gintUserId;
    string ScriptType = string.Empty;
    string EmployeeID;
    string strSwipeCard = "";
    PermissionEventData objPermissionEventData = new PermissionEventData();
    DataTable dtSanctionView = new DataTable();
    DataSet ds_EmailIdOfSanctionAuthority = new DataSet();
    DataSet dsEmailIdOfReportingTo = new DataSet();
    DataSet dsRecordsCount = new DataSet();
    int intCount, EmployeeCategory, EmployeeType;
    int Employee_Id, InsertCount = 0;
    string strOnDutyApplicationDate, Fromdatettime, Todatettime;
    string Remarks, strEmailIdSanctionAuthority, strEmailIdReportingTo, EmployeeName, EmployeeEamilId;
    string strEmpFirstName, strEmpLastName, strlevelName, strEmployeeEmailId, strEmailIdSanctioningAuthority;
    bool checkEmail = true;
    bool blnCheckEmail = true;
    DataSet ds_ReportingToSanctionAuthorityList = new DataSet();
    string Employee_Code_Id = string.Empty;
    int intApproval = 0, intAuthorityLevel = 0, intFirstLevelAuthorityId = 0, intSecondLevelAuthorityId = 0;
    string strHtml = string.Empty;
    string ChkBoxIDs = string.Empty;
    string[] chkBoxIDs;
    LeaveEventData objLeave = new LeaveEventData();
    DataTable dtLeaveavailedinMonth = new DataTable();
    DataTable dtManualEntrySanctionView = new DataTable();
    int intLoginEmpId = 0;
    string strApprovalCC = string.Empty;
    org_levelsEventData getOrg = new org_levelsEventData();
    DataSet ds_getOrg = new DataSet();
    DataSet ds_LeaveSanctionSettings = new DataSet();
    DataTable dt_LeaveSettings = new DataTable();
    DataTable dt_ApprovalAuthority = new DataTable();
    DataSet dsDepartmentMailIds = new DataSet();
    string levelName = string.Empty;
    string strYearSettingsFromdate, strYearSettingsTodate;
    int gintCompanyId = 0;
    string strHtmlLeaveDetails = string.Empty;
    bool boolChkLeave = true;
    DataSet dsYear = new DataSet();
    string TimeFormatMail = string.Empty;
    int intCommentsBy = 0;
    bool CheckGrid = false;
    bool statusProcess = false; int payrollConfig = 0;
    #endregion
    #region Page Load events
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        gdOndutySanctionViewBulk.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        //btnBack.Attributes.Add("onClick", "javascript:history.back(); return false;");
        //int manualEntryExists = 0;
        //manualEntryExists = objcls_Common.CheckPageExistsInLicense(174);
        //if (manualEntryExists == 0)
        //{
        //    string strScripts = "";
        //    strScripts = strScripts + "<script language='javascript'>";
        //    strScripts = strScripts + "window.close();</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"]);
        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);
        payrollConfig = objcls_Common.CheckPageExistsInLicense(185);
        UserRights();
        if (Request.QueryString["Status"] != null)
        {
            Status = Request.QueryString["Status"].ToString();
            Session["OndutyStatus"] = Status;
        }
        else
        {
            Status = Convert.ToString(Session["OndutyStatus"]);
        }
        if (Request.QueryString["FromDate"] != null)
        {
            From_Date = Request.QueryString["FromDate"].ToString();
            Session["ODFrmDate"] = Request.QueryString["FromDate"].ToString();
        }
        else if (Convert.ToString(Session["ODFrmDate"]) != string.Empty)
        {
            From_Date = Convert.ToString(Session["ODFrmDate"]);
        }
        if (Request.QueryString["ToDate"] != null)
        {
            To_Date = Request.QueryString["ToDate"].ToString();
            Session["ODToDate"] = Request.QueryString["ToDate"].ToString();
        }
        else if (Convert.ToString(Session["ODToDate"]) != string.Empty)
        {
            To_Date = Convert.ToString(Session["ODToDate"]);
        }
        if (Request.QueryString["EmpId"] != null)
        {
            EmployeeID = Request.QueryString["EmpId"].ToString();
            Session["ODEmpID"] = Request.QueryString["EmpId"].ToString();
        }
        else if (Convert.ToString(Session["ODEmpID"]) != string.Empty)
        {
            EmployeeID = Convert.ToString(Session["ODEmpID"]);
        }
        if (Request.QueryString["EmpName"] != null)
        {
            EmployeeName = Request.QueryString["EmpName"].ToString();
            Session["ODEmpName"] = Request.QueryString["EmpName"].ToString();
        }
        else if (Convert.ToString(Session["ODEmpName"]) != string.Empty)
        {
            EmployeeName = Convert.ToString(Session["ODEmpName"]);
        }
        if (Request.QueryString["EmpCategory"] != null)
        {
            EmployeeCategory = Convert.ToInt32(Request.QueryString["EmpCategory"].ToString());
            Session["ODEmpCat"] = Convert.ToInt32(Request.QueryString["EmpCategory"].ToString());
        }
        else if (Convert.ToString(Session["ODEmpCat"]) != string.Empty)
        {
            EmployeeCategory = Convert.ToInt32(Session["ODEmpCat"]);
        }
        if (Request.QueryString["EmpType"] != null)
        {
            EmployeeType = Convert.ToInt32(Request.QueryString["EmpType"].ToString());
            Session["ODEmpType"] = Convert.ToInt32(Request.QueryString["EmpType"].ToString());
        }
        else if (Convert.ToString(Session["ODEmpType"]) != string.Empty)
        {
            EmployeeType = Convert.ToInt32(Session["ODEmpType"]);
        }
        if (Request.QueryString["SwipeCard"] != null)
        {
            strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
            Session["ODSwipeCard"] = Convert.ToString(Request.QueryString["SwipeCard"].ToString());
        }
        else if (Convert.ToString(Session["ODSwipeCard"]) != string.Empty)
        {
            strSwipeCard = Convert.ToString(Session["ODSwipeCard"]);
        }
        LevelId = rptcommon.getNodes(Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        if (From_Date != string.Empty && From_Date != null)
        {
            From_Date = objcls_Common.DateConvertion(gstrDateFormat, From_Date);
        }
        if (To_Date != string.Empty && To_Date != null)
        {
            To_Date = objcls_Common.DateConvertion(gstrDateFormat, To_Date);
        }
        dsYear = objcls_Common.GetYearsetting();
        if (dsYear.Tables[0].Rows.Count <= 0)
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertLeavePolicyYear", strScript);
        }
        else
        {
            strYearSettingsFromdate = dsYear.Tables[0].Rows[0]["FromDate"].ToString();
            strYearSettingsTodate = dsYear.Tables[0].Rows[0]["ToDate"].ToString();
            dsYear.Dispose();
        }
        if (Status == "Approved,Pending,Resend,Forwarded,Rejected,Reply")
        {
            Status = "All";
        }
        if (Status != null && Status != "")
        {
            Status = Status.Replace(",", "','");
        }
        BindManualEntrySanctionDetails();
        if (!IsPostBack)
        {
            if (payrollConfig == 0)
            {
                objcls_Common.menu("OnDuty", "248");
            }
            else
            {
                objcls_Common.menu("OnDuty", "174");
            }
            int intCompanyId;
            string strStatus = string.Empty;
            string strModule = string.Empty;
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            bool blnParentExists = true;
            strModule = "Approval";
            if (Session["parentLevelId"] == null)
            {
                blnParentExists = false;
            }
            else if (Convert.ToInt32(Session["parentLevelId"]) == 0)
            {
                blnParentExists = false;
            }
            if (blnParentExists == false)
            {
                strScript = strScript + "alert('" + rm.GetString("Alert_SelectCompany", ci) + "');window.close();";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertManualApproval", strScript);
                return;
            }
            intCompanyId = getParentCompany(Convert.ToInt32(Session["parentLevelId"]));
            strStatus = GetApprovalStatus(intCompanyId, strModule);
            if (strStatus == "ApprovalNotRequired")
            {
                strStatus = rm.GetString("Alert_ApprovalNotRequiredforthiscompany", ci);
                strScript = strScript + "alert('" + strStatus + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertManualApproval", strScript);
                return;
            }
            else if (strStatus == "ApprovalRequired")
            {
            }
            else if (strStatus == "NotDefined")
            {
                strStatus = rm.GetString("Alert_ApprovalSettingsnotdefinedforthiscompany", ci);
                strScript = strScript + "alert('" + strStatus + "');location.replace('../Organization%20Settings/Organization_ShiftSetting.aspx');";
                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 (From_Date == string.Empty)
            {
                From_Date = startDate;
            }
            if (To_Date == string.Empty)
            {
                To_Date = endDate;
            }
            Session["LeaveChecked"] = null;
            dvRemarks.Visible = false;
            btnForward.Visible = false;
            btnApprove.Visible = false;
            int EmpID = Convert.ToInt32(Session["EmpAutoID"].ToString());
            DataSet ds = new DataSet();
            DataSet ds1 = new DataSet();
            ds = objPermissionEventData.CheckSanctioningPerson(EmpID);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0][0] != DBNull.Value && Convert.ToInt16(ds.Tables[0].Rows[0][0]) > 0)
                {
                    btnApprove.Visible = true;
                    dvRemarks.Visible = true;
                }
                else
                {
                    btnApprove.Visible = false;
                    ds1 = objPermissionEventData.CheckReportingPerson(EmpID);
                    if (ds1.Tables[0].Rows[0][0] != DBNull.Value && Convert.ToInt16(ds1.Tables[0].Rows[0][0]) > 0 && Convert.ToString(Session["OndutyStatus"]) != "Forwarded")
                    {
                        btnForward.Visible = true;
                        dvRemarks.Visible = true;
                    }
                    else
                    {
                        btnForward.Visible = false;
                        gdOndutySanctionViewBulk.Columns[0].Visible = false;
                    }
                }
            }
            if (Convert.ToString(Session["OndutyStatus"]) == "All" || Convert.ToString(Session["OndutyStatus"]) == "Approved" || Convert.ToString(Session["OndutyStatus"]) == "Rejected" || Convert.ToString(Session["OndutyStatus"]) == "Resend" || Convert.ToString(Session["OndutyStatus"]) == "Reply")
            {
                dvRemarks.Visible = false;
                btnForward.Visible = false;
                btnApprove.Visible = false;
                gdOndutySanctionViewBulk.Columns[0].Visible = false;
            }
            if (Convert.ToString(Session["OndutyStatus"]) == "Pending")
            {
                dvRemarks.Visible = true;
                btnForward.Visible = true;
                btnApprove.Visible = false;
            }
            if (gdOndutySanctionViewBulk.VisibleRowCount == 0)
            {
                dvRemarks.Visible = false;
                btnForward.Visible = false;
                btnApprove.Visible = false;
                gdOndutySanctionViewBulk.Columns[0].Visible = false;
            }
            if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["OndutyStatus"]) == "Pending" && Convert.ToString(Session["HasSpecialRights"]) == "True")
            {
                dvRemarks.Visible = false;
                btnForward.Visible = false;
                btnApprove.Visible = false;
                // Added this line by gopinath as per the QA team suggestion during the 1.8 final testing.
                gdOndutySanctionViewBulk.Columns[0].Visible = false;
            }
        }
    }
    #endregion
    #region User Defined Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("OnDutyApproval_Header", ci);
        btnSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btnForward.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Forwarded", ci);
        btnApprove.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Approved", ci);
        lblLoading.Text = "&nbsp;&nbsp;" + rm.GetString("ProgressBarText", ci);
        gdOndutySanctionViewBulk.Columns[1].Caption = rm.GetString("email_EmployeeId", ci);
        gdOndutySanctionViewBulk.Columns[2].Caption = rm.GetString("email_EmployeeName", ci);
        gdOndutySanctionViewBulk.Columns[3].Caption = rm.GetString("ManualTimeEntry_ManualTimeEntryDate", ci);
        gdOndutySanctionViewBulk.Columns[4].Caption = rm.GetString("OnDuty_InDate", ci);
        gdOndutySanctionViewBulk.Columns[5].Caption = rm.GetString("OnDuty_InTime", ci);
        gdOndutySanctionViewBulk.Columns[6].Caption = rm.GetString("OnDuty_OutDate", ci);
        gdOndutySanctionViewBulk.Columns[7].Caption = rm.GetString("OnDuty_OutTime", ci);
        gdOndutySanctionViewBulk.Columns[8].Caption = rm.GetString("email_Reason", ci);
        gdOndutySanctionViewBulk.Columns[9].Caption = rm.GetString("email_Status", ci);
    }
    private void UserRights()
    {
        int pageid = 0;
        if (payrollConfig == 0)
        {
            pageid = 248;
        }
        else
        {
            pageid = 174;
        }
        ds_Checkuser = objCheckUser.checkRights(pageid, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    public void BindManualEntrySanctionDetails()
    {
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            dtManualEntrySanctionView = objManualEntryEventData.GetOnDutyEntrySanctionForSuperAdmin(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;
            // gdOndutySanctionViewBulk.Columns[0].Visible = false;
            dvRemarks.Visible = false;
            btnApprove.Visible = false;
            btnForward.Visible = false;
        }
        else
        {
            dtManualEntrySanctionView = objManualEntryEventData.GetOnDutySanctionForUser(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;
        }
        if (dtManualEntrySanctionView.Rows.Count > 0)
        {
            gdOndutySanctionViewBulk.DataSource = dtManualEntrySanctionView;
            gdOndutySanctionViewBulk.DataBind();
        }
        else
        {
            gdOndutySanctionViewBulk.DataSource = dtManualEntrySanctionView;
            gdOndutySanctionViewBulk.DataBind();
        }
    }
    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 int MonthValue(string monthName)
    {
        if (monthName == "January")
            return 1;
        else if (monthName == "February")
            return 2;
        else if (monthName == "March")
            return 3;
        else if (monthName == "April")
            return 4;
        else if (monthName == "May")
            return 5;
        else if (monthName == "June")
            return 6;
        else if (monthName == "July")
            return 7;
        else if (monthName == "August")
            return 8;
        else if (monthName == "September")
            return 9;
        else if (monthName == "October")
            return 10;
        else if (monthName == "November")
            return 11;
        else if (monthName == "December")
            return 12;
        else
            return 0;
    }
    /// <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["dtSanctionView"];
        strRemarks = txtRemarks.Text.Trim();
        intCount = dtManual.Rows.Count;
        Isprocessedrecord = false;
        if (dtManual.Rows.Count > 0)
        {
            DataTable dtDataToBeUpdated = new DataTable();
            dtDataToBeUpdated = dtManual.DefaultView.ToTable();
            if (dtDataToBeUpdated.Rows.Count > 0)
            {
                CheckGrid = true;
                //dtDataToBeUpdated.Columns.Remove("Employee_Code_Id");
                //dtDataToBeUpdated.Columns.Remove("Employee_Name");
                //dtDataToBeUpdated.Columns.Remove("Mdate");
                //dtDataToBeUpdated.Columns.Remove("InDate");
                //dtDataToBeUpdated.Columns.Remove("OutDate");
                //dtDataToBeUpdated.Columns.Remove("ManualTimeEntry_Status");
                //dtDataToBeUpdated.Columns.Remove("ManualTimeEntry_Reason");
                StringWriter strXMLData = new StringWriter();
                dtDataToBeUpdated.WriteXml(strXMLData);
                //DataSet dsProcessedData = new DataSet();
                if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
                {
                    //dsProcessedData = objManualEntryEventData.UpdateODEntrySanction_Group(Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]), strXMLData.ToString());
                    //if (dsProcessedData.Tables[0].Rows.Count > 0)
                    //{
                    statusProcess = true;
                    Session["dtSanctionView"] = null;
                    InsertCount = InsertCount + 1;
                    objManualEntryEventData.UpdateOndutyEntrySanction_Approvel(Convert.ToInt32(gintManualTimeEntryId), Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    objManualEntryEventData.UpdateOnDutyApplicationConversation(gintManualTimeEntryId, Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    //}
                }
                else
                {
                    //dsProcessedData = objManualEntryEventData.UpdateManualTimeEntrySanction_Group(Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]), strXMLData.ToString());
                    //if (dsProcessedData.Tables[0].Rows.Count > 0)
                    //{
                    statusProcess = true;
                    Session["dtSanctionView"] = null;
                    InsertCount = InsertCount + 1;
                    //if (Convert.ToInt16(dsProcessedData.Tables[0].Rows[0]["ProcessedDataCount"]) > 0)
                    //{
                    //    Isprocessedrecord = true;
                    //    Session["dtSanctionView"] = null;
                    //    string str = "<script language=\"javascript\">";
                    //    str = str + "alert('" + rm.GetString("Msg_TheRecordhasbeenalreadyprocessedCannotModifytheStatus", ci) + "');window.location.href = 'TA_UI_Transactions_OnDutySanction.aspx';";
                    //    str = str + "</script>";
                    //    Page.RegisterStartupScript("alert", str);
                    //    return;
                    //}
                    //else
                    //{
                    objManualEntryEventData.UpdateOndutyEntrySanction_Approvel(Convert.ToInt32(gintManualTimeEntryId), Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    objManualEntryEventData.UpdateOnDutyApplicationConversation(gintManualTimeEntryId, Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    //}
                    //}
                }
                #region Commented Part
                #endregion
            }
        }
    }
    private string[] SplitCCTo(string CCTo)
    {
        string[] strArrEmailAddressForCC;
        strArrEmailAddressForCC = CCTo.Split(';');
        return (strArrEmailAddressForCC);
    }
    private void ControlCreation()
    {
        DataTable dtReplyResend = new DataTable();
        dtReplyResend.TableName = "dtReplyResend";
        DataColumn dcDate = new DataColumn("Date");
        DataColumn dcCommentsBy = new DataColumn("Comments By");
        DataColumn dcComments = new DataColumn("Comments");
        dtReplyResend.Columns.Add(dcDate);
        dtReplyResend.Columns.Add(dcCommentsBy);
        dtReplyResend.Columns.Add(dcComments);
        DataRow dRowReplyResend;
        dsOnDutyConversation = objManualEntryEventData.GetOndutyConversation(gintManualTimeEntryId);
        if (dsOnDutyConversation != null && dsOnDutyConversation.Tables[0].Rows.Count > 0)
        {
            Table leaveConversation = new Table();
            leaveConversation.BorderWidth = 1;
            leaveConversation.CellPadding = 5;
            leaveConversation.CellSpacing = 0;
            leaveConversation.Width = Unit.Pixel(600);
            leaveConversation.CssClass = "td";
            leaveConversation.Attributes.Add("border", "1");
            TableHeaderRow leaveConversationHr = new TableHeaderRow();
            TableHeaderCell leaveConversationHeading3 = new TableHeaderCell();
            leaveConversationHeading3.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
            leaveConversationHeading3.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading3);
            TableHeaderCell leaveConversationHeading1 = new TableHeaderCell();
            leaveConversationHeading1.Text = rm.GetString("leaveConversationHeading1", ci);
            leaveConversationHeading1.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading1);
            TableHeaderCell leaveConversationHeading2 = new TableHeaderCell();
            leaveConversationHeading2.Text = rm.GetString("leaveConversationHeading2", ci);
            leaveConversationHeading2.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading2);
            leaveConversation.Rows.Add(leaveConversationHr);
            if (dsOnDutyConversation.Tables[0].Rows.Count > 0)
            {
                int rowIndex = 0;
                foreach (DataRow drLeaveConversation in dsOnDutyConversation.Tables[0].Rows)
                {
                    dRowReplyResend = dtReplyResend.NewRow();
                    TableRow trLeaveConversation = new TableRow();
                    TableCell tcLeaveConversationRepliedOn = new TableCell();
                    Label lblLeaveConversationRepliedOn = new Label();
                    tcLeaveConversationRepliedOn.BorderWidth = 1;
                    tcLeaveConversationRepliedOn.Width = 120;
                    lblLeaveConversationRepliedOn.ID = "lblLeaveConversationRepliedOn" + rowIndex;
                    lblLeaveConversationRepliedOn.Text = Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MDateFormat"].ToString()) + " " + Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MTimeFormat"].ToString());
                    dRowReplyResend["Date"] = Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MDateFormat"].ToString()) + " " + Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MTimeFormat"].ToString());
                    tcLeaveConversationRepliedOn.Controls.Add(lblLeaveConversationRepliedOn);
                    trLeaveConversation.Cells.Add(tcLeaveConversationRepliedOn);
                    TableCell tcLeaveConversationCommentsBy = new TableCell();
                    Label lblLeaveConversationCommentsBy = new Label();
                    tcLeaveConversationCommentsBy.Width = 120;
                    lblLeaveConversationCommentsBy.Text = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                    dRowReplyResend["Comments By"] = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                    tcLeaveConversationCommentsBy.Controls.Add(lblLeaveConversationCommentsBy);
                    trLeaveConversation.Cells.Add(tcLeaveConversationCommentsBy);
                    TableCell tcLeaveConversationComments = new TableCell();
                    Label lblLeaveConversationComments = new Label();
                    lblLeaveConversationComments.ID = "lblLeaveConversationComments" + rowIndex;
                    lblLeaveConversationComments.Text = drLeaveConversation["Comments"].ToString();
                    dRowReplyResend["Comments"] = drLeaveConversation["Comments"].ToString();
                    tcLeaveConversationComments.Controls.Add(lblLeaveConversationComments);
                    trLeaveConversation.Cells.Add(tcLeaveConversationComments);
                    leaveConversation.Rows.Add(trLeaveConversation);
                    rowIndex += 1;
                    dtReplyResend.Rows.Add(dRowReplyResend);
                }
            }
        }
        if (dsOnDutyConversation.Tables[0].Rows.Count > 0)
        {
            strHtml = buildPage("ReplyResend", dtReplyResend);
        }
    }
    public string buildPage(string strPageTitle, DataTable myDT)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<html>");
        sb.Append("<head>");
        sb.Append("<title>");
        sb.Append(strPageTitle);
        sb.Append("</title>");
        sb.Append("<style type='text/css'>");
        sb.Append(".Header {color: #FFFFFF; font-family: Arial;font-size: x-small;font-weight: bold;}");
        sb.Append(".rows {font-family: Arial; font-size: x-small;background-color:#FFE3B9}");
        sb.Append(".rowsNew {font-family: Arial; font-size: x-small;background-color:#FFEED5}");
        sb.Append("</style>");
        sb.Append("</head>");
        sb.Append("<body>");
        sb.Append("<table border='1' cellpadding='2' style='border-collapse: collapse' bordercolor='#666666' width='700'>");
        sb.Append("  <tr bgcolor='#003466'>");
        foreach (DataColumn Col in myDT.Columns)
        {
            sb.Append("<td><span class='Header'>" + Col.ColumnName.ToString() + "</span></td>");
        }
        sb.Append("  </tr>");
        int intWidth = 0;
        int intIncrement = 0;
        foreach (DataRow Row in myDT.Rows)
        {
            intWidth = 0;
            if (intIncrement % 2 == 0)
            {
                sb.Append("  <tr>");
            }
            else
            {
                sb.Append("  <tr>");
            }
            foreach (DataColumn Col in myDT.Columns)
            {
                if (intWidth == 2)
                {
                    sb.Append("<td><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");
                }
                else if (intWidth != 2)
                {
                    sb.Append("<td><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");
                }
                intWidth = intWidth + 1;
            }
            sb.Append("  </tr>");
            intIncrement = intIncrement + 1;
        }
        sb.Append("</table>");
        sb.Append("</body>");
        sb.Append("</html>");
        return sb.ToString();
    }
    #region Sending mail to the reporting to person.
    private void SendMailOnduty(int OnDutyID, int LevelID, string strEmployeeEmailId, string ToMailId, string SanctionMailId, string FromDate, string FromTime, string ToDate, string ToTime, string ApplicationDate, string EmployeeName, string Employee_Code_Id, string strReason, string strRemarks, string strlevelName, string OndutyStatus)
    {
        string strFromEmailId = string.Empty;
        MailMessage mailMessage = new MailMessage();
        try
        {
            string scriptText;
            DataTable dtTableScript = new DataTable();
            string ScriptType = "Onduty Application Modify";
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            if (dtTableScript.Rows.Count > 0)
            {
                scriptText = Convert.ToString(dtTableScript.Rows[0]["ScriptText"]);
                //if (Session["loginEmailId"] != null && Convert.ToString(Session["loginEmailId"]) != string.Empty)
                //{
                //    mailMessage.From = new MailAddress(Convert.ToString(Session["loginEmailId"]));
                //    strFromEmailId = Convert.ToString(Session["loginEmailId"]);
                //}
                //else
                //{
                mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
                strFromEmailId = Convert.ToString(ConfigurationManager.AppSettings.Get("FromId"));
                //}
                //mailMessage.To.Add(new MailAddress(ToMailId));                
                if (OndutyStatus == "Forwarded")
                {
                    if (SanctionMailId != string.Empty)
                    {
                        mailMessage.To.Add(new MailAddress(SanctionMailId));
                    }
                    if (strEmployeeEmailId != string.Empty)
                    {
                        mailMessage.CC.Add(new MailAddress(strEmployeeEmailId));
                    }
                }
                if (Session["loginEmailId"] != null && Session["loginEmailId"].ToString() != string.Empty)
                {
                    if (SanctionMailId != strEmailIdReportingTo)
                    {
                        if (OndutyStatus != "Forwarded")
                        {
                            if (Session["loginEmailId"].ToString() == SanctionMailId)
                            {
                                if (strEmployeeEmailId != string.Empty)
                                {
                                    mailMessage.To.Add(new MailAddress(strEmployeeEmailId));
                                }
                                if (strEmailIdReportingTo != string.Empty)
                                {
                                    mailMessage.CC.Add(new MailAddress(strEmailIdReportingTo));
                                }
                            }
                            if (Session["loginEmailId"].ToString() == strEmailIdReportingTo)
                            {
                                if (strEmployeeEmailId != string.Empty)
                                {
                                    mailMessage.To.Add(new MailAddress(strEmployeeEmailId));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (OndutyStatus != "Forwarded")
                        {
                            if (strEmployeeEmailId != string.Empty)
                            {
                                mailMessage.To.Add(new MailAddress(strEmployeeEmailId));
                            }
                        }
                    }
                }
                else
                {
                    if (OndutyStatus != "Forwarded")
                    {
                        if (strEmployeeEmailId != string.Empty)
                        {
                            mailMessage.To.Add(new MailAddress(strEmployeeEmailId));
                        }
                    }
                }
                if (Status == "Approved")
                {
                    DataSet dsCCEmailIds = new DataSet();
                    DataSet dsSanctionView = new DataSet();
                    dsSanctionView = objManualEntryEventData.SelectODEntryById(gintManualTimeEntryId);
                    dtSanctionView = dsSanctionView.Tables[0];
                    dsCCEmailIds = objCCGroup.GetCCEmailIds(Convert.ToInt16(dtSanctionView.Rows[0]["levelid"].ToString()), Convert.ToInt16(dtSanctionView.Rows[0]["DesignationID"].ToString()), "OD");
                    if (dsCCEmailIds != null)
                    {
                        if (dsCCEmailIds.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow drCcEmailId in dsCCEmailIds.Tables[0].Rows)
                            {
                                MailAddressCollection MailAddrCollectionCC = mailMessage.CC;
                                // added by Gopinath.k for Mantis Bug no.24059 & 24098
                                if (drCcEmailId["EmailId"].ToString() != string.Empty)
                                {
                                    MailAddress newCC = new MailAddress(drCcEmailId["EmailId"].ToString());
                                    MailAddrCollectionCC.Add(newCC);
                                }
                            }
                        }
                    }
                }
                TimeFormatMail = Convert.ToString(Session["ITimeFormat"]);
                if (TimeFormatMail == "HH:mm")
                {
                    TimeFormatMail = "HH:mm";
                }
                else
                {
                    TimeFormatMail = "hh:mm tt";
                }
                mailMessage.Subject = rm.GetString("email_YourOndutyApplicationFor", ci) + " - " + ApplicationDate + " | " + Employee_Code_Id + " - " + EmployeeName + " | " + strlevelName + " - " + OndutyStatus;
                mailMessage.Body = scriptText.Replace("<<lblOndutyForm>>", rm.GetString("email_OndutyApplicationForm", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ltr_rtl>>", rm.GetString("Direction", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeID>>", rm.GetString("email_EmployeeId", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<EmployeeID>>", Employee_Code_Id);
                mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeName>>", rm.GetString("email_EmployeeName", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<EmployeeName>>", EmployeeName);
                mailMessage.Body = mailMessage.Body.Replace("<<lblApplicationDate>>", rm.GetString("ODEntry_ODEntryDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ApplicationDate>>", ApplicationDate);
                mailMessage.Body = mailMessage.Body.Replace("<<lblODDate>>", rm.GetString("OnDutyDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblFromDate>>", rm.GetString("email_FromDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<FromDate>>", FromDate + " " + Convert.ToDateTime(FromTime).ToString(TimeFormatMail));
                mailMessage.Body = mailMessage.Body.Replace("<<lblToDate>>", rm.GetString("email_ToDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ToDate>>", ToDate + " " + Convert.ToDateTime(ToTime).ToString(TimeFormatMail));
                mailMessage.Body = mailMessage.Body.Replace("<<lblStatus>>", rm.GetString("email_Status", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Status>>", OndutyStatus);
                mailMessage.Body = mailMessage.Body.Replace("<<lblReason>>", rm.GetString("email_Reason", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Reason>>", strReason);
                mailMessage.Body = mailMessage.Body.Replace("<<lblRemarks>>", rm.GetString("email_Remarks", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Remarks>>", strRemarks);
                if (OndutyStatus == "Forwarded" || OndutyStatus == "Pending")
                {
                    mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?ODID=" + Convert.ToString(OnDutyID) + "&LevelId=" + LevelID + "&Status=" + OndutyStatus + "&ApprovalType=Onduty&ParentID=" + Convert.ToString(Session["parentLevelId"]) + "");
                }
                else
                {
                    string strReplaceText = "<font face=\"Arial\" size=\"2\"><a href=\"<<LinkData>>\">Click here for approval </a></font>";
                    mailMessage.Body = mailMessage.Body.Replace(strReplaceText, string.Empty);
                }
                objcls_Common.SendMail(mailMessage);
            }
            else
            {
                blnCheckEmail = false;
            }
        }
        catch
        {
            blnCheckEmail = false;
            //objLeaveApplicationEventData.InsertLeaveApplicationDetailsInEmailTrigger(intLeaveApplicationId, strFromEmailId, ToMailId, strEmployeeEmailId, rm.GetString("email_LeaveApplicationForm", objCultureInfo) + " - " + ApplicationDate + " | " + Employee_Code_Id + " - " + EmployeeName + " | " + strlevelName + " - " + strMailStatus, Convert.ToString(mailMessage.Body), "", "LeaveApplication");
        }
    }
    #endregion
    #endregion
    #region Button events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Transactions/TA_UI_Transactions_OnDutySanction.aspx");
    }
    protected void btnForward_Click(object sender, EventArgs e)
    {
        string strReason = "";
        cls_Common objClassCommon = new cls_Common();
        DataTable dtSanctionView = new DataTable();
        DataSet dsSanctionView = new DataSet();
        if (txtRemarks.Text == string.Empty)
        {
            base.Message("Remarks is required");
            return;
        }
        else
        {
            string strLengthCheck = txtRemarks.Text.Trim().Replace("'", "''");
            if (strLengthCheck.Length > 1000)
            {
                Message("Maximum character for Reason is 1000");
                return;
            }
            #region OnDutyUpdation
            if (hdnSelectRow.Value != "")
            {
                chkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
                for (int i = 0; i < chkBoxIDs.Length; i++)
                {
                    gintManualTimeEntryId = Convert.ToInt32(chkBoxIDs[i]);
                    ViewState["Permission_Id"] = gintManualTimeEntryId;
                    dsSanctionView = objManualEntryEventData.SelectODEntryById(gintManualTimeEntryId);
                    dtSanctionView = dsSanctionView.Tables[0];
                    int EmployeeID = Convert.ToInt16(dsSanctionView.Tables[0].Rows[0]["Employee_Id"]);
                    int LevelID = 0;
                    string EmployeeCodeID = string.Empty;
                    Session["dtSanctionView"] = dtSanctionView;
                    int EmpAutoID = Convert.ToInt32(Session["EmpAutoID"].ToString());
                    DataSet ds = new DataSet();
                    ds = objPermissionEventData.CheckODForwardingPerson(EmployeeID);
                    if (ds.Tables[0].Rows[0][0] != DBNull.Value && Convert.ToInt16(ds.Tables[0].Rows[0][0]) > 0)
                    {
                        int ForwardingID = Convert.ToInt16(ds.Tables[0].Rows[0]["Reporting_to"]);
                        if (ForwardingID == EmpAutoID)
                        {
                            EmployeeCodeID = dtSanctionView.Rows[0]["Employee_Code_Id"].ToString();
                            DataSet dsEmployeeDetails = new DataSet();
                            dsEmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(EmployeeID));
                            if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                            {
                                strEmpFirstName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                                strEmpLastName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);
                                strEmployeeCodeId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_Code_Id"]);
                                strEmployeeName = strEmpFirstName + " " + strEmpLastName;
                                strlevelName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["levelName"]);
                                strEmployeeEmailId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["EmailID"]);
                                strEmailIdSanctioningAuthority = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ApprovalAuthorityEmailID"]);
                                strEmailIdReportingTo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ReportingToEmailID"]);
                                LevelID = Convert.ToInt32(dsEmployeeDetails.Tables[0].Rows[0]["LevelID"]);
                            }
                            UpdatedManualTimeEntryStatus("Forwarded");
                            if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                            {
                                SendMailOnduty(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, dtSanctionView.Rows[0]["Onduty_FromDate"].ToString(), dtSanctionView.Rows[0]["Onduty_FromTime"].ToString(), dtSanctionView.Rows[0]["Onduty_ToDate"].ToString(), dtSanctionView.Rows[0]["Onduty_ToTime"].ToString(), dtSanctionView.Rows[0]["Onduty_EntryDate"].ToString(), strEmployeeName, strEmployeeCodeId, dtSanctionView.Rows[0]["Onduty_Reason"].ToString(), txtRemarks.Text, strlevelName, "Forwarded");
                            }
                            #region SMSNotification
                            try
                            {
                                DataSet dsGateway = new DataSet();
                                DataSet dsStatus = new DataSet();
                                bool isSmsEnabled = false;
                                string destinationKey = string.Empty;
                                string MessageKey = string.Empty;
                                string ServiceUrl = string.Empty;
                                string mobileNo = string.Empty;
                                string strTemplateName = string.Empty;
                                bool isApplyAndReceiverSame = false;
                                if (Status == "Pending")
                                    strTemplateName = "OnDuty - Apply";
                                else if (Status == "Forwarded")
                                    strTemplateName = "OnDuty - Forward";
                                else if (Status == "Approved")
                                    strTemplateName = "OnDuty - Approved";
                                else if (Status == "Rejected")
                                    strTemplateName = "OnDuty - Rejected";
                                dsStatus = objsms.GetTemplateStauts(strTemplateName);
                                if (dsStatus.Tables.Count > 0)
                                {
                                    if (dsStatus.Tables[0].Rows.Count > 0 && Convert.ToBoolean(dsStatus.Tables[0].Rows[0]["Status"]) != false)
                                    {
                                        dsGateway = objsms.SelectGatewayDetails();
                                        if (dsGateway.Tables.Count > 0)
                                        {
                                            if (dsGateway.Tables[0].Rows.Count > 0)
                                            {
                                                ServiceUrl = Convert.ToString(dsGateway.Tables[0].Rows[0]["ServiceUrl"]);
                                                destinationKey = Convert.ToString(dsGateway.Tables[0].Rows[0]["DestinationKey"]);
                                                MessageKey = Convert.ToString(dsGateway.Tables[0].Rows[0]["MessageKey"]);
                                                isSmsEnabled = Convert.ToBoolean(dsStatus.Tables[0].Rows[0]["ToEmployee"]);
                                                if (dsEmployeeDetails.Tables.Count > 0)
                                                {
                                                    if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                                                    {
                                                        mobileNo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Mobile_Number"]);
                                                    }
                                                }
                                                DataSet dsReceivers = new DataSet();
                                                dsReceivers = objsms.GetReceiversDetails(strTemplateName, strEmployeeCodeId, strEmpFirstName, Convert.ToString(dtSanctionView.Rows[0]["Onduty_FromDate"]) + " " + Convert.ToDateTime(dtSanctionView.Rows[0]["Onduty_FromTime"]).ToString(TimeFormatMail) + " To " + Convert.ToString(dtSanctionView.Rows[0]["Onduty_ToDate"]) + " " + Convert.ToDateTime(dtSanctionView.Rows[0]["Onduty_FromTime"].ToString()).ToString(TimeFormatMail), "", Convert.ToString(""));
                                                if (dsReceivers.Tables.Count > 0)
                                                {
                                                    if (dsReceivers.Tables[1].Rows.Count > 0)
                                                    {
                                                        foreach (DataRow dr in dsReceivers.Tables[1].Rows)
                                                        {
                                                            if (Convert.ToString(dr["Mobile_Number"]) != "")
                                                            {
                                                                blnCheckSMS = objsms.SendSMSNotifications
                                                                (
                                                                    ServiceUrl,
                                                                    destinationKey,
                                                                    MessageKey,
                                                                    Convert.ToString(dr["Receivers"]),
                                                                    Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]),
                                                                    Convert.ToString(dr["Mobile_Number"]),
                                                                    strEmployeeCodeId,
                                                                    strTemplateName,
                                                                    Convert.ToString(dr["SwipeCardNo"])
                                                                );
                                                                if (isSmsEnabled)
                                                                {
                                                                    if (Convert.ToString(dr["SwipeCardNo"]) == Employee_Code_Id)
                                                                    {
                                                                        isApplyAndReceiverSame = true;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                objsms.InsertLogDetails(strTemplateName, Convert.ToString(dr["SwipeCardNo"]), Employee_Code_Id, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Mobile Number is not configured in employee master");
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        objsms.InsertLogDetails(strTemplateName, "", Employee_Code_Id, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Receivers are not having the configured usergroup");
                                                    }
                                                }
                                                if (isSmsEnabled)
                                                {
                                                    if (mobileNo != string.Empty && isApplyAndReceiverSame != true)
                                                    {
                                                        blnCheckSMS = objsms.SendSMSNotifications
                                                                    (
                                                                        ServiceUrl,
                                                                        destinationKey,
                                                                        MessageKey,
                                                                        "",
                                                                        Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]),
                                                                        Convert.ToString(mobileNo),
                                                                        strEmployeeCodeId,
                                                                         strTemplateName,
                                                                    Convert.ToString(strEmployeeCodeId)
                                                                    );
                                                    }
                                                    else if (mobileNo == string.Empty && isApplyAndReceiverSame != true)
                                                    {
                                                        objsms.InsertLogDetails(strTemplateName, Convert.ToString(Employee_Code_Id), Employee_Code_Id, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Mobile Number is not configured in employee master");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                            #endregion
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SorryyouarenotForwardingauthorityfortheselectedUser", ci) + "');", true);
                            return;
                        }
                    }
                }
                if (InsertCount > 0)
                {
                    Session["dtSanctionView"] = null;
                    string str = "<script language=\"javascript\">";
                    str = str + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                    str = str + "</script>";
                    Page.RegisterStartupScript("alert", str);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Selectanyentrytochangestatus", ci) + "');", true);
                return;
            }
            #endregion
        }
    }
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        string strReason = "";
        cls_Common objClassCommon = new cls_Common();
        DataTable dtSanctionView = new DataTable();
        DataSet dsSanctionView = new DataSet();
        if (txtRemarks.Text == string.Empty)
        {
            base.Message("Remarks is required");
            return;
        }
        else
        {
            string strLengthCheck = txtRemarks.Text.Trim().Replace("'", "''");
            if (strLengthCheck.Length > 1000)
            {
                Message("Maximum character for Reason is 1000");
                return;
            }
            #region OnDutyUpdation
            if (hdnSelectRow.Value != "")
            {
                chkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
                for (int i = 0; i < chkBoxIDs.Length; i++)
                {
                    gintManualTimeEntryId = Convert.ToInt32(chkBoxIDs[i]);
                    ViewState["Permission_Id"] = gintManualTimeEntryId;
                    dsSanctionView = objManualEntryEventData.SelectODEntryById(gintManualTimeEntryId);
                    dtSanctionView = dsSanctionView.Tables[0];
                    int EmployeeID = Convert.ToInt16(dsSanctionView.Tables[0].Rows[0]["Employee_Id"]);
                    int LevelID = 0;
                    Session["dtSanctionView"] = dtSanctionView;
                    int EmpAutoID = Convert.ToInt32(Session["EmpAutoID"].ToString());
                    ViewState["vwReason"] = dtSanctionView.Rows[0]["Onduty_Reason"].ToString();
                    EmployeeName = dtSanctionView.Rows[0]["Employee_Name"].ToString();
                    Employee_Id = Convert.ToInt32(dtSanctionView.Rows[0]["Employee_Id"]);
                    EmployeeEamilId = dtSanctionView.Rows[0]["Emailid"].ToString();
                    Fromdatettime = dtSanctionView.Rows[0]["Onduty_FromDate"].ToString() + " " + dtSanctionView.Rows[0]["Onduty_FromTime"].ToString();
                    Todatettime = dtSanctionView.Rows[0]["Onduty_ToDate"].ToString() + " " + dtSanctionView.Rows[0]["Onduty_ToTime"].ToString();
                    levelName = dtSanctionView.Rows[0]["LevelName"].ToString();
                    string EmployeeCodeID = dtSanctionView.Rows[0]["Employee_Code_Id"].ToString();
                    DataSet ds = new DataSet();
                    ds = objPermissionEventData.CheckODApprovalPerson(EmployeeID);
                    if (ds.Tables[0].Rows[0][0] != DBNull.Value && Convert.ToInt16(ds.Tables[0].Rows[0][0]) > 0)
                    {
                        int ApprovalID = Convert.ToInt16(ds.Tables[0].Rows[0]["Leave_Sanc_Authority"]);
                        if (ApprovalID == EmpAutoID)
                        {
                            EmployeeCodeID = dtSanctionView.Rows[0]["Employee_Code_Id"].ToString();
                            DataSet dsEmployeeDetails = new DataSet();
                            dsEmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(Employee_Id));
                            if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                            {
                                strEmpFirstName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                                strEmpLastName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);
                                strEmployeeCodeId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_Code_Id"]);
                                strEmployeeName = strEmpFirstName + " " + strEmpLastName;
                                strlevelName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["levelName"]);
                                strEmployeeEmailId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["EmailID"]);
                                strEmailIdSanctioningAuthority = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ApprovalAuthorityEmailID"]);
                                strEmailIdReportingTo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ReportingToEmailID"]);
                                LevelID = Convert.ToInt32(dsEmployeeDetails.Tables[0].Rows[0]["LevelID"]);
                            }
                            UpdatedManualTimeEntryStatus("Approved");
                            if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                            {
                                SendMailOnduty(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, dtSanctionView.Rows[0]["Onduty_FromDate"].ToString(), dtSanctionView.Rows[0]["Onduty_FromTime"].ToString(), dtSanctionView.Rows[0]["Onduty_ToDate"].ToString(), dtSanctionView.Rows[0]["Onduty_ToTime"].ToString(), dtSanctionView.Rows[0]["Onduty_EntryDate"].ToString(), strEmployeeName, strEmployeeCodeId, dtSanctionView.Rows[0]["Onduty_Reason"].ToString(), txtRemarks.Text, strlevelName, "Approved");
                            }
                        }
                        else
                        {
                            if (InsertCount > 0)
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_NotSavedSucessfullySorry", ci) + "');", true);
                                return;
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SorryyouarenotApprovalauthority", ci) + "');", true);
                                return;
                            }
                        }
                    }
                }
                if (InsertCount > 0)
                {
                    Session["dtSanctionView"] = null;
                    string str = "<script language=\"javascript\">";
                    str = str + "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                    str = str + "</script>";
                    Page.RegisterStartupScript("alert", str);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Selectanyentrytochangestatus", ci) + "');", true);
                return;
            }
            #endregion
        }
    }
    #endregion
}
