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.Web.Mail;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
using System.Net;
using System.IO;
using System.Web.Services;

public partial class Transactions_TA_UI_Transactions_PermissionAdd_Eastman : Base.BasePage
{
    #region VariableDeclaration
    internal enum permissionHeader
    {
        FIRST = 1,
        SECOND = 2,
        THIRD = 3,
        FOURTH = 4,
        FIFTH = 5
    }
    Panel pn = new Panel();
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    EmployeeEventData objEmployeeEventData = new EmployeeEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    LeaveEventData objLeaveEventData = new LeaveEventData();
    cls_Common objClassCommon = new cls_Common();
    PermissionEventData objPermissionEventData = new PermissionEventData();
    Rpt_Common rptcommon = new Rpt_Common();
    DataSet ds_LeaveType = new DataSet();
    DataSet ds_HoursAlreadyTaken = new DataSet();
    DataSet ds_MaxNoOfHours = new DataSet();
    DataSet dsEmailIdOfSanctionAuthority = new DataSet();
    DataSet ds_EmailIdOfReportingTo = new DataSet();
    DataSet ds_EmployeeDetails = new DataSet();
    DataSet ds_Year = new DataSet();
    SMSNotification objsms = new SMSNotification();
    int intPermissionId = 0;
    string strFromTime, strEndTime, strReason, MaxPermitHours, strEmailIdReportingTo, EmployeeEamilId, strEmpFirstName, strEmpLastName, Employee_Code_Id, gstrDateFormat, gstrTimeFormat, strApplicationDate, strFromDateTime, strToDateTime, strlevelName;
    DateTime currDate;
    int iEmployeeID, iPermissionType_Id, count, StartYear, EndYear;
    int iInsertFlag = 0;
    CCGroupEventData_Angler objCCGroup = new CCGroupEventData_Angler();
    DataSet ds_NextYear = new DataSet();
    //string strEmailIdSanctionAuthority;
    //string strType;
    //string strPermissionDate;
    //double dNoOfHoursTaken, dTotalHours, dNoOfHoursAlreadyTaken;
    bool checkEmail = true, checkPermissionHrsExist, blnCheckSMS = true;
    string dNumberOfHoursApplied, dNoOfRemainingHours, EmpID;
    string gstrYearSettingStartDate = string.Empty;
    string gstrYearSettingsEndDate = string.Empty;
    string gstrNextYearSettingStartDate = string.Empty;
    string gstrNextYearSettingsEndDate = string.Empty;
    DataSet dsPermission = new DataSet();
    int payrollConfig = 0;
    DataSet prevDs = new DataSet();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("PermissionTransaction", "23");
            //bindDummyGrid();
        }
        payrollConfig = objClassCommon.CheckPageExistsInLicense(185);
        //get the culture info to set the language        
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SibindteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "Emp('" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Errorinretrivingdetails", ci) + "','" + rm.GetString("Select", ci) + "');";
        //Adding values for alert message for time checking for dd/MM/yyyy
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alery_PermissionDay", ci) + "','" + rm.GetString("Alert_StartTime", ci) + "','" + rm.GetString("Alert_EndTime", ci) + "','" + rm.GetString("Alert_FillReasons", ci) + "','" + rm.GetString("Alert_PermissionHoursEmpty", ci) + "','" + rm.GetString("Alert_SelectanEmployee", ci) + "','" + rm.GetString("Alert_Are_you_sure_to_Save", ci) + "','" + rm.GetString("Alert_FromAndEndTime", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessagesAjax_Permission('" + rm.GetString("lblSelectEmployee", ci) + "','" + rm.GetString("Alert_SelectvalidPermissionDate", ci) + "','" + rm.GetString("Alert_SelectvalidPermissionFromDateandTime", ci) + "','" + rm.GetString("Alert_SelectvalidPermissionFromDateandTime", ci) + "','" + rm.GetString("Master_Holiday_Select_Valid_Year", ci) + "','" + rm.GetString("ALert_Permissionshouldnotbeappliedbeforedateofjoining", ci) + "','" + rm.GetString("Alert_PermissionHoursfallsonWeeklyOffGlobalHoliday", ci) + "','" + rm.GetString("Alert_SelectValidPermissionHours", ci) + "','" + rm.GetString("Report_ShiftNotAllocated", ci) + "','" + rm.GetString("Alert_PermissionHoursdoesnotfallinsidetheshift", ci) + "','" + rm.GetString("ALert_PermissionHoursfallwiththeshiftbreaktimes", ci) + "','" + rm.GetString("ALert_PermissionHoursShouldNotInNegativeHours", ci) + "','" + rm.GetString("Alert_PermissionHoursNotdefinedforthisemployee", ci) + "','" + rm.GetString("Alert_MaxNumberofInstancespermonthExceeds", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_ValiddateDateDDMMYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddateDateDDMMYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //Set UserRights
        UserRights();
        Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
        Hidden2.Value = Convert.ToString(Session["ITimeFormat"]);
        ds_Year = objClassCommon.GetYearsetting();
        if (ds_Year.Tables[0].Rows.Count <= 0)
        {
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Msg_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertLeavePolicyYear", strScript);
        }
        else
        {
            StartYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["StartYear"]);
            EndYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["EndYear"]);
            gstrYearSettingStartDate = Convert.ToString(ds_Year.Tables[0].Rows[0]["FromDate"]);
            gstrYearSettingsEndDate = Convert.ToString(ds_Year.Tables[0].Rows[0]["ToDate"]);
            ViewState["YearSettings_Id"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
            ds_Year.Dispose();
        }
        //Fill the next Year Settings Detail
        ds_NextYear = objClassCommon.GetNextYearsetting();
        if (ds_NextYear.Tables[0].Rows.Count > 0)
        {
            gstrNextYearSettingStartDate = ds_NextYear.Tables[0].Rows[0]["FromDate"].ToString();
            gstrNextYearSettingsEndDate = ds_NextYear.Tables[0].Rows[0]["ToDate"].ToString();
            ViewState["NextYearSettings_Id"] = ds_NextYear.Tables[0].Rows[0]["YearSettings_Id"].ToString();
            ds_NextYear.Dispose();
        }
        //btn_add.Attributes.Add("onclick", "return Validation();");
        //ddlEmployeeNames.Items.Add("-Select-");
        ListItem liSelect = new ListItem();
        liSelect.Value = "-Select-";
        liSelect.Text = rm.GetString("Select", ci);
        //ddlEmployeeNames.Items.Insert(0, liSelect);
        checkPermissionHrsExist = true;
        //GetEmployeeName();
        currDate = Convert.ToDateTime(System.DateTime.Today.Date.ToShortDateString());
        lbl_PermissionApplicationDate.Text = currDate.ToString(Convert.ToString(Session["MDateFormat"]));
        //To add permission by Administrator
        DataSet dsEmployeeGroup = new DataSet();
        dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        if (dsEmployeeGroup.Tables[0].Rows.Count > 0)
        {
            Session["UserGroupName"] = Convert.ToString(dsEmployeeGroup.Tables[0].Rows[0]["GroupName"]);
            if (Convert.ToString(dsEmployeeGroup.Tables[0].Rows[0]["GroupName"]) == "SuperAdmin" || Convert.ToString(Session["IndividualUsers"]) != "True")
            {
                divEmployees.Visible = false;
                divAdmin.Visible = true;
                //PlaceHolder1.Visible = true;
            }
            else
            {
                divEmployees.Visible = true;
                //PlaceHolder1.Controls.Clear();
                divAdmin.Visible = false;
                hdnEmployeeId.Value = Convert.ToString(Session["EmpAutoId"]);
                GetEmployeeName();
                //CheckRemainingHours(hdnEmployeeId.Value); 
            }
        }
        else
        {
            divEmployees.Visible = true;
            //PlaceHolder1.Controls.Clear();
            divAdmin.Visible = false;
            hdnEmployeeId.Value = Convert.ToString(Session["EmpAutoId"]);
            GetEmployeeName();

            //CheckRemainingHours(hdnEmployeeId.Value);
        }
        //End of To add permission by Administrator 
    }
    #endregion
    #region UserDefinedFunction
    public void GetEmployeeName()
    {
        if (Session["user"] == null || Convert.ToString(Session["user"]) == string.Empty)
        {
            Response.Redirect("../Index.aspx");
        }
        else
        {
            lbl_EmployeeID.Text = Convert.ToString(Session["EmployeeCodeId"]);
            iEmployeeID = Convert.ToInt32(hdnEmployeeId.Value);
            DataSet ds_EmployeeDetails = new DataSet();
            ds_EmployeeDetails = objEmployeeEventData.Select_EmployeeDetailsNewbyId(iEmployeeID);
            strEmpFirstName = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
            strEmpLastName = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);
            Employee_Code_Id = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_Code_Id"]);
            lbl_EmployeeName.Text = strEmpFirstName + " " + strEmpLastName;
        }
    }
    private void SendMail(int intPermissionId, string strEmployeeEmailId, string ToMailId, string strEmailIdSanctioningAuthority, string NoOfHoursApplied, string FromTime, string ToTime, string PermissionTime, string Reason, string levelName, string PerStatus)
    {
        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;
        string strFromEmailId = string.Empty;
        string strMailStatus = string.Empty;
        DataTable dtTableScript = new DataTable();
        try
        {
            GetEmployeeName();
            int LevelID = 0;
            //LevelID = rptcommon.getNodes(Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
            string ScriptType = "New Permission Form";
            //   cl.fillDT("Select * from TA_TBL_EmailScripts where ScriptType='New Permission Form'", dtTableScript);
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            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"));
            }
            if (ToMailId != string.Empty)
            {
                mailMessage.To.Add(new MailAddress(ToMailId));
            }
            if (ToMailId != strEmailIdSanctioningAuthority)
            {
                //strMailStatus = "Pending";
                strMailStatus = rm.GetString("btn_Pending", ci);
            }
            else
            {
                //strMailStatus = "Forwarded";
                strMailStatus = rm.GetString("btn_Forwarded", ci);
            }
            //if (mailMessage.From.ToString() != strEmployeeEmailId)
            //{
            if (strEmployeeEmailId != string.Empty)
            {
                mailMessage.CC.Add(new MailAddress(strEmployeeEmailId));
            }
            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"]);
                LevelID = Convert.ToInt32(dsEmployeeDetails.Tables[0].Rows[0]["LevelID"]);
            }
            //}
            //string breks = "<br>";
            //mail.From = System.Configuration.ConfigurationManager.AppSettings["FromId"];
            //mail.To = ToMailId;
            //mail.Subject = "Permission Form - " + PermissionTime + " | " + Employee_Code_Id + " | " + lbl_EmployeeName.Text + " - " + levelName;
            //mail.BodyFormat = MailFormat.Html;
            //mail.Priority = MailPriority.Normal;
            //mailMessage.Subject = levelName + " | " + lbl_EmployeeName.Text + " - " + Employee_Code_Id + " | " + PermissionTime + " | " + "Permission Form" + " " + strMailStatus;
            mailMessage.Subject = rm.GetString("email_PermissionForm", ci) + " - " + PermissionTime + " | " + Employee_Code_Id + " - " + lbl_EmployeeName.Text + " | " + levelName + " - " + PerStatus;
            mailMessage.Body = scriptText.Replace("<<PermissionForm>>", rm.GetString("email_PermissionForm", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeId>>", Employee_Code_Id);
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeId>>", rm.GetString("email_EmployeeId", ci));
            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>>", PermissionTime);
            mailMessage.Body = mailMessage.Body.Replace("<<lblNumberOfHoursApplied>>", rm.GetString("email_NumberOfHoursApplied", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<NumberOfHoursApplied>>", Convert.ToString(NoOfHoursApplied));
            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>>", FromTime);
            mailMessage.Body = mailMessage.Body.Replace("<<lblToTime>>", rm.GetString("email_ToDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<ToTime>>", ToTime);
            mailMessage.Body = mailMessage.Body.Replace("<<lblReason>>", rm.GetString("email_Reason", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<Reason>>", Reason);
            if (payrollConfig == 1)
            {
                mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?Permission_Id=" + Convert.ToString(intPermissionId) + "&LevelId=" + LevelID + "&Status=" + PerStatus + "&ApprovalType=Permission&Angler=1");
            }
            else
            {
                mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?Permission_Id=" + Convert.ToString(intPermissionId) + "&LevelId=" + LevelID + "&Status=" + PerStatus + "&ApprovalType=Permission");
            }
            objClassCommon.SendMail(mailMessage);
        }
        catch
        {
            //Response.Write(ex.Message);
            objLeaveApplicationEventData.InsertLeaveApplicationDetailsInEmailTrigger(intPermissionId, Convert.ToString(Session["loginEmailId"]), ToMailId, strEmployeeEmailId, rm.GetString("email_PermissionForm", ci) + "-" + PermissionTime + " | " + Employee_Code_Id + " - " + lbl_EmployeeName.Text + "|" + levelName + "-" + strMailStatus, Convert.ToString(mailMessage.Body), "", "PermissionApplication");
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_PermissionApplicationsavedEmailnotsent", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
            strScript = strScript + "</script>";
            //Dispaly alert messsage.
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            //Page.RegisterStartupScript("AlertPAdd", strScript);
            checkEmail = false;
        }
    }
    /// <summary>
    /// Sending mail to the Reporting to Person
    /// </summary>
    /// <param name="ToMailId"></param>
    /// <param name="NoOfHoursApplied"></param>
    /// <param name="FromTime"></param>
    /// <param name="ToTime"></param>
    /// <param name="PermissionTime"></param>
    private void SendMail(Int64 PermissionId, Int64 LevelId, int intFirstLevelAuthorityId, int intSecondLevelAuthorityId, string strEmailIdReportingTo, string strEmailIdSanctionAuthority, string EmployeeEamilId, string NoOfHoursApplied, string FromTime, string ToTime, string PermissionTime, string Reason, string levelName, string strPermissionStatus)
    {
        try
        {
            // Get the Application Root Path
            string strApplicationPath = Request.UrlReferrer.ToString();
            int intLastIndex = strApplicationPath.LastIndexOf('/');
            strApplicationPath = strApplicationPath.Substring(0, (intLastIndex - 1));
            intLastIndex = strApplicationPath.LastIndexOf('/');
            strApplicationPath = strApplicationPath.Substring(0, (intLastIndex + 1));
            string[] strSysName;
            strSysName = strApplicationPath.Split('/');
            string strServerIP = string.Empty;
            //= GetIPAddress();
            strServerIP = System.Configuration.ConfigurationManager.AppSettings["ServerIP"].ToString();
            strApplicationPath = strApplicationPath.Replace(strSysName[2].ToString(), strServerIP);
            DataSet dsCCEmailIds = new DataSet();
            bool blnMailToSecondLevel = false;
            //For plannned permission
            if (Convert.ToInt16(dsPermission.Tables[0].Rows[0]["UnPlanned"].ToString()) == 0)
            {
                dsCCEmailIds = objCCGroup.GetCCEmailIds(Convert.ToInt16(ds_EmployeeDetails.Tables[0].Rows[0]["LevelId"].ToString()), Convert.ToInt16(ds_EmployeeDetails.Tables[0].Rows[0]["Designation_Id"].ToString()), "P");
                if (dsCCEmailIds != null)
                {
                    if (dsCCEmailIds.Tables[1].Rows.Count > 0)
                    {
                        if (Convert.ToBoolean(dsCCEmailIds.Tables[1].Rows[0]["MailTo_SecondLevel_Planned"].ToString()) == true)
                        {
                            blnMailToSecondLevel = true;
                        }
                    }
                }
            }
            //For UnPlanned permission
            else
            {
                dsCCEmailIds = objCCGroup.GetCCEmailIds(Convert.ToInt16(ds_EmployeeDetails.Tables[0].Rows[0]["LevelId"].ToString()), Convert.ToInt16(ds_EmployeeDetails.Tables[0].Rows[0]["Designation_Id"].ToString()), "U");
                if (dsCCEmailIds != null)
                {
                    if (dsCCEmailIds.Tables[1].Rows.Count > 0)
                    {
                        if (Convert.ToBoolean(dsCCEmailIds.Tables[1].Rows[0]["MailTo_SecondLevel_UnPlanned"].ToString()) == true)
                        {
                            blnMailToSecondLevel = true;
                        }
                    }
                }
            }
            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();
            GetEmployeeName();
            string ScriptType = "New Permission Form";
            string status = "";
            //   cl.fillDT("Select * from TA_TBL_EmailScripts where ScriptType='New Permission Form'", dtTableScript);
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
            status = strPermissionStatus;
            if (strEmailIdReportingTo == strEmailIdSanctionAuthority)
            {

                mailMessage.To.Add(new MailAddress(strEmailIdReportingTo));
                mailMessage.Subject = "TimeCheck : " + levelName + " | " + lbl_EmployeeName.Text + " " + Employee_Code_Id + " | Permission  |" + " Forwarded";
                //mailMessage.Subject = levelName + " | " + lbl_EmployeeName.Text + " - " + Employee_Code_Id + " | " + PermissionTime + " | " + "Permission Form" + " | " + "Forwarded";
            }
            else
            {
                mailMessage.To.Add(new MailAddress(strEmailIdReportingTo));
                if (blnMailToSecondLevel == true)
                {
                    mailMessage.CC.Add(new MailAddress(strEmailIdSanctionAuthority));
                }
                mailMessage.Subject = "TimeCheck : " + levelName + " | " + lbl_EmployeeName.Text + " " + Employee_Code_Id + " | Permission  |" + " Pending";
                //mailMessage.Subject = levelName + " | " + lbl_EmployeeName.Text + " - " + Employee_Code_Id + " | " + PermissionTime + " | " + "Permission Form" + " | " + "Pending";
            }

            if (Session["loginEmailId"] != null && Convert.ToString(Session["loginEmailId"]) != string.Empty)
            {
                mailMessage.From = new MailAddress(Convert.ToString(Session["loginEmailId"]));
            }
            else
            {
                mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
            }


            //if (Session["loginEmailId"].ToString() != string.Empty || Session["loginEmailId"] != null)
            //{
            //    if (Session["loginEmailId"].ToString() != ViewState["vsEmployeeEamilId"].ToString())
            //    {
            //        mailMessage.From = new MailAddress(Session["loginEmailId"].ToString());
            //        //mailMessage.CC.Add(new MailAddress(ViewState["vsEmployeeEamilId"].ToString()));
            //    }
            //    else if (ViewState["vsEmployeeEamilId"].ToString() != string.Empty)
            //    {
            //        mailMessage.From = new MailAddress(ViewState["vsEmployeeEamilId"].ToString());
            //    }
            //    else
            //    {
            //        mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
            //    }
            //}
            //else
            //{
            //    mailMessage.From = new MailAddress(ConfigurationManager.AppSettings.Get("FromId"));
            //}
            mailMessage.CC.Add(new MailAddress(ViewState["vsEmployeeEamilId"].ToString()));
            string strCcMails = txtApprovalCC.Text;
            //CC mails using CC group
            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);
                        }
                    }
                }
            }
            //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.Body = scriptText.Replace("<<PermissionForm>>", rm.GetString("email_PermissionForm", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<EmployeeId>>", Employee_Code_Id);
            mailMessage.Body = mailMessage.Body.Replace("<<lblEmployeeId>>", rm.GetString("email_EmployeeId", ci));
            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("<<lblApplicationDate>>", "Application Date");
            mailMessage.Body = mailMessage.Body.Replace("<<ApplicationDate>>", lbl_PermissionApplicationDate.Text);
            mailMessage.Body = mailMessage.Body.Replace("<<lblPermissionDate>>", rm.GetString("Permission_PermissionDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<PermissionDate>>", PermissionTime);
            mailMessage.Body = mailMessage.Body.Replace("<<lblNumberOfHoursApplied>>", rm.GetString("email_NumberOfHoursApplied", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<NumberOfHoursApplied>>", Convert.ToString(NoOfHoursApplied));
            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>>", FromTime);
            mailMessage.Body = mailMessage.Body.Replace("<<lblToTime>>", rm.GetString("email_ToDate", ci));
            mailMessage.Body = mailMessage.Body.Replace("<<ToTime>>", ToTime);
            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>>", Reason);
            //mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", strServerIP + "Index.aspx?Permission_Id=" + PermissionId + "&LevelId=" + LevelId + "&ApprovalType=Permission");
            if (payrollConfig == 1)
            {
                mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?Permission_Id=" + PermissionId + "&LevelId=" + LevelId + "&ApprovalType=Permission&Status=" + status + "&From_Date=&To_Date=strSwipeCardNo=&strEmployeeName=&strEmployeeCodeId=&Angler=1");
            }
            else
            {
                mailMessage.Body = mailMessage.Body.Replace("<<LinkData>>", Convert.ToString(Session["HostServerURL"]) + "?Permission_Id=" + PermissionId + "&LevelId=" + LevelId + "&ApprovalType=Permission&Status=" + status + "&From_Date=&To_Date=strSwipeCardNo=&strEmployeeName=&strEmployeeCodeId=");
            }
            objClassCommon.SendMail(mailMessage);
        }
        catch
        {
            checkEmail = false;
        }
    }
    private string[] SplitCCTo(string CCTo)
    {
        string[] strArrEmailAddressForCC;
        strArrEmailAddressForCC = CCTo.Split(';');
        return (strArrEmailAddressForCC);
    }
    //Check permission status
    protected string PermissionStatusonShift(string PermissionDate, int shiftId, DateTime PermissionFromTime, DateTime PermissionToTime)
    {
        DataSet dsShiftDetails = new DataSet();
        string ShiftStartTime = string.Empty;
        string ShiftEndTime = string.Empty;
        string ShiftFirstHalfStart = string.Empty;
        string ShiftFirstHalfEnd = string.Empty;
        string ShiftSecondHalfStart = string.Empty;
        string ShiftSecondHalfEnd = string.Empty;
        string status = string.Empty;
        DateTime dtShiftFirstHalfStart = new DateTime();
        DateTime dtShiftFirstHalfEnd = new DateTime();
        DateTime dtShiftSecondHalfStart = new DateTime();
        DateTime dtShiftSecondHalfEnd = new DateTime();
        dsShiftDetails = objPermissionEventData.GetShiftTime(shiftId);
        if (dsShiftDetails.Tables.Count > 0)
        {
            if (dsShiftDetails.Tables[0].Rows.Count > 0)
            {
                if (dsShiftDetails.Tables[0].Rows[0]["shift_StartTime"] != DBNull.Value)
                {
                    ShiftStartTime = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["shift_StartTime"]);
                }
                if (dsShiftDetails.Tables[0].Rows[0]["shift_EndTime"] != DBNull.Value)
                {
                    ShiftEndTime = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["shift_EndTime"]);
                }
                if (dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"] != DBNull.Value)
                {
                    dtShiftFirstHalfStart = DateTime.Parse(PermissionDate + " " + Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"]));
                    ShiftFirstHalfStart = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"]);
                }
                if (dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"] != DBNull.Value)
                {
                    dtShiftFirstHalfEnd = DateTime.Parse(PermissionDate + " " + Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"]));
                    ShiftFirstHalfEnd = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"]);
                }
                if (dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"] != DBNull.Value)
                {
                    dtShiftSecondHalfStart = DateTime.Parse(PermissionDate + " " + Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"]));
                    ShiftSecondHalfStart = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"]);
                }
                if (dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"] != DBNull.Value)
                {
                    dtShiftSecondHalfEnd = DateTime.Parse(PermissionDate + " " + Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"]));
                    ShiftSecondHalfEnd = Convert.ToString(dsShiftDetails.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"]);
                }
                if (ShiftStartTime.Substring(6, 2) == "PM" && ShiftEndTime.Substring(6, 2) == "AM")
                {
                    if (ShiftFirstHalfEnd != string.Empty)
                    {
                        if (ShiftFirstHalfEnd.Substring(6, 2) == "AM")
                        {
                            dtShiftFirstHalfEnd.AddDays(1);
                        }
                    }
                    if (ShiftSecondHalfStart != string.Empty)
                    {
                        if (ShiftSecondHalfStart.Substring(6, 2) == "AM")
                        {
                            dtShiftSecondHalfStart.AddDays(1);
                        }
                    }
                    if (ShiftSecondHalfEnd != string.Empty)
                    {
                        if (ShiftSecondHalfEnd.Substring(6, 2) == "AM")
                        {
                            dtShiftSecondHalfEnd = dtShiftSecondHalfEnd.AddDays(1);
                        }
                    }
                }
            }
        }
        if ((PermissionFromTime >= dtShiftFirstHalfStart && PermissionFromTime <= dtShiftFirstHalfEnd) && (PermissionToTime >= dtShiftFirstHalfStart && PermissionToTime <= dtShiftFirstHalfEnd))
        {
            status = "First Half";
        }
        else if ((PermissionFromTime >= dtShiftSecondHalfStart && PermissionFromTime <= dtShiftSecondHalfEnd) && (PermissionToTime >= dtShiftSecondHalfStart && PermissionToTime <= dtShiftSecondHalfEnd))
        {
            status = "Second Half";
        }
        return status;
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EmployeeID1.Text = lblEmpId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName1.Text = rm.GetString("email_EmployeeName", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_StartTime.Text = rm.GetString("AllSwipes_FromTime", ci);
        lbl_EndTime.Text = rm.GetString("AllSwipes_ToTime", ci);
        lbl_NumberofHoursapplied.Text = rm.GetString("email_NumberOfHoursApplied", ci);
        lbl_PermissionApplicationDate1.Text = rm.GetString("LeaveApplication_LeaveApplicationDate", ci);
        lbl_PermissionDate.Text = rm.GetString("Permission_PermissionDate", ci);
        //lbl_PermissionType.Text = rm.GetString("Permission_PermissionType", ci);
        lbl_PermisssionTime.Text = rm.GetString("Permission_PermissionTime", ci);
        lbl_Reason.Text = rm.GetString("email_Reason", ci);
        lbl_RemainingNumberofHours.Text = rm.GetString("Permission_RemaininigNumberOfHours", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        //CustomValidator2.ErrorMessage = rm.GetString("Validator_LeavePermission_StartTime", ci);
        //CustomValidator3.ErrorMessage = rm.GetString("Validator_LeavePermission_EndTime", ci);
        //CustomValidator1.ErrorMessage = rm.GetString("Alert_SelectvalidPermissionDate", ci);
        lbl_HeaderPermission.Text = rm.GetString("Menu_Transactions_Permission", ci);
        lblLoading.Text = rm.GetString("ProgressBarText", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblSelectEmployee.Text = rm.GetString("lblSelectEmployee", ci);
        btn_CalculateHrs.Text = "";
        btn_Search.Text = "";
        //btn_Search.Text =  rm.GetString("btn_Search", ci);
        //btn_CalculateHrs.Text =  rm.GetString("Calculate_Hours", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(23, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    #region Message.
    /// <summary>
    /// Messages the specified message content.
    /// </summary>
    /// <param name="messageContent">Content of the message.</param>
    private void Message(string messageContent)
    {
        string strScript = "<script language='javascript' type='text/javascript'>";
        strScript += "alert('" + messageContent + "');";
        strScript += " </script>";
        //this.RegisterStartupScript("setScript", strScript);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }
    #endregion
    /// <summary>
    /// Compare ToDate with FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            //Convert Date Format to MM/dd/yyyy Format
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            gstrTimeFormat = Convert.ToString(Session["MTimeFormat"]);
            // strApplicationDate = objClassCommon.DateConvertion(gstrDateFormat, TxtPermissionDate.Text);
            //Convert Date Format to MM/dd/yyyy Format
            //commented on 26_sep_08
            //strFromDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), txt_StartTime.Text, "B");
            //strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), txt_EndTime.Text, "B");
            strFromDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), txt_StartTime.Text, "B");
            strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), txt_EndTime.Text, "B");
            DateTime dtToDate = DateTime.Parse(strToDateTime);
            DateTime dtFromDate = DateTime.Parse(strFromDateTime);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
                e.IsValid = false;
        }
        catch
        {
            //
        }
    }
    /// <summary>
    /// Compare FromMonth With Current Month
    /// </summary>
    public void CompareCurrentdate(object s, ServerValidateEventArgs e)
    {
        try
        {
            //Convert Date Format to MM/dd/yyyy Format
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strApplicationDate = objClassCommon.DateTimeConvertion((gstrDateFormat), TxtPermissionDate.Text, "D");
            DateTime dtCurrentDate = DateTime.Now;
            DateTime dtFromDate = DateTime.Parse(strApplicationDate);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
                e.IsValid = false;
        }
        catch
        {
            //
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            e.IsValid = true;
        }
    }
    /// <summary>
    /// Compare Tomonth with Current Month
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareTodate(object s, ServerValidateEventArgs e)
    {
        try
        {
            //Convert Date Format to MM/dd/yyyy Format
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            gstrTimeFormat = Convert.ToString(Session["MTimeFormat"]);
            strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), txt_EndTime.Text, "B");
            DateTime dtCurrentDate = DateTime.Now;
            DateTime dtFromDate = DateTime.Parse(strToDateTime);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
                e.IsValid = false;
        }
        catch
        {
            //
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        {
            e.IsValid = true;
        }
    }
    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 = Convert.ToString(tsDiff);
        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>
    /// Check Remaining number of permission Hours
    /// </summary>
    /// <param name="NoOfHoursApplied"></param>
    /// <param name="TotNoOfRemainingHours"></param>
    public void CheckHours(string NoOfHoursApplied, string TotNoOfRemainingHours)
    {
        //if (NoOfHoursApplied > TotNoOfRemainingHours)
        //{
        //    lbl_Error.Text = "You have exceeded the Permission Hours Limit";
        //    iInsertFlag = 1;
        //    return;
        //}
        //else if (NoOfHoursApplied <= 0)
        //{
        //    lbl_Error.Text = "Select Valid Hours";
        //    iInsertFlag = 1;
        //    return;
        //}
        if (NoOfHoursApplied != string.Empty && TotNoOfRemainingHours != string.Empty)
        {
            TimeSpan dsDiff;
            double MaxPermitHours_Mins = ConvertHoursMinsToMinutes(TotNoOfRemainingHours + ":00");
            double HoursTakenInMinutes_Mins = ConvertHoursMinsToMinutes(NoOfHoursApplied);
            double diffHours_Mins = MaxPermitHours_Mins - HoursTakenInMinutes_Mins;
            //diffHours = DateTime.Parse(MaxPermitHours).Subtract(DateTime.Parse(ds_HoursAlreadyTaken.Tables[0].Rows[0]["HoursTakenInMinutes"].ToString()));
            string s;
            s = ConvertMinutesToHoursMins(diffHours_Mins);
            //dsDiff = DateTime.Parse(TotNoOfRemainingHours).Subtract(DateTime.Parse(NoOfHoursApplied));
            //dsDiff = TimeSpan.Parse(s + ":00");
            //dsDiff = DateTime.Parse(NoOfHoursApplied).Subtract(DateTime.Parse(TotNoOfRemainingHours));
            DateTime NoOfHours = DateTime.Parse(NoOfHoursApplied);
            if (diffHours_Mins < 0)
            {
                //lbl_Error.Text = "You have exceeded the Permission Hours Limit";
                //base.Message(rm.GetString("Msg_ValidHour", ci));
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ValidHour", ci) + "');", true);
                iInsertFlag = -1;
                return;
            }
            else if (NoOfHours.Hour < 0)
            {
                //lbl_Error.Text = "Select Valid Hours";
                //base.Message(rm.GetString("Msg_ValidHour", ci));
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ValidHour", ci) + "');", true);
                iInsertFlag = -1;
                return;
            }
        }
    }
    /// <summary>
    /// Check Remaining number of permission Hours
    /// </summary>
    public void CheckRemainingHours(string EmpID, DateTime permissionDate)
    {
        ds_MaxNoOfHours = objPermissionEventData.GetMaxNoOfHours_ByLeavePolicy(Convert.ToInt32(EmpID));
        if (ds_MaxNoOfHours.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dRow in ds_MaxNoOfHours.Tables[0].Rows)
            {
                if (dRow["Permission_MaxHrs_Month"] != null)
                {
                    MaxPermitHours = Convert.ToString(dRow["Permission_MaxHrs_Month"]);
                }
                else
                {
                    MaxPermitHours = "00:00";
                }
            }
            //Comment on 21-Aug-07
            //string[] MaxPermissionHours = MaxPermitHours.Split(':');
            // MaxPermitHours = MaxPermissionHours[0] + "." + MaxPermissionHours[1];
            ds_HoursAlreadyTaken = objPermissionEventData.GetHoursAlreadyTaken(Convert.ToInt32(EmpID), permissionDate);
            if (Convert.ToInt32(ds_HoursAlreadyTaken.Tables[0].Rows[0]["InstancesTaken"]) >= Convert.ToInt32(ds_MaxNoOfHours.Tables[0].Rows[0]["Permission_MaxInstances_Month"]))
            {
                iInsertFlag = -1;
                //lbl_Error.Text = "You are Exceeding Maximum Number of Instances Per Month";
                //base.Message(rm.GetString("Msg_ExceddNoOfinstance", ci));
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ExceddNoOfinstance", ci) + "');", true);
                lblRemainNoOfHours.Text = "00:00";
                return;
            }
            TimeSpan tsPermission_MaxHrs_Instance = new TimeSpan();
            string Permission_MaxHrs_Instance = Convert.ToString(ds_MaxNoOfHours.Tables[0].Rows[0]["Permission_MaxHrs_Instance"]);
            string nHrs = hdnNoOfHours.Value;
            if (Permission_MaxHrs_Instance != string.Empty && Permission_MaxHrs_Instance != null)
            {
                tsPermission_MaxHrs_Instance = DateTime.Parse(Permission_MaxHrs_Instance).Subtract(DateTime.Parse(nHrs));
            }
            if (tsPermission_MaxHrs_Instance.TotalHours < 0)
            {
                iInsertFlag = -1;
                //lbl_Error.Text = "Your Maximum Number of Hours per Instance is" + " " + Permission_MaxHrs_Instance;
                //base.Message(rm.GetString("Msg_MaxNoOfHrsInstance", ci) + " " + Permission_MaxHrs_Instance + "");
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_MaxNoOfHrsInstance", ci) + " " + Permission_MaxHrs_Instance + "');", true);
                lblRemainNoOfHours.Text = "00:00";
                return;
            }
            // Comment on 21-Aug_07 , Because null check in db and values return in hh:mm format
            //if (Convert.IsDBNull(ds_HoursAlreadyTaken.Tables[0].Rows[0]["HoursTakenInMinutes"]))
            //{
            //    dNoOfHoursAlreadyTaken = 0;
            //}
            //else
            //{
            //    dNoOfHoursAlreadyTaken = Convert.ToDouble(ds_HoursAlreadyTaken.Tables[0].Rows[0]["HoursTakenInMinutes"]) / 60;
            //}
            //TimeSpan diffHours;
            double MaxPermitHours_Mins = ConvertHoursMinsToMinutes(MaxPermitHours);
            double HoursTakenInMinutes_Mins = ConvertHoursMinsToMinutes(Convert.ToString(ds_HoursAlreadyTaken.Tables[0].Rows[0]["HoursTakenInMinutes"]));
            double diffHours_Mins = MaxPermitHours_Mins - HoursTakenInMinutes_Mins;
            //diffHours = DateTime.Parse(MaxPermitHours).Subtract(DateTime.Parse(ds_HoursAlreadyTaken.Tables[0].Rows[0]["HoursTakenInMinutes"].ToString()));
            string s;
            s = ConvertMinutesToHoursMins(diffHours_Mins);
            //diffHours.ToString();
            int sReturn = s.LastIndexOf(':');
            //Commented .Remove(sReturn); because this is no need if the hours is in correct format.by MAnjula.P on 11-Jan-2014
            string RemainHours = s;
            //.Remove(sReturn);
            lblRemainNoOfHours.Text = RemainHours;
            hdnRemainNoOfHours.Value = RemainHours;
        }
        else
        {
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_NoPermissionHoursdefinedforthisEmployee", ci) + "');";
            strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
            strScript = strScript + "</script>";
            //Dispaly alert messsage.
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
            //Page.RegisterStartupScript("AlertPAddload", strScript);
            checkPermissionHrsExist = false;
        }
    }
    #endregion

    [WebMethod(EnableSession = true)]
    public static string PermissionDetails(string empid, string permissionDate)
    {
        DataSet ds = new DataSet("Table");
        PermissionEventData pe = new PermissionEventData();
        ds = pe.selectPermissionDetails(empid, permissionDate);
        ds.Tables[0].TableName = "Table";
        ds.Tables[1].TableName = "Table1";
        //if (ds.Tables[0].Rows.Count == 0)
        //{
        //    ds.Tables[0].Rows.Add();
        //}
        HttpContext.Current.Session["Prev_PermissionDetails"] = ds;
        return ds.GetXml();
    }

    #region ButtonEvents
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        if (PolicyExistsEmployees.Value == "true")
        {
            if (Session["Prev_PermissionDetails"] != null)
            {
                prevDs = (DataSet)Session["Prev_PermissionDetails"];
                if (prevDs != null)
                {
                    if (prevDs.Tables.Count > 0)
                    {
                        GenerateEmployeeTableControls(prevDs);
                        Session["Prev_PermissionDetails"] = null;
                    }
                }
            }
        }
        else
        {
            Response.Redirect("TA_UI_Transactions_LeavePermission.aspx");
        }
    }
    protected void btn_add_Click(object sender, EventArgs e)
    {
        //if (hdnRemainNoOfHours.Value != string.Empty)
        //{

        if (Page.IsValid == true)
        {

            //Thread.Sleep(50000000);
            //Convert Date Format to MM/dd/yyyy Format
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            gstrTimeFormat = Convert.ToString(Session["MTimeFormat"]);
            strApplicationDate = objClassCommon.DateConvertion(gstrDateFormat, TxtPermissionDate.Text);

            //Convert Date Format to MM/dd/yyyy Format
            //commented on 26_sep-08
            //strFromDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), txt_StartTime.Text, "B");
            //strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " hh:mm tt"), txt_EndTime.Text, "B");
            //strFromDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), txt_StartTime.Text, "B");
            //strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat + " " + gstrTimeFormat), txt_EndTime.Text, "B");
            int LeaveStartYear = DateTime.Parse(strApplicationDate).Year;
            int LeaveEndYear = DateTime.Parse(strApplicationDate).Year;
            if ((LeaveStartYear >= StartYear && LeaveStartYear <= EndYear) && (LeaveEndYear >= StartYear && LeaveEndYear <= EndYear))
            {
            }
            else
            {
                lbl_Error.Text = rm.GetString("Master_Holiday_Select_Valid_Year", ci);
                return;
            }
            //if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
            //{
            //}
            //else
            //{
            //    //Commented by Manikandan.RR on 10-06-2015 11.23 AM
            //    //its not allowing to save current date records. current date future hours.
            //    //if (Convert.ToDateTime(strApplicationDate) < DateTime.Now)
            //    //{
            //    //    //base.Message(rm.GetString("Alert_SelectvalidPermissionDate", ci));
            //    //    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SelectvalidPermissionDate", ci) + "');", true);
            //    //    return;
            //    //}
            //    if (Convert.ToDateTime(strFromDateTime) < DateTime.Now || Convert.ToDateTime(strToDateTime) < DateTime.Now)
            //    {
            //        // base.Message(rm.GetString("Permission_PastDate", ci));
            //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Permission_PastDate", ci) + "');", true);
            //        return;
            //    }
            //}
            //Validate less than Year settings
            if ((DateTime.Parse(strApplicationDate)) < (DateTime.Parse(gstrYearSettingStartDate)))
            {
                Message("Permission duration should not be less than the current year");
                return;
            }
            //Validate permission beyond the next year setting
            if (ViewState["NextYearSettings_Id"] != null || Convert.ToString(ViewState["NextYearSettings_Id"]) != string.Empty)
            {
                if (DateTime.Parse(strApplicationDate) > DateTime.Parse(gstrNextYearSettingsEndDate))
                {
                    Message("Permission application cannot be raised beyond the next year");
                    return;
                }
            }
            else
            {
                if (DateTime.Parse(strApplicationDate) > DateTime.Parse(gstrYearSettingsEndDate))
                {
                    Message("Permission application cannot be raised beyond the current year");
                    return;
                }
            }
            int CurrentYearLeaveCount = 0;
            int NextYearLeaveCount = 0;
            if (DateTime.Parse(strApplicationDate) <= DateTime.Parse(gstrYearSettingsEndDate))
            {
                CurrentYearLeaveCount = 1;
            }
            else if (DateTime.Parse(strApplicationDate) >= DateTime.Parse(gstrNextYearSettingStartDate))
            {
                NextYearLeaveCount = 1;
            }
            string YearSettingIDforSave = string.Empty;
            if (CurrentYearLeaveCount == 1)
            {
                YearSettingIDforSave = Convert.ToString(ViewState["YearSettings_Id"]);
            }
            else if (NextYearLeaveCount == 1)
            {
                YearSettingIDforSave = Convert.ToString(ViewState["NextYearSettings_Id"]);
            }
            //dNumberOfHoursApplied = CalculateNumberOfHoursApplied(strFromDateTime, strToDateTime);
            // txt_NumberOfHours.Text = dNumberOfHoursApplied.ToString();
            //if (iInsertFlag == -1)
            //{
            //    return;
            //}
            ds_EmployeeDetails = objLeaveApplicationEventData.GetEmployeeDetails(Convert.ToInt32(hdnEmployeeId.Value));
            if (ds_EmployeeDetails.Tables[0].Rows.Count > 0)
            {
                strlevelName = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["levelName"]);
                EmpID = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_Code_id"]);
                EmployeeEamilId = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["EmailId"]);

                strEmpFirstName = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_FirstName"]);
                strEmpLastName = Convert.ToString(ds_EmployeeDetails.Tables[0].Rows[0]["Employee_LastName"]);

                ViewState["vsEmpFirstName"] = strEmpFirstName;
                ViewState["vsEmpLastName"] = strEmpLastName;
                ViewState["vslevelName"] = strlevelName;
                ViewState["vsEmpID"] = EmpID;
                ViewState["vsEmployeeEamilId"] = EmployeeEamilId;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("lblSelectEmployee", ci) + "');", true);
                return;
            }
            dNoOfRemainingHours = hdnRemainNoOfHours.Value;
            //CheckRemainingHours(hdnEmployeeId.Value, DateTime.Parse(strApplicationDate));
            //if (checkPermissionHrsExist == false)
            //{
            //    lbl_Error.Text = string.Empty;
            //    return;
            //}
            //CheckHours(dNumberOfHoursApplied, dNoOfRemainingHours);
            //Check Permission Before Leave
            string PermissionStatus;
            DataSet dsShiftid = new DataSet();
            DataSet dsLeaveDetails = new DataSet();
            int ShiftId;
            //Checking session of permission hours 
            //dsShiftid = objPermissionEventData.GetShiftID(EmpID, DateTime.Parse(strApplicationDate).Year, DateTime.Parse(strApplicationDate).Month, DateTime.Parse(strApplicationDate).Day);
            //ShiftId = Convert.ToInt32(dsShiftid.Tables[0].Rows[0][0]);
            //PermissionStatus = PermissionStatusonShift(strApplicationDate, ShiftId, DateTime.Parse(strFromDateTime), DateTime.Parse(strToDateTime));
            //if (ds_MaxNoOfHours.Tables[0].Rows.Count > 0)
            //{
            //    if (Convert.ToString(ds_MaxNoOfHours.Tables[0].Rows[0]["PermissionBeforeLeave"]) == "False")
            //    {
            //        dsLeaveDetails = objPermissionEventData.CheckPermissionBeforeAfterWithLeave(DateTime.Parse(strFromDateTime).ToShortDateString(), DateTime.Parse(strToDateTime).ToShortDateString(), "PermissionBeforeLeave", Convert.ToInt32(hdnEmployeeId.Value), DateTime.Parse(strApplicationDate).ToShortDateString());
            //        if (dsLeaveDetails.Tables.Count > 0)
            //        {
            //            if (dsLeaveDetails.Tables[0].Rows.Count > 0)
            //            {
            //                if (PermissionStatus == "First Half")
            //                {
            //                    //No need to check
            //                }
            //                else if (PermissionStatus == "Second Half")
            //                {
            //                    if (Convert.ToString(dsLeaveDetails.Tables[0].Rows[0]["Leave_SessionFrom"]) == "First half")
            //                    {
            //                        Message(rm.GetString("Msg_PermissionBeforeLeave", ci));
            //                        //lbl_Error.Text = "Permission before leave is not applicable";
            //                        return;
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
            ////Check Permission After Leave
            //if (ds_MaxNoOfHours.Tables[0].Rows.Count > 0)
            //{
            //    if (Convert.ToString(ds_MaxNoOfHours.Tables[0].Rows[0]["PermissionAfterLeave"]) == "False")
            //    {
            //        dsLeaveDetails = objPermissionEventData.CheckPermissionBeforeAfterWithLeave(DateTime.Parse(strFromDateTime).ToShortDateString(), DateTime.Parse(strToDateTime).ToShortDateString(), "PermissionAfterLeave", Convert.ToInt32(hdnEmployeeId.Value), DateTime.Parse(strApplicationDate).ToShortDateString());
            //        if (dsLeaveDetails.Tables.Count > 0)
            //        {
            //            if (dsLeaveDetails.Tables[0].Rows.Count > 0)
            //            {
            //                if (PermissionStatus == "First Half")
            //                {
            //                    if (Convert.ToString(dsLeaveDetails.Tables[0].Rows[0]["Leave_SessionTo"]) == "Second half")
            //                    {
            //                        Message(rm.GetString("Msg_PermissionAfterLeave", ci));
            //                        //lbl_Error.Text = "Permission after leave is not applicable";
            //                        return;
            //                    }
            //                }
            //                else
            //                {
            //                    //Permission allowed
            //                }
            //            }
            //        }
            //    }
            //}
            //Check Permission and Leave on Same day
            //dsLeaveDetails = objPermissionEventData.CheckPermissionBeforeAfterWithLeave(DateTime.Parse(strFromDateTime).ToShortDateString(), DateTime.Parse(strToDateTime).ToShortDateString(), "PermissionOnLeave", Convert.ToInt32(hdnEmployeeId.Value), DateTime.Parse(strApplicationDate).ToShortDateString());
            //if (dsLeaveDetails.Tables.Count > 0)
            //{
            //    if (dsLeaveDetails.Tables[0].Rows.Count > 0)
            //    {
            //        Message(rm.GetString("Msg_AppliedAlready", ci));
            //        //lbl_Error.Text = "Leave already applied for this day";
            //        return;
            //    }
            //}
            string strScript = string.Empty;
            if (iInsertFlag == 0)
            {
                //     //Check FromTime and EndTime. Check whether the Permission has already applied for a particular Date and Hour. 
                //iEmployeeID = Convert.ToInt32(Session.Contents["EmpAutoId"]);
                iEmployeeID = Convert.ToInt32(hdnEmployeeId.Value);
                //iPermissionType_Id = ddl_PermissionType.SelectedIndex;
                // strPermissionDate = DateTime.Parse(lbl_PermissionApplicationDate.Text).ToShortDateString();
                iPermissionType_Id = 1;
                count = objPermissionEventData.CheckPermissionHours(iEmployeeID, strApplicationDate, strFromDateTime, strToDateTime);
                //     //Calling InsertpermissionHours Method
                if (count == 0)
                {
                    //strFromTime = DateTime.Parse(strFromDateTime).ToLongTimeString();
                    //strEndTime = DateTime.Parse(strToDateTime).ToLongTimeString();
                    strReason = txtReason.Text;
                    try
                    {
                        //Check Approval Settings for EnterPrise Edition and Demo Version
                        // Demo Edition - 0
                        //Standard Edition -  1
                        //Profession Edition - 2
                        //Enterprise Edition - 3
                        //Declare Permission Status
                        string strPermissionStatus = string.Empty;
                        string strPermissionStatusNew = string.Empty;
                        int permissionSanctionExists = 0;
                        int approvalSettingsPageExists = 0;
                        int payrollConfig = 0;
                        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
                        payrollConfig = objClassCommon.CheckPageExistsInLicense(185);
                        /*Below parameter is used for Angler*/
                        if (payrollConfig == 0)
                        {
                            permissionSanctionExists = objClassCommon.CheckPageExistsInLicense(248);
                        }
                        else
                        {
                            permissionSanctionExists = objClassCommon.CheckPageExistsInLicense(110);
                        }
                        //Checking grade module is available or not and changed the id value from 110 to 228
                        approvalSettingsPageExists = objClassCommon.CheckPageExistsInLicense(228);
                        //if (Session["Edition"].ToString() == "0" || Session["Edition"].ToString() == "3")
                        if (permissionSanctionExists == 1)
                        {
                            if (approvalSettingsPageExists == 1)
                            {
                                //Get Compnay Id of the Employeee
                                int intCompanyId = base.GetCompanyId(iEmployeeID);
                                //Get Approval Settings Based on Company Id
                                DataSet dsApprovalSettings = new DataSet();
                                ShiftEvenData objShift = new ShiftEvenData();
                                dsApprovalSettings = objShift.SelectApprovalSettings(intCompanyId);
                                if (dsApprovalSettings != null)
                                {
                                    if (dsApprovalSettings.Tables.Count > 0)
                                    {
                                        if (dsApprovalSettings.Tables[0].Rows.Count > 0)
                                        {
                                            if (Convert.ToBoolean(dsApprovalSettings.Tables[0].Rows[0]["PermissionSanction"]) == false)
                                            {
                                                strPermissionStatus = "Approved";
                                            }
                                            else
                                            {
                                                strPermissionStatusNew = objShift.GetApprovalStatus(Convert.ToInt32(Session["EmpAutoID"]), Convert.ToString(hdnEmployeeId.Value), Convert.ToBoolean(Session["ReportsBasedOn"]));
                                                if (strPermissionStatusNew != string.Empty && strPermissionStatusNew != null)
                                                {
                                                    strPermissionStatus = strPermissionStatusNew;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //base.Message(rm.GetString("Msg_ApprovalSettings", ci));
                                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ApprovalSettings", ci) + "');", true);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            strPermissionStatus = "Approved";
                        }
                        string strCCMail = txtApprovalCC.Text;
                        string strPerHours = txt_NumberOfHours.Text;
                        DataTable dtSanctionView = new DataTable();
                        string strEmployeeEmailId = string.Empty;
                        string strEmailIdSanctioningAuthority = string.Empty;
                        string strPerStatus = string.Empty;
                        dsPermission = objPermissionEventData.InsertPermissionHours
                            (
                            iEmployeeID,
                            strApplicationDate,
                            iPermissionType_Id,
                            strApplicationDate + " " + txt_StartTime.Text,
                            strApplicationDate + " " + txt_EndTime.Text,
                            strReason,
                            Convert.ToString(Session["EmpAutoId"]),
                            Convert.ToString(ViewState["YearSettings_Id"]),
                            strPermissionStatus,
                            strCCMail,
                            Convert.ToString(txt_NumberOfHours.Text));
                        Int64 intLevelId = 0;
                        int intFirstLevelAuthorityId = 0, intSecondLevelAuthorityId = 0;
                        if (dsPermission.Tables[0].Rows.Count > 0)
                        {
                            if (dsPermission.Tables[0].Rows[0]["Permission_Id"] != DBNull.Value && Convert.ToString(dsPermission.Tables[0].Rows[0]["Permission_Id"]) != string.Empty)
                            {
                                intPermissionId = Convert.ToInt32(dsPermission.Tables[0].Rows[0]["Permission_Id"]);
                            }
                            if (dsPermission.Tables[0].Rows[0]["LevelId"] != DBNull.Value && Convert.ToString(dsPermission.Tables[0].Rows[0]["LevelId"]) != string.Empty)
                            {
                                intLevelId = Convert.ToInt64(dsPermission.Tables[0].Rows[0]["LevelId"]);
                            }
                            if (dsPermission.Tables[0].Rows[0]["Status"] != DBNull.Value && Convert.ToString(dsPermission.Tables[0].Rows[0]["Status"]) != string.Empty)
                            {
                                strPerStatus = Convert.ToString(dsPermission.Tables[0].Rows[0]["Status"]);
                            }
                        }

                        if (intPermissionId > 0)
                        {
                            if (Session["Prev_PermissionDetails"] != null)
                            {
                                prevDs = (DataSet)Session["Prev_PermissionDetails"];
                                foreach (DataRow dr in prevDs.Tables[0].Rows)
                                {
                                    if (dr["Permission_Id"] != null && dr["Permission_Date"] != null && dr["Permission_FromTime"] != null && dr["Permission_ToTime"] != null && dr["Permission_Reason"] != null && dr["Permission_AppliedDate"] != null)
                                    {
                                        if (Convert.ToString(dr["Permission_Id"]) != "" && Convert.ToString(dr["Permission_Date"]) != "" && Convert.ToString(dr["Permission_FromTime"]) != "" && Convert.ToString(dr["Permission_ToTime"]) != "" && Convert.ToString(dr["Permission_Reason"]) != "" && Convert.ToString(dr["Permission_AppliedDate"]) != "")
                                        {
                                            objPermissionEventData.InsertPrevPermissionHours
                                            (
                                                intPermissionId,
                                                Convert.ToDouble(dr["Permission_Id"]),
                                                Convert.ToString(dr["Permission_Date"]),
                                                Convert.ToString(dr["Permission_FromTime"]),
                                                Convert.ToString(dr["No_Of_Hours"]),
                                                Convert.ToString(dr["Permission_ToTime"]),
                                                Convert.ToString(dr["Permission_Reason"]),
                                                Convert.ToString(dr["Permission_AppliedDate"])
                                            );
                                        }
                                    }
                                }
                                if (prevDs != null)
                                {
                                    if (prevDs.Tables.Count > 0)
                                    {
                                        DataTable dt = prevDs.Tables[0];
                                        DataRow dr = dt.NewRow();
                                        dr["Permission_Id"] = Convert.ToString(intPermissionId);
                                        dr["Permission_Date"] = Convert.ToString(TxtPermissionDate.Text);
                                        dr["Permission_FromTime"] = Convert.ToString(txt_StartTime.Text);
                                        dr["Permission_ToTime"] = Convert.ToString(txt_EndTime.Text);
                                        dr["Permission_Reason"] = Convert.ToString(txtReason.Text);
                                        dr["No_Of_Hours"] = Convert.ToString(txt_NumberOfHours.Text);
                                        dr["Permission_AppliedDate"] = Convert.ToString(lbl_PermissionApplicationDate.Text);
                                        dt.Rows.Add(dr);
                                        dt.AcceptChanges();
                                        Session["Prev_PermissionDetails"] = prevDs;
                                    }
                                }
                            }
                        }
                        dtSanctionView = objPermissionEventData.GetPermissionByPermissionId(intPermissionId);
                        strEmployeeEmailId = Convert.ToString(dtSanctionView.Rows[0]["emailId"]);
                        string strPermissionDate = strApplicationDate;
                        if (strPermissionStatus == "Approved")
                        {
                            // Update Processed Data Flag
                            objLeaveApplicationEventData.UpdateProcessedDataFlag(iEmployeeID, strPermissionDate, strPermissionDate, 0);
                        }
                        ds_EmailIdOfReportingTo = objPermissionEventData.SelectMailIdOfReportingTo(iEmployeeID);
                        dsEmailIdOfSanctionAuthority = objPermissionEventData.SelectMailIdOfSanctionAuthority(iEmployeeID);
                        strEmailIdSanctioningAuthority = string.Empty;
                        if (dsEmailIdOfSanctionAuthority != null)
                        {
                            if (dsEmailIdOfSanctionAuthority.Tables.Count > 0)
                            {
                                if (dsEmailIdOfSanctionAuthority.Tables[0].Rows.Count > 0)
                                {
                                    if (dsEmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"] != DBNull.Value)
                                    {
                                        if (Convert.ToString(dsEmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"]) != "")
                                        {
                                            strEmailIdSanctioningAuthority = Convert.ToString(dsEmailIdOfSanctionAuthority.Tables[0].Rows[0]["EmailId"]);
                                            intSecondLevelAuthorityId = int.Parse(dsEmailIdOfSanctionAuthority.Tables[0].Rows[0]["Employee_Id"].ToString());
                                        }
                                    }
                                }
                            }
                        }
                        if (ds_EmailIdOfReportingTo != null)
                        {
                            if (ds_EmailIdOfReportingTo.Tables.Count > 0)
                            {
                                if (ds_EmailIdOfReportingTo.Tables[0].Rows.Count > 0)
                                {
                                    if (ds_EmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"] != DBNull.Value)
                                    {
                                        if (Convert.ToString(ds_EmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"]) != "")
                                        {
                                            strEmailIdReportingTo = Convert.ToString(ds_EmailIdOfReportingTo.Tables[0].Rows[0]["EmailId"]);
                                            intFirstLevelAuthorityId = int.Parse(ds_EmailIdOfReportingTo.Tables[0].Rows[0]["Employee_Id"].ToString());
                                            //SendMail(intPermissionId, strEmployeeEmailId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, dNumberOfHoursApplied, txt_StartTime.Text, txt_EndTime.Text, TxtPermissionDate.Text, strReason, strlevelName, strPerStatus);
                                            SendMail(intPermissionId, intLevelId, intFirstLevelAuthorityId, intSecondLevelAuthorityId, strEmailIdReportingTo, strEmailIdSanctioningAuthority, EmployeeEamilId, dNumberOfHoursApplied, txt_StartTime.Text, txt_EndTime.Text, TxtPermissionDate.Text, strReason, strlevelName, strPerStatus);
                                        }
                                        else
                                        {
                                            //checkEmail = false;
                                        }
                                    }
                                    else
                                    {
                                        //checkEmail = false;
                                        //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_LeavePermission.aspx');";
                                        //strScript = strScript + "</script>";
                                        ////Dispaly alert messsage.
                                        //Page.RegisterStartupScript("AlertPAdd1", strScript);
                                    }
                                }
                                else
                                {
                                    //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_LeavePermission.aspx');";
                                    //strScript = strScript + "</script>";
                                    ////Dispaly alert messsage.
                                    //Page.RegisterStartupScript("AlertPAdd2", strScript);
                                    //checkEmail = false;
                                }
                            }
                        }

                    }
                    catch
                    {
                        checkEmail = false;
                    }

                    //if (checkEmail == true && blnCheckSMS == true)
                    //{
                    //    strScript = strScript + "<script language='javascript'>";
                    //    strScript = strScript + "alert('" + rm.GetString("Alert_PermissionApplicationsaved", ci) + "');";
                    //    strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
                    //    strScript = strScript + "</script>";
                    //}
                    //else if (checkEmail == false && blnCheckSMS == true)
                    //{
                    //    strScript = strScript + "<script language='javascript'>";
                    //    strScript = strScript + "alert('" + rm.GetString("Alert_PermissionApplicationsavedEmailnotsent", ci) + "');";
                    //    strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
                    //    strScript = strScript + "</script>";
                    //}
                    //else if (checkEmail == true && blnCheckSMS == false)
                    //{
                    //    strScript = strScript + "<script language='javascript'>";
                    //    strScript = strScript + "alert('" + rm.GetString("Alert_PermissionApplicationSavedbutSMSisnottriggered", ci) + "');";
                    //    strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
                    //    strScript = strScript + "</script>";
                    //}
                    //else
                    //{
                    //    strScript = strScript + "<script language='javascript'>";
                    //    strScript = strScript + "alert('" + rm.GetString("Alert_PermissionApplicationsavedEmailnotsent", ci) + "');";
                    //    strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
                    //    strScript = strScript + "</script>";
                    //}
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                    if (PolicyExistsEmployees.Value == string.Empty)
                    {
                        AddJavascriptCode();
                        return;
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_permissionAppliedforDay", ci) + "');", true);
                }
            }
            else
            {
                return;
            }
        }
        else
        {
            lblRemainNoOfHours.Text = hdnRemainNoOfHours.Value;
        }
        //}
        //else
        //{
        //    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_AvailableHourscouldnotbeempty", ci) + "');", true);
        //    return;
        //}
    }
    public int ConvertHoursMinsToMinutes(string inHoursMins)
    {
        try
        {
            int intTotalMinutes = 0, intHours = 0, intMinutes = 0;
            string[] HoursMins = inHoursMins.Split(':');
            intHours = Int16.Parse(HoursMins[0]);
            intMinutes = Int16.Parse(HoursMins[1]);
            intTotalMinutes = (intHours * 60) + intMinutes;
            return (intTotalMinutes);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    // Function to Convert Total Minutes to hh:mm format
    public string ConvertMinutesToHoursMins(double inTotalMinutes)
    {
        string strHoursMins = "00:00";
        try
        {
            double dTotHrs = Math.Floor(inTotalMinutes / 60);
            double dTotMins = inTotalMinutes % 60;
            int iTotHrs = Convert.ToInt32(dTotHrs);
            int iTotMins = Convert.ToInt32(dTotMins);
            if (Convert.ToInt32(dTotMins) >= 60)
            {
                iTotMins = Convert.ToInt32(dTotMins) % 60;
                iTotHrs += Convert.ToInt32(dTotMins) / 60;
            }
            strHoursMins = iTotHrs.ToString("00") + ":" + iTotMins.ToString("00");
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return (strHoursMins);
    }
    #endregion
    private void AddJavascriptCode()
    {
        string alertmessage = string.Empty;
        if (checkEmail == true)
            alertmessage = rm.GetString("Alert_PermissionApplicationsaved", ci);
        else if (checkEmail == false)
            alertmessage = rm.GetString("Alert_PermissionApplicationsavedEmailnotsent", ci);
        string script = " objHiddenField = document.getElementById('" + PolicyExistsEmployees.ClientID + @"'); objSubmit = document.getElementById('" + btn_cancel.ClientID + @"'); if(confirm('" + alertmessage + @", Do You want to print this application?') == true){ objHiddenField.value = 'true'; objSubmit.click();}else { objHiddenField.value = 'cancel'; objSubmit.click();}";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "confirm1", script, true);
    }

    private void GenerateEmployeeTableControls(DataSet savedds)
    {
        string scriptText = "";
        DataTable dtTableScript = new DataTable();
        dtTableScript = objLeaveApplicationEventData.GetEmailScripts("PermissionApplication_Print");
        if (dtTableScript.Rows.Count > 0)
        {
            scriptText = Convert.ToString(dtTableScript.Rows[0]["ScriptText"]);
            scriptText = scriptText.Replace("<<employeeidfield>>", Convert.ToString(ViewState["vsEmpID"]));
            scriptText = scriptText.Replace("<<employeenamefield>>", Convert.ToString(ViewState["vsEmpFirstName"]) + " " + Convert.ToString(ViewState["vsEmpLastName"]));
            scriptText = scriptText.Replace("<<departmentnamefield>>", Convert.ToString(ViewState["vslevelName"]));
            DataSet ds = savedds;
            int tot = (ds.Tables[0].Rows.Count > 5) ? (ds.Tables[0].Rows.Count - 5) : 0;
            int increment = 1;
            for (int i = tot; i < ds.Tables[0].Rows.Count; i++)
            {
                string testing = "<hr id='hr" + increment + "' style='display: none;";
                string testing1 = "<hr id='hr" + increment + "' style='";
                scriptText = scriptText.Replace("<table id='table" + increment + "' style='display: none'>", "<table id='table" + increment + "'>");
                scriptText = scriptText.Replace("<hr id='hr" + increment + "' style='display: none;", "<hr id='hr" + increment + "' style='");
                scriptText = scriptText.Replace("<<date" + increment + ">>", Convert.ToString(ds.Tables[0].Rows[i]["Permission_Date"]));
                scriptText = scriptText.Replace("<<intime" + increment + ">>", Convert.ToString(ds.Tables[0].Rows[i]["Permission_ToTime"]));
                scriptText = scriptText.Replace("<<latehours" + increment + ">>", Convert.ToString(ds.Tables[0].Rows[i]["No_Of_Hours"]));
                scriptText = scriptText.Replace("<<reason" + increment + ">>", Convert.ToString(ds.Tables[0].Rows[i]["Permission_Reason"]));
                scriptText = scriptText.Replace("<<receiveddate" + increment + ">>", Convert.ToString(ds.Tables[0].Rows[i]["Permission_AppliedDate"]));
                increment += 1;
            }
            pn.Controls.Add(new LiteralControl(scriptText));
            Session["ctrl"] = pn;
            string strScript = "";
            strScript = strScript + "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
            strScript = strScript + "<meta http-equiv='X-UA-Compatible' content='IE=edge' />";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "window.open('Print.aspx','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
            strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
            strScript = strScript + "</script>";
            Response.Write(strScript);
            return;
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Table script is missing,contact support team of timecheck');", true);
            return;
        }


        //Label lblFormHeader = new Label();
        //lblFormHeader.Text = "Permission Request Slip";
        //lblFormHeader.Style.Add("font-size", "25px");

        //Table tblEmployee = new Table();
        //tblEmployee.CellPadding = 5;
        //tblEmployee.CellSpacing = 0;
        //tblEmployee.Width = Unit.Pixel(600);
        //tblEmployee.Style.Add("border", "1px solid black");
        //TableHeaderRow hr = new TableHeaderRow();
        //hr.Font.Size = 10;

        //TableCell thcEmployeeid = new TableCell();
        //thcEmployeeid.Font.Size = 10;
        //thcEmployeeid.Attributes.Add("style", "width:15%;height:10px;border:1px solid black");
        //TableCell thcName = new TableCell();
        //thcName.Font.Size = 10;
        //thcName.Attributes.Add("style", "width:28%;height:10px;border:1px solid black");
        //TableCell thcDepartment = new TableCell();
        //thcDepartment.Font.Size = 10;
        //thcDepartment.Attributes.Add("style", "width:28%;height:10px;border:1px solid black");
        //TableCell thcDivShortForm = new TableCell();
        //thcDivShortForm.Font.Size = 10;
        //thcDivShortForm.Attributes.Add("style", "width:28%;height:10px;border:1px solid black");
        //thcEmployeeid.Text = "Employee ID";
        //thcName.Text = "Employee Name";
        //thcDepartment.Text = "Department Name";
        //thcDivShortForm.Text = "DivShortForm";



        //hr.Cells.Add(thcEmployeeid);
        //hr.Cells.Add(thcName);
        //hr.Cells.Add(thcDepartment);
        //hr.Cells.Add(thcDivShortForm);
        //tblEmployee.Rows.Add(hr);

        //TableHeaderRow hrv = new TableHeaderRow();
        //hrv.Style.Add("border", "1px solid black");
        //hrv.Font.Size = 10;
        //TableCell thcEmployeeidValue = new TableCell();
        //thcEmployeeidValue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;background-color:silver");
        //thcEmployeeidValue.Font.Size = 10;

        //TableCell thcNamevalue = new TableCell();
        //thcNamevalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;background-color:silver");
        //thcNamevalue.Font.Size = 10;
        //TableCell thcDepartmentvalue = new TableCell();
        //thcDepartmentvalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;background-color:silver");
        //thcDepartmentvalue.Font.Size = 10;
        //TableCell thcDivShortFormvalue = new TableCell();
        //thcDivShortFormvalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;background-color:silver");
        //thcDivShortFormvalue.Font.Size = 10;

        //thcEmployeeidValue.Text = Convert.ToString(ViewState["vsEmpID"]);
        //thcNamevalue.Text = Convert.ToString(ViewState["vsEmpFirstName"]) + " " + Convert.ToString(ViewState["vsEmpLastName"]);
        //thcDepartmentvalue.Text = Convert.ToString(ViewState["vslevelName"]);
        //thcDivShortFormvalue.Text = "";

        //hrv.Cells.Add(thcEmployeeidValue);
        //hrv.Cells.Add(thcNamevalue);
        //hrv.Cells.Add(thcDepartmentvalue);
        //hrv.Cells.Add(thcDivShortFormvalue);
        //tblEmployee.Rows.Add(hrv);
        //pn.Controls.Add(lblFormHeader);
        //pn.Controls.Add(tblEmployee);
        //GeneratePermissionTableControls(savedds);
    }

    private void GeneratePermissionTableControls(DataSet savedds)
    {
        DataSet ds = savedds;
        int tot = (ds.Tables[0].Rows.Count > 5) ? (ds.Tables[0].Rows.Count - 5) : 0;
        for (int i = tot; i < ds.Tables[0].Rows.Count; i++)
        {
            Table tblEmployee = new Table();
            tblEmployee.CellPadding = 5;
            tblEmployee.CellSpacing = 0;
            tblEmployee.Width = Unit.Pixel(600);
            tblEmployee.Height = Unit.Pixel(80);
            if (i == 0)
            {
                tblEmployee.Attributes.Add("style", "width: 600px;height:60px;");
            }
            else
            {
                tblEmployee.Attributes.Add("style", "margin-top:-5px;width: 600px;height:60px;");
            }
            for (int j = 1; j <= 2; j++)
            {
                TableRow hr = new TableRow();
                if (j == 1)
                {
                    TableCell thcPermissionHeader = new TableCell();
                    thcPermissionHeader.Text = Enum.GetName(typeof(permissionHeader), i + 1) + " PERMISSION";
                    thcPermissionHeader.Attributes.Add("style", "margin-left:-5px;text-decoration: underline;");
                    thcPermissionHeader.Font.Size = 10;
                    thcPermissionHeader.Font.Bold = true;
                    thcPermissionHeader.ColumnSpan = 5;
                    hr.Cells.Add(thcPermissionHeader);
                    tblEmployee.Rows.Add(hr);
                }
                else
                {
                    TableCell thcDate = new TableCell();
                    thcDate.Attributes.Add("style", "width:15%;height:10px;border:1px solid black");
                    thcDate.Font.Size = 10;
                    TableCell thcInTime = new TableCell();
                    thcInTime.Font.Size = 10;
                    thcInTime.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");
                    TableCell thcLateTime = new TableCell();
                    thcLateTime.Font.Size = 10;
                    thcLateTime.Attributes.Add("style", "width:18%;height:10px;border:1px solid black");
                    TableCell thcReason = new TableCell();
                    thcReason.Font.Size = 10;
                    thcReason.Attributes.Add("style", "width:37%;height:10px;border:1px solid black");
                    TableCell thcreceived = new TableCell();
                    thcreceived.Font.Size = 10;
                    thcreceived.Attributes.Add("style", "width:20%;height:10px;border:1px solid black");

                    thcDate.Text = "DATE";
                    thcInTime.Text = "INTIME";
                    thcLateTime.Text = "LATE HOURS";
                    thcReason.Text = "REASON";
                    thcreceived.Text = "RECEIVED DATE";


                    hr.Cells.Add(thcDate);
                    hr.Cells.Add(thcInTime);
                    hr.Cells.Add(thcLateTime);
                    hr.Cells.Add(thcReason);
                    hr.Cells.Add(thcreceived);
                    tblEmployee.Rows.Add(hr);

                    TableRow hrv = new TableRow();
                    thcreceived.Font.Size = 10;

                    TableCell thcDateval = new TableCell();
                    thcDateval.Font.Size = 10;
                    thcDateval.Attributes.Add("style", "width:15%;height:10px;border:1px solid black");

                    TableCell thcInTimeval = new TableCell();
                    thcInTimeval.Font.Size = 10;
                    thcInTimeval.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");

                    TableCell thcLateTimeval = new TableCell();
                    thcLateTimeval.Font.Size = 10;
                    thcLateTimeval.Attributes.Add("style", "width:18%;height:10px;border:1px solid black");

                    TableCell thcReasonval = new TableCell();
                    thcReasonval.Font.Size = 10;
                    thcReasonval.Attributes.Add("style", "width:37%;height:10px;border:1px solid black");

                    TableCell thcreceivedval = new TableCell();
                    thcreceivedval.Font.Size = 10;
                    thcreceivedval.Attributes.Add("style", "width:20%;height:10px;border:1px solid black");


                    thcDateval.Text = Convert.ToString(ds.Tables[0].Rows[i]["Permission_Date"]);
                    thcInTimeval.Text = Convert.ToString(ds.Tables[0].Rows[i]["Permission_ToTime"]);
                    thcLateTimeval.Text = Convert.ToString(ds.Tables[0].Rows[i]["No_Of_Hours"]);
                    thcReasonval.Text = Convert.ToString(ds.Tables[0].Rows[i]["Permission_Reason"]);
                    thcreceivedval.Text = Convert.ToString(ds.Tables[0].Rows[i]["Permission_AppliedDate"]);

                    hrv.Cells.Add(thcDateval);
                    hrv.Cells.Add(thcInTimeval);
                    hrv.Cells.Add(thcLateTimeval);
                    hrv.Cells.Add(thcReasonval);
                    hrv.Cells.Add(thcreceivedval);
                    tblEmployee.Rows.Add(hrv);
                }
            }
            pn.Controls.Add(tblEmployee);
            pn.Controls.Add(new LiteralControl("<hr style='width: 598px; margin-top:5px;margin-left: 0px; background-color: Gray; color: Gray; height: 2px;' />"));
        }
        GenerateSignatureTableControls();
    }

    private void GenerateSignatureTableControls()
    {
        Table tblEmployee = new Table();
        tblEmployee.Width = Unit.Pixel(600);
        tblEmployee.CellPadding = 5;
        tblEmployee.CellSpacing = 0;
        TableHeaderRow hr = new TableHeaderRow();
        hr.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;text-align: center;");
        hr.Font.Size = 10;
        TableCell thcEmployeeid = new TableCell();
        thcEmployeeid.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;text-align: center;");
        thcEmployeeid.Font.Size = 10;
        TableCell thcName = new TableCell();
        thcName.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;text-align: center;");
        thcName.Font.Size = 10;
        TableCell thcDepartment = new TableCell();
        thcDepartment.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;text-align: center;");
        thcDepartment.Font.Size = 10;
        TableCell thcDivShortForm = new TableCell();
        thcDivShortForm.Attributes.Add("style", "width:10%;height:10px;border:1px solid black;text-align: center;");
        thcDivShortForm.Font.Size = 10;

        thcEmployeeid.Text = "Employee Signature";
        thcName.Text = "HOD Signature";
        thcDepartment.Text = "IAD Signature";
        thcDivShortForm.Text = "HR Signature";

        hr.Cells.Add(thcEmployeeid);
        hr.Cells.Add(thcName);
        hr.Cells.Add(thcDepartment);
        hr.Cells.Add(thcDivShortForm);
        tblEmployee.Rows.Add(hr);

        TableHeaderRow hrv = new TableHeaderRow();
        hrv.Style.Add("border", "1px solid black");


        hrv.Height = Unit.Point(80);
        TableCell thcEmployeeidValue = new TableCell();
        thcEmployeeidValue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");
        thcEmployeeidValue.Height = Unit.Point(80);
        TableCell thcNamevalue = new TableCell();
        thcNamevalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");
        thcNamevalue.Height = Unit.Point(80);
        TableCell thcDepartmentvalue = new TableCell();
        thcDepartmentvalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");
        thcDepartmentvalue.Height = Unit.Point(80);
        TableCell thcDivShortFormvalue = new TableCell();
        thcDivShortFormvalue.Attributes.Add("style", "width:10%;height:10px;border:1px solid black");
        thcDivShortFormvalue.Height = Unit.Point(80);

        hrv.Cells.Add(thcEmployeeidValue);
        hrv.Cells.Add(thcNamevalue);
        hrv.Cells.Add(thcDepartmentvalue);
        hrv.Cells.Add(thcDivShortFormvalue);
        tblEmployee.Rows.Add(hrv);
        pn.Controls.Add(tblEmployee);
        Session["ctrl"] = pn;
        string strScript = "";
        strScript = strScript + "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
        strScript = strScript + "<meta http-equiv='X-UA-Compatible' content='IE=edge' />";
        strScript = strScript + "<script language='javascript'>";
        strScript = strScript + "window.open('Print.aspx','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
        strScript = strScript + "location.replace('TA_UI_Transactions_LeavePermission.aspx');";
        strScript = strScript + "</script>";
        Response.Write(strScript);
        return;
    }

}