using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
//using System.Web.Mail;
using System.Net.Mail;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
using System.Net;
using System.Text;
/****************************************************************************************************************************
* Project Name    : TimeCheck                              Started Date  : 12-Aug-2007
* Module          : Permission Sanction                    Last Modified : 14-Aug-2007
* Programmer      : Prabakaran.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Transactions_TA_UI_Transactions_PermissionSanctionModify_Angler : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    //Cls_Connect cl = new Cls_Connect();
    DataTable dtSanctionView = new DataTable();
    LeaveApplicationEventData_Angler objLeaveApplicationEventData = new LeaveApplicationEventData_Angler();
    PermissionEventData_Angler objPermissionEventData = new PermissionEventData_Angler();
    LeaveSettingsEventData_Angler objLeaveSettingsEventData = new LeaveSettingsEventData_Angler();
    cls_Common objClassCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet ds_EmailIdOfSanctionAuthority = new DataSet();
    CCGroupEventData_Angler objCCGroup = new CCGroupEventData_Angler();
    DataSet dsEmailIdOfReportingTo = new DataSet();
    DataSet dsRecordsCount = new DataSet();
    int Permission_Id, Employee_Id, gintCompanyId;
    string Status, Remarks, EmployeeEamilId, strEmailIdReportingTo, strEmailIdSanctionAuthority, EmployeeName, Employee_Code_Id, gstrDateFormat, strlevelName, gstrTimeFormat, reportingToEmployee, sanctioningEmployee;
    //string strToTime,strFromTime;
    string strHtml = string.Empty;
    bool checkEmail = true;
    protected override void Page_Load(object sender, EventArgs e)
    {
        //Request.QueryString["Permission_Id"].ToString();
        //Request.QueryString["LevelId"].ToString();
        //Request.QueryString["ApprovalType"].ToString();
        // session checking
        base.Page_Load(sender, e);
        //if Standar Edition set the visibility to false
        if (Session["Edition"].ToString() == "1")
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
       // if (Request.UrlReferrer != null)
        //{
        //    string GetURL = Request.UrlReferrer.ToString();
        //}
        //else
        //{
        //    Response.Redirect("TransactionLandingPage.aspx");
        //}
        //get the culture info to set the language       
        string source_Language;
        source_Language = Session["Session_ActiveLanguage"].ToString();
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        if (!IsPostBack)
        {
            Userrights();
            if (Convert.ToString(Session["TopMenuPrevious"]) == "")
            {
                GenerateMenu();
                loadMenu();
                LoadYear();
                objClassCommon.menu("PermissionTransaction", "261");
            }
            SanctionViewDetails();
        }
        // dynamic controls for leave conversation
        ControlCreation();
    }
    /// <summary>
    /// Display permission Application Details
    /// </summary>
    private void SanctionViewDetails()
    {
        // Check for SuperAdmin Login and Load all the Status in the Radio Button if group name is SuperAdmin
        bool checkPermissionCancel = false;
        DataSet dsEmployeeGroup = new DataSet();
        DataSet ds_PermissionSettings = new DataSet();
        DataTable dt_PermissionSettings = new DataTable();
        DataTable dt_ApprovalAuthority = new DataTable();
        int intLoginEmpId = 0, intAuditEmpId = 0;
        dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
        {
            if (dsEmployeeGroup.Tables[0].Rows[0]["GroupName"].ToString() == "SuperAdmin" || Session["HasSpecialRights"].ToString() == "True")
            {
                //rblStatus.Items.Clear();
                //rblStatus.Items.Insert(0, "Approved");
                //rblStatus.Items.Insert(1, "Forwarded");
                //rblStatus.Items.Insert(2, "Pending");
                //rblStatus.Items.Insert(3, "Rejected");
                //rblStatus.Items.Insert(4, "Resend");
                //rblStatus.Items.Insert(5, "Reply");
                //rblStatus.Enabled = true;
                //txtRemarks.ReadOnly = false;
                rbApproved.Enabled = true;
                rbForwarded.Enabled = true;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
                rbReply.Enabled = true;
                rbResend.Enabled = true;
                txtRemarks.ReadOnly = false;
            }
            else
            {
            }
        }
        else
        {
        }
        Permission_Id = Convert.ToInt32(Request.QueryString["Permission_Id"]);
        dtSanctionView = objPermissionEventData.GetPermissionByPermissionId(Permission_Id);
        if (dtSanctionView.Rows.Count == 0)
        {
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('No records found');";
            strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanction_Angler.aspx')";
            strScript = strScript + "</script>";
            //Dispaly alert messsage.
            Page.RegisterStartupScript("AlertPA5dd3674", strScript);
            return;
        }
        ViewState["dtSanctionView"] = dtSanctionView;
        if (dtSanctionView.Rows[0]["IsDeleted"].ToString() == "True")
        {
            checkPermissionCancel = true;
        }
        // Get the Employee Id
        int intEmployeeId = 0;
        if (dtSanctionView.Rows[0]["Employee_Id"] != DBNull.Value)
        {
            intEmployeeId = int.Parse(dtSanctionView.Rows[0]["Employee_Id"].ToString());
        }
        // Get the Employee Id who have last updated the Permission Application
        if (dtSanctionView.Rows[0]["Emp_Id"] != DBNull.Value)
        {
            intAuditEmpId = int.Parse(dtSanctionView.Rows[0]["Emp_Id"].ToString());
        }
        // Generate status radio button based on the first or second level authority
        int intApproval = 0, intAuthorityLevel = 0, intFirstLevelAuthorityId = 0, intSecondLevelAuthorityId = 0;
        // Get the Parent Company Id for the Employee by passing the Level Id
        org_levelsEventData getOrg = new org_levelsEventData();
        DataSet ds_getOrg = new DataSet();
        DataSet dsDepartmentMailIds = new DataSet();
        dsDepartmentMailIds = objLeaveSettingsEventData.GetDepartmentMailIds(Convert.ToInt32(dtSanctionView.Rows[0]["LevelId"]));
        ViewState["vsStrApprovalToDept"] = dsDepartmentMailIds.Tables[0].Rows[0]["ToMailIds"].ToString();
        ViewState["vsStrApprovalCCDept"] = dsDepartmentMailIds.Tables[0].Rows[0]["CCMailIds"].ToString();
        getOrg.GetOrgParentLevels_FromID(Convert.ToInt32(dtSanctionView.Rows[0]["LevelId"]));
        ds_getOrg = getOrg.GetOrgParentLevels();
        gintCompanyId = Convert.ToInt32(ds_getOrg.Tables[0].Rows[0]["LevelID"].ToString());
        ViewState["CompanyId"] = gintCompanyId;
        ds_PermissionSettings = objLeaveSettingsEventData.GetLeaveSettingsByComId(gintCompanyId);
        if (ds_PermissionSettings.Tables.Count > 0)
        {
            dt_PermissionSettings = ds_PermissionSettings.Tables[0];
        }
        if (dt_PermissionSettings.Rows.Count > 0)
        {
            if (dt_PermissionSettings.Rows[0]["Approval"] != DBNull.Value && dt_PermissionSettings.Rows[0]["Approval"].ToString() != string.Empty)
            {
                if (dt_PermissionSettings.Rows[0]["Approval"].ToString() == "False")
                {
                    // Both First and Second Level Authority Approval
                    intApproval = 0;
                }
                else if (dt_PermissionSettings.Rows[0]["Approval"].ToString() == "True")
                {
                    // First or Second Level Authority Approval - Either or one
                    intApproval = 1;
                }
                else
                {
                    // Nothing
                }
            }
            if (dt_PermissionSettings.Rows[0]["ApprovalCC"] != DBNull.Value && dt_PermissionSettings.Rows[0]["ApprovalCC"].ToString() != string.Empty)
            {
                ViewState["vsStrApprovalCC"] = dt_PermissionSettings.Rows[0]["ApprovalCC"].ToString(); ;
            }
            else
            {
                ViewState["vsStrApprovalCC"] = string.Empty;
            }
        }
        // Get the Employee Auto Id who have Logged In from Session
        intLoginEmpId = Convert.ToInt32(Session["EmpAutoId"]);
        if (intEmployeeId == intLoginEmpId)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        // Get First and Second Level Authority Ids
        dt_ApprovalAuthority = objLeaveApplicationEventData.GetApprovalAuthorityIds(intEmployeeId);
        if (dt_ApprovalAuthority.Rows.Count > 0)
        {
            if (dt_ApprovalAuthority.Rows[0]["Reporting_To"] != DBNull.Value && dt_ApprovalAuthority.Rows[0]["Reporting_To"].ToString() != string.Empty)
            {
                intFirstLevelAuthorityId = int.Parse(dt_ApprovalAuthority.Rows[0]["Reporting_To"].ToString());
                reportingToEmployee = dt_ApprovalAuthority.Rows[0]["ReportingToEmployee"].ToString();
                ViewState["reportingToEmployee"] = reportingToEmployee;
            }
            if (dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"] != DBNull.Value && dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"].ToString() != string.Empty)
            {
                intSecondLevelAuthorityId = int.Parse(dt_ApprovalAuthority.Rows[0]["Leave_Sanc_Authority"].ToString());
                sanctioningEmployee = dt_ApprovalAuthority.Rows[0]["SanctioningEmployee"].ToString();
                ViewState["sanctioningEmployee"] = sanctioningEmployee;
            }
        }
        // Check whether the Login Employee Id is whether First or Second Level Sanctioning Authority
        if (intFirstLevelAuthorityId != intSecondLevelAuthorityId)
        {
            if (intLoginEmpId == intFirstLevelAuthorityId)
            {
                intAuthorityLevel = 1;
            }
            else if (intLoginEmpId == intSecondLevelAuthorityId)
            {
                intAuthorityLevel = 2;
            }
            else
            {
                // Nothing
            }
        }
        else if (intFirstLevelAuthorityId == intSecondLevelAuthorityId)
        {
            if (intLoginEmpId == intSecondLevelAuthorityId)
            {
                intAuthorityLevel = 2;
            }
            else
            {
                intAuthorityLevel = 3;
            }
        }
        else
        {
            intAuthorityLevel = 3;
        }
        ViewState["vsCommentsBy"] = intAuthorityLevel;
        // If the Login employee is First Level Authority for the selected Applicant
        if (intAuthorityLevel == 1)
        {
            rblStatus.Items.Clear();
            if (intApproval == 1)
            {
                //rblStatus.Items.Insert(0, "Approved");
                //rblStatus.Items.Insert(1, "Forwarded");
                //rblStatus.Items.Insert(2, "Pending");
                //rblStatus.Items.Insert(3, "Rejected");
                //rblStatus.Items.Insert(4, "Resend");
                //rblStatus.Items.Insert(5, "Reply");
                rbApproved.Enabled = true;
                rbForwarded.Enabled = true;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
                rbReply.Enabled = true;
                rbResend.Enabled = true;
            }
            else
            {
                //rblStatus.Items.Insert(0, "Forwarded");
                //rblStatus.Items.Insert(1, "Pending");
                //rblStatus.Items.Insert(2, "Rejected");
                //rblStatus.Items.Insert(3, "Resend");
                //rblStatus.Items.Insert(4, "Reply");
                rbApproved.Enabled = false;
                rbForwarded.Enabled = true;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
                rbReply.Enabled = true;
                rbResend.Enabled = true;
            }
        }
        // If the Login employee is Second Level Authority for the selected Applicant
        else if (intAuthorityLevel == 2)
        {
          //  rblStatus.Items.Clear();
            if (intApproval == 1)
            {
                //rblStatus.Items.Insert(0, "Approved");
                //rblStatus.Items.Insert(1, "Pending");
                //rblStatus.Items.Insert(2, "Rejected");
                //rblStatus.Items.Insert(3, "Resend");
                //rblStatus.Items.Insert(4, "Reply");
                rbApproved.Enabled = true;
                rbForwarded.Enabled = false;
                rbPending.Enabled = true;
                rbRejected.Enabled = true;
                rbReply.Enabled = true;
                rbResend.Enabled = true;
            }
            else
            {
                //rblStatus.Items.Insert(0, "Approved");
                //rblStatus.Items.Insert(1, "Rejected");
                //rblStatus.Items.Insert(2, "Resend");
                //rblStatus.Items.Insert(3, "Reply");
                rbApproved.Enabled = true;
                rbForwarded.Enabled = false;
                rbPending.Enabled = false;
                rbRejected.Enabled = true;
                rbReply.Enabled = true;
                rbResend.Enabled = true;
            }
        }
        //rblStatus.Items.Clear();
        //rblStatus.Items.Insert(0, "Approved");
        //rblStatus.Items.Insert(1, "Forwarded");
        //rblStatus.Items.Insert(2, "Pending");
        //rblStatus.Items.Insert(3, "Rejected");
        //rblStatus.Items.Insert(4, "Resend");
        //rblStatus.Items.Insert(5, "Reply");
        rbApproved.Enabled = true;
        rbForwarded.Enabled = true;
        rbPending.Enabled = true;
        rbRejected.Enabled = true;
        rbReply.Enabled = true;
        rbResend.Enabled = true;
        string LastName = "";
        if (dtSanctionView.Rows[0]["Employee_LastName"] != DBNull.Value)
        {
            LastName = dtSanctionView.Rows[0]["Employee_LastName"].ToString();
        }
        lbl_EmployeeName.Text = dtSanctionView.Rows[0]["Employee_FirstName"].ToString() + " " + LastName;
        lblLevel.Text = dtSanctionView.Rows[0]["name"].ToString();
        lblEmpID.Text = dtSanctionView.Rows[0]["Employee_code_id"].ToString();
        EmployeeEamilId = dtSanctionView.Rows[0]["EmailId"].ToString();
        ViewState["vsEmployeeEamilId"] = EmployeeEamilId;
        lblPermissionApplicationDateData.Text = (Convert.ToDateTime(dtSanctionView.Rows[0]["Permission_AppliedDate"])).ToString(Session["MDateFormat"].ToString() + " " + Session["MTimeFormat"].ToString());
        lblPermissionDate.Text = (Convert.ToDateTime(dtSanctionView.Rows[0]["Permission_Date"])).ToString(Session["MDateFormat"].ToString());
        lblAppliedHours.Text = dtSanctionView.Rows[0]["Permission_Hours"].ToString();
        //lblPermissionFromTime.Text = (DateTime.Parse(dtSanctionView.Rows[0]["Permission_FromTime"].ToString())).ToString(Session["MDateFormat"].ToString());
        //lblPermissionToTime.Text = (DateTime.Parse(dtSanctionView.Rows[0]["Permission_ToTime"].ToString())).ToString(Session["MDateFormat"].ToString());
        string[] PerTime = dtSanctionView.Rows[0]["Permission_FromTime"].ToString().Split(" ".ToCharArray());
        string timePart1 = PerTime[1].ToString() + " " + PerTime[2].ToString();
        //txt_StartTime.Text = (Convert.ToDateTime(PerTime[0])).ToString(Session["MDateFormat"].ToString()) + " " + DateTime.Parse(PerTime[1]).ToString("hh:mm") + " " + PerTime[2];
        lblPermissionFromTime.Text = (Convert.ToDateTime(PerTime[0])).ToString(Session["MDateFormat"].ToString()) + " " + DateTime.Parse(timePart1).ToString(Session["MTimeFormat"].ToString());
        string[] PerTime1 = dtSanctionView.Rows[0]["Permission_ToTime"].ToString().Split(" ".ToCharArray());
        string timePart2 = PerTime1[1].ToString() + " " + PerTime1[2].ToString();
        //txt_EndTime.Text = (Convert.ToDateTime(PerTime1[0])).ToString(Session["MDateFormat"].ToString()) + " " + DateTime.Parse(PerTime1[1]).ToString("hh:mm") + " " + PerTime1[2];
        lblPermissionToTime.Text = (Convert.ToDateTime(PerTime1[0])).ToString(Session["MDateFormat"].ToString()) + " " + DateTime.Parse(timePart2).ToString(Session["MTimeFormat"].ToString());
        ViewState["vPermissionFromTime"] = lblPermissionFromTime.Text;
        ViewState["vPermissionToTime"] = lblPermissionToTime.Text;
        //lblPermissionFromTime.Text = (DateTime.Parse(dtSanctionView.Rows[0]["Permission_FromTime"].ToString())).ToString(Session["MTimeFormat"].ToString());
        //lblPermissionToTime.Text = (DateTime.Parse(dtSanctionView.Rows[0]["Permission_ToTime"].ToString())).ToString(Session["MTimeFormat"].ToString());
        lblReason.Text = dtSanctionView.Rows[0]["Permission_Reason"].ToString();
        //txtRemarks.Text = dtSanctionView.Rows[0]["Remarks"].ToString();
        ViewState["StatusOnLoad"] = dtSanctionView.Rows[0]["Permission_Status"].ToString();
        if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Pending")
        {
            //rblStatus.SelectedValue = "Pending";
            rbPending.Checked = true;
        }
        else if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Forwarded")
        {
            //rblStatus.SelectedValue = "Forwarded";
            //rblStatus.Enabled = true;
            rbForwarded.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Rejected")
        {
            //rblStatus.SelectedValue = "Rejected";
            //rblStatus.Enabled = true;
            rbRejected.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Approved")
        {
            //rblStatus.SelectedValue = "Approved";
            //rblStatus.Enabled = true;
            rbApproved.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Resend")
        {
            //rblStatus.SelectedValue = "Resend";
            //rblStatus.Enabled = true;
            rbResend.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        else if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Reply")
        {
            //rblStatus.SelectedValue = "Reply";
            //rblStatus.Enabled = true;
            rbReply.Checked = true;
            txtRemarks.ReadOnly = false;
        }
        if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
        {
            if (dsEmployeeGroup.Tables[0].Rows[0]["GroupName"].ToString() == "SuperAdmin")
            {
                rblStatus.Enabled = true;
                txtRemarks.ReadOnly = false;
            }
            else
            {
            }
        }
        else
        {
        }
        bool blnApproved = false;
        if (rbApproved.Checked == true)
        {
            rbApproved.Enabled = false;
            blnApproved = true;
        }
        if (rbForwarded.Checked == true)
        {
            rbForwarded.Enabled = false;
        }
        if (rbPending.Checked == true)
        {
            rbPending.Enabled = false;
        }
        if (rbRejected.Checked == true)
        {
            rbRejected.Enabled = false;
        }
        if (rbReply.Checked == true)
        {
            rbReply.Enabled = false;
        }
        if (rbResend.Checked == true)
        {
            rbResend.Enabled = false;
            divStatus.Visible = false;
        }
        rbPending.Enabled = false;
        rbReply.Enabled = false;
        if (intAuthorityLevel == 2)
        {
            //if (rbForwarded.Checked == true)
            //{
            rbForwarded.Enabled = false;
            //}
        }
        if (blnApproved == true)
        {
            //if (rbRejected.Checked != true)
            //{
            rbRejected.Enabled = true;
            rbApproved.Enabled = false;
            rbForwarded.Enabled = false;
            rbPending.Enabled = false;
            rbRejected.Enabled = true;
            rbReply.Enabled = false;
            rbResend.Enabled = false;
            //}
        }
        if (intAuthorityLevel == 1)
        {
            rbApproved.Enabled = false;
            rbRejected.Enabled = false;
            //if (blnForwarded == true)
            //{
            //    rbForwarded.Enabled = false;
            //}
        }
        //for (int i = 0; i < rblStatus.Items.Count; i++)
        //{
        //    if (rblStatus.Items[i].Selected == true)
        //    {
        //        rblStatus.Items[i].Enabled = false;
        //    }
        //    if (rblStatus.Items[i].Value == "Pending")
        //    {
        //        rblStatus.Items[i].Enabled = false;
        //    }
        //    if (rblStatus.Items[i].Selected == true)
        //    {
        //        if (rblStatus.Items[i].Value == "Resend")
        //        {
        //            rblStatus.Enabled = false;
        //            //divStatus.Visible = false;
        //        }
        //        else if (rblStatus.Items[i].Value == "Approved")
        //        {
        //            blnApproved = true;
        //        }
        //    }
        //    if (rblStatus.Items[i].Value == "Reply")
        //    {
        //        rblStatus.Items[i].Enabled = false;
        //    }
        //    if (intAuthorityLevel == 2)
        //    {
        //        if (rblStatus.Items[i].Value == "Forwarded")
        //        {
        //            rblStatus.Items[i].Enabled = false;
        //        }
        //    }
        //    if (blnApproved == true)
        //    {
        //        if (rblStatus.Items[i].Value != "Rejected")
        //        {
        //            rblStatus.Items[i].Enabled = false;
        //        }
        //    }
        //    if (intAuthorityLevel == 1)
        //    {
        //        if (rblStatus.Items[i].Value == "Approved" || rblStatus.Items[i].Value == "Rejected")
        //        {
        //            rblStatus.Items[i].Enabled = false;
        //        }
        //    }
        //}
        if (intAuthorityLevel == 2)
        {
            if (dtSanctionView.Rows[0]["Permission_Status"].ToString() == "Pending")
            {
                hdnStatusofApplication.Value = "Pending";
                hdnAutorityLevel.Value = "2";
            }
        }
        if (Session["UserGroupName"].ToString() != "SuperAdmin" && Session["HasSpecialRights"].ToString() == "False")
        {
            if (intAuthorityLevel == 0)
            {
                string strScript = string.Empty;
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('You do not have rights to access this Permission Request!');";
                strScript = strScript + "location.replace('TransactionLandingPage.aspx')";
                strScript = strScript + "</script>";
                //Dispaly alert messsage.
                Page.RegisterStartupScript("AlertPerA5dd3674access", strScript);
                return;
            }
        }
        if (checkPermissionCancel == true)
        {
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('Permission already cancelled');";
            strScript = strScript + "location.replace('TransactionLandingPage.aspx')";
            strScript = strScript + "</script>";
            //Dispaly alert messsage.
            Page.RegisterStartupScript("AlertPerA5dd3674", strScript);
            return;
        }
    }
    /// <summary>
    /// Calculate Number of hours applied
    /// </summary>
    /// <param name="startTime"></param>
    /// <param name="EndTime"></param>
    /// <returns></returns>
    public string CalculateNumberOfHoursApplied(string startTime, string EndTime)
    {
        //TimeSpan tsStartTime = DateTime.Parse(txt_StartTime.Text).TimeOfDay;
        //TimeSpan tsEndTime = DateTime.Parse(txt_EndTime.Text).TimeOfDay;
        TimeSpan tsDiff = new TimeSpan();
        DateTime dtmIn = DateTime.Parse(startTime);
        DateTime dtmOut = DateTime.Parse(EndTime);
        tsDiff = dtmOut.Subtract(dtmIn);
        string s = tsDiff.ToString();
        int sReturn = s.LastIndexOf(':');
        string RemainHours = s.Remove(sReturn);
        //tsDiff = tsEndTime.Subtract(tsStartTime);
        //int iDays = DateDifference(DateTime.Parse(txtToDate.Text), DateTime.Parse(txtFromDate.Text));
        //  double dDays = Double.Parse(iDays.ToString());
        return (RemainHours);
    }
    /// <summary>
    /// Save Permission sanction Details
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        //ViewState["Status"] = rblStatus.SelectedValue;
        if (txtRemarks.Text == string.Empty)
        {
            base.Message("Remarks is required");
            return;
        }
        else
        {
            string strLengthCheck = txtRemarks.Text.Trim().Replace("'", "''");
            if (strLengthCheck.Length > 1000)
            {
                Message("Maximum character for Reason is 1000");
                return;
            }
            Permission_Id = Convert.ToInt32(Request.QueryString["Permission_Id"]);
            dtSanctionView = objPermissionEventData.GetPermissionByPermissionId(Permission_Id);
            if (dtSanctionView.Rows.Count > 0)
            {
                if (dtSanctionView.Rows[0]["EmailId"] != DBNull.Value)
                {
                    EmployeeEamilId = dtSanctionView.Rows[0]["EmailId"].ToString();
                }
                if (dtSanctionView.Rows[0]["Employee_Id"] != DBNull.Value)
                {
                    Employee_Id = Convert.ToInt32(dtSanctionView.Rows[0]["Employee_Id"]);
                }
                if (dtSanctionView.Rows[0]["Employee_Code_Id"] != DBNull.Value)
                {
                    Employee_Code_Id = dtSanctionView.Rows[0]["Employee_Code_Id"].ToString();
                }
                if (dtSanctionView.Rows[0]["Employee_FirstName"] != DBNull.Value)
                {
                    EmployeeName = dtSanctionView.Rows[0]["Employee_FirstName"].ToString();
                }
                if (dtSanctionView.Rows[0]["name"] != DBNull.Value)
                {
                    strlevelName = dtSanctionView.Rows[0]["name"].ToString();
                }
                DataSet ds_PermissionSettings = new DataSet();
                DataTable dt_PermissionSettings = new DataTable();
                string strApprovalCC = string.Empty;
                gintCompanyId = int.Parse(ViewState["CompanyId"].ToString());
                ds_PermissionSettings = objLeaveSettingsEventData.GetLeaveSettingsByComId(gintCompanyId);
                if (ds_PermissionSettings.Tables.Count > 0)
                {
                    dt_PermissionSettings = ds_PermissionSettings.Tables[0];
                }
                if (dt_PermissionSettings.Rows.Count > 0)
                {
                    if (dt_PermissionSettings.Rows[0]["ApprovalCC"] != DBNull.Value && dt_PermissionSettings.Rows[0]["ApprovalCC"].ToString() != string.Empty)
                    {
                        strApprovalCC = dt_PermissionSettings.Rows[0]["ApprovalCC"].ToString();
                    }
                }
                //Convert Date Format to MM/dd/yyyy Format
                //Convert Date Format to MM/dd/yyyy Format
                //strFromTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), lblPermissionFromTime.Text, "B");
                //strToTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), lblPermissionToTime.Text, "B");
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                gstrTimeFormat = Session["MTimeFormat"].ToString();
                string strFromDateTime = string.Empty;
                string strToDateTime = string.Empty;
                strFromDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), lblPermissionFromTime.Text, "B");
                strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), lblPermissionToTime.Text, "B");
                string dNumberOfHoursApplied = string.Empty;
                dNumberOfHoursApplied = CalculateNumberOfHoursApplied(strFromDateTime, strToDateTime);
                //TimeSpan tsHours = DateTime.Parse(lblPermissionToTime.Text).Subtract(DateTime.Parse(lblPermissionFromTime.Text));
                //if (rblStatus.SelectedValue != "")
                //{
                //    Status = rblStatus.SelectedValue;
                //}
                //else
                //{
                //    Status = "";
                //}
                if (rbApproved.Checked == true)
                    Status = "Approved";
                else if (rbForwarded.Checked == true)
                    Status = "Forwarded";
                else if (rbPending.Checked == true)
                    Status = "Pending";
                else if (rbRejected.Checked == true)
                    Status = "Rejected";
                else if (rbReply.Checked == true)
                    Status = "Reply";
                else if (rbResend.Checked == true)
                    Status = "Resend";
                else
                    Status = string.Empty;
                if (Status == "")
                {
                    //lbl_Error.Text = "Choose an option";
                    base.Message("Choose an option");
                    return;
                }
                Remarks = txtRemarks.Text.Trim().Replace("'", "''");
                try
                {
                    if (ViewState["StatusOnLoad"].ToString() != Status)
                    {
                        // update the status,remareks(only) of permission application
                        //insert into TA_Tbl_PermissionConversation
                        objPermissionEventData.UpdatePermissionApplicationConversation(Permission_Id, Status, Convert.ToInt32(ViewState["vsCommentsBy"].ToString()), Remarks, Convert.ToInt32(Session["EmpAutoId"]));
                        objPermissionEventData.UpdatePermissionSanction(Permission_Id, Status, Remarks, Convert.ToInt32(Session["EmpAutoId"]));
                        cls_Common objclscommon = new cls_Common();
                        string strPermissionDate = objclscommon.DateConvertion(gstrDateFormat, lblPermissionDate.Text);
                        // Update Processed Data Flag
                        objLeaveApplicationEventData.UpdateProcessedDataFlag(Employee_Id, strPermissionDate, strPermissionDate, 0);
                        // To find Reporting To & Leave Sanction Authority Email_ID
                        // Gets the Reporting To Authority Id and Email Id
                        int intFirstLevelAuthorityId = 0, intSecondLevelAuthorityId = 0;
                        //To find Leave Sanction Authorities Email_ID
                        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() != "")
                                {
                                    intSecondLevelAuthorityId = int.Parse(ds_EmailIdOfSanctionAuthority.Tables[0].Rows[0]["Employee_Id"].ToString());
                                    strEmailIdSanctionAuthority = ds_EmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"].ToString();
                                }
                                else
                                {
                                    checkEmail = false;
                                }
                            }
                            else
                            {
                                checkEmail = false;
                            }
                        }
                        else
                        {
                            checkEmail = false;
                        }
                        //mail to Reporting to person
                        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)
                                {
                                    intFirstLevelAuthorityId = int.Parse(dsEmailIdOfReportingTo.Tables[0].Rows[0]["Employee_Id"].ToString());
                                    strEmailIdReportingTo = dsEmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"].ToString();
                                }
                            }
                        }
                        if (strEmailIdSanctionAuthority == string.Empty && strEmailIdReportingTo == string.Empty)
                        {
                            checkEmail = false;
                        }
                        if (strEmailIdSanctionAuthority == null && strEmailIdReportingTo == null)
                        {
                            checkEmail = false;
                        }
                        if (checkEmail == true)
                        {
                            ControlCreation();
                            SendMail(intFirstLevelAuthorityId, intSecondLevelAuthorityId, strEmailIdReportingTo, strEmailIdSanctionAuthority, EmployeeEamilId, Status, Employee_Code_Id, EmployeeName, txtRemarks.Text.Trim().Replace("'", "''"), lblAppliedHours.Text, strlevelName, strApprovalCC);
                        }
                        if (checkEmail == true)
                        {
                            string strScript = string.Empty;
                            strScript = strScript + "<script language='javascript'>";
                            strScript = strScript + "alert('Permission Application saved');";
                            strScript = strScript + "RedirectionFunction();";
                            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanctionView.aspx?Permission_Id=" + Request.QueryString["Permission_Id"].ToString() + "&LevelId=" + Request.QueryString["LevelId"].ToString() + "&Status=" + Request.QueryString["Status"].ToString() + "&From_Date=" + Request.QueryString["From_Date"].ToString() + "&To_Date=" + Request.QueryString["To_Date"].ToString() + "&strSwipeCardNo=" + Request.QueryString["strSwipeCardNo"].ToString() + "&strEmployeeName=" + Request.QueryString["strEmployeeName"].ToString() + "&strEmployeeCodeId=" + Request.QueryString["strEmployeeCodeId"].ToString() + "')";
                            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanction.aspx');";
                            strScript = strScript + "</script>";
                            //Dispaly alert messsage.
                            Page.RegisterStartupScript("AlertPsaved36774", strScript);
                        }
                        else
                        {
                            string strScript = string.Empty;
                            strScript = strScript + "<script language='javascript'>";
                            strScript = strScript + "alert('Permission Application saved,Email not sent');";
                            strScript = strScript + "RedirectionFunction();";
                            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanctionView.aspx?Permission_Id=" + Request.QueryString["Permission_Id"].ToString() + "&LevelId=" + Request.QueryString["LevelId"].ToString() + "&Status=" + Request.QueryString["Status"].ToString() + "&From_Date=" + Request.QueryString["From_Date"].ToString() + "&To_Date=" + Request.QueryString["To_Date"].ToString() + "&strSwipeCardNo=" + Request.QueryString["strSwipeCardNo"].ToString() + "&strEmployeeName=" + Request.QueryString["strEmployeeName"].ToString() + "&strEmployeeCodeId=" + Request.QueryString["strEmployeeCodeId"].ToString() + "')";
                            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanction.aspx');";
                            strScript = strScript + "</script>";
                            //Dispaly alert messsage.
                            Page.RegisterStartupScript("AlertPAdd3674", strScript);
                        }
                    }
                    else
                    {
                        //lbl_Error.Text = "Please change the status";
                        Message("Please change the status");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }
    /// <summary>
    /// Sending email to the Employee who applied for this permission
    /// </summary>
    /// <param name="EmployeeEamilId"></param>
    /// <param name="Status"></param>
    private void SendMailToApplicant(string EmployeeEamilId, string Status, string Remarks, string EmployeeCodeId, string TotalHours, string levelName)
    {
        try
        {
            MailMessage mailMessage = new MailMessage();
            SmtpClient loSMTPServer = new SmtpClient();
            System.Net.Mime.ContentType loTextType = new System.Net.Mime.ContentType("text/plain");
            System.Net.Mime.ContentType loHTMLType = new System.Net.Mime.ContentType("text/html");
            AlternateView loTextView = null;
            AlternateView loHTMLView = null;
            string scriptText;
            DataTable dtTableScript = new DataTable();
            string ScriptType = "Permission Application Sanction By Reporting to Person";
            //      cl.fillDT("Select * from TA_TBL_EmailScripts where ScriptType='Permission Application Sanction By Reporting to Person'", dtTableScript);
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
            //mail.From = System.Configuration.ConfigurationManager.AppSettings["FromId"];
            //mail.To = EmployeeEamilId;
            //mail.Subject = "Permission Application | " + lblPermissionDate.Text + " | " +  EmployeeCodeId + " | " + lbl_EmployeeName.Text  + " - " + levelName + " | " + Status;
            //mail.BodyFormat = MailFormat.Html;
            //mail.Priority = MailPriority.Normal;
            mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
            mailMessage.To.Add(new MailAddress(EmployeeEamilId));
            //mailMessage.Subject = levelName + " | " + lbl_EmployeeName.Text + " - " + EmployeeCodeId + " | " + lblPermissionDate.Text + " | " + "Permission " + Status;
            mailMessage.Subject = "TimeCheck : " + rm.GetString("email_YourPermissionApplicationFor", ci) + " - " + lblPermissionDate.Text + " | " + Status;
            mailMessage.Body = scriptText.Replace("<<lblPermissionSanction>>", rm.GetString("email_PermissionForm", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeId>>", rm.GetString("email_EmployeeId", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeId>>", EmployeeCodeId);
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeName>>", rm.GetString("email_EmployeeName", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeName>>", lbl_EmployeeName.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblPermissionDate>>", rm.GetString("Permission_PermissionDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<PermissionDate>>", lblPermissionDate.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblNumberOfHoursApplied>>", rm.GetString("email_NumberOfHoursApplied", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<NumberOfHoursApplied>>", TotalHours);
            mailMessage.Body = mailMessage.Body.Replace("<<lblPermission>>", rm.GetString("Dash_Permission", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<lblFromTime>>", rm.GetString("email_FromDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<FromTime>>", lblPermissionFromTime.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblToTime>>", rm.GetString("email_ToDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<ToTime>>", lblPermissionToTime.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblStatus>>", rm.GetString("email_Status", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<Status>>", Status);
            mailMessage.Body = mailMessage.Body.Replace("<<lblRemarks>>", rm.GetString("email_Remarks", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<Remarks>>", Remarks);
            objClassCommon.SendMail(mailMessage);
        }
        catch
        {
            //string strScript = string.Empty;
            //strScript = strScript + "<script language='javascript'>";
            //strScript = strScript + "alert('Permission Application saved,Email not sent');";
            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanction.aspx');";
            //strScript = strScript + "</script>";
            ////Dispaly alert messsage.
            //Page.RegisterStartupScript("AlertPAdd34", strScript);
            checkEmail = false;
        }
    }
    /// <summary>
    /// Sending Mail to Sanctioning Authority of the Employee
    /// </summary>
    /// <param name="EmailIdSanctionAuthority"></param>
    /// <param name="Status"></param>
    /// <param name="EmployeeId"></param>
    /// <param name="EmployeeName"></param>
    private void SendMail(int FirstLevelAuthorityId, int SecondLevelAuthorityId, string strEmailIdReportingTo, string strEmailIdSanctionAuthority, string ApplicantEmailId, string Status, string EmployeeCodeId, string EmployeeName, string Remarks, string TotalHours, string levelName, string ApprovalCC)
    {
        try
        {
            MailMessage mailMessage = new MailMessage();
            SmtpClient loSMTPServer = new SmtpClient();
            System.Net.Mime.ContentType loTextType = new System.Net.Mime.ContentType("text/plain");
            System.Net.Mime.ContentType loHTMLType = new System.Net.Mime.ContentType("text/html");
            AlternateView loTextView = null;
            AlternateView loHTMLView = null;
            string scriptText;
            DataTable dtTableScript = new DataTable();
            string ScriptType = "Forwarded Permission Application Sanction";
            //cl.fillDT("Select * from TA_TBL_EmailScripts where ScriptType='Forwarded Permission Application Sanction'", dtTableScript);
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
            // Select the Recipient for To and CC based on the Approval Authority and Status
            int intLoginEmpId = 0;
            string strCCTo = string.Empty;
            // Get the Employee Auto Id who have Logged In from Session
            intLoginEmpId = Convert.ToInt32(Session["EmpAutoId"]);
            if (intLoginEmpId == SecondLevelAuthorityId)
            {
                if (Status == "Pending")
                {
                    mailMessage.From = new MailAddress(strEmailIdSanctionAuthority);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority;
                    strCCTo = strEmailIdReportingTo;
                }
                else if (Status == "Rejected")
                {
                    mailMessage.From = new MailAddress(strEmailIdSanctionAuthority);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                    strCCTo = strEmailIdReportingTo;
                }
                else if (Status == "Approved")
                {
                    mailMessage.From = new MailAddress(strEmailIdSanctionAuthority);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                    strCCTo = strEmailIdReportingTo;
                }
                else if (Status == "Resend")
                {
                    mailMessage.From = new MailAddress(strEmailIdSanctionAuthority);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                    strCCTo = strEmailIdReportingTo;
                }
                else
                {
                    // Nothing
                }
            }
            else if (intLoginEmpId == FirstLevelAuthorityId)
            {
                if (Status == "Forwarded")
                {
                    mailMessage.From = new MailAddress(strEmailIdReportingTo);
                    mailMessage.To.Add(new MailAddress(strEmailIdSanctionAuthority));
                    strCCTo = ApplicantEmailId;
                }
                else if (Status == "Resend")
                {
                    mailMessage.From = new MailAddress(strEmailIdReportingTo);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                }
                else if (Status == "Rejected")
                {
                    mailMessage.From = new MailAddress(strEmailIdReportingTo);
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    //strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                }
            }
            else
            {
                if (Status == "Pending" || Status == "Rejected")
                {
                    mailMessage.From = new MailAddress(Session["loginEmailId"].ToString());
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    strCCTo = strEmailIdReportingTo;
                }
                else if (Status == "Forwarded")
                {
                    mailMessage.From = new MailAddress(Session["loginEmailId"].ToString());
                    mailMessage.To.Add(new MailAddress(strEmailIdSanctionAuthority));
                    strCCTo = strEmailIdReportingTo + ";" + ApplicantEmailId;
                }
                else if (Status == "Approved")
                {
                    mailMessage.From = new MailAddress(Session["loginEmailId"].ToString());
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                }
                else if (Status == "Resend")
                {
                    mailMessage.From = new MailAddress(Session["loginEmailId"].ToString());
                    mailMessage.To.Add(new MailAddress(ApplicantEmailId));
                    strCCTo = strEmailIdSanctionAuthority + ";" + strEmailIdReportingTo;
                }
                else
                {
                    // Nothing
                }
            }
            //CC mails using CC group
            if (Status == "Approved")
            {
                DataSet dsCCEmailIds = new DataSet();
                dtSanctionView = (DataTable)ViewState["dtSanctionView"];
                dsCCEmailIds = objCCGroup.GetCCEmailIds(Convert.ToInt16(dtSanctionView.Rows[0]["LevelId"].ToString()), Convert.ToInt16(dtSanctionView.Rows[0]["DesignationId"].ToString()), "O");
                if (dsCCEmailIds != null)
                {
                    if (dsCCEmailIds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow drCcEmailId in dsCCEmailIds.Tables[0].Rows)
                        {
                            MailAddressCollection MailAddrCollectionCC = mailMessage.CC;
                              // added by Gopinath.k for Mantis Bug no.24059 & 24098
                            if (drCcEmailId["EmailId"].ToString() != string.Empty)
                            {
                                MailAddress newCC = new MailAddress(drCcEmailId["EmailId"].ToString());
                                MailAddrCollectionCC.Add(newCC);
                            }
                        }
                    }
                }
            }
            if (strCCTo != string.Empty)
            {
                string[] strArrEmailAddressForCC;
                strArrEmailAddressForCC = SplitCCTo(strCCTo);
                MailAddressCollection MailAddrCollectionCC = mailMessage.CC;
                for (int iLoop = 0; iLoop < strArrEmailAddressForCC.Length; iLoop++)
                {
                    MailAddress newCC = new MailAddress(strArrEmailAddressForCC[iLoop]);
                    MailAddrCollectionCC.Add(newCC);
                }
            }
            //Send mails by selection Emails
           // string strToMails = txtApprovalTO.Text;
            string strCcMails = txtApprovalCC.Text;
            //CC Mails in text box.
            if (strCcMails != string.Empty)
            {
                string[] strArrEmailAddressForCC;
                strArrEmailAddressForCC = SplitCCTo(strCcMails);
                MailAddressCollection MailAddrCollectionCC = mailMessage.CC;
                for (int iLoop = 0; iLoop < strArrEmailAddressForCC.Length; iLoop++)
                {
                    MailAddress newCC = new MailAddress(strArrEmailAddressForCC[iLoop]);
                    MailAddrCollectionCC.Add(newCC);
                }
            }
            //check for duplicate mail Ids
            //included by sashma on 20-Oct-2010
            Hashtable htToMails = new Hashtable();
            Hashtable htCCMails = new Hashtable();
            int intToMailCount = 0;
            int intCCMailCount = 0;
            //inserts the TO mailIds in the hashtable
            foreach (MailAddress ToMail in mailMessage.To)
            {
                if (htToMails.ContainsValue(ToMail) == false)
                {
                    htToMails.Add(intToMailCount++, ToMail);
                }
            }
            //inserts the CC mailIds in the hashtable
            foreach (MailAddress CCMail in mailMessage.CC)
            {
                //check whether the mail alredy exists in CC mails.
                if (htCCMails.ContainsValue(CCMail) == false)
                {
                    //check whether the mail alredy exists in TO mails.
                    if (htToMails.ContainsValue(CCMail) == false)
                    {
                        htCCMails.Add(intCCMailCount++, CCMail);
                    }
                }
            }
            mailMessage.To.Clear();
            mailMessage.CC.Clear();
            //Adds the TO mails from the hastable.
            foreach (DictionaryEntry ToMails in htToMails)
            {
                mailMessage.To.Add(ToMails.Value.ToString());
            }
            //Adds the CC mails from the hastable.
            foreach (DictionaryEntry CCMails in htCCMails)
            {
                mailMessage.CC.Add(CCMails.Value.ToString());
            }
            mailMessage.Subject = "TimeCheck : " + levelName + " | " + lbl_EmployeeName.Text + " - " + EmployeeCodeId + " | Permission  | " + Status;
            //mailMessage.Subject = levelName + " | " + lbl_EmployeeName.Text + " - " + EmployeeCodeId + " | " + lblPermissionDate.Text + " | " + "Permission " + " | " + Status;
            mailMessage.Body = scriptText.Replace("<<lblPermissionSanction>>", rm.GetString("email_PermissionForm", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeId>>", rm.GetString("email_EmployeeId", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeId>>", EmployeeCodeId);
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeName>>", rm.GetString("email_EmployeeName", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeName>>", lbl_EmployeeName.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblDepartment>>", "Department");
            mailMessage.Body = mailMessage.Body.Replace("<<Department>>", levelName);
            mailMessage.Body = mailMessage.Body.Replace("<<lblPermissionDate>>", rm.GetString("Permission_PermissionDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<PermissionDate>>", lblPermissionDate.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblNumberOfHoursApplied>>", rm.GetString("email_NumberOfHoursApplied", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<NumberOfHoursApplied>>", TotalHours);
            mailMessage.Body = mailMessage.Body.Replace("<<lblPermission>>", rm.GetString("Dash_Permission", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<lblFromTime>>", rm.GetString("email_FromDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<FromTime>>", lblPermissionFromTime.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblToTime>>", rm.GetString("email_ToDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<ToTime>>", lblPermissionToTime.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblStatus>>", rm.GetString("email_Status", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<Status>>", Status);
            mailMessage.Body = mailMessage.Body.Replace("<<lblReason>>", rm.GetString("email_Reason", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<Reason>>", lblReason.Text);
            // mailMessage.Body = mailMessage.Body.Replace("<<divMailThread>>", strHtml.Replace("width='70%'", " ").Replace("width='30%'", " ").Replace("<td><span class='Header'>Comments</span></td>", "<td style='width:60%'><span class='Header'>Comments</span></td>"));
            mailMessage.Body = mailMessage.Body.Replace("<<divMailThread>>", strHtml);
            string strServerIP = string.Empty;
            strServerIP = System.Configuration.ConfigurationManager.AppSettings["ServerIP"].ToString();
            if (Status == "Forwarded")
            {
                string LevelId = "1";
               // mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", strServerIP + "Index.aspx?Permission_Id=" + Convert.ToInt32(Request.QueryString["Permission_Id"]) + "&LevelId=" + LevelId + "&ApprovalType=Permission");
                mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?Permission_Id=" + Convert.ToInt32(Request.QueryString["Permission_Id"]) + "&LevelId=" + LevelId + "&ApprovalType=Permission&Status=All&From_Date=&To_Date=&strSwipeCardNo=&strEmployeeName=&strEmployeeCodeId=&Angler=1");
            }
            else
            {
                //string strReplaceText = "<font face='Arial' size='2'><a href='<<LinkData>>'>Click here for approval</a></font>";
                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);
        }
        catch
        {
            //string strScript = string.Empty;
            //strScript = strScript + "<script language='javascript'>";
            //strScript = strScript + "alert('Permission Application saved,Email not sent');";
            //strScript = strScript + "location.replace('TA_UI_Transactions_PermissionSanction.aspx');";
            //strScript = strScript + "</script>";
            ////Dispaly alert messsage.
            //Page.RegisterStartupScript("AlertPAdd678", strScript);
            checkEmail = false;
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["PermissionSanctionStatus"]) == rm.GetString("btn_Pending", ci) || Convert.ToString(Session["PermissionSanctionStatus"]) == rm.GetString("btn_Forwarded", ci))
        {
            Response.Redirect("../Transactions/TA_UI_Transactions_PermissionBulkSanction_Angler.aspx?Permission_Id=" + Request.QueryString["Permission_Id"].ToString() + "&LevelId=" + Request.QueryString["LevelId"].ToString() + "&Status=" + Request.QueryString["Status"].ToString() + "&From_Date=" + Request.QueryString["From_Date"].ToString() + "&To_Date=" + Request.QueryString["To_Date"].ToString() + "&strSwipeCardNo=" + Request.QueryString["strSwipeCardNo"].ToString() + "&strEmployeeName=" + Request.QueryString["strEmployeeName"].ToString() + "&strEmployeeCodeId=" + Request.QueryString["strEmployeeCodeId"].ToString());
        }
        else
        {
            // Response.Redirect("../Transactions/TA_UI_Transactions_PermissionSanctionView.aspx");
            Response.Redirect("../Transactions/TA_UI_Transactions_PermissionSanctionView_Angler.aspx?Permission_Id=" + Request.QueryString["Permission_Id"].ToString() + "&LevelId=" + Request.QueryString["LevelId"].ToString() + "&Status=" + Request.QueryString["Status"].ToString() + "&From_Date=" + Request.QueryString["From_Date"].ToString() + "&To_Date=" + Request.QueryString["To_Date"].ToString() + "&strSwipeCardNo=" + Request.QueryString["strSwipeCardNo"].ToString() + "&strEmployeeName=" + Request.QueryString["strEmployeeName"].ToString() + "&strEmployeeCodeId=" + Request.QueryString["strEmployeeCodeId"].ToString());
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Transaction_PermissionSanction_PermissionSanction", ci);
        lbl_EmpName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_Permissiondate.Text = rm.GetString("Permission_PermissionDate", ci);
        lbl_PermissionFromTime.Text = rm.GetString("PermissionSanction_PermissionFromTime", ci);
        lbl_PermissionToTime.Text = rm.GetString("PermissionSanction_PermissionToTime", ci);
        lbl_Reason.Text = rm.GetString("email_Reason", ci);
        lbl_Remarks.Text = rm.GetString("email_Remarks", 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);
    }
    private void ControlCreation()
    {
        //New Data table definition
        DataTable dtReplyResend = new DataTable();
        dtReplyResend.TableName = "dtReplyResend";
        DataColumn dcDate = new DataColumn("Date");
        DataColumn dcCommentsBy = new DataColumn("Comments By");
        DataColumn dcComments = new DataColumn("Comments");
        dtReplyResend.Columns.Add(dcDate);
        dtReplyResend.Columns.Add(dcCommentsBy);
        dtReplyResend.Columns.Add(dcComments);
        DataRow dRowReplyResend;
        divLeaveConversation.Controls.Clear();
        DataSet ds_PermissionConversation = new DataSet();
        ds_PermissionConversation = objPermissionEventData.GetPermissionConversation(Convert.ToInt32(Request.QueryString["Permission_Id"]));
        //if (!IsPostBack)
        //{
        //    // getting leave conversation 
        //    ViewState["PermissionConversation"] = ds_PermissionConversation;
        //}
        if (ds_PermissionConversation != null && ds_PermissionConversation.Tables[0].Rows.Count > 0)
        {
            //if (ViewState["PermissionConversation"] != null)
            //{
            //    ds_PermissionConversation =(DataSet) ViewState["PermissionConversation"];
            //}
            Table leaveConversation = new Table();
            leaveConversation.BorderWidth = 1;
            leaveConversation.CellPadding = 5;
            leaveConversation.CellSpacing = 0;
           // leaveConversation.Width = Unit.Pixel(600);
            leaveConversation.CssClass = "table das-table1";
            leaveConversation.Attributes.Add("border", "1");
            TableHeaderRow leaveConversationHr = new TableHeaderRow();
            leaveConversationHr.CssClass = "empheader";
            TableHeaderCell leaveConversationHeading3 = new TableHeaderCell();
            leaveConversationHeading3.Text = rm.GetString("TerminalDataType_Date_And_Time", ci); 
            leaveConversationHeading3.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading3);
            TableHeaderCell leaveConversationHeading1 = new TableHeaderCell();
            //leaveConversationHeading1.Width = 75;
            leaveConversationHeading1.Text = rm.GetString("leaveConversationHeading1", ci);
            leaveConversationHeading1.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading1);
            TableHeaderCell leaveConversationHeading2 = new TableHeaderCell();
            leaveConversationHeading2.Text = rm.GetString("leaveConversationHeading2", ci);
            //leaveConversationHeading2.Width = 200;
            leaveConversationHeading2.HorizontalAlign = HorizontalAlign.Left;
            leaveConversationHr.Cells.Add(leaveConversationHeading2);
            leaveConversation.Rows.Add(leaveConversationHr);
            if (ds_PermissionConversation.Tables[0].Rows.Count > 0)
            {
                int rowIndex = 0;
                foreach (DataRow drLeaveConversation in ds_PermissionConversation.Tables[0].Rows)
                {
                    dRowReplyResend = dtReplyResend.NewRow();
                    TableRow trLeaveConversation = new TableRow();
                    TableCell tcLeaveConversationRepliedOn = new TableCell();
                    Label lblLeaveConversationRepliedOn = new Label();
                    tcLeaveConversationRepliedOn.BorderWidth = 1;
                    tcLeaveConversationRepliedOn.Width = 200;
                    tcLeaveConversationRepliedOn.BorderColor = System.Drawing.Color.White;
                    lblLeaveConversationRepliedOn.ID = "lblLeaveConversationRepliedOn" + rowIndex;
                    lblLeaveConversationRepliedOn.Text = Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MDateFormat"].ToString()) + " " + Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MTimeFormat"].ToString());
                    dRowReplyResend["Date"] = Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MDateFormat"].ToString()) + " " + Convert.ToDateTime(drLeaveConversation["TimeStamp"]).ToString(Session["MTimeFormat"].ToString());
                    tcLeaveConversationRepliedOn.Controls.Add(lblLeaveConversationRepliedOn);
                    trLeaveConversation.Cells.Add(tcLeaveConversationRepliedOn);
                    TableCell tcLeaveConversationCommentsBy = new TableCell();
                    Label lblLeaveConversationCommentsBy = new Label();
                    tcLeaveConversationCommentsBy.Width = 200;
                    lblLeaveConversationCommentsBy.ID = "lblLeaveConversationCommentsBy" + rowIndex;
                    if (drLeaveConversation["CommentsBy"].ToString() == "0")
                    {
                        lblLeaveConversationCommentsBy.Text = lbl_EmployeeName.Text;
                        dRowReplyResend["Comments By"] = lbl_EmployeeName.Text;
                    }
                    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();
                    lblLeaveConversationComments.ID = "lblLeaveConversationComments" + rowIndex;
                    lblLeaveConversationComments.Text = drLeaveConversation["Comments"].ToString();
                    dRowReplyResend["Comments"] = drLeaveConversation["Comments"].ToString();
                    tcLeaveConversationComments.Controls.Add(lblLeaveConversationComments);
                    trLeaveConversation.Cells.Add(tcLeaveConversationComments);
                    leaveConversation.Rows.Add(trLeaveConversation);
                    rowIndex += 1;
                    dtReplyResend.Rows.Add(dRowReplyResend);
                }
            }
            divLeaveConversation.Controls.Add(leaveConversation);
        }
        if (ds_PermissionConversation.Tables[0].Rows.Count > 0)
        {
            strHtml = buildPage("Test", dtReplyResend);
        }
    }
    public string buildPage(string strPageTitle, DataTable myDT)
    {
        StringBuilder sb = new StringBuilder();
        //HTML header
        sb.Append("<html>");
        sb.Append("<head>");
        sb.Append("<title>");
        sb.Append(strPageTitle);
        sb.Append("</title>");
        sb.Append("<style type='text/css'>");
        sb.Append(".Header {color: #FFFFFF; font-family: Arial;font-size: x-small;font-weight: bold;}");
        sb.Append(".rows {font-family: Arial; font-size: x-small;background-color:#FFE3B9}");
        sb.Append(".rowsNew {font-family: Arial; font-size: x-small;background-color:#FFEED5}");
        sb.Append("</style>");
        sb.Append("</head>");
        sb.Append("<body>");
        sb.Append("<table border='1' cellpadding='2' style='border-collapse: collapse' bordercolor='#666666' width='700'>");
        sb.Append("  <tr bgcolor='#003466'>");
        //Table header       
        foreach (DataColumn Col in myDT.Columns)
        {
            sb.Append("<td><span class='Header'>" + Col.ColumnName.ToString() + "</span></td>");
        }
        sb.Append("  </tr>");
        //add rows to the table for the length of the dataset
        int intWidth = 0;
        int intIncrement = 0;
        foreach (DataRow Row in myDT.Rows)
        {
            intWidth = 0;
            if (intIncrement % 2 == 0)
            {
                sb.Append("  <tr>");
            }
            else
            {
                sb.Append("  <tr>");
            }
            foreach (DataColumn Col in myDT.Columns)
            {
                if (intWidth == 2)
                {
                    sb.Append("<td width='60%'><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");
                    //intWidth = 1;
                }
                else
                {
                    sb.Append("<td><font face='Arial' size='2'>" + Row[Col.ColumnName].ToString() + "</font></td>");
                    //intWidth = 0;
                }
                intWidth = intWidth + 1;
            }
            sb.Append("  </tr>");
            intIncrement = intIncrement + 1;
        }
        //Close the html string
        sb.Append("</table>");
        sb.Append("</body>");
        sb.Append("</html>");
        return sb.ToString();
    }
    private string[] SplitCCTo(string CCTo)
    {
        string[] strArrEmailAddressForCC;
        strArrEmailAddressForCC = CCTo.Split(';');
        return (strArrEmailAddressForCC);
    }
    private void Userrights()
    {
        ds_Checkuser = objCheckUser.checkRights(261, 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)
            {
            }
            else
            {
            }
        }
        else
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
    }
    protected void rbRejected_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = true;
        rbReply.Checked = false;
        rbResend.Checked = false;
    }
    protected void rbPending_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = true;
        rbRejected.Checked = false;
        rbReply.Checked = false;
        rbResend.Checked = false;
    }
    protected void rbForwarded_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = true;
        rbPending.Checked = false;
        rbRejected.Checked = false;
        rbReply.Checked = false;
        rbResend.Checked = false;
    }
    protected void rbApproved_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = true;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = false;
        rbReply.Checked = false;
        rbResend.Checked = false;
    }
    protected void rbResend_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = false;
        rbReply.Checked = false;
        rbResend.Checked = true;
    }
    protected void rbReply_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        rbForwarded.Checked = false;
        rbPending.Checked = false;
        rbRejected.Checked = false;
        rbReply.Checked = true;
        rbResend.Checked = 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;
        }
    }
    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;
    }
}
