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.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
using System.Text;

public partial class Reports_TA_UI_Report_LeaveApplication_Angler : Base.BasePage
{
    #region Variable Declaration

    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    GetReports rptEmp = new GetReports();
    Rpt_Common rptcommon = new Rpt_Common();
    ResourceManager rm;
    LeaveEventData objLeaveEventData = new LeaveEventData();
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    string strFromdate, gstrDateFormat, strTodate;
    DataSet ds_LeaveType = new DataSet();
    CultureInfo ci;
    int intIndividualUser = 0;
    bool blnNormal;
    string strReportType = string.Empty;
    string dtFrom = "", dtTo = "";

    #endregion

    #region Page Load event

    /// <summary>
    /// On page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objCommon.menu("LeaveReports", "242");
        }
        //get the culture info to set the language       
        string source_Language;
        source_Language = Session["Session_ActiveLanguage"].ToString();
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterDate", ci) + "','" + rm.GetString("Alert_EnterToDate", 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_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);

        //Set UserRights
        UserRights();

        if (!IsPostBack)
        {
            Hidden1.Value = Session["IDateFormat"].ToString();

            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();

            FillDesignation();
            ddlDesignation.PreRender += LB_PreRender;
            //txtFromDate.Text = Convert.ToDateTime(Session["SearchFromDate"]).ToShortDateString();
            txtFromDate.Text = (Convert.ToDateTime(Session["SearchFromDate"].ToString())).ToString(Session["MDateFormat"].ToString());
            txtToDate.Text = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Session["MDateFormat"].ToString());

            LoadLeaveType();
            //    LoadLeaveStatus();
        }

        if (IsPostBack)
        {
            if (rbtnSummary.Checked == true)
            {
                trTime.Style.Add("display", "none");
            }
            else
            {
                trTime.Style.Add("display", "''");
            }
        }
        //Check whether the employee is Individual User
        intIndividualUser = objCheckUser.CheckIndividualUser(Session["UserGroupName"].ToString());
        if(Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
        {
            divReportType.Visible = true;
        }
        else
        {
            divReportType.Visible = false;
        }
        if (intIndividualUser >= 1)
        {
            PlaceHolderLeaveApplication.Controls.Clear();
            divEmployeeDetails.Visible = false;

            lblEmpSwipe.Visible = false;
            txtSwipeCard.Visible = false;
        }

        //Convert date time to MM/dd/YYYY format

        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromdate = txtFromDate.Text;
        strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
        strTodate = txtToDate.Text;
        strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);

        int leaveSanctionExists = 0;

        leaveSanctionExists = objCommon.CheckPageExistsInLicense(248);

        //if Standar Edition set the visibility to false
        //if (Session["Edition"].ToString() == "1")
        if (leaveSanctionExists == 0)
        {
            lblStatus.Style.Add("display", "none");
            //ddlLeaveStatus.Style.Add("display", "none");
            //Added by Manjula.P on 08-May-2014
            ckStatus.Style.Add("display", "none");
        }
    }

    #endregion

    #region User Defined Functions

    /// <summary>
    /// Fills the designation in the drop down
    /// </summary>
    private void FillDesignation()
    {
        DataSet ds_designation = new DataSet();
        ds_designation = objEmployee.select_CommonDesignation();

        if (ds_designation != null)
        {
            if (ds_designation.Tables[0].Rows.Count > 0)
            {
                ddlDesignation.DataSource = ds_designation;
                ddlDesignation.DataTextField = "TitleName";
                ddlDesignation.DataValueField = "TitleId";
                ddlDesignation.DataBind();
            }
            ds_designation.Dispose();

            foreach (ListItem item in ddlDesignation.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }

    /// <summary>
    /// Bindings the employee category and type.
    /// </summary>
    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();

            foreach (ListItem item in ddlEmpCatagory.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }

        // employee type binding
        DataSet dsType = new DataSet();
        dsType = objEmployee.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();

            foreach (ListItem item in ddlEmpType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }

    /// <summary>
    /// Display the leave types in DropDownList
    /// </summary>
    public void LoadLeaveType()
    {
        string strusergroupname = string.Empty;
        ds_LeaveType = objLeaveEventData.SelectLeaveTypeDetails(strusergroupname);

        if (ds_LeaveType.Tables[0].Rows.Count > 0)
        {
            ddlLeaveType.DataSource = ds_LeaveType;
            ddlLeaveType.DataTextField = "LeaveType";
            ddlLeaveType.DataValueField = "LeaveType_Id";
            ddlLeaveType.DataBind();

            ListItem liAll = new ListItem();
            liAll.Value = "All";
            liAll.Text = rm.GetString("ExportData_All", ci);
            ddlLeaveType.Items.Insert(0, liAll);
            int indexcount = ds_LeaveType.Tables[0].Rows.Count;
            ListItem liRes = new ListItem();
            liRes.Value = "Restricted Holiday";
            liRes.Text = rm.GetString("Holiday_RestrictedHoliday", ci);
            ddlLeaveType.Items.Insert(indexcount + 1, liRes);
            ListItem liComp = new ListItem();
            liComp.Value = "Comp Off";
            liComp.Text = rm.GetString("Caption_CompOff", ci);
            ddlLeaveType.Items.Insert(indexcount + 2, liComp);
            ListItem liESI = new ListItem();
            liESI.Value = "ESI";
            liESI.Text = rm.GetString("Caption_ESI", ci);
            ddlLeaveType.Items.Insert(indexcount + 3, liESI);
            ListItem liLOP = new ListItem();
            liLOP.Value = "LOP";
            liLOP.Text = rm.GetString("lbl_LOP", ci);
            ddlLeaveType.Items.Insert(indexcount + 4, liLOP);

            foreach (ListItem item in ddlLeaveType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }

            //ddlLeaveType.Items.Insert(0, rm.GetString("ExportData_All", ci));
            //int indexcount = ds_LeaveType.Tables[0].Rows.Count;
            //ddlLeaveType.Items.Insert(indexcount + 1, rm.GetString("Holiday_RestrictedHoliday", ci));
            //ddlLeaveType.Items.Insert(indexcount + 2, rm.GetString("Caption_CompOff", ci));
            //ddlLeaveType.Items.Insert(indexcount + 3, rm.GetString("Caption_ESI", ci));
            //ddlLeaveType.Items.Insert(indexcount + 4, rm.GetString("lbl_LOP", ci));

        }
        else
        {
            ddlLeaveType.DataSource = ds_LeaveType;
            ddlLeaveType.DataBind();
            ListItem liAll = new ListItem();
            liAll.Value = "All";
            liAll.Text = rm.GetString("ExportData_All", ci);
            ddlLeaveType.Items.Insert(0, liAll);
            ListItem liRes = new ListItem();
            liRes.Value = "Restricted Holiday";
            liRes.Text = rm.GetString("Holiday_RestrictedHoliday", ci);
            ddlLeaveType.Items.Insert(1, liRes);
            ListItem liComp = new ListItem();
            liComp.Value = "Comp Off";
            liComp.Text = rm.GetString("Caption_CompOff", ci);
            ddlLeaveType.Items.Insert(2, liComp);
            ListItem liESI = new ListItem();
            liESI.Value = "ESI";
            liESI.Text = rm.GetString("Caption_ESI", ci);
            ddlLeaveType.Items.Insert(3, liESI);
            ListItem liLOP = new ListItem();
            liLOP.Value = "LOP";
            liLOP.Text = rm.GetString("lbl_LOP", ci);
            ddlLeaveType.Items.Insert(4, liLOP);
            //ddlLeaveType.Items.Insert(0, "All");
            //ddlLeaveType.Items.Insert(1, "Restricted Holiday");
            //ddlLeaveType.Items.Insert(2, "Comp Off");
            //ddlLeaveType.Items.Insert(3, "ESI");
            //ddlLeaveType.Items.Insert(4, "LOP");
            //ddlLeaveType.Items.Insert(0, rm.GetString("ExportData_All", ci));
            //ddlLeaveType.Items.Insert(1, rm.GetString("Holiday_RestrictedHoliday", ci));
            //ddlLeaveType.Items.Insert(2, rm.GetString("Caption_CompOff", ci));
            //ddlLeaveType.Items.Insert(3, rm.GetString("Caption_ESI", ci));
            //ddlLeaveType.Items.Insert(4, rm.GetString("lbl_LOP", ci));
        }
    }

    /// <summary>
    /// Validate the FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateFromDate(object s, ServerValidateEventArgs e)
    {
        try
        {

            strFromdate = txtFromDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            //strCurrentDate = objCommon.DateConvertion(gstrDateFormat,DateTime.Today.Date.ToString());
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            //strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);

            //DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date.ToString("MM/dd/yyyy")); ;
            DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
            DateTime dtFromDate = DateTime.Parse(strFromdate);

            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
            {
                Message(rm.GetString("Alert_SelectvalidFromDate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }


    }

    /// <summary>
    /// Validate the ToDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateToDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            //strCurrentDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Today.Date.ToString());
            strTodate = txtToDate.Text;
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            //DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date.ToString("MM/dd/yyyy"));
            DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
            DateTime dtFromDate = DateTime.Parse(strTodate);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
            {
                //Message("Select Valid To Date");
                Message(rm.GetString("Alert_EnterValidToDate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }


    /// <summary>
    /// Compare ToDate with FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            strTodate = txtToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);

            DateTime dtToDate = DateTime.Parse(strTodate);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
            {
                //Message("Select valid Todate compare with Fromdate");
                Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }

    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        lblTimePeriod.Text = rm.GetString("Reports_TimePeriod", ci);
        lblFrom.Text = rm.GetString("email_FromDate", ci);
        lblTo.Text = rm.GetString("email_ToDate", ci);
        lblLeaveType.Text = rm.GetString("lbl_leavetype", ci);
        lblStatus.Text = rm.GetString("email_Status", ci);
        lblLeaveReport.Text = rm.GetString("Reports_Leave_LeaveReport", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        ddlLeaveStatus.Items[0].Text = rm.GetString("ExportData_All", ci);
        ddlLeaveStatus.Items[1].Text = rm.GetString("btn_Approved", ci);
        ddlLeaveStatus.Items[2].Text = rm.GetString("btn_Forwarded", ci);
        ddlLeaveStatus.Items[3].Text = rm.GetString("btn_Pending", ci);
        ddlLeaveStatus.Items[4].Text = rm.GetString("btn_Reject", ci);
        reqFromDate.ErrorMessage = rm.GetString("Alert_PleaseselectFromDate", ci);
        reqToDate.ErrorMessage = rm.GetString("Alert_PleaseselectToDate", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        lblDesignation.Text = rm.GetString("EmployeeMaster_Designation", ci);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        ddlGender.Items[0].Text = rm.GetString("Caption_Both", ci);
        ddlGender.Items[1].Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
        ddlGender.Items[2].Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
        ddlDesignation.Items[0].Text = rm.GetString("ExportData_All", ci);

        lblReportType.Text = rm.GetString("EmployeeInOutReportType", ci);
        rbtnSummary.Text = rm.GetString("EmployeeInOutSummary", ci);
        rbtnDetails.Text = rm.GetString("EmployeeInOutDetails", ci);

        //Getting Status for checkbox by Manjula.P on 08-May-2014
        cbAll.Text = rm.GetString("ExportData_All", ci);
        CbApproved.Text = rm.GetString("btn_Approved", ci);
        CBForwarded.Text = rm.GetString("btn_Forwarded", ci);
        CBPending.Text = rm.GetString("btn_Pending", ci);
        CBRejected.Text = rm.GetString("btn_Reject", ci);
        CBResend.Text =  rm.GetString("Sanction_Resend", ci);
        CBReply.Text =  rm.GetString("Sanction_Reply", ci);
        CBCanceled.Text =  rm.GetString("Sanction_Canceled", ci);
        CBResend.Text = rm.GetString("lbl_Resend", ci);
        CBReply.Text = rm.GetString("lbl_Reply", ci);
        CBCanceled.Text = rm.GetString("lbl_Canceled", ci);
    }

    /// <summary>
    /// To check the user rights
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(242, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");

        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                btn_View.Visible = true;
            }
            else
            {
                btn_View.Visible = false;
            }
        }
        else
        {
            Response.Redirect("ReportsLandingPage.aspx");
        }
    }

    /// <summary>
    /// To apply tooltip for the designation in the drop down
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void LB_PreRender(object sender, System.EventArgs e)
    {
        foreach (ListItem item in ddlDesignation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }

    #endregion

    #region Button Events

    /// <summary>
    /// Load the Leave report
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {
        string strSwipeCard = "";
        try
        {
            if (Page.IsValid == true)
            {

                if (rbtnSummary.Checked == true)
                {

                    cls_Common objClassCommon = new cls_Common();
                    DataSet dsYear = new DataSet();
                    strReportType = "Summary";
                    //Call to a function to get the Year setting details
                    dsYear = objClassCommon.GetYearsetting();
                    dtFrom = dsYear.Tables[0].Rows[0]["YearSettingFromDate"].ToString();
                    dtTo = dsYear.Tables[0].Rows[0]["YearSettingToDate"].ToString();
                }
                else
                {
                    //trTime.Visible = true;
                    if (txtFromDate.Text != "")
                        dtFrom = strFromdate;

                    if (txtToDate.Text != "")
                        dtTo = strTodate;
                    strReportType = "Details";
                }

                int shft = 0;
                string Level = string.Empty;
                string employeeName = string.Empty;
                string empName = string.Empty;
                string empId = string.Empty;
                int employeeCategory = 0, employeeType = 0;
                // set employee category and type
                if (Convert.ToInt32(ddlEmpCatagory.SelectedValue) != 0)
                {
                    employeeCategory = Convert.ToInt32(ddlEmpCatagory.SelectedValue);
                }
                else
                {
                    employeeCategory = 0;
                }

                if (Convert.ToInt32(ddlEmpType.SelectedValue) != 0)
                {
                    employeeType = Convert.ToInt32(ddlEmpType.SelectedValue);
                }
                else
                {
                    employeeType = 0;
                }


                //shft =Convert.ToInt32(ddlShift.SelectedValue);
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    shft = 0;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = txtEmployeeName.Text.ToString();
                    empId = txtEmployeeId.Text.Trim().ToString();
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    // employeeName = employeeName.Replace(' ', '%');
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                }

                if (rbtNormalReport.Checked == true)
                {
                    blnNormal = true;
                }
                else
                {
                    blnNormal = false;
                }


                string LeaveType = "0";

                LeaveType = ddlLeaveType.SelectedValue;

                strSwipeCard = txtSwipeCard.Text.ToString().Trim().Replace("'", "''");
                string strEmpAutoId = string.Empty;
                if (Session["ReportsBasedOn"] != null)
                {
                    if (Session["ReportsBasedOn"].ToString() == "False")
                    {
                        strEmpAutoId = "0";
                    }
                    else
                    {
                        strEmpAutoId = Session["EmpAutoID"].ToString();
                    }
                }
                //Included by A.Amsaveni on 20/04/2013 
                //Reason:To retrieve data based on unplanned or All 
                int chkunplanned = 0;
                if (rdoall.Checked)
                {
                    chkunplanned = 0;
                }
                else
                {
                    chkunplanned = 1;
                }
                //Added by Manjula.P on 08-May-2014 to getting status from checkboxes 
                string strStatus1 = "";
                strStatus1 = CbApproved.Checked == true ? "Approved," : strStatus1;
                strStatus1 = CBPending.Checked == true ? strStatus1 + "Pending," : strStatus1;
                strStatus1 = CBResend.Checked == true ? strStatus1 + "Resend," : strStatus1;
                strStatus1 = CBForwarded.Checked == true ? strStatus1 + "Forwarded," : strStatus1;
                strStatus1 = CBRejected.Checked == true ? strStatus1 + "Rejected," : strStatus1;
                strStatus1 = CBReply.Checked == true ? strStatus1 + "Reply," : strStatus1;
                strStatus1 = CBCanceled.Checked == true ? strStatus1 + "Canceled," : strStatus1;
                strStatus1 = strStatus1.Length > 0 ? strStatus1.Substring(0, strStatus1.Length - 1) : strStatus1;
                strStatus1 = strStatus1 == "" ? "Approved,Pending,Resend,Forwarded,Rejected,Reply,Canceled" : strStatus1;
                if (ddlLeaveStatus.SelectedIndex != 0)
                {
                    strStatus1 = ddlLeaveStatus.SelectedItem.Value;
                }
                //Redirect the page to the report viewer                
                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=document.documentMode;' />";
                strScript = strScript + "<script language='javascript'>";
                //strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=Leave&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + Convert.ToString(shft) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToString(employeeCategory) + "&EmpType=" + Convert.ToString(employeeType) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Session["UserGroupName"].ToString() + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&Normal=" + Convert.ToString(blnNormal) + "&LeaveType=" + Convert.ToString(LeaveType) + "&Status=" + ddlLeaveStatus.SelectedItem.Text + "&SwipeCard=" + strSwipeCard + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&LeaveReportType=" + strReportType + "&Planned=" + chkunplanned + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=Leave_Angler&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + Convert.ToString(shft) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToString(employeeCategory) + "&EmpType=" + Convert.ToString(employeeType) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Session["UserGroupName"].ToString() + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&Normal=" + Convert.ToString(blnNormal) + "&LeaveType=" + Convert.ToString(LeaveType) + "&Status=" + strStatus1 + "&SwipeCard=" + strSwipeCard + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&LeaveReportType=" + strReportType + "&Planned=" + chkunplanned + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                strScript = strScript + "</script>";
                Response.Write(strScript);
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }

    #endregion

    #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);

    }

    #endregion

    /// <summary>
    /// Display Leave Status in DropDownList
    /// </summary>

    //public void LoadLeaveStatus()
    //{
    //    ddlLeaveStatus.Items.Insert(0, "All");
    //    ddlLeaveStatus.Items.Insert(1, "Approved");
    //    ddlLeaveStatus.Items.Insert(2, "Forwarded");
    //    ddlLeaveStatus.Items.Insert(3, "Pending");
    //    ddlLeaveStatus.Items.Insert(4, "Rejected");
    //    ddlLeaveStatus.Items.Insert(5, "Resend");
    //    ddlLeaveStatus.Items.Insert(6, "Reply");
    //    ddlLeaveStatus.Items.Insert(7, "Canceled");
    //}
}
