using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Globalization;
using System.Threading;
using System.Resources;
public partial class Transactions_TA_UI_Transactions_OnDutyList : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ManualEntryEventData objManualTimeEntry = new ManualEntryEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    cls_Common objClassCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int LevelID = 0;
    string strEmpFirstName, strEmpLastName, strEmployeeCodeId, strEmployeeName, strlevelName, strEmployeeEmailId, strEmailIdSanctioningAuthority, strEmailIdReportingTo;
    string strInDate, strInTime, strOutDate, strOutTime, strEntryDate, strReason;
    string source_Language;
    bool blnCheckEmail;
    string TimeFormatMail = string.Empty;
    string strSetAlert = "";
    #endregion
    #region Page Load Events
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        gvOnduty.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("OnDuty", "173");
            btn_Add.Focus();
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            LoadStrings(ci);            
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Errorinretrivingdetails", ci) + "','" + rm.GetString("Alert_SelectEntranceID", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
            UserRights();
            BindGridView();
        }
        if (Convert.ToString(ViewState["GroupName"]) == "Normal")
        {
            trSwipeCardNo.Visible = false;
            trEmployeeDetails.Visible = false;
        }
    }

    private void BindGridView()
    {
        DataSet dsEmployeeGroup = new DataSet();
        dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
        {
            if (Convert.ToString(dsEmployeeGroup.Tables[0].Rows[0]["GroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
            {
                gvOnduty.DataSourceID = "";
                gvOnduty.DataSourceID = ObjectDataSource1.ID;
                ViewState["GroupName"] = "SuperAdmin";
            }
            else
            {
                gvOnduty.DataSourceID = ObjectDataSource2.ID;
                gvOnduty.Columns[2].Visible = false;
                gvOnduty.Columns[3].Visible = false;
                ViewState["GroupName"] = "Normal";
            }
        }
        else
        {
            gvOnduty.DataSourceID = ObjectDataSource2.ID;
            gvOnduty.Columns[2].Visible = false;
            ViewState["GroupName"] = "Normal";
        }
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualODEntry", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        lblLeaveStartDate.Text = rm.GetString("email_FromDate", ci);
        lblLeaveEndDate.Text = rm.GetString("email_ToDate", ci);
        btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Clear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Clear", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
        lblDataView.Text = rm.GetString("lblDataView", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblTimePeriod.Text = rm.GetString("ShiftExchange_DateRange", ci);
        gvOnduty.Columns[1].Caption = rm.GetString("LeaveApplication_LeaveApplicationDate", ci);
        gvOnduty.Columns[2].Caption = rm.GetString("email_EmployeeId", ci);
        gvOnduty.Columns[3].Caption = rm.GetString("email_EmployeeName", ci);
        gvOnduty.Columns[4].Caption = "Shift - " + rm.GetString("OnDuty_InDate", ci);
        gvOnduty.Columns[5].Caption = rm.GetString("OnDuty_InTime", ci);
        gvOnduty.Columns[6].Caption = "Shift - " + rm.GetString("OnDuty_OutDate", ci);
        gvOnduty.Columns[7].Caption = rm.GetString("OnDuty_OutTime", ci);
        gvOnduty.Columns[9].Caption = rm.GetString("email_Reason", ci);
        gvOnduty.Columns[8].Caption = rm.GetString("email_Status", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(173, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_Add.Visible = true;
            }
            else
            {
                this.btn_Add.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                this.gvOnduty.Columns[10].Visible = true;
            }
            else
            {
                this.gvOnduty.Columns[10].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.gvOnduty.Columns[12].Visible = true;
            }
            else
            {
                this.gvOnduty.Columns[12].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["ModifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["ModifyPrv"]) == 1)
            {
                this.gvOnduty.Columns[11].Visible = true;
            }
            else
            {
                this.gvOnduty.Columns[11].Visible = false;
            }
        }
        else
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            lnktbnexcel.Visible = true;
            lnkbtnpdf.Visible = true;
        }
    }
    private void grid_RestoreDefault()
    {
        txt_EmpName.Text = string.Empty;
        txtEmployeeId.Text = string.Empty;
        txtStartDate.Text = string.Empty;
        txtEndDate.Text = string.Empty;
        txtSwipeCard.Text = string.Empty;
        gvOnduty.PageIndex = 0;
        if (Convert.ToString(ViewState["GroupName"]) == "Normal")
        {
            gvOnduty.DataSourceID = ObjectDataSource2.ID;
        }
        else
        {
            gvOnduty.DataSourceID = ObjectDataSource1.ID;
        }
    }
    private void FillGrid_Search()
    {
        string empName = txt_EmpName.Text.Trim();
        txt_EmpName.Text = empName;
        string empId = txtEmployeeId.Text.Trim();
        txtEmployeeId.Text = empId;
        string strStartDate = txtStartDate.Text;
        string strEndDate = txtEndDate.Text;
        bool boolErrorStatus = true;
        string gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strStartDate = objClassCommon.DateConvertion("MM/dd/yyyy", strStartDate);
        strEndDate = objClassCommon.DateConvertion("MM/dd/yyyy", strEndDate);
        string strSwipeCard = "";
        strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
        if (strStartDate == string.Empty && strEndDate == string.Empty)
        {
            boolErrorStatus = false;
        }
        else if (strStartDate != string.Empty && strEndDate != string.Empty)
        {
            if (Convert.ToDateTime(strEndDate).Date < Convert.ToDateTime(strStartDate).Date)
            {
                base.Message("From Date should be lesser than To date");
                gvOnduty.DataSourceID = "";
                boolErrorStatus = true;
                return;
            }
            else
            {
                boolErrorStatus = false;
            }
        }
        else
        {
            gvOnduty.DataSourceID = "";
            boolErrorStatus = true;
            return;
        }
        if (boolErrorStatus == true)
        {
            grid_RestoreDefault();
        }
        else
        {
            lbl_Error.Text = string.Empty;
            gvOnduty.PageIndex = 0;
            if (Convert.ToString(ViewState["GroupName"]) == "Normal")
            {
                gvOnduty.DataSourceID = ObjectDataSource2.ID;
            }
            else
            {
                gvOnduty.DataSourceID = ObjectDataSource1.ID;
            }
        }
    }
    #endregion
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        FillGrid_Search();
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        grid_RestoreDefault();
        lbl_Error.Text = string.Empty;
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyAdd.aspx");
    }
    protected void EditLinkButton_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int gintManualTimeEntryId = Convert.ToInt32(btn.CommandName);
        string ManuStatus = btn.CommandArgument;
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyEntryModify.aspx?MID=" + gintManualTimeEntryId);
        }
        else
        {
            switch (ManuStatus)
            {
                case "Approved":
                    base.Message(rm.GetString("Msg_ApprovedOnDutyEntryCannotbemodified", ci));
                    break;
                default:
                    Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyEntryModify.aspx?MID=" + gintManualTimeEntryId);
                    break;
            }
        }
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int gintManualTimeEntryId = Convert.ToInt32(btn.CommandName);
        int EmpID = Convert.ToInt32(btn.ValidationGroup);
        string ManuStatus = btn.CommandArgument;
        int gintUserId = Int32.Parse(Session["EmpAutoID"].ToString());
        string strScript = string.Empty;
        DataSet dsSanctionView = new DataSet();
        string strLeaveStatus = string.Empty;
        int approvalSettingsPageExists = 0;
        //Checking grade module is available or not and changed the id value from 110 to 228
        approvalSettingsPageExists = objClassCommon.CheckPageExistsInLicense(228);
        if (approvalSettingsPageExists == 1)
        {
            //Get Compnay Id of the Employeee
            int intCompanyId = base.GetCompanyId(EmpID);
            //Get Approval Settings Based on Company Id
            DataSet dsApprovalSettings = new DataSet();
            ShiftEvenData objShift = new ShiftEvenData();
            dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
            if (dsApprovalSettings != null)
            {
                if (dsApprovalSettings.Tables.Count > 0)
                {
                    if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                    {
                        if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["ODEntry"]) == false)
                        {
                            ManuStatus = "ApprovalNotRequired";
                        }
                    }
                    else
                    {
                        base.Message(rm.GetString("Msg_ApprovalSettings", ci));
                        return;
                    }
                }
            }
        }
        else
        {
            ManuStatus = "ApprovalNotRequired";
        }
        dsSanctionView = objManualTimeEntry.SelectODEntryById(gintManualTimeEntryId);
        if (dsSanctionView.Tables.Count > 0)
        {
            if (dsSanctionView.Tables[0].Rows.Count > 0)
            {
                strInDate = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_FromDate"]);
                strInTime = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_FromTime"]);
                strOutDate = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_ToDate"]);
                strOutTime = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_ToTime"]);
                strEntryDate = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_EntryDate"]);
                strReason = Convert.ToString(dsSanctionView.Tables[0].Rows[0]["Onduty_Reason"]);
            }
        }
        if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin" && Convert.ToString(Session["HasSpecialRights"]) != "True")
        {
            if (ManuStatus != "ApprovalNotRequired")
            {
                if (ManuStatus == "Approved" || ManuStatus == "Forwarded")
                {
                    base.Message(rm.GetString("Msg_ApprovedOnDutyEntryCannotbeDeleted", ci));
                    return;
                }
                else
                {
                    objManualTimeEntry.DeleteOndutyEntry(gintManualTimeEntryId, gintUserId);
                    GetEmployeeDetails(EmpID);
                    if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                    {
                        SendMail(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, strInTime, strOutDate, strOutTime, strEntryDate, strEmployeeName, strEmployeeCodeId, "", strlevelName, "Delete", strlevelName);
                    }
                    Message(rm.GetString("Alert_OnDutyEntryhasbeendeletedsucessfully", ci));
                    BindGridView();
                    return;
                }
            }
            else
            {
                objManualTimeEntry.DeleteOndutyEntry(gintManualTimeEntryId, gintUserId);
                GetEmployeeDetails(EmpID);
                if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                {
                    SendMail(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, strInTime, strOutDate, strOutTime, strEntryDate, strEmployeeName, strEmployeeCodeId, "", strlevelName, "Delete", strlevelName);
                }
                Message(rm.GetString("Alert_OnDutyEntryhasbeendeletedsucessfully", ci));
                BindGridView();
                return;
            }
        }
        else
        {
            objManualTimeEntry.DeleteOndutyEntry(gintManualTimeEntryId, gintUserId);
            GetEmployeeDetails(EmpID);
            if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
            {
                SendMail(Convert.ToInt32(gintManualTimeEntryId), LevelID, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, strInTime, strOutDate, strOutTime, strEntryDate, strEmployeeName, strEmployeeCodeId, strReason, strlevelName, "Deleted", strlevelName);
            }
            Message(rm.GetString("Alert_OnDutyEntryhasbeendeletedsucessfully", ci));
            BindGridView();
            return;
        }
    }

    private void GetEmployeeDetails(int EmpID)
    {
        DataSet dsEmployeeDetails = new DataSet();
        dsEmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(EmpID));
        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"]);
        }
    }
    #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 From";
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            if (dtTableScript.Rows.Count > 0)
            {
                scriptText = Convert.ToString(dtTableScript.Rows[0]["ScriptText"]);
                mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
                strFromEmailId = Convert.ToString(ConfigurationManager.AppSettings.Get("FromId"));
                if (ToMailId != SanctionMailId)
                {
                    strMailStatus = rm.GetString("btn_Pending", ci);
                }
                else
                {
                    strMailStatus = rm.GetString("btn_Forwarded", ci);
                }
                if (OndutyStatus == "Deleted")
                {
                    if (SanctionMailId != string.Empty)
                    {
                        mailMessage.To.Add(new MailAddress(SanctionMailId));
                    }
                    if (strEmployeeEmailId != string.Empty)
                    {
                        mailMessage.CC.Add(new MailAddress(strEmployeeEmailId));
                    }
                }
                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("<<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>>", 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");
                }
                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);
                }
                objClassCommon.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

    protected void lnktbnexcel_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = (LinkButton)sender;  //Called From  Grid Report Icon click / both excel and pdf
        DisableControls();
        ASPxGridViewExporter1.Landscape = true;
        ASPxGridViewExporter1.LeftMargin = 10;
        ASPxGridViewExporter1.RightMargin = 10;
        ASPxGridViewExporter1.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
        ASPxGridViewExporter1.MaxColumnWidth = 400;
        string saveAsFileName = string.Format("ListofOnDutyApplications - {0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
        ASPxGridViewExporter1.FileName = saveAsFileName;
        ASPxGridViewExporter1.PaperKind = System.Drawing.Printing.PaperKind.A3;
        switch (lnkbtn.CommandName)
        {
            case "excel":
                ASPxGridViewExporter1.WriteXlsxToResponse();
                break;
            case "pdf":
                ASPxGridViewExporter1.WritePdfToResponse();
                break;
            case "csv":
                ASPxGridViewExporter1.WriteCsvToResponse();
                break;
        }
    }
    private void DisableControls()
    {
        gvOnduty.Columns[10].Visible = false;
        gvOnduty.Columns[11].Visible = false;
        gvOnduty.Columns[12].Visible = false;
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        BindGridView();
    }
}
