using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Net.Mail;
using System.Net;
public partial class Transactions_TA_UI_Transactions_OnDutyEntryView : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ManualEntryEventData objManualTimeEntry = new ManualEntryEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    Int64 gintManualTimeEntryId, gintUserId;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet dsManualTimeEntry;
    cls_Common objCommon = new cls_Common();
    string NewTimeFormat = string.Empty;
    string strInDate, strOutDate;
    int LevelID;
    string strEmpFirstName, strEmpLastName, strEmployeeCodeId, strlevelName, OndutyType;
    string strEmployeeEmailId = string.Empty, strIncludeWeekOff;
    string strEmployeeIds = string.Empty, strEmailIdSanctioningAuthority = string.Empty, strEmailIdReportingTo = string.Empty;
    string strEmployeeName = string.Empty;
    bool blnCheckEmail = true;
    string strScript = string.Empty;
    #endregion
    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;
        LoadStrings(ci);
        loadcss();
        UserRights();
        gintManualTimeEntryId = Convert.ToInt64(Request.QueryString["MID"]);
        gintUserId = Int32.Parse(Session["EmpAutoID"].ToString());
        btn_Modify.Focus();
        if (Session["ITimeFormat"].ToString() == "%H:%M")
        {
            NewTimeFormat = "HH:mm:ss";
        }
        else
        {
            NewTimeFormat = "hh:mm:ss tt";
        }
        if (!Page.IsPostBack)
        {
            GetManualEntryDetails();
            ControlCreation();
        }
        int intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            if ((lbl_Status.Text == "Pending") || (lbl_Status.Text == "Rejected"))
            {
                btn_Modify.Enabled = false;
                btn_Delete.Enabled = true;
            }
            else
            {
                btn_Delete.Enabled = false;
            }
        }
    }
    private void GetManualEntryDetails()
    {
        dsManualTimeEntry = new DataSet();
        DataTable dtManualTimeEntry = new DataTable();
        dsManualTimeEntry = objManualTimeEntry.SelectODEntryById(gintManualTimeEntryId);
        dtManualTimeEntry = dsManualTimeEntry.Tables[0];
        if (dtManualTimeEntry.Rows.Count > 0)
        {
            if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"].ToString() != string.Empty)
                {
                    lbl_EmpId.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Code_Id"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Employee_Id"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Employee_Id"].ToString() != string.Empty)
                {
                    hdnEmployeeId.Value = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Id"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Employee_Name"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Employee_Name"].ToString() != string.Empty)
                {
                    lbl_EmpName.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Name"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_EntryDate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_EntryDate"].ToString() != string.Empty)
                {
                    lbl_EntryDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_EntryDate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_FromDate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_FromDate"].ToString() != string.Empty)
                {
                    lbl_InDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_FromDate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_FromTime"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_FromTime"].ToString() != string.Empty)
                {
                    lbl_InTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_FromTime"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_ToDate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_ToDate"].ToString() != string.Empty)
                {
                    lbl_OutDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_ToDate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_ToTime"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_ToTime"].ToString() != string.Empty)
                {
                    lbl_OutTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_ToTime"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_Reason"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_Reason"].ToString() != string.Empty)
                {
                    lbl_Reason.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Reason"]);
                    lbl_Reason.ToolTip = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Reason"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_Status"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_Status"].ToString() != string.Empty)
                {
                    lbl_Status.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Onduty_Status"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Onduty_Type"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Onduty_Type"].ToString() != string.Empty)
                {
                    int ODType = Convert.ToInt32(dtManualTimeEntry.Rows[0]["Onduty_Type"]);
                    if (ODType == 1)
                    {
                        divSingle.Visible = true;
                        divMulti.Visible = false;
                        lblOnDutyTypeName.Text = "Single Day";
                    }
                    else
                    {
                        divSingle.Visible = false;
                        divMulti.Visible = true;
                        lblOnDutyTypeName.Text = "Multiple Days";
                        lblFromDate.Text = dtManualTimeEntry.Rows[0]["Onduty_FromDate"].ToString();
                        lblToDate.Text = dtManualTimeEntry.Rows[0]["Onduty_ToDate"].ToString();
                        if (dtManualTimeEntry.Rows[0]["From_Session"] != DBNull.Value)
                        {
                            if (dtManualTimeEntry.Rows[0]["From_Session"].ToString() != string.Empty)
                            {
                                lblFromSession.Text = dtManualTimeEntry.Rows[0]["From_Session"].ToString();
                            }
                        }
                        if (dtManualTimeEntry.Rows[0]["To_Session"] != DBNull.Value)
                        {
                            if (dtManualTimeEntry.Rows[0]["To_Session"].ToString() != string.Empty)
                            {
                                lblTosession.Text = dtManualTimeEntry.Rows[0]["To_Session"].ToString();
                            }
                        }
                    }
                }
            }
        }
    }
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
        {
            Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyEntryModify.aspx?MID=" + gintManualTimeEntryId);
        }
        else
        {
            if (lbl_Status.Text == "Approved")
            {
                base.Message(rm.GetString("Msg_ApprovedOnDutyEntryCannotbemodified", ci));
                return;
            }
            Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyEntryModify.aspx?MID=" + gintManualTimeEntryId);
        }

    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Transactions/TA_UI_Transactions_OnDutyList.aspx");
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualODEntry", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EntranceName1.Text = rm.GetString("EntranceMaster_Entrance_Name", ci);
        lbl_InDate1.Text = rm.GetString("OnDuty_InDate", ci);
        lbl_InTime1.Text = rm.GetString("OnDuty_InTime", ci);
        lbl_InPunchType1.Text = rm.GetString("ManualTimeEntry_InPunchType", ci);
        lbl_ManualTimeEntryDate.Text = rm.GetString("LeaveApplication_LeaveApplicationDate", ci);
        lbl_OutDate1.Text = rm.GetString("OnDuty_OutDate", ci);
        lbl_OutTime1.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_OutPunchType1.Text = rm.GetString("ManualTimeEntry_OutPunchType", ci);
        lbl_Reason1.Text = rm.GetString("email_Reason", ci);
        lbl_Status1.Text = rm.GetString("email_Status", ci);
        lblEntryType.Text = rm.GetString("ManualTimeEntryType", ci);
        btn_Modify.Text = rm.GetString("btn_Modify", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lbl_Shiftname1.Text = rm.GetString("ShiftTiming_ShiftShortName", ci);
        lblFromDate1.Text = rm.GetString("OnDuty_InDate", ci);
        lbl_OnDutyType.Text = rm.GetString("lbl_SingleDay", ci);
        lblToDate1.Text = rm.GetString("OnDuty_OutDate", ci);
        lblFromSession1.Text = rm.GetString("lbl_FromSession", ci);
        lblTosession1.Text = rm.GetString("lbl_ToSession", 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]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Transactions_ManualTimeEntry.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Modify.Visible = true;
            }
            else
            {
                this.btn_Modify.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
            }
        }
        else
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }

    private void loadcss()
    {
        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
        htmlODView.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }
    private void Reprocess_Data(DateTime strFromDate, DateTime strToDate, string employeeID)
    {
        objManualTimeEntry.ReprocessEmployeeData(strFromDate, strToDate, employeeID);
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
        {
            string gstrDateFormat = string.Empty;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            if (lblOnDutyTypeName.Text == "Multiple Days")
            {
                strInDate = lblFromDate.Text;
                strOutDate = lblToDate.Text;
            }
            if (lblOnDutyTypeName.Text == "Single Day")
            {
                strInDate = lbl_InDate.Text;
                strOutDate = lbl_OutDate.Text;
            }
            string strScript = string.Empty;
            objManualTimeEntry.DeleteOndutyEntry(gintManualTimeEntryId, gintUserId);
            Reprocess_Data(Convert.ToDateTime(objCommon.DateConvertion(gstrDateFormat, strInDate)), Convert.ToDateTime(objCommon.DateConvertion(gstrDateFormat, strInDate)), lbl_EmpId.Text);
            //This below function added by karthikeyan for the send mail.
            DataSet dsEmployeeDetails = new DataSet();
            dsEmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(hdnEmployeeId.Value));

            if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
            {
                strEmpFirstName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                strEmpLastName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);
                strEmployeeCodeId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_Code_Id"]);
                strEmployeeName = strEmpFirstName + " " + strEmpLastName;
                strlevelName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["levelName"]);
                strEmployeeEmailId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["EmailID"]);
                strEmailIdSanctioningAuthority = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ApprovalAuthorityEmailID"]);
                strEmailIdReportingTo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ReportingToEmailID"]);
                LevelID = Convert.ToInt32(dsEmployeeDetails.Tables[0].Rows[0]["LevelID"]);
            }
            if (strEmailIdSanctioningAuthority != "" || strEmailIdReportingTo != "")
            {
                string strEntryDate = lbl_EntryDate.Text;
                if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                {
                    SendMail(strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, lbl_InTime.Text, strOutDate, lbl_OutTime.Text, strEntryDate, strEmployeeName, strEmployeeCodeId, lbl_Reason.Text, strlevelName, "Deleted");
                }
            }
            //End
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_OnDutyEntryhasbeendeletedsucessfully", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_Transactions_OnDutyList.aspx')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("Alert", strScript);
        }
        else
        {
            string strScript = string.Empty;
            string gstrDateFormat = string.Empty;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            if (lblOnDutyTypeName.Text == "Multiple Days")
            {
                strInDate = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), lblFromDate.Text);
                strOutDate = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), lblToDate.Text);
            }
            if (lblOnDutyTypeName.Text == "Single Day")
            {
                strInDate = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), lbl_InDate.Text);
                strOutDate = objCommon.DateConvertion(Convert.ToString(Session["MDateFormat"]), lbl_OutDate.Text);
            }
            if (lbl_Status.Text == "Approved")
            {
                base.Message(rm.GetString("Alert_ApprovedOnDutyEntryCannotbedeleted", ci));
                return;
            }
            else
            {

                objManualTimeEntry.DeleteOndutyEntry(gintManualTimeEntryId, gintUserId);
                Reprocess_Data(Convert.ToDateTime(strInDate), Convert.ToDateTime(strOutDate), lbl_EmpId.Text);
                //This below function added by karthikeyan for the send mail.
                DataSet dsEmployeeDetails = new DataSet();
                dsEmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(hdnEmployeeId.Value));

                if (dsEmployeeDetails.Tables[0].Rows.Count > 0)
                {
                    strEmpFirstName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                    strEmpLastName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);
                    strEmployeeCodeId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["Employee_Code_Id"]);
                    strEmployeeName = strEmpFirstName + " " + strEmpLastName;
                    strlevelName = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["levelName"]);
                    strEmployeeEmailId = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["EmailID"]);
                    strEmailIdSanctioningAuthority = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ApprovalAuthorityEmailID"]);
                    strEmailIdReportingTo = Convert.ToString(dsEmployeeDetails.Tables[0].Rows[0]["ReportingToEmailID"]);
                    LevelID = Convert.ToInt32(dsEmployeeDetails.Tables[0].Rows[0]["LevelID"]);
                }
                if (strEmailIdSanctioningAuthority != "" || strEmailIdReportingTo != "")
                {
                    string strEntryDate = lbl_EntryDate.Text;
                    if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                    {
                        SendMail(strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, strInDate, lbl_InTime.Text, strOutDate, lbl_OutTime.Text, strEntryDate, strEmployeeName, strEmployeeCodeId, lbl_Reason.Text, strlevelName, "Deleted");
                    }
                }
                //End
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_OnDutyEntryhasbeendeletedsucessfully", ci) + "');";
                strScript = strScript + "location.replace('TA_UI_Transactions_OnDutyList.aspx')";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("Alert", strScript);
            }
        }
    }
    private void SendMail(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 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"]);
                //if (Session["loginEmailId"] != null && Convert.ToString(Session["loginEmailId"]) != string.Empty)
                //{
                //    mailMessage.From = new MailAddress(Convert.ToString(Session["loginEmailId"]));
                //    strFromEmailId = Convert.ToString(Session["loginEmailId"]);
                //}
                //else
                //{
                mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
                strFromEmailId = Convert.ToString(ConfigurationManager.AppSettings.Get("FromId"));
                //}
                mailMessage.To.Add(new MailAddress(ToMailId));
                if (Convert.ToString(mailMessage.From) != strEmployeeEmailId)
                {
                    if (strEmployeeEmailId != string.Empty)
                    {
                        mailMessage.CC.Add(new MailAddress(strEmployeeEmailId));
                    }
                }
                mailMessage.Subject = rm.GetString("email_OndutyApplicationForm", ci) + " - " + ApplicationDate + " | " + Employee_Code_Id + " - " + EmployeeName + " | " + strlevelName + " - " + OndutyStatus;
                mailMessage.Body = scriptText.Replace("<<lblOndutyForm>>", rm.GetString("email_OndutyApplicationForm", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ltr_rtl>>", rm.GetString("Direction", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeID>>", rm.GetString("email_EmployeeId", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<EmployeeID>>", Employee_Code_Id);
                mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeName>>", rm.GetString("email_EmployeeName", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<EmployeeName>>", EmployeeName);
                mailMessage.Body = mailMessage.Body.Replace("<<lblApplicationDate>>", rm.GetString("ODEntry_ODEntryDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ApplicationDate>>", ApplicationDate);
                mailMessage.Body = mailMessage.Body.Replace("<<lblODDate>>", rm.GetString("OnDutyDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<lblFromDate>>", rm.GetString("email_FromDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<FromDate>>", FromDate + " " + FromTime);
                mailMessage.Body = mailMessage.Body.Replace("<<lblToDate>>", rm.GetString("email_ToDate", ci));
                mailMessage.Body = mailMessage.Body.Replace("<<ToDate>>", ToDate + " " + ToTime);
                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);
                string strReplaceText = "<font face=\"Arial\" size=\"2\"><a href=\"<<LinkData>>\">Click here for approval </a></font>";
                mailMessage.Body = mailMessage.Body.Replace(strReplaceText, string.Empty);
                objCommon.SendMail(mailMessage);
            }
            else
            {
                blnCheckEmail = false;
            }
        }
        catch
        {
            blnCheckEmail = false;
            //objLeaveApplicationEventData.InsertLeaveApplicationDetailsInEmailTrigger(intLeaveApplicationId, strFromEmailId, ToMailId, strEmployeeEmailId, rm.GetString("email_LeaveApplicationForm", objCultureInfo) + " - " + ApplicationDate + " | " + Employee_Code_Id + " - " + EmployeeName + " | " + strlevelName + " - " + strMailStatus, Convert.ToString(mailMessage.Body), "", "LeaveApplication");
        }
    }

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

        if (dsLeaveConversation.Tables[0].Rows.Count > 0)
        {
            Table leaveConversation = new Table();
            //leaveConversation.BorderWidth = 1;
            //leaveConversation.CellPadding = 5;
            //leaveConversation.CellSpacing = 0;
            //leaveConversation.BorderColor = System.Drawing.Color.White;
            leaveConversation.Width = Unit.Percentage(100);
            leaveConversation.CssClass = "table das-table1";
            //leaveConversation.Attributes.Add("border", "1");

            TableHeaderRow leaveConversationHr = new TableHeaderRow();

            TableHeaderCell leaveConversationHeading3 = new TableHeaderCell();
            leaveConversationHeading3.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
            leaveConversationHeading3.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading3);

            TableHeaderCell leaveConversationHeading1 = new TableHeaderCell();
            leaveConversationHeading1.Text = rm.GetString("leaveConversationHeading1", ci);
            leaveConversationHeading1.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading1);

            TableHeaderCell leaveConversationHeading2 = new TableHeaderCell();
            leaveConversationHeading2.Text = rm.GetString("leaveConversationHeading2", ci);
            leaveConversationHeading2.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading2);
            leaveConversationHr.CssClass = "empheader";
            leaveConversation.Rows.Add(leaveConversationHr);

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

                        TableCell tcLeaveConversationRepliedOn = new TableCell();

                        Label lblLeaveConversationRepliedOn = new Label();
                        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());

                        tcLeaveConversationRepliedOn.Controls.Add(lblLeaveConversationRepliedOn);
                        trLeaveConversation.Cells.Add(tcLeaveConversationRepliedOn);

                        TableCell tcLeaveConversationCommentsBy = new TableCell();
                        Label lblLeaveConversationCommentsBy = new Label();
                        tcLeaveConversationCommentsBy.Width = 200;

                        lblLeaveConversationCommentsBy.ID = "lblLeaveConversationCommentsBy" + rowIndex;

                        lblLeaveConversationCommentsBy.Text = objLeaveApplicationEventData.GetEmployeeName(Convert.ToInt32(drLeaveConversation["Emp_Id"].ToString()));

                        tcLeaveConversationCommentsBy.Controls.Add(lblLeaveConversationCommentsBy);
                        trLeaveConversation.Cells.Add(tcLeaveConversationCommentsBy);

                        TableCell tcLeaveConversationComments = new TableCell();

                        Label lblLeaveConversationComments = new Label();

                        lblLeaveConversationComments.ID = "lblLeaveConversationComments" + rowIndex;
                        lblLeaveConversationComments.Text = drLeaveConversation["Comments"].ToString();
                        tcLeaveConversationComments.Controls.Add(lblLeaveConversationComments);
                        trLeaveConversation.Cells.Add(tcLeaveConversationComments);
                        leaveConversation.Rows.Add(trLeaveConversation);
                        rowIndex += 1;
                    }

                }
            }

            divLeaveConversation.Controls.Add(leaveConversation);
        }
    }

}
