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;
using System.IO;
/****************************************************************************************************************************
* Project Name    : TimeCheck                         Started Date  : 12-Aug-2007
* Module          : Leave Sanction                    Last Modified : 14-Aug-2007
* Programmer      : Prabakaran.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
* 
* Modified By      :   Manjula.P
* Modified On      :   28-Sep-2013
* Descriptinos     :   Condition added for getting when the forward authority is in super admin group. Code : 0019023
****************************************************************************************************************************/
public partial class Transactions_TA_UI_Transactions_LeaveSanctionModify : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    PermissionEventData objPermissionEventData = new PermissionEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    SMSNotification objsms = new SMSNotification();
    DataTable dtSanctionView = new DataTable();
    DataSet ds_EmailIdOfSanctionAuthority = new DataSet();
    DataSet dsEmailIdOfReportingTo = new DataSet();
    cls_Common objclscommon = new cls_Common();
    DataSet dsRecordsCount = new DataSet();
    int LeaveApplication_Id, Employee_Id, LeaveTypeId;
    string Status, Remarks, strEmailIdSanctionAuthority = "", strEmailIdReportingTo = "", EmployeeName, EmployeeEamilId, strLeaveApplicationDate, strNoOfDays, Leave_FromDate, Leave_ToDate;
    double NumberOfDays;
    bool checkEmail = true, blnCheckSMS = true;
    DataSet ds_RecordsCountLeaveReportingTo = new DataSet();
    DataSet ds_ReportingToSanctionAuthorityList = new DataSet();
    DataSet dsLeaveConversation = new DataSet();
    string gstrDateFormat;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        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"]);
        Session["SanctionSelected"] = "1";
        LeaveApplication_Id = Convert.ToInt32(Request.QueryString["LeaveApplication_Id"]);
        if (!IsPostBack)
        {
            LoadStrings(ci);
            UserRights();
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_LeaveType", ci) + "','" + rm.GetString("Alert_LeaveRestictHoliday", ci) + "','" + rm.GetString("Alert_Fromdate", ci) + "','" + rm.GetString("Alert_ToDate", ci) + "','" + rm.GetString("Alert_FillReasons", ci) + "','" + rm.GetString("Alert_Are_you_sure_to_Save", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            if (Status != "Approved" && Status != "Rejected")
            {
                ds_RecordsCountLeaveReportingTo = objLeaveApplicationEventData.GetRecordsCountLeaveReportingTo(Convert.ToInt32(Session["EmpAutoId"]));
                if (Convert.ToInt32(ds_RecordsCountLeaveReportingTo.Tables[0].Rows[0]["RecordsCount"]) > 0)
                {
                    rbApproved.Enabled = false;
                }
                dsRecordsCount = objLeaveApplicationEventData.GetRecordsCountLeaveSanction(Convert.ToInt32(Session["EmpAutoId"]));
                if (Convert.ToInt32(dsRecordsCount.Tables[0].Rows[0]["RecordsCount"]) > 0)
                {
                    rbForwarded.Enabled = false;
                    rbPending.Enabled = false;
                }
            }
            Status = Request.QueryString["Status"];
            SanctionViewDetails();
            ds_ReportingToSanctionAuthorityList = objLeaveApplicationEventData.SelectReportingToSanctionAuthority(LeaveApplication_Id);
            if (Status != "Approved" && Status != "Rejected")
            {
                if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin")
                {
                    if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]) && Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                    {
                        rbApproved.Enabled = true;
                        rbForwarded.Enabled = false;
                        rbPending.Enabled = false;
                        rbRejected.Enabled = true;
                    }
                    else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]))
                    {
                        rbApproved.Enabled = false;
                        rbForwarded.Enabled = true;
                        rbPending.Enabled = false;
                        if (Status == "Forwarded")
                        {
                            btn_Save.Enabled = false;
                            btn_Save.OnClientClick = null;
                        }
                    }
                    else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                    {
                        rbApproved.Enabled = true;
                    }
                }
                else
                {
                    rbApproved.Enabled = true;
                    rbForwarded.Enabled = true;
                    rbPending.Enabled = true;
                    rbRejected.Enabled = true;
                }
            }
            else if (Status == "Approved")
            {
                if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]))
                {
                    btn_Save.Enabled = false;
                    btn_Save.OnClientClick = null;
                }
                else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                {
                    btn_Save.Enabled = false;
                    btn_Save.OnClientClick = null;
                }
            }
            if (Convert.ToString(Session["TopMenuPrevious"]) == "")
            {
                GenerateMenu();
                loadMenu();
                LoadYear();
            }
            objclscommon.menu("Approvals", "248");
        }
        ControlCreation();
    }
    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;
    }
    #endregion
    #region ButtonEvents
    /// <summary>
    /// Redirects to Leave sanction page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    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["LeaveSanctionStatus"]) == string.Empty)
            {
                Session["LeaveSanctionStatus"] = "All";
            }
        }
        Response.Redirect("../Transactions/TA_UI_Transaction_Sanctions.aspx?Type=Leave");
    }
    protected void rbRejected_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = true;
    }
    protected void rbPending_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = true;
        rbRejected.Checked = false;
    }
    protected void rbForwarded_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = true;
        rbPending.Checked = false;
        rbRejected.Checked = false;
    }
    protected void rbApproved_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = true;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = false;
    }
    /// <summary>
    /// Save leave sanction Details
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Request.QueryString["LeaveApplication_Id"]) != "")
        {
            if (Convert.ToString(Session["LevelId"]) == string.Empty)
            {
                Session["LevelId"] = Request.QueryString["LevelId"].ToString();
            }
            if (Convert.ToString(Session["LeaveSanctionStatus"]) == string.Empty)
            {
                Session["LeaveSanctionStatus"] = "All";
            }
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            LeaveApplication_Id = Convert.ToInt32(Request.QueryString["LeaveApplication_Id"]);
            dtSanctionView = objLeaveApplicationEventData.GetLeaveApplicationByLeaveApplicationId(LeaveApplication_Id);
            if (dtSanctionView.Rows.Count > 0)
            {
                if (Convert.ToString(dtSanctionView.Rows[0]["Employee_FirstName"]) != "")
                {
                    EmployeeName = dtSanctionView.Rows[0]["Employee_FirstName"].ToString();
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["Employee_Id"]) != "")
                {
                    Employee_Id = Convert.ToInt32(dtSanctionView.Rows[0]["Employee_Id"]);
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["EmailId"]) != "")
                {
                    EmployeeEamilId = dtSanctionView.Rows[0]["EmailId"].ToString();
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["Leave_ApplicationDate"]) != "")
                {
                    strLeaveApplicationDate = dtSanctionView.Rows[0]["Leave_ApplicationDate"].ToString();
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["NumberOfDays"]) != "")
                {
                    strNoOfDays = dtSanctionView.Rows[0]["NumberOfDays"].ToString();
                    NumberOfDays = Convert.ToDouble(dtSanctionView.Rows[0]["NumberOfDays"]);
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["NumberOfDays"]) != "")
                {
                    LeaveTypeId = Convert.ToInt32(dtSanctionView.Rows[0]["LeaveType_id"]);
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["Leave_FromDate"]) != "")
                {
                    Leave_FromDate = objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_FromDate"].ToString());
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["Leave_ToDate"]) != "")
                {
                    Leave_ToDate = objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_ToDate"].ToString());
                }
                if (Convert.ToString(dtSanctionView.Rows[0]["LevelName"]) != "")
                {
                    ViewState["LevelName"] = dtSanctionView.Rows[0]["LevelName"].ToString();
                }
                string strTypeOfLeave = "";
                if (Convert.ToString(dtSanctionView.Rows[0]["Type"]) != "")
                {
                    strTypeOfLeave = dtSanctionView.Rows[0]["Type"].ToString();
                }
                int YearSetting_ID = 0;
                if (Convert.ToString(dtSanctionView.Rows[0]["YearSettings_Id"]) != "")
                {
                    YearSetting_ID = Convert.ToInt16(dtSanctionView.Rows[0]["YearSettings_Id"]);
                }
                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
                    Status = string.Empty;
                if (Status == string.Empty)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ChooseOption", ci) + "');", true);
                    return;
                }
                else if (Convert.ToString(Request.QueryString["Status"]) == Status)
                {
                    Message(rm.GetString("Alert_SelectAnyOtherOption", ci));
                    return;
                }
                Remarks = txtRemarks.Text.Trim().Replace("'", "''");
                bool boolChkLeave = true;
                int intBorrowCount = 0;
                int intLeaveCount = 0;
                try
                {
                    //update Leave Application
                    if (strTypeOfLeave == "Leave")
                    {
                        if (Convert.ToString(ViewState["StatusBorrow"]) == "False")
                        {
                            if (Convert.ToString(ViewState["StatusOnLoad"]) != Status)
                            {
                                if (Status == "Approved")
                                {
                                    objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "A", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                }
                                else if ((Status == "Rejected" || Status == "Forwarded" || Status == "Pending") && Convert.ToString(ViewState["StatusOnLoad"]) == "Approved")
                                {
                                    //Check Borrow Leave Exists after normal leaves
                                    intBorrowCount = objLeaveApplicationEventData.CheckBorrowLeaveExists(Leave_FromDate, Leave_ToDate, LeaveTypeId, Employee_Id);
                                    if (intBorrowCount > 0)
                                    {
                                        boolChkLeave = false;
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_BorrowLeavesareavailabletoapprovereject", ci) + "');", true);
                                        return;
                                    }
                                    else
                                    {
                                        objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "R", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                    }
                                }
                                else if ((Status == "Forwarded" || Status == "Pending") && Convert.ToString(ViewState["StatusOnLoad"]) == "Rejected")
                                {
                                    intBorrowCount = objLeaveApplicationEventData.CheckBorrowLeaveExists(Leave_FromDate, Leave_ToDate, LeaveTypeId, Employee_Id);
                                    if (intBorrowCount > 0)
                                    {
                                        boolChkLeave = false;
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_BorrowLeavesareavailabletoapprovereject", ci) + "');", true);
                                        return;
                                    }
                                    else
                                    {
                                        objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "R", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                    }
                                }
                                else if (Status == "Rejected")
                                {
                                    intBorrowCount = objLeaveApplicationEventData.CheckBorrowLeaveExists(Leave_FromDate, Leave_ToDate, LeaveTypeId, Employee_Id);
                                    if (intBorrowCount > 0)
                                    {
                                        boolChkLeave = false;
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_BorrowLeavesareavailabletoapprovereject", ci) + "');", true);
                                        return;
                                    }
                                    else
                                    {
                                        objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "R", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                    }
                                }
                            }
                        }
                        if (Convert.ToString(ViewState["StatusBorrow"]) == "True")
                        {
                            DataSet dsRemainingNoOfleaves = new DataSet();
                            double dblCurrLeave = 0.0;
                            if (Convert.ToString(ViewState["StatusOnLoad"]) != Status)
                            {
                                if ((Status == "Forwarded" || Status == "Pending") && Convert.ToString(ViewState["StatusOnLoad"]) == "Rejected")
                                {
                                    dsRemainingNoOfleaves = objLeaveApplicationEventData.GetRemainingNumberOfLeaves(Employee_Id, LeaveTypeId);
                                    dsRemainingNoOfleaves.Tables[0].TableName = "Details";
                                    if (dsRemainingNoOfleaves.Tables.Count > 0)
                                    {
                                        if (dsRemainingNoOfleaves.Tables[0].Rows.Count > 0)
                                        {
                                            dblCurrLeave = Convert.ToDouble(dsRemainingNoOfleaves.Tables["Details"].Rows[0]["RemainingNoOfLeaves"]);
                                        }
                                    }
                                    if (dblCurrLeave > 0)
                                    {
                                        boolChkLeave = false;
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_Currentyearquotaavailableforthisleavetype", ci) + "');", true);
                                        return;
                                    }
                                }
                                else if (Status == "Approved")
                                {
                                    intLeaveCount = objLeaveApplicationEventData.CheckLeaveExistsBeforeBorrow(Leave_FromDate, Leave_ToDate, LeaveTypeId, Employee_Id);
                                    if (intLeaveCount > 0)
                                    {
                                        boolChkLeave = false;
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_Alreadycurrentyearleaveapplicationsareavailabletoapprovereject", ci) + "');", true);
                                        return;
                                    }
                                    else
                                    {
                                        dsRemainingNoOfleaves = objLeaveApplicationEventData.GetRemainingNumberOfLeaves(Employee_Id, LeaveTypeId);
                                        dsRemainingNoOfleaves.Tables[0].TableName = "Details";
                                        if (dsRemainingNoOfleaves.Tables.Count > 0)
                                        {
                                            if (dsRemainingNoOfleaves.Tables[0].Rows.Count > 0)
                                            {
                                                dblCurrLeave = Convert.ToDouble(dsRemainingNoOfleaves.Tables["Details"].Rows[0]["RemainingNoOfLeaves"]);
                                            }
                                        }
                                        if (dblCurrLeave > 0)
                                        {
                                            boolChkLeave = false;
                                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_Currentyearquotaavailableforthisleavetype", ci) + "');", true);
                                            return;
                                        }
                                        objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "AB", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                    }
                                }
                                else if ((Status == "Rejected" || Status == "Forwarded" || Status == "Pending") && Convert.ToString(ViewState["StatusOnLoad"]) == "Approved")
                                {
                                    objLeaveApplicationEventData.UpdateYearClosureByLeaveSanction(NumberOfDays, LeaveTypeId, Employee_Id, "RB", Convert.ToInt32(Session["EmpAutoId"]), YearSetting_ID);
                                }
                            }
                        }
                    }
                    if (boolChkLeave == true) //
                    {
                        objLeaveApplicationEventData.UpdateLeaveApplicationSanction(LeaveApplication_Id, Status, 0,Remarks, Convert.ToInt32(Session["EmpAutoId"]));
                    }
                    objLeaveApplicationEventData.UpdateLeaveApplicationConversation(LeaveApplication_Id, Status, Convert.ToInt32(Session["EmpAutoId"]), Remarks, Convert.ToInt32(Session["EmpAutoId"]));
                    if (Status == "Approved")
                        objLeaveApplicationEventData.UpdateProcessedDataFlag(Employee_Id, Leave_FromDate, Leave_ToDate, 0);
                    if (Convert.ToString(ViewState["StatusOnLoad"]) != Status)
                    {
                        ds_EmailIdOfSanctionAuthority = objPermissionEventData.SelectMailIdOfSanctionAuthority(Employee_Id);
                        if (ds_EmailIdOfSanctionAuthority.Tables[0].Rows.Count > 0)
                        {
                            if (ds_EmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"] != DBNull.Value)
                            {
                                if (ds_EmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"].ToString() != string.Empty)
                                {
                                    strEmailIdSanctionAuthority = ds_EmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"].ToString();
                                }
                            }
                        }
                        dsEmailIdOfReportingTo = objPermissionEventData.SelectMailIdOfReportingTo(Employee_Id);
                        if (dsEmailIdOfReportingTo.Tables[0].Rows.Count > 0)
                        {
                            if (dsEmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"] != DBNull.Value)
                            {
                                if (dsEmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"].ToString() != string.Empty)
                                {
                                    strEmailIdReportingTo = dsEmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"].ToString();
                                }
                            }
                        }
                        if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                        {
                            SendMailToApplicant(Convert.ToInt32(Session["LevelId"]), LeaveApplication_Id, EmployeeEamilId, strEmailIdReportingTo, strEmailIdSanctionAuthority, EmployeeName, Status, txtRemarks.Text.Trim().Replace("'", "''"), strLeaveApplicationDate, strNoOfDays, lblLeaveType.Text);
                        }
                    }
                    #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 = objclscommon.CheckPageExistsInLicense(244);
                        if (smsIsRequired > 0)
                        {
                            DataSet dsGateway = new DataSet();
                            DataSet dsStatus = new DataSet();
                            bool isSmsEnabledForEmployee = false;
                            string destinationKey = string.Empty;
                            string MessageKey = string.Empty;
                            string ServiceUrl = string.Empty;
                            string mobileNo = string.Empty;
                            string strTemplateName = string.Empty;
                            string EmployeecodeId = string.Empty;
                            bool isApplyAndReceiverSame = false;
                            string empName = string.Empty;
                            if (Status == "Pending")
                            {
                                strTemplateName = "Leave Application - Apply";
                            }
                            else if (Status == "Forwarded")
                            {
                                strTemplateName = "Leave Application - Forward";
                            }
                            else if (Status == "Approved")
                            {
                                strTemplateName = "Leave Application - Approved";
                            }
                            else if (Status == "Rejected")
                            {
                                strTemplateName = "Leave Application - 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)
                                            {
                                                isSmsEnabledForEmployee = Convert.ToBoolean(dsStatus.Tables[0].Rows[0]["ToEmployee"]);
                                            }
                                            if (isSmsEnabledForEmployee)
                                            {
                                                if (dtSanctionView.Rows.Count > 0)
                                                {
                                                    if (dtSanctionView.Rows[0]["Mobile_Number"] != null)
                                                    {
                                                        mobileNo = Convert.ToString(dtSanctionView.Rows[0]["Mobile_Number"]);
                                                    }
                                                    if (dtSanctionView.Rows[0]["Employee_code_id"] != null)
                                                    {
                                                        EmployeecodeId = Convert.ToString(dtSanctionView.Rows[0]["Employee_code_id"]);
                                                    }
                                                    if (dtSanctionView.Rows[0]["Employee_FirstName"] != null)
                                                    {
                                                        empName = Convert.ToString(dtSanctionView.Rows[0]["Employee_FirstName"]);
                                                    }
                                                }
                                            }
                                            DataSet dsReceivers = new DataSet();
                                            string[] strleaveType = Convert.ToString(lblLeaveType.Text).Split('/');
                                            dsReceivers = objsms.GetReceiversDetails(strTemplateName, EmployeecodeId, EmployeeName, lblFromDate.Text + " To " + lblToDate.Text, strleaveType[0], Convert.ToString(strNoOfDays));
                                            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"]),
                                                                EmployeecodeId,
                                                                strTemplateName,
                                                                Convert.ToString(dr["SwipeCardNo"])
                                                            );
                                                            if (isSmsEnabledForEmployee)
                                                            {
                                                                if (Convert.ToString(dr["SwipeCardNo"]) == EmployeecodeId)
                                                                {
                                                                    isApplyAndReceiverSame = true;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            objsms.InsertLogDetails(strTemplateName, Convert.ToString(dr["SwipeCardNo"]), EmployeecodeId, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Mobile Number is not configured in employee master");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    objsms.InsertLogDetails(strTemplateName, "", EmployeecodeId, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Receivers are not having the configured usergroup");
                                                }
                                                if (isSmsEnabledForEmployee)
                                                {
                                                    if (mobileNo != string.Empty && isApplyAndReceiverSame != true)
                                                    {
                                                        blnCheckSMS = objsms.SendSMSNotifications
                                                                        (
                                                                            ServiceUrl,
                                                                            destinationKey,
                                                                            MessageKey,
                                                                            empName,
                                                                            Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]),
                                                                            Convert.ToString(mobileNo),
                                                                            EmployeecodeId,
                                                                             strTemplateName,
                                                                        Convert.ToString(EmployeecodeId)
                                                                        );
                                                    }
                                                    else if (mobileNo == string.Empty && isApplyAndReceiverSame != true)
                                                    {
                                                        objsms.InsertLogDetails(strTemplateName, Convert.ToString(EmployeecodeId), EmployeecodeId, false, Convert.ToString(dsReceivers.Tables[0].Rows[0]["Message"]), "Mobile Number is not configured in employee master");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    #endregion
                    if (checkEmail == true && blnCheckSMS == true)
                    {
                        string strScript = string.Empty;
                        strScript = strScript + "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_LeaveSanctionApplicationSaved", ci) + "');";
                        strScript = strScript + "location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Leave');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    }
                    else if (checkEmail == false && blnCheckSMS == true)
                    {
                        string strScript = string.Empty;
                        strScript = strScript + "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_LeaveSanctionApplicationSavedEmailnotsent", ci) + "');";
                        strScript = strScript + "location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Leave');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    }
                    else if (checkEmail == true && blnCheckSMS == false)
                    {
                        string strScript = string.Empty;
                        strScript = strScript + "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_LeaveApplicationSavedbutSMSisnottriggeredSanction", ci) + "');";
                        strScript = strScript + "location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Leave');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    }
                    else
                    {
                        string strScript = string.Empty;
                        strScript = strScript + "<script language='javascript'>";
                        strScript = strScript + "alert('" + rm.GetString("Alert_LeaveSanctionApplicationSavedEmailnotsent", ci) + "');";
                        strScript = strScript + "location.replace('TA_UI_Transaction_Sanctions.aspx?Type=Leave');";
                        strScript = strScript + "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    }
                }
                catch (Exception ex)
                {
                    Message(ex.ToString());
                }
            }
        }
    }
    #endregion
    #region UserDefinedFunction
    /// <summary>
    /// Display Leave permission Details
    /// </summary>
    private void SanctionViewDetails()
    {
        //For SuperAdmin Login 
        dtSanctionView = objLeaveApplicationEventData.GetLeaveApplicationByLeaveApplicationId(LeaveApplication_Id);
        ViewState["Employee_code_Id"] = dtSanctionView.Rows[0]["Employee_code_Id"].ToString();
        lblEmpid.Text = dtSanctionView.Rows[0]["employeeid"].ToString();
        lbl_EmployeeName.Text = dtSanctionView.Rows[0]["Employee_FirstName"].ToString();
        lblFromDate.Text = dtSanctionView.Rows[0]["Leave_FromDate"].ToString();
        lblToDate.Text = dtSanctionView.Rows[0]["Leave_ToDate"].ToString();
        lblNoOfDaysValue.Text = dtSanctionView.Rows[0]["NumberOfDays"].ToString();
        lblLeaveType.Text = dtSanctionView.Rows[0]["LeaveType"].ToString();
        if (lblLeaveType.Text == "Restricted Holiday")
            lblLeaveType.Text = rm.GetString("Holiday_RestrictedHoliday", ci);
        else if (lblLeaveType.Text == "Comp Off")
            lblLeaveType.Text = rm.GetString("Caption_CompOff", ci);
        else if (lblLeaveType.Text.Contains("LOP"))
            lblLeaveType.Text = lblLeaveType.Text.Replace("LOP", rm.GetString("lbl_LOP", ci));
        else if (lblLeaveType.Text == "ESI")
            lblLeaveType.Text = rm.GetString("Caption_ESI", ci);
        else if (lblLeaveType.Text.Contains("Leave"))
            lblLeaveType.Text = lblLeaveType.Text.Replace("Leave", rm.GetString("LeaveApplication_Leave", ci));
        lblReason.Text = dtSanctionView.Rows[0]["Reason"].ToString();
        lblSessionFrom.Text = dtSanctionView.Rows[0]["Leave_SessionFrom"].ToString();
        lblSessionTo.Text = dtSanctionView.Rows[0]["Leave_SessionTo"].ToString();
        if (Convert.ToString(dtSanctionView.Rows[0]["Result"]) == "Download")
        {
            divDownload.Style.Add("display", "");
        }
        if (lblSessionFrom.Text == "First half")
            lblSessionFrom.Text = rm.GetString("Caption_Firsthalf", ci);
        else if (lblSessionFrom.Text == "Second half")
            lblSessionFrom.Text = rm.GetString("Caption_Secondhalf", ci);
        if (lblSessionTo.Text == "First half")
            lblSessionTo.Text = rm.GetString("Caption_Firsthalf", ci);
        else if (lblSessionTo.Text == "Second half")
            lblSessionTo.Text = rm.GetString("Caption_Secondhalf", ci);
        ViewState["StatusOnLoad"] = dtSanctionView.Rows[0]["Status"].ToString();
        ViewState["StatusBorrow"] = dtSanctionView.Rows[0]["IsBorrow"].ToString();
        if (dtSanctionView.Rows[0]["Status"].ToString() == "Pending")
            rbPending.Checked = true;
        else if (dtSanctionView.Rows[0]["Status"].ToString() == "Forwarded")
            rbForwarded.Checked = true;
        else if (dtSanctionView.Rows[0]["Status"].ToString() == "Rejected")
        {
            rbRejected.Checked = true;
            if (Status == "Rejected")
            {
                ds_ReportingToSanctionAuthorityList = objLeaveApplicationEventData.SelectReportingToSanctionAuthority(LeaveApplication_Id);
                if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin")
                {
                    if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]) && Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                    {
                        string s = objclscommon.DateConvertion(gstrDateFormat, DateTime.Now.ToString());
                        if (Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_FromDate"].ToString())) >= Convert.ToDateTime(s) && Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_ToDate"].ToString())) >= Convert.ToDateTime(s))
                        {
                            if (Status == "Approved")
                                rbApproved.Checked = true;
                            else if (Status == "Forwarded")
                                rbForwarded.Checked = true;
                            else if (Status == "Pending")
                                rbPending.Checked = true;
                            else if (Status == "Rejected")
                                rbRejected.Checked = true;
                            rbApproved.Enabled = true;
                        }
                        else
                        {
                            btn_Save.Enabled = false;
                            btn_Save.OnClientClick = null;
                        }
                    }
                    else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]))
                    {
                        string s = objclscommon.DateConvertion(gstrDateFormat, DateTime.Now.ToString());
                        if (Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_FromDate"].ToString())) >= Convert.ToDateTime(s) && Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_ToDate"].ToString())) >= Convert.ToDateTime(s))
                        {
                            rbForwarded.Enabled = true;
                        }
                        else
                        {
                            btn_Save.Enabled = false;
                            btn_Save.OnClientClick = null;
                        }
                    }
                    else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                    {
                        string s = DateTime.Now.ToString(gstrDateFormat);
                        if (Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_FromDate"].ToString())) >= Convert.ToDateTime(s) && Convert.ToDateTime(objclscommon.DateConvertion(gstrDateFormat, dtSanctionView.Rows[0]["Leave_ToDate"].ToString())) >= Convert.ToDateTime(s))
                        {
                            rbApproved.Enabled = true;
                            rbPending.Enabled = true;
                            if (Status == "Approved")
                                rbApproved.Checked = true;
                            else if (Status == "Forwarded")
                                rbForwarded.Checked = true;
                            else if (Status == "Pending")
                                rbPending.Checked = true;
                            else if (Status == "Rejected")
                                rbRejected.Checked = true;
                        }
                        else
                        {
                            btn_Save.Enabled = false;
                            btn_Save.OnClientClick = null;
                        }
                    }
                }
            }
        }
        else if (dtSanctionView.Rows[0]["Status"].ToString() == "Approved")
            rbApproved.Checked = true;
    }
    /// <summary>
    /// Sending email to the Employee who applied for this permission
    /// </summary>
    /// <param name="EmployeeEamilId"></param>
    /// <param name="Status"></param>
    private void SendMailToApplicant(int LevelID, int LeaveApplication_Id, string EmployeeEamilId, string strEmailIdReportingTo, string strEmailIdSanctionAuthority, string EmployeeName, string Status, string Remarks, string LeaveApplicationDate, string NoOfDays, string strLeaveType)
    {
        MailMessage mailMessage = new MailMessage();
        string strFromEmailId = string.Empty;
        string scriptText;
        DataTable dtTableScript = new DataTable();
        try
        {
            string ScriptType = "Leave Application Sanction By Reporting to Person";
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            if (dtTableScript.Rows.Count > 0)
            {
                switch (strLeaveType)
                {
                    case "Restricted Holiday":
                        strLeaveType = rm.GetString("Holiday_RestrictedHoliday", ci);
                        break;
                    case "Comp Off":
                        strLeaveType = rm.GetString("Caption_CompOff", ci);
                        break;
                    case "LOP":
                        strLeaveType = strLeaveType.Replace("LOP", rm.GetString("lbl_LOP", ci));
                        break;
                    case "ESI":
                        strLeaveType = rm.GetString("Caption_ESI", ci);
                        break;
                    default:
                        if (strLeaveType.Contains("Leave"))
                            strLeaveType = strLeaveType.Replace("Leave", rm.GetString("LeaveApplication_Leave", ci));
                        break;
                }
                scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
                string Employee_Code_Id = Convert.ToString(ViewState["Employee_code_Id"]);
                // As per elite partner requisition, mail should be trigger from admin id, whatever we configured in setting page.
                //25-Dec-2019 02:06 PM
                //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"));
                //}
                if (Status == "Forwarded")
                {
                    if (strEmailIdSanctionAuthority != string.Empty)
                        mailMessage.To.Add(new MailAddress(strEmailIdSanctionAuthority));
                    if (EmployeeEamilId != string.Empty)
                        mailMessage.CC.Add(new MailAddress(EmployeeEamilId));
                }
                if (Session["loginEmailId"] != null && Convert.ToString(Session["loginEmailId"]) != string.Empty)
                {
                    if (strEmailIdSanctionAuthority != strEmailIdReportingTo)
                    {
                        if (Status != "Forwarded")
                        {
                            if (Convert.ToString(Session["loginEmailId"]) == strEmailIdSanctionAuthority)
                            {
                                if (EmployeeEamilId != string.Empty)
                                    mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                                if (strEmailIdReportingTo != string.Empty)
                                    mailMessage.CC.Add(new MailAddress(strEmailIdReportingTo));
                            }
                            else if (Convert.ToString(Session["loginEmailId"]) == strEmailIdReportingTo)
                            {
                                if (EmployeeEamilId != string.Empty)
                                    mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                            }
                        }
                    }
                    else
                    {
                        if (Status != "Forwarded")
                            if (EmployeeEamilId != string.Empty)
                                mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                    }
                }
                else
                {
                    if (Status != "Forwarded")
                        if (EmployeeEamilId != string.Empty)
                            mailMessage.To.Add(new MailAddress(EmployeeEamilId));
                }
                switch (Status)
                {
                    case "Approved":
                        Status = rm.GetString("btn_Approved", ci);
                        break;
                    case "Forwarded":
                        Status = rm.GetString("btn_Forwarded", ci);
                        break;
                    case "Pending":
                        Status = rm.GetString("btn_Pending", ci);
                        break;
                    case "Rejected":
                        Status = rm.GetString("btn_Reject", ci);
                        break;
                }
                mailMessage.Subject = rm.GetString("email_YourLeaveApplicationFor", ci) + " - " + lblFromDate.Text + " | " + Employee_Code_Id + " - " + EmployeeName + " | " + Status;
                mailMessage.Body = scriptText.Replace("<<lblLeaveApplicationForm>>", rm.GetString("email_LeaveApplicationForm", 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("email_LeaveApplicationDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ApplicationDate>>", LeaveApplicationDate);
                mailMessage.Body = mailMessage.Body.Replace("<<lblLeaveType>>", rm.GetString("lbl_leavetype", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<LeaveType>>", strLeaveType);
                mailMessage.Body = mailMessage.Body.Replace("<<lblLeaveDate>>", rm.GetString("email_LeaveDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblFromDate>>", rm.GetString("email_FromDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<FromDate>>", lblFromDate.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblToDate>>", rm.GetString("email_ToDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ToDate>>", lblToDate.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblSession>>", rm.GetString("email_Session", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<FromSession>>", lblSessionFrom.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblFromSession>>", rm.GetString("email_FromDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ToSession>>", lblSessionTo.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblToSession>>", rm.GetString("email_ToDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblNumberDaysApplied>>", rm.GetString("email_NumberOfDaysApplied", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<NumberDaysApplied>>", NoOfDays);
                mailMessage.Body = mailMessage.Body.Replace("<<lblStatus>>", rm.GetString("email_Status", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Status>>", Status);
                mailMessage.Body = mailMessage.Body.Replace("<<lblreason>>", "Reason");
                mailMessage.Body = mailMessage.Body.Replace("<<reason>>", lblReason.Text);
                mailMessage.Body = mailMessage.Body.Replace("<<lblRemarks>>", rm.GetString("email_Remarks", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<Remarks>>", Remarks);
                if (Status == "Forwarded" || Status == "Pending")
                {
                    mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?LeaveApplication_Id=" + Convert.ToString(LeaveApplication_Id) + "&LevelId=" + LevelID + "&Status=" + Status + "&ApprovalType=Leave");
                }
                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);
                }
                objclscommon.SendMail(mailMessage);
            }
            else
            {
                checkEmail = false;
                objLeaveApplicationEventData.InsertLeaveApplicationDetailsInEmailTrigger(LeaveApplication_Id, strFromEmailId, EmployeeEamilId, strEmailIdReportingTo, rm.GetString("email_YourLeaveApplicationFor", ci) + " - " + lblFromDate.Text + " - " + lblToDate.Text + " | " + Status, mailMessage.Body.ToString(), "", "LeaveSanction");
            }
        }
        catch
        {
            checkEmail = false;
            objLeaveApplicationEventData.InsertLeaveApplicationDetailsInEmailTrigger(LeaveApplication_Id, strFromEmailId, EmployeeEamilId, strEmailIdReportingTo, rm.GetString("email_YourLeaveApplicationFor", ci) + " - " + lblFromDate.Text + " - " + lblToDate.Text + " | " + Status, mailMessage.Body.ToString(), "", "LeaveSanction");
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Menu_Transactions_LeaveSanction", ci);
        lbl_Empid.Text = rm.GetString("email_EmployeeId", ci);
        lbl_LeaveType.Text = rm.GetString("lbl_leavetype", ci);
        lbl_EmpName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_FromDate.Text = rm.GetString("email_FromDate", ci);
        lbl_Todate.Text = rm.GetString("email_ToDate", ci);
        lbl_Reason.Text = rm.GetString("email_Reason", ci);
        lbl_Remarks.Text = rm.GetString("email_Remarks", ci);
        lbl_NoOfDays.Text = rm.GetString("LeaveSanction_NumberOfDays", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        //rblStatus.Items[0].Text = rm.GetString("btn_Approved", ci);
        //rblStatus.Items[1].Text = rm.GetString("btn_Forwarded", ci);
        //rblStatus.Items[2].Text = rm.GetString("btn_Pending", ci);
        //rblStatus.Items[3].Text = rm.GetString("btn_Reject", 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);
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        lbl_Status.Text = rm.GetString("email_Status", ci);
    }
    private void UserRights()
    {
        DataSet ds_Checkuser = new DataSet();
        Cls_CheckUser objCheckUser = new Cls_CheckUser();
        ds_Checkuser = objCheckUser.checkRights(248, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            loadMenu();
            LoadYear();
            objclscommon.menu("LeaveTransaction", "22");
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    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;
        // getting leave conversation 
        dsLeaveConversation = objLeaveApplicationEventData.GetLeaveConversation(LeaveApplication_Id);
        if (dsLeaveConversation.Tables[0].Rows.Count > 0)
        {
            Table leaveConversation = new Table();
            leaveConversation.BorderWidth = 1;
            leaveConversation.BorderColor = System.Drawing.Color.White;
            leaveConversation.CellPadding = 5;
            leaveConversation.CellSpacing = 0;
            //leaveConversation.Width = Unit.Pixel(720);
            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.Width = 120;
            leaveConversationHeading3.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading3);
            TableHeaderCell leaveConversationHeading1 = new TableHeaderCell();
            //leaveConversationHeading1.Width = 100;
            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 = 500;
            leaveConversationHeading2.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading2);
            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)
                    {
                        dRowReplyResend = dtReplyResend.NewRow();
                        TableRow trLeaveConversation = new TableRow();
                        TableCell tcLeaveConversationRepliedOn = new TableCell();
                        Label lblLeaveConversationRepliedOn = new Label();
                        tcLeaveConversationRepliedOn.BorderWidth = 1;
                        tcLeaveConversationRepliedOn.BorderColor = System.Drawing.Color.White;
                        tcLeaveConversationRepliedOn.Width = 200;
                        //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.BorderWidth = 1;
                        tcLeaveConversationCommentsBy.BorderColor = System.Drawing.Color.White;
                        tcLeaveConversationCommentsBy.Width = 200;
                        //lblLeaveConversationCommentsBy.ID = "lblLeaveConversationCommentsBy" + rowIndex;
                        //if (drLeaveConversation["CommentsBy"].ToString() == "0")
                        //{
                        //    //lblLeaveConversationCommentsBy.Text = lbl_EmployeeName.Text;
                        //    //dRowReplyResend["Comments By"] = lbl_EmployeeName.Text;
                        //    lblLeaveConversationCommentsBy.Text = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //    dRowReplyResend["Comments By"] = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //}
                        //else if (drLeaveConversation["CommentsBy"].ToString() == "1")
                        //{
                        //    lblLeaveConversationCommentsBy.Text = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //    dRowReplyResend["Comments By"] = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //}
                        //else if (drLeaveConversation["CommentsBy"].ToString() == "2")
                        //{
                        //    lblLeaveConversationCommentsBy.Text = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //    dRowReplyResend["Comments By"] = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));
                        //}
                        //else if (drLeaveConversation["CommentsBy"].ToString() == "3")
                        //{
                        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();
                        tcLeaveConversationComments.BorderWidth = 1;
                        tcLeaveConversationComments.BorderColor = System.Drawing.Color.White;
                        //tcLeaveConversationComments.ColumnSpan = 2;
                        // tcLeaveConversationComments.Width = 500;
                        //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);
        }
        else
        {
            divLeaveConversation.Visible = false;
        }
        //if (dsLeaveConversation.Tables[0].Rows.Count > 0)
        //{
        //    blnPrivateNotes = true;
        //    strHtml = buildPage("ReplyResend", dtReplyResend);
        //    blnPrivateNotes = false;
        //}
    }
    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;
        }
    }
    #endregion

    protected void btnDownload_Click(object sender, ImageClickEventArgs e)
    {
        Download_MedicalCertificate(LeaveApplication_Id);
    }
    protected void lnkbtnDownload_Click(object sender, EventArgs e)
    {
        Download_MedicalCertificate(LeaveApplication_Id);
    }
    private bool Download_MedicalCertificate(int LeaveApplication_ID)
    {
        string GetType = "SelectMedicalCertificate";
        bool fileflage = false;
        int LeaveApplication_Id = LeaveApplication_ID;
        DataSet dsFileDetails = objLeaveApplicationEventData.EditLeaveApplication_FileUpload(LeaveApplication_Id, GetType);
        if (dsFileDetails.Tables[0].Rows.Count > 0)
        {
            string GetPath = dsFileDetails.Tables[0].Rows[0]["FilePath"].ToString();
            string filename = Path.GetFileName(GetPath);
            string FilePath = Server.MapPath("~/Transactions/LeaveApplicationUploadFiles/" + filename);
            FileInfo fileInfo = new FileInfo(FilePath);

            if (fileInfo.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.Flush();
                Response.TransmitFile(fileInfo.FullName);
                Response.End();
                fileflage = true;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + rm.GetString("Alert_MedicalCertificateNotAvailable", ci) + "');", true);
                fileflage = false;
            }
        }
        return fileflage;

    }

}
