using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Web.Mail;
using System.Net.Mail;
using System.Globalization;
using System.Threading;
using System.Resources;
public partial class Transactions_TA_UI_Transactions_OnDutySanctionModify : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ManualEntryEventData objManualTimeEntry = new ManualEntryEventData();
    PermissionEventData objPermissionEventData = new PermissionEventData();
    SMSNotification objsms = new SMSNotification();
    bool blnCheckSMS = true;
    CCGroupEventData_Angler objCCGroup = new CCGroupEventData_Angler();
    DataTable dtSanctionView = new DataTable();
    Int64 gintManualTimeEntryId, gintUserId;
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet dsManualTimeEntry;
    DataSet dsYear = new DataSet();
    DataSet dsOnDutyConversation = new DataSet();
    DataSet dsLeavePrivateNotes = new DataSet();
    string NewTimeFormat = string.Empty;
    string LeaveApplicationIDs;
    int LevelID = 0;
    string TimeFormatMail = string.Empty;
    int LeaveApplication_Id, Employee_Id, LeaveTypeId, intCount, EmployeeCategory, EmployeeType;
    string strEmpFirstName, strEmpLastName, strEmployeeCodeId, strEmployeeName, strlevelName, strEmployeeEmailId, strEmailIdSanctioningAuthority, strEmailIdReportingTo;
    bool CheckGrid = false;
    bool statusProcess = false;
    bool Isprocessedrecord;
    string strHtml = string.Empty;
    string strHtmlPrivateNotes = string.Empty;
    string strHtmlLeaveDetails = string.Empty;
    string strCrossdate = string.Empty;
    string strMonthValue = string.Empty;
    static string prevPage = String.Empty;
    string strInDate, strOutDate, strEntryDate;
    bool checkEmail = true;
    bool blnCheckEmail = true;
    bool blnPrivateNotes = false;
    int intApproval = 0, intAuthorityLevel = 0, intFirstLevelAuthorityId, intSecondLevelAuthorityId, intInsertCount;
    int intLoginEmpId = 0, intAuditEmpId = 0;
    string gstrDateFormat = string.Empty;
    string Status, Remarks, strEmailIdSanctionAuthority, EmployeeName, EmployeeEamilId, Employee_Code_Id, strOnDutyApplicationDate, reportingToEmployee, sanctioningEmployee, levelName, strYearSettingsFromdate, strYearSettingsTodate, Fromdatettime, Todatettime;
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData(); int payrollConfig = 0;
    #endregion
    #region Page Load events
    protected override void Page_Load(object sender, EventArgs e)
    {

        base.Page_Load(sender, e);
        //btn_Cancel.Attributes.Add("onClick", "javascript:history.back(); return false;");
        if (Session["Edition"].ToString() == "1")
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        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);
        cls_Common objClassCommon = new cls_Common();
        dsYear = objClassCommon.GetYearsetting();
        if (dsYear.Tables[0].Rows.Count <= 0)
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Msg_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();
        }
        gintManualTimeEntryId = Convert.ToInt64(Request.QueryString["ODID"]);
        gintUserId = Int32.Parse(Session["EmpAutoID"].ToString());
        btn_Modify.Focus();
        Session["SanctionSelected"] = "3";
        if (Session["ITimeFormat"].ToString() == "%H:%M")
        {
            NewTimeFormat = "HH:mm:ss";
        }
        else
        {
            NewTimeFormat = "hh:mm:ss tt";
        }
        if (!Page.IsPostBack)
        {
            payrollConfig = objCommon.CheckPageExistsInLicense(185);
            if (Session["parentLevelId"] == null)
                if (Request.QueryString["LevelId"] != null)
                    Session["parentLevelId"] = Request.QueryString["LevelId"];
            if (Session["SanctionUrl"] != null)
                Session["SanctionUrl"] = null;
            UserRights();
            if (Convert.ToString(Session["TopMenuPrevious"]) == "")
            {
                GenerateMenu();
                loadMenu();
                LoadYear();
            }
            if (payrollConfig == 0)
                objCommon.menu("Approvals", "248");
            else
                objCommon.menu("Approvals", "174");
            GetManualEntryDetails();
            SanctionViewDetails();
        }
        ControlCreation();
    }
    #endregion
    #region User Defined Functions
    private void GetManualEntryDetails()
    {
        dsManualTimeEntry = new DataSet();
        DataTable dtManualTimeEntry = new DataTable();
        dsManualTimeEntry = objManualTimeEntry.SelectODEntryById(gintManualTimeEntryId);
        dtManualTimeEntry = dsManualTimeEntry.Tables[0];
        Session["DataManualEntrySanction"] = dtManualTimeEntry;
        if (dtManualTimeEntry.Rows.Count > 0)
        {
            if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"].ToString() != string.Empty)
                {
                    lbl_EmpId.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Code_Id"]);
                    Employee_Code_Id = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Code_Id"]);
                }
            if (dtManualTimeEntry.Rows[0]["Employee_Name"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Employee_Name"].ToString() != string.Empty)
                    lbl_EmpName.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Name"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_EntryDate"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_EntryDate"].ToString() != string.Empty)
                    lbl_EntryDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_EntryDate"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_FromDate"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_FromDate"].ToString() != string.Empty)
                    lbl_InDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_FromDate"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_FromTime"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_FromTime"].ToString() != string.Empty)
                    lbl_InTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_FromTime"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_ToDate"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_ToDate"].ToString() != string.Empty)
                    lbl_OutDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_ToDate"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_ToTime"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_ToTime"].ToString() != string.Empty)
                    lbl_OutTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_ToTime"]);
            if (dtManualTimeEntry.Rows[0]["Onduty_Reason"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_Reason"].ToString() != string.Empty)
                {
                    lbl_Reason.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Reason"]);
                    lbl_Reason.ToolTip = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Reason"]);
                }
            if (dtManualTimeEntry.Rows[0]["Onduty_Status"] != DBNull.Value)
                if (dtManualTimeEntry.Rows[0]["Onduty_Status"].ToString() != string.Empty)
                    lbl_Status.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Status"]);
            lbl_EntryType.Text = "On Duty";
            if (dtManualTimeEntry.Rows[0]["Onduty_Type"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_Type"].ToString() != string.Empty)
                {
                    int ODType = Convert.ToInt32(dtManualTimeEntry.Rows[0]["Onduty_Type"]);
                    if (ODType == 1)
                    {
                        divSingle.Visible = true;
                        divMulti.Visible = false;
                        lblOnDutyTypeName.Text = "Single Day";
                    }
                    else
                    {
                        divSingle.Visible = false;
                        divMulti.Visible = true;
                        lblOnDutyTypeName.Text = "Multiple Days";
                        lblFromDate.Text = dtManualTimeEntry.Rows[0]["Onduty_FromDate"].ToString();
                        lblToDate.Text = dtManualTimeEntry.Rows[0]["Onduty_ToDate"].ToString();
                        if (dtManualTimeEntry.Rows[0]["From_Session"] != DBNull.Value)
                            if (dtManualTimeEntry.Rows[0]["From_Session"].ToString() != string.Empty)
                                lblFromSession.Text = dtManualTimeEntry.Rows[0]["From_Session"].ToString();
                        if (dtManualTimeEntry.Rows[0]["To_Session"] != DBNull.Value)
                            if (dtManualTimeEntry.Rows[0]["To_Session"].ToString() != string.Empty)
                                lblTosession.Text = dtManualTimeEntry.Rows[0]["To_Session"].ToString();
                    }
                }
            }
        }
        if (dsManualTimeEntry.Tables[1].Rows.Count > 0)
        {
            txtRemarks.Text = Convert.ToString(dsManualTimeEntry.Tables[1].Rows[0]["Comments"]);
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("OnDutyApproval_Header", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EntranceName1.Text = rm.GetString("EntranceMaster_Entrance_Name", ci);
        lbl_InDate1.Text = rm.GetString("ManualTimeEntry_InDate", ci);
        lbl_InTime1.Text = rm.GetString("ManualTimeEntry_InTime", ci);
        lbl_InPunchType1.Text = rm.GetString("ManualTimeEntry_InPunchType", ci);
        lbl_ManualTimeEntryDate.Text = rm.GetString("ODEntry_ODEntryDate", ci);
        lbl_OutDate1.Text = rm.GetString("ManualTimeEntry_OutDate", ci);
        lbl_OutTime1.Text = rm.GetString("ManualTimeEntry_OutTime", ci);
        lbl_OutPunchType1.Text = rm.GetString("ManualTimeEntry_OutPunchType", ci);
        lbl_Reason1.Text = rm.GetString("email_Reason", ci);
        lbl_Status1.Text = rm.GetString("email_Status", ci);
        lblEntryType.Text = rm.GetString("ManualTimeEntryType", ci);
        btn_Modify.Text = rm.GetString("btn_Modify", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        lbl_Man.Text = rm.GetString("IndicatesMandatoryFields", ci);
        //  btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lbl_Shiftname1.Text = rm.GetString("ShiftTiming_ShiftShortName", ci);
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        lbl_OnDutyType.Text = rm.GetString("lbl_SingleDay", ci);
        lblFromDate1.Text = rm.GetString("OnDuty_InDate", ci);
        lblToDate1.Text = rm.GetString("OnDuty_OutDate", ci);
        lblFromSession1.Text = rm.GetString("lbl_FromSession", ci);
        lblTosession1.Text = rm.GetString("lbl_ToSession", ci);
        lbl_Remarks.Text = rm.GetString("email_Remarks", ci);
        lblStatus.Text = rm.GetString("email_Status", ci);
        rbApproved.Text = rm.GetString("btn_Approved", ci);
        rbForwarded.Text = rm.GetString("btn_Forwarded", ci);
        rbPending.Text = rm.GetString("btn_Pending", ci);
        rbRejected.Text = rm.GetString("btn_Reject", ci);
    }
    protected void GenerateMenu()
    {
        //Get Year Setting Details for Menu constructing and Year Setting Display
        cls_Common objClassCommon = new cls_Common();
        DataSet ds_Year = new DataSet();
        string strYearData = string.Empty;
        string StartYear = string.Empty, EndYear = string.Empty, StartMonth = string.Empty, EndMonth = string.Empty;
        ds_Year = objClassCommon.GetYearsetting();
        if (ds_Year.Tables[0].Rows.Count > 0)
        {
            Session["YearSettingsId"] = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
            Session["YearSettingFromDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingFromDate"]);
            Session["YearSettingToDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingToDate"]);
            StartYear = ds_Year.Tables[0].Rows[0]["StartYear"].ToString();
            StartMonth = ds_Year.Tables[0].Rows[0]["StartMonth"].ToString();
            EndYear = ds_Year.Tables[0].Rows[0]["EndYear"].ToString();
            EndMonth = ds_Year.Tables[0].Rows[0]["EndMonth"].ToString();
            Session["SearchFromDate"] = Convert.ToDateTime(ds_Year.Tables[0].Rows[0]["FromDate"]);
            strYearData = StartMonth + " " + StartYear + " - " + EndMonth + " " + EndYear;
            string sYearValue = Convert.ToString(Cache["ActiveYearSetting"]);
            if (sYearValue == null || sYearValue == String.Empty)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            }
            else if (strYearData != sYearValue)
            {
                TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                HttpContext.Current.Cache.Remove("ActiveYearSetting");
                HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            }
        }
        else
        {
            TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
            HttpContext.Current.Cache.Remove("ActiveYearSetting");
            HttpContext.Current.Cache.Insert("ActiveYearSetting", "", null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
            Session["SearchFromDate"] = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Session["MDateFormat"].ToString());
        }
    }
    private void LoadYear()
    {
        Label lblYear = (Label)this.Master.FindControl("lblYear");
        Label lblYearData = (Label)this.Master.FindControl("lblYearData");
        //Year Setting Display in Main Menu
        string sYearValue = Convert.ToString(Cache["ActiveYearSetting"]);
        if (sYearValue != null && sYearValue != "")
        {
            lblYear.Text = rm.GetString("Year", ci);
            lblYearData.Text = sYearValue;
            if (lblYearData.Text.Contains("January"))
                lblYearData.Text = lblYearData.Text.Replace("January", "Jan");
            if (lblYearData.Text.Contains("February"))
                lblYearData.Text = lblYearData.Text.Replace("February", "Feb");
            if (lblYearData.Text.Contains("March"))
                lblYearData.Text = lblYearData.Text.Replace("March", "Mar");
            if (lblYearData.Text.Contains("April"))
                lblYearData.Text = lblYearData.Text.Replace("April", "Apr");
            if (lblYearData.Text.Contains("May"))
                lblYearData.Text = lblYearData.Text.Replace("May", "May");
            if (lblYearData.Text.Contains("June"))
                lblYearData.Text = lblYearData.Text.Replace("June", "Jun");
            if (lblYearData.Text.Contains("July"))
                lblYearData.Text = lblYearData.Text.Replace("July", "Jul");
            if (lblYearData.Text.Contains("August"))
                lblYearData.Text = lblYearData.Text.Replace("August", "Aug");
            if (lblYearData.Text.Contains("September"))
                lblYearData.Text = lblYearData.Text.Replace("September", "Sep");
            if (lblYearData.Text.Contains("October"))
                lblYearData.Text = lblYearData.Text.Replace("October", "Oct");
            if (lblYearData.Text.Contains("November"))
                lblYearData.Text = lblYearData.Text.Replace("November", "Nov");
            if (lblYearData.Text.Contains("December"))
                lblYearData.Text = lblYearData.Text.Replace("December", "Dec");
        }
        else
            lblYearData.Text = string.Empty;
    }
    private void loadMenu()
    {
        //Session["MenuCreate"] = "1";
        CultureInfo ci;
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        string strType = string.Empty;
        if (Session["Demo"] != null)
            if (Session["Demo"].ToString() == "Standard")
                strType = "Standard";
            else if (Session["Demo"].ToString() == "Express")
                strType = "Express";
        cls_Common getmenu = new cls_Common();
        DataSet ds = new DataSet();
        DataSet dsChildMenus = new DataSet();
        DataSet dsReportsMenu = new DataSet();
        DataSet dsReportsSubMenu = new DataSet();
        int intReportsMenu = 0;
        int intReportsSubMenu = 0;
        int MenuNo = 1;
        string strMenu = string.Empty;
        if (source_Language == "Resources.Resource_AR")
        {
            strMenu += "<ul class='sidebar-menu' id='MainMenu' runat='server'>";
            strMenu = "<ul class='treeview-menu'>";
            if (Convert.ToInt16(Session["userGroup_Id"]) != 0)
            {
                ds = getmenu.getUserMenu(0, Convert.ToInt16(Session["userGroup_Id"]), strType);
                for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
                {
                    String txt = ds.Tables[0].Rows[iloop]["displayName"].ToString();
                    strMenu += "<li class='hasmore'><a href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '><span>" + rm.GetString(txt, ci) + "</span> </a>";
                    dsChildMenus = getmenu.getUserMenu(Convert.ToInt32(ds.Tables[0].Rows[iloop]["pageid"]), Convert.ToInt16(Session["userGroup_Id"]), strType);
                    strMenu += "<ul class='treeview-menu'>";
                    for (int iloopChild = 0; iloopChild <= dsChildMenus.Tables[0].Rows.Count - 1; iloopChild++)
                    {
                        string txtChild = dsChildMenus.Tables[0].Rows[iloopChild]["displayName"].ToString();
                        string[] splittedPath = ds.Tables[0].Rows[iloop]["path"].ToString().Split("/".ToCharArray());
                        //strMenu += "<li><a href='" + dsChildMenus.Tables[0].Rows[iloopChild]["path"] + "' title='" + rm.GetString(txtChild, ci) + " '>" + rm.GetString(txtChild, ci) + " </a></li>";
                        if (dsChildMenus.Tables[0].Rows[iloopChild]["path"].ToString() != string.Empty)
                            strMenu += "<li class='hasmore'><a href='" + dsChildMenus.Tables[0].Rows[iloopChild]["path"] + "' title='" + rm.GetString(txtChild, ci) + " '>" + rm.GetString(txtChild, ci) + " </a>";
                        else
                            strMenu += "<li class='hasmore'><a title='" + rm.GetString(txtChild, ci) + " '><span class='nav-arrow'>" + rm.GetString(txtChild, ci) + " </span></a>";
                        dsReportsMenu = getmenu.getReportMenu("ReportsMenu", Convert.ToInt16(Session["userGroup_Id"]));
                        for (intReportsMenu = 0; intReportsMenu <= dsReportsMenu.Tables[0].Rows.Count - 1; intReportsMenu++)
                        {
                            if (dsChildMenus.Tables[0].Rows[iloopChild]["pageId"].ToString() == dsReportsMenu.Tables[0].Rows[intReportsMenu]["ParentIdForSubMenu"].ToString())
                            {
                                dsReportsSubMenu = getmenu.getReportMenu(dsReportsMenu.Tables[0].Rows[intReportsMenu]["ParentIdForSubMenu"].ToString(), Convert.ToInt16(Session["userGroup_Id"]));
                                strMenu += "<ul class='dropdown'>";
                                for (intReportsSubMenu = 0; intReportsSubMenu <= dsReportsSubMenu.Tables[0].Rows.Count - 1; intReportsSubMenu++)
                                {
                                    string txtChild1 = dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["displayName"].ToString();
                                    strMenu += "<li class='hasmore'><a href='" + dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["path"] + "' title='" + rm.GetString(txtChild1, ci) + " '>" + rm.GetString(txtChild1, ci) + "</a></li>";
                                }
                                strMenu += "</ul>";
                            }
                        }
                        strMenu += "</li>";
                    }
                    strMenu += "</ul>";
                    strMenu += "</li>";
                    //dsChildMenus.Clear();
                    dsChildMenus.Dispose();
                    MenuNo = MenuNo + 1;
                }
            }
            strMenu += "</ul>";
            strMenu += "</div>";
        }
        else
        {
            if (Convert.ToInt16(Session["userGroup_Id"]) != 0)
            {
                ds = getmenu.getUserMenu(0, Convert.ToInt16(Session["userGroup_Id"]), strType);
                for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
                {
                    String txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
                    string title = txt + "_Title";
                    string Icon = txt + "_Icon";
                    dsChildMenus = getmenu.getUserMenu(Convert.ToInt32(ds.Tables[0].Rows[iloop]["pageid"]), Convert.ToInt16(Session["userGroup_Id"]), strType);
                    if (dsChildMenus.Tables[0].Rows.Count > 0)
                    {
                        strMenu += "<li id='" + Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]) + "'><a class='menu-hed' href='" + ds.Tables[0].Rows[iloop]["path"] + "' id='" + Convert.ToString(ds.Tables[0].Rows[iloop]["pageid"]) + "' title='" + rm.GetString(title, ci) + " '><img class='icon' src='dist/img/" + rm.GetString(Icon, ci) + "'><span>" + rm.GetString(txt, ci) + "</span><i class='fa fa-angle-right pull-right'></i></a>";
                        strMenu += "<ul class='treeview-menu'>";
                    }
                    else
                        strMenu += "<li id='" + Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]) + "'><a class='menu-hed' href='" + ds.Tables[0].Rows[iloop]["path"] + "' id='" + Convert.ToString(ds.Tables[0].Rows[iloop]["pageid"]) + "' title='" + rm.GetString(title, ci) + " '><img class='icon' src='dist/img/" + rm.GetString(Icon, ci) + "'><span>" + rm.GetString(txt, ci) + "</span></a>";
                    for (int iloopChild = 0; iloopChild <= dsChildMenus.Tables[0].Rows.Count - 1; iloopChild++)
                    {
                        string txtChild = Convert.ToString(dsChildMenus.Tables[0].Rows[iloopChild]["displayName"]);
                        string titlechild = txtChild + "_Title";

                        string[] splittedPath = Convert.ToString(ds.Tables[0].Rows[iloop]["path"]).Split("/".ToCharArray());
                        if (dsChildMenus.Tables[0].Rows[iloopChild]["path"].ToString() != string.Empty)
                            strMenu += "<li id='" + Convert.ToString(dsChildMenus.Tables[0].Rows[iloopChild]["displayName"]) + "'><a href='" + dsChildMenus.Tables[0].Rows[iloopChild]["path"] + "' id='" + Convert.ToString(dsChildMenus.Tables[0].Rows[iloopChild]["pageid"]) + "' title='" + rm.GetString(titlechild, ci) + " '><i class='fa fa-circle-o'></i>" + rm.GetString(txtChild, ci) + " </a>";
                        else
                            strMenu += "<li id='" + Convert.ToString(dsChildMenus.Tables[0].Rows[iloopChild]["displayName"]) + "'><a id='" + Convert.ToString(dsChildMenus.Tables[0].Rows[iloopChild]["pageid"]) + "' title='" + rm.GetString(titlechild, ci) + " '><i class='fa fa-circle-o'></i>" + rm.GetString(txtChild, ci) + " <i class='fa fa-angle-right pull-right' style='padding-left:10px' ></i></a>";
                        dsReportsSubMenu = getmenu.getUserMenu(Convert.ToInt32(dsChildMenus.Tables[0].Rows[iloopChild]["pageId"]), Convert.ToInt16(Session["userGroup_Id"]), strType);
                        if (dsReportsSubMenu.Tables[0].Rows.Count > 0)
                        {
                            strMenu += "<ul class='treeview-menu' id='" + dsChildMenus.Tables[0].Rows[iloopChild]["displayname"].ToString() + "' style='padding:10px'>";
                            for (intReportsSubMenu = 0; intReportsSubMenu <= dsReportsSubMenu.Tables[0].Rows.Count - 1; intReportsSubMenu++)
                            {
                                string txtChild1 = Convert.ToString(dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["displayName"]);
                                string titlechild1 = txtChild1 + "_Title";
                                strMenu += "<li class='active' id='" + Convert.ToString(dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["displayName"]) + "' style='padding-left:8px'><a href='" + dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["path"] + "' id='" + Convert.ToString(dsReportsSubMenu.Tables[0].Rows[intReportsSubMenu]["pageid"]) + "' title='" + rm.GetString(titlechild1, ci) + " '><i class='fa fa-circle-o'></i>" + rm.GetString(txtChild1, ci) + "</a></li>";
                            }
                            if (dsReportsSubMenu.Tables[0].Rows.Count == 2)
                                strMenu += "<li class='line-spec'></li>";
                            strMenu += "</ul>";
                        }
                        strMenu += "</li>";
                    }
                    if (dsChildMenus.Tables[0].Rows.Count > 0)
                        strMenu += "</ul>";
                    strMenu += "</li>";
                    dsChildMenus.Dispose();
                    MenuNo = MenuNo + 1;
                }
            }
        }
        ds.Clear();
        ds.Dispose();
        Session["TopMenu"] = strMenu;
        Session["TopMenuPrevious"] = strMenu;
    }
    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)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Transactions_ManualTimeEntry.aspx");
            }
        }
        else
        {
            if (Convert.ToString(Session["TopMenuPrevious"]) == "")
            {
                GenerateMenu();
                loadMenu();
                LoadYear();
            }
            if (payrollConfig == 0)
                objCommon.menu("Approvals", "248");
            else
                objCommon.menu("Approvals", "174");
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    private void SanctionViewDetails()
    {
        DataSet dsEmployeeGroup = new DataSet();
        DataSet dsSanctionView = new DataSet();
        dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        DataTable dt_ApprovalAuthority = new DataTable();
        int intApproval = 0, intAuthorityLevel = 0, intFirstLevelAuthorityId = 0, intSecondLevelAuthorityId = 0;
        int intLoginEmpId = 0, intAuditEmpId = 0;
        string strApprovalCC = string.Empty;
        dsSanctionView = objManualTimeEntry.SelectODEntryById(gintManualTimeEntryId);
        dtSanctionView = dsSanctionView.Tables[0];
        ViewState["dtSanctionView"] = dtSanctionView;
        int intEmployeeId = 0;
        if (dtSanctionView.Rows[0]["Employee_Id"] != DBNull.Value)
        {
            intEmployeeId = int.Parse(dtSanctionView.Rows[0]["Employee_Id"].ToString());
            ViewState["vSEmployeeId"] = intEmployeeId;
        }
        intLoginEmpId = Convert.ToInt32(Session["EmpAutoId"]);
        if (intEmployeeId == intLoginEmpId)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        dt_ApprovalAuthority = objLeaveApplicationEventData.GetApprovalAuthorityIds(intEmployeeId);
        if (dt_ApprovalAuthority.Rows.Count > 0)
        {
            if (dt_ApprovalAuthority.Rows[0]["Reporting_To"] != DBNull.Value && dt_ApprovalAuthority.Rows[0]["Reporting_To"].ToString() != string.Empty)
            {
                intFirstLevelAuthorityId = int.Parse(dt_ApprovalAuthority.Rows[0]["Reporting_To"].ToString());
                reportingToEmployee = dt_ApprovalAuthority.Rows[0]["ReportingToEmployee"].ToString();
                ViewState["reportingToEmployee"] = dt_ApprovalAuthority.Rows[0]["ReportingToEmployee"].ToString();
            }
            if (dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"] != DBNull.Value && dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"].ToString() != string.Empty)
            {
                intSecondLevelAuthorityId = int.Parse(dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"].ToString());
                sanctioningEmployee = dt_ApprovalAuthority.Rows[0]["SanctioningEmployee"].ToString();
                ViewState["sanctioningEmployee"] = dt_ApprovalAuthority.Rows[0]["SanctioningEmployee"].ToString();
            }
        }
        if (intFirstLevelAuthorityId != intSecondLevelAuthorityId)
        {
            if (intLoginEmpId == intFirstLevelAuthorityId)
                intAuthorityLevel = 1;
            else if (intLoginEmpId == intSecondLevelAuthorityId)
                intAuthorityLevel = 2;
        }
        else if (intFirstLevelAuthorityId == intSecondLevelAuthorityId)
        {
            if (intLoginEmpId == intSecondLevelAuthorityId)
                intAuthorityLevel = 2;
            else
                intAuthorityLevel = 3;
        }
        else
            intAuthorityLevel = 3;
        ViewState["vsCommentsBy"] = intAuthorityLevel;
        if (intAuthorityLevel == 1)
        {
            if (intApproval == 1)
            {
                rbApproved.Enabled = true;
                rbForwarded.Enabled = true;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
            }
            else
            {
                rbApproved.Enabled = false;
                rbForwarded.Enabled = true;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
            }
        }
        else if (intAuthorityLevel == 2)
        {
            if (intApproval == 1)
            {
                rbApproved.Enabled = true;
                rbForwarded.Enabled = false;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
            }
            else
            {
                rbApproved.Enabled = true;
                rbForwarded.Enabled = false;
                rbPending.Enabled = false;
                rbRejected.Enabled = true;
            }
        }
        else if (intAuthorityLevel == 3)
        {

            rbApproved.Enabled = true;
            rbForwarded.Enabled = false;
            rbPending.Enabled = true;
            rbRejected.Enabled = true;
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            rbApproved.Enabled = true;
            rbForwarded.Enabled = true;
            rbPending.Enabled = true;
            rbRejected.Enabled = true;
            txtRemarks.ReadOnly = false;
        }
        rbApproved.Enabled = true;
        rbForwarded.Enabled = true;
        rbPending.Enabled = true;
        rbRejected.Enabled = true;

        bool blnApproved = false;
        bool blnForwarded = false;
        ViewState["StatusOnLoad"] = dtSanctionView.Rows[0]["Onduty_Status"].ToString();

        if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Pending")
        {
            rbPending.Checked = true;
        }
        else if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Forwarded")
        {
            blnForwarded = true;
            rbForwarded.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Rejected")
        {
            rbRejected.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Approved")
        {
            rbApproved.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Resend")
        {
            rbResend.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Reply")
        {
            rbReply.Checked = true;
            txtRemarks.ReadOnly = false;
        }

        if (rbApproved.Checked == true)
            rbApproved.Enabled = false;
        if (rbForwarded.Checked == true)
            rbForwarded.Enabled = false;
        if (rbPending.Checked == true)
            rbPending.Enabled = false;
        if (rbRejected.Checked == true)
            rbRejected.Enabled = true;
        if (rbReply.Checked == true)
            rbReply.Enabled = false;
        if (rbResend.Checked == true)
            rbResend.Enabled = false;

        if (intAuthorityLevel == 2)
            rbForwarded.Enabled = false;
        if (blnApproved == true)
            rbRejected.Enabled = true;
        if (intAuthorityLevel == 1)
        {
            rbApproved.Enabled = false;
            rbRejected.Enabled = true;
            if (blnForwarded == true)
                rbForwarded.Enabled = false;
        }
        if (intAuthorityLevel == 2)
        {
            if (dtSanctionView.Rows[0]["Onduty_Status"].ToString() == "Pending")
            {
                hdnStatusofApplication.Value = "Pending";
                hdnAutorityLevel.Value = "2";
            }
        }
        if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin")
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False") btn_Save.Visible = true;
            else
                if (intLoginEmpId != intFirstLevelAuthorityId && intLoginEmpId != intSecondLevelAuthorityId && dsEmployeeGroup.Tables[0].Rows[0]["GroupName"].ToString() != "SuperAdmin")
                btn_Save.Visible = false;
        }
    }
    /// <summary>
    /// To update the manual entry status if the manual entry is not processed
    /// </summary>
    /// <param name="Status"></param>
    protected void UpdatedManualTimeEntryStatus(string Status)
    {
        intInsertCount = 0;
        Isprocessedrecord = false;
        //string strEmployeeName = string.Empty;
        string strRemarks = string.Empty;
        DataTable dtManual = new DataTable();
        dtManual = (DataTable)Session["DataManualEntrySanction"];
        strRemarks = txtRemarks.Text.Trim().Replace("'", "''");
        intCount = dtManual.Rows.Count;
        int payrollConfig = 0;
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        payrollConfig = objCommon.CheckPageExistsInLicense(185);

        if (dtManual.Rows.Count > 0)
        {
            DataTable dtDataToBeUpdated = new DataTable();
            dtDataToBeUpdated = dtManual.DefaultView.ToTable();
            if (dtDataToBeUpdated.Rows.Count > 0)
            {
                CheckGrid = true;
                if (lbl_Status.Text != "Approved")
                {
                    int intstatus = 0;
                    objManualTimeEntry.UpdateOndutyEntrySanction_Approvel(Convert.ToInt32(gintManualTimeEntryId), Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    statusProcess = true;
                    objManualTimeEntry.UpdateOnDutyApplicationConversation(gintManualTimeEntryId, Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                    intInsertCount = 1;
                    //Session["DataManualEntrySanction"] = null;
                    if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                    {
                        SendMail(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, lbl_InTime.Text, strOutDate, lbl_OutTime.Text, strEntryDate, strEmployeeName, strEmployeeCodeId, txtRemarks.Text.Trim().Replace("'", "''"), strlevelName, Status, strlevelName);
                    }
                    if (payrollConfig == 0)
                    {
                        string str = "<script language=\"javascript\">";
                        if (blnCheckEmail == true)
                            str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanction", ci) + "');location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Onduty');";
                        else
                            str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanctionButemailnotsend", ci) + "');location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Onduty');";
                        str = str + "</script>";
                        Page.RegisterStartupScript("alert", str);
                    }
                    else
                    {
                        string str = "<script language=\"javascript\">";
                        if (blnCheckEmail == true)
                            str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanction", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                        else
                            str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanctionButemailnotsend", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                        str = str + "</script>";
                        Page.RegisterStartupScript("alert", str);
                    }
                }
                else
                {
                    if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
                    {
                        //dsProcessedData = objManualTimeEntry.UpdateODEntrySanction_Group(Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]), strXMLData.ToString());
                        int intstatus = 0;
                        objManualTimeEntry.UpdateOndutyEntrySanction_Approvel(Convert.ToInt32(gintManualTimeEntryId), Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                        statusProcess = true;
                        objManualTimeEntry.UpdateOnDutyApplicationConversation(gintManualTimeEntryId, Status, strRemarks, Convert.ToInt32(Session["EmpAutoId"]));
                        intInsertCount = 1;
                        //Session["DataManualEntrySanction"] = null;
                        if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                        {
                            SendMail(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, lbl_InTime.Text, strOutDate, lbl_OutTime.Text, strEntryDate, strEmployeeName, strEmployeeCodeId, txtRemarks.Text.Trim().Replace("'", "''"), strlevelName, Status, strlevelName);
                        }
                        if (payrollConfig == 0)
                        {
                            string str = "<script language=\"javascript\">";
                            if (blnCheckEmail == true)
                                str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanction", ci) + "');location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Onduty');";
                            else
                                str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanctionButemailnotsend", ci) + "');location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Onduty');";
                            str = str + "</script>";
                            Page.RegisterStartupScript("alert", str);
                        }
                        else
                        {
                            string str = "<script language=\"javascript\">";
                            if (blnCheckEmail == true)
                                str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanction", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                            else
                                str = str + "alert('" + rm.GetString("Alert_OndutyApplicationsavedSanctionButemailnotsend", ci) + "');location.replace('TA_UI_Transactions_OnDutySanction.aspx');";
                            str = str + "</script>";
                            Page.RegisterStartupScript("alert", str);
                        }

                    }
                    else
                    {
                        string str = "<script language=\"javascript\">";
                        str = str + "alert('" + rm.GetString("Alert_ApprovedOnDutyEntryCannotbeModified", ci) + "');";
                        str = str + "</script>";
                        Page.RegisterStartupScript("alert", str);
                    }
                }
            }
        }
    }
    private string[] SplitCCTo(string CCTo)
    {
        string[] strArrEmailAddressForCC;
        strArrEmailAddressForCC = CCTo.Split(';');
        return (strArrEmailAddressForCC);
    }

    //private void ControlCreation()
    //{
    //    // getting leave conversation 
    //    DataSet dsLeaveConversation = objManualTimeEntry.GetOndutyConversation(gintManualTimeEntryId);

    //    if (dsLeaveConversation.Tables[0].Rows.Count > 0)
    //    {
    //        Table leaveConversation = new Table();
    //        leaveConversation.Width = Unit.Percentage(100);
    //        leaveConversation.CssClass = "table das-table1";

    //        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);
    //        leaveConversationHr.CssClass = "empheader";
    //        leaveConversation.Rows.Add(leaveConversationHr);

    //        if (dsLeaveConversation != null && dsLeaveConversation.Tables.Count > 0)
    //        {
    //            if (dsLeaveConversation.Tables[0].Rows.Count > 0)
    //            {
    //                int rowIndex = 0;
    //                foreach (DataRow drLeaveConversation in dsLeaveConversation.Tables[0].Rows)
    //                {
    //                    TableRow trLeaveConversation = new TableRow();

    //                    TableCell tcLeaveConversationRepliedOn = new TableCell();

    //                    Label lblLeaveConversationRepliedOn = new Label();

    //                    lblLeaveConversationRepliedOn.ID = "lblLeaveConversationRepliedOn" + rowIndex;
    //                    lblLeaveConversationRepliedOn.Text = 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();

    //                    lblLeaveConversationCommentsBy.ID = "lblLeaveConversationCommentsBy" + rowIndex;

    //                    lblLeaveConversationCommentsBy.Text = 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();
    //                    tcLeaveConversationComments.Controls.Add(lblLeaveConversationComments);
    //                    trLeaveConversation.Cells.Add(tcLeaveConversationComments);
    //                    leaveConversation.Rows.Add(trLeaveConversation);
    //                    rowIndex += 1;
    //                }

    //            }
    //        }

    //        divLeaveConversation.Controls.Add(leaveConversation);
    //    }
    //}


    private void ControlCreation()
    {
        //New Data table definition
        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;

        divLeaveConversation.Controls.Clear();
        DataSet ds_PermissionConversation = new DataSet();
        ds_PermissionConversation = objManualTimeEntry.GetOndutyConversation(gintManualTimeEntryId);
        //if (!IsPostBack)
        //{
        //    // getting leave conversation 

        //    ViewState["PermissionConversation"] = ds_PermissionConversation;
        //}
        if (ds_PermissionConversation != null && ds_PermissionConversation.Tables[0].Rows.Count > 0)
        {
            //if (ViewState["PermissionConversation"] != null)
            //{
            //    ds_PermissionConversation =(DataSet) ViewState["PermissionConversation"];
            //}

            Table leaveConversation = new Table();
            leaveConversation.BorderWidth = 1;
            leaveConversation.CellPadding = 5;
            leaveConversation.CellSpacing = 0;
            // leaveConversation.Width = Unit.Pixel(600);
            leaveConversation.CssClass = "table das-table1";
            leaveConversation.Attributes.Add("border", "1");

            TableHeaderRow leaveConversationHr = new TableHeaderRow();

            leaveConversationHr.CssClass = "empheader";
            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.Width = 75;
            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.Width = 200;
            leaveConversationHeading2.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading2);

            leaveConversation.Rows.Add(leaveConversationHr);


            if (ds_PermissionConversation.Tables[0].Rows.Count > 0)
            {
                int rowIndex = 0;
                foreach (DataRow drLeaveConversation in ds_PermissionConversation.Tables[0].Rows)
                {
                    dRowReplyResend = dtReplyResend.NewRow();
                    TableRow trLeaveConversation = new TableRow();

                    TableCell tcLeaveConversationRepliedOn = new TableCell();
                    Label lblLeaveConversationRepliedOn = new Label();
                    tcLeaveConversationRepliedOn.BorderWidth = 1;
                    tcLeaveConversationRepliedOn.Width = 200;
                    tcLeaveConversationRepliedOn.BorderColor = System.Drawing.Color.White;

                    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 = 200;

                    lblLeaveConversationCommentsBy.ID = "lblLeaveConversationCommentsBy" + rowIndex;

                    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);
                }
            }
            divLeaveConversation.Controls.Add(leaveConversation);
        }

        if (ds_PermissionConversation.Tables[0].Rows.Count > 0)
        {
            strHtml = buildPage("Test", dtReplyResend);
        }
    }

    public string buildPage(string strPageTitle, DataTable myDT)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        //HTML header
        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'>");
        //Table header       
        foreach (DataColumn Col in myDT.Columns)
        {
            sb.Append("<td><span class='Header'>" + Col.ColumnName.ToString() + "</span></td>");
        }

        sb.Append("  </tr>");
        //add rows to the table for the length of the dataset
        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 width='60%'><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");

                    //intWidth = 1;
                }
                else
                {

                    sb.Append("<td><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");

                    //intWidth = 0;
                }
                intWidth = intWidth + 1;
            }
            sb.Append("  </tr>");
            intIncrement = intIncrement + 1;
        }
        //Close the html string
        sb.Append("</table>");
        sb.Append("</body>");
        sb.Append("</html>");

        return sb.ToString();
    }

    #endregion
    #region Button Click Events
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Request.QueryString["LevelId"]) != null)
        {
            if (Convert.ToString(Session["LevelId"]) == string.Empty)
            {
                Session["LevelId"] = Request.QueryString["LevelId"].ToString();
            }
        }
        //if (Convert.ToString(Request.QueryString["Status"]) != null)
        //{
        //    if (Convert.ToString(Session["OndutyStatus"]) == string.Empty)
        //    {
        //        Session["OndutyStatus"] = "All";
        //    }
        //}
        if (Convert.ToString(Session["OndutyStatus"]) == string.Empty)
        {
            Session["OndutyStatus"] = "All";
        }
        int payrollConfig = 0;
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        payrollConfig = objCommon.CheckPageExistsInLicense(185);
        /*Below parameter is used for Angler*/
        if (payrollConfig == 0)
        {
            Response.Redirect("../Transactions/TA_UI_Transaction_Sanctions.aspx?Type=Onduty");
        }
        else
        {
            Response.Redirect("../Transactions/TA_UI_Transactions_OnDutySanction.aspx");
        }
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        //if (txtRemarks.Text.Trim() == "")
        //{
        //    base.Message("Enter Remarks");
        //    return;
        //}
        string strLengthCheck = txtRemarks.Text.Trim().Replace("'", "''");
        if (strLengthCheck.Length > 250)
        {
            Message("Maximum character for Reason is 250");
            return;
        }

        //if (rbApproved.Checked == true)
        //    Status = "Approved";
        //else if (rbForwarded.Checked == true)
        //    Status = "Forwarded";
        //else if (rbPending.Checked == true)
        //    Status = "Pending";
        //else if (rbRejected.Checked == true)
        //    Status = "Rejected";
        //else if (rbResend.Checked == true)
        //    Status = "Resend";
        //else if (rbReply.Checked == true)
        //    Status = "Reply";
        //else
        //    Status = string.Empty;
        Status = hfstatus.Value;

        //if (rblStatus.SelectedValue != "")
        //{
        //    Status = rblStatus.SelectedValue;
        //}
        //else
        //{
        //    Status = "";
        //}
        if (Status == string.Empty)
        {
            base.Message(rm.GetString("Alert_SelectAnyOtherOption", ci));
            return;
        }
        if (ViewState["StatusOnLoad"].ToString() == Status)
        {
            base.Message("Please change the status");
            return;
        }
        //Status = rblStatus.SelectedItem.Text;
        DataSet dsSanctionView = new DataSet();
        string OndutyType = string.Empty;
        dsSanctionView = objManualTimeEntry.SelectODEntryById(gintManualTimeEntryId);
        dtSanctionView = dsSanctionView.Tables[0];
        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();
        if (Convert.ToInt32(dtSanctionView.Rows[0]["Onduty_Type"].ToString()) == 1)
        {
            OndutyType = rm.GetString("rbSingleDayYes", ci);
        }
        else if (Convert.ToInt32(dtSanctionView.Rows[0]["Onduty_Type"].ToString()) == 2)
        {
            OndutyType = rm.GetString("rbSingleDayNo", ci);
        }

        //LevelID = dtSanctionView.Rows[0]["LevelID"].ToString();
        string 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"]);
        }

        if (lblOnDutyTypeName.Text == "Single Day")
        {
            strInDate = lbl_InDate.Text;
            strOutDate = lbl_InDate.Text;
        }
        else if (lblOnDutyTypeName.Text == "Multiple Days")
        {
            strInDate = lblFromDate.Text;
            strOutDate = lblToDate.Text;
        }
        strEntryDate = lbl_EntryDate.Text;
        //if (Convert.ToString(Request.QueryString["Status"]) != null)
        //{
        //    if (Convert.ToString(Session["OndutyStatus"]) == string.Empty)
        //    {
        //        Session["OndutyStatus"] = "All";
        //    }
        //}
        if (Convert.ToString(Session["OndutyStatus"]) == string.Empty)
            Session["OndutyStatus"] = "All";
        UpdatedManualTimeEntryStatus(Status);

        //SendMail(gintManualTimeEntryId,LevelID,
        #region SMSNotification
        try
        {
            int smsIsRequired = 0;
            //To check SMS Template is available in page table or not. if no then it will skip the SMS Triggering portion.
            //244 is template page id
            smsIsRequired = objCommon.CheckPageExistsInLicense(244);
            if (smsIsRequired > 0)
            {
                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)
                            {
                                if (dsGateway.Tables[0].Rows[0]["ServiceUrl"] != null)
                                {
                                    ServiceUrl = Convert.ToString(dsGateway.Tables[0].Rows[0]["ServiceUrl"]);
                                }
                                if (dsGateway.Tables[0].Rows[0]["DestinationKey"] != null)
                                {
                                    destinationKey = Convert.ToString(dsGateway.Tables[0].Rows[0]["DestinationKey"]);
                                }
                                if (dsGateway.Tables[0].Rows[0]["MessageKey"] != null)
                                {
                                    MessageKey = Convert.ToString(dsGateway.Tables[0].Rows[0]["MessageKey"]);
                                }
                                if (dsStatus.Tables[0].Rows[0]["ToEmployee"] != null)
                                {
                                    isSmsEnabled = Convert.ToBoolean(dsStatus.Tables[0].Rows[0]["ToEmployee"]);
                                }
                                if (isSmsEnabled)
                                {
                                    if (dsEmployeeDetails.Tables.Count > 0)
                                    {
                                        if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                                        {
                                            mobileNo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Mobile_Number"]);
                                        }
                                    }
                                }
                                if (dsEmployeeDetails.Tables.Count > 0)
                                {
                                    if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                                    {
                                        EmployeeName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                                    }
                                }
                                DataSet dsReceivers = new DataSet();
                                dsReceivers = objsms.GetReceiversDetails(strTemplateName, strEmployeeCodeId, strEmpFirstName, strInDate + " " + Convert.ToDateTime(lbl_InTime.Text).ToString(TimeFormatMail) + " To " + strOutDate + " " + Convert.ToDateTime(lbl_OutTime.Text).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,
                                                        EmployeeName,
                                                        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
    }

    #endregion
    #region Sending mail to the reporting to person.
    private void SendMail(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 strlevelName, string OndutyStatus, string Levelname)
    {
        string strFromEmailId = string.Empty;
        MailMessage mailMessage = new MailMessage();
        string strMailStatus = string.Empty;
        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.CC.Add(new MailAddress(ToMailId));
                //}
                //mailMessage.To.Add(new MailAddress(ToMailId));
                if (OndutyStatus == "Forwarded")
                {
                    if (SanctionMailId != string.Empty)
                    {
                        mailMessage.To.Add(new MailAddress(SanctionMailId));
                    }
                    if (EmployeeEamilId != string.Empty)
                    {
                        mailMessage.CC.Add(new MailAddress(EmployeeEamilId));
                    }
                }
                if (Session["loginEmailId"] != null && Session["loginEmailId"].ToString() != string.Empty)
                {
                    if (SanctionMailId != strEmailIdReportingTo)
                    {
                        if (OndutyStatus != "Forwarded")
                        {
                            if (Session["loginEmailId"].ToString() == SanctionMailId)
                            {
                                if (EmployeeEamilId != string.Empty)
                                {
                                    mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                                }
                                if (strEmailIdReportingTo != string.Empty)
                                {
                                    mailMessage.CC.Add(new MailAddress(strEmailIdReportingTo));
                                }
                            }
                            if (Session["loginEmailId"].ToString() == strEmailIdReportingTo)
                            {
                                if (EmployeeEamilId != string.Empty)
                                {
                                    mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (OndutyStatus != "Forwarded")
                        {
                            if (EmployeeEamilId != string.Empty)
                            {
                                mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                            }
                        }
                    }
                }
                else
                {
                    if (OndutyStatus != "Forwarded")
                    {
                        if (EmployeeEamilId != string.Empty)
                        {
                            mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                        }
                    }
                }
                DataSet dsCCEmailIds = new DataSet();
                dtSanctionView = (DataTable)ViewState["dtSanctionView"];
                dsCCEmailIds = objCCGroup.GetCCEmailIds(Convert.ToInt16(dtSanctionView.Rows[0]["levelid"].ToString()), Convert.ToInt16(dtSanctionView.Rows[0]["DesignationID"].ToString()), "O");
                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("<<lbldepartment>>", "Department");
                mailMessage.Body = mailMessage.Body.Replace("<<department>>", Levelname);
                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>>", lbl_Reason.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblRemarks>>", rm.GetString("email_Remarks", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Remarks>>", strReason);

                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);
                }
                objCommon.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
}
