using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Text;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.Util;
using System.IO;
public partial class Reports_TA_UI_Report_LateInstance : 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();
    EmployeeEventData objEmployee = new EmployeeEventData();
    ResourceManager rm;
    CultureInfo ci;
    ISheet sheet;
    TimeSpan result;
    string fromTimeString;
    string saveAsFileName = string.Empty;
    bool ok;
    string dtFrom = "", dtTo = "";
    string empName = "", EmployeeId = "";
    cls_Common objCommon = new cls_Common();
    string strFromdate, gstrDateFormat, strTodate;
    int intIndividualUser = 0;
    string gStrLevel = string.Empty;
    string ParenetLevelid = string.Empty;
    int payrollConfig = 0, Cellvalcount = 0;
    string SheetName = "", ReportName = "LateEntry";
    int shft;
    string empId = "";
    string employeeName = string.Empty;
    string Level = string.Empty; string strEmpAutoId = "0";
    string MinExceptkHours = "";
    string strReportType = "Normal";
    String hdnEmpID = "";
    String HdnReportName = "";
    String HdnFrom = "";
    string HdnTo = "";
    #endregion
    #region Page Load Events
    /// <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);
            ddlShift.Focus();
            objCommon.menu("Exception Reports", "37");
        }
        //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["SiteMapProvider"]);
        int value = 0;
        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) + "');";
        value = rbtlatein.Checked == true ? 0 : rbtEarlyExit.Checked == true ? 0 : rbtAll.Checked == true ? 1 : 3;
        strSetAlert = strSetAlert + "Click_Option('" + value + "')";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        if (!IsPostBack)
        {
            LoadStrings(ci);
            //Set UserRights
            UserRights();
            fillShift();
            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();
            FillDesignation();
            if (Request.QueryString["Source"] != null)
            {
                if (Request.QueryString["Source"].ToString() == "Email" || Request.QueryString["Source"].ToString() == "WhatsApp")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                    IDTest1.Visible = false;
                    rbtNormalReport.Visible = false;
                    rbtGraphReport.Visible = false;
                    if (Request.QueryString["ScheduleId"] != null || Request.QueryString["WhatsAppScheduleID"] != null)
                    {
                        DataSet ds = new DataSet();
                        if (Request.QueryString["ScheduleId"] != null)
                        {
                            ds = rptEmp.GetEmailSchedulerFilterDetails(Convert.ToInt32(Request.QueryString["ScheduleId"]));
                        }
                        else
                        {
                            ds = rptEmp.GetWhatsAppSchedulerFilterDetails(Convert.ToInt32(Request.QueryString["WhatsAppScheduleID"]));
                        }

                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                if (ds.Tables[1].Rows.Count > 0)
                                {
                                    string strReportType;
                                    strReportType = Convert.ToString(ds.Tables[1].Rows[0][0]);
                                    txtEmployeeName.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeName"]);
                                    Session["EMailParentId"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentID"]);
                                    Session["parentLevelId_modify"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentId"]);
                                    ddlEmpCatagory.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeCategory"]);
                                    ddlEmpType.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeType"]);
                                    ddlShift.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["shift"]);
                                    txtMinExceptionHours.Text = Convert.ToString(ds.Tables[0].Rows[0]["MINExceptionHOURS"]);
                                    switch (strReportType)
                                    {
                                        case "LateEntry":
                                        case "LateExit":
                                        case "EarlyExit":
                                        case "All":
                                            if (strReportType == "EarlyExit")
                                                txtEmployeeId.Text = Convert.ToString(ds.Tables[0].Rows[0]["empId"]);
                                            else
                                                txtEmployeeId.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeID"]);
                                            ddlDesignation.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["DesignationID"]);
                                            ddlGender.SelectedItem.Text = Convert.ToString(ds.Tables[0].Rows[0]["Gender"]);
                                            if (strReportType == "LateEntry")
                                                rbtlatein.Checked = true;
                                            else if (strReportType == "LateExit")
                                                rbtLateExit.Checked = true;
                                            else if (strReportType == "EarlyExit")
                                                rbtEarlyExit.Checked = true;
                                            else
                                                rbtAll.Checked = true;
                                            break;
                                        case "EarlyEntry":
                                            txtEmployeeId.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeID"]);
                                            rbtEarlyEntry.Checked = true;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Convert.ToString(Session["hdnReportFilters"]) != string.Empty)
                        {
                            string strhdnParameters = Convert.ToString(Session["hdnReportFilters"]);
                            string[] strArray = new string[50];
                            string[] strArray1 = new string[50];
                            strArray = strhdnParameters.Split(',');
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                string[] strTemp = new string[5];
                                strTemp = strArray[i].Split('=');
                                strArray1[i] = strTemp[1];
                            }
                            txtEmployeeId.Text = strArray1[2].ToString().Replace("~", ",");
                            ddlShift.SelectedValue = strArray1[3].ToString();
                            txtEmployeeName.Text = strArray1[4].ToString().Replace("~", ",");
                            ddlEmpCatagory.SelectedValue = strArray1[6].ToString();
                            ddlEmpType.SelectedValue = strArray1[7].ToString();
                            ddlDesignation.SelectedValue = Convert.ToString(strArray1[12]);
                            ddlGender.SelectedValue = Convert.ToString(strArray1[15]);
                            txtMinExceptionHours.Text = Convert.ToString(strArray1[14]);
                            switch (Convert.ToString(Session["LateReportName"]))
                            {
                                case "LateEntry":
                                    rbtlatein.Checked = true;
                                    break;
                                case "EarlyExit":
                                    rbtEarlyExit.Checked = true;
                                    break;
                                case "EarlyEntry":
                                    rbtEarlyEntry.Checked = true;
                                    break;
                                case "LateExit":
                                    rbtLateExit.Checked = true;
                                    break;
                                case "All":
                                    rbtAll.Checked = true;
                                    break;
                            }
                            Session["EMailParentId"] = Convert.ToInt16(strArray1[11]);
                        }
                    }
                }
            }
            else
            {
                divdateTime.Visible = true;
                trView.Visible = true;
                trSave.Visible = false;
                IDTest1.Visible = false;
            }
            if (Request.QueryString["ScheduleId"] != null)
            {
                string strGet = hdnReportFilters.Value;
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "GethiddenValue();";
                strScript += " </script>";
                this.RegisterStartupScript("setScript", strScript);
                IDTest1.Visible = false;
            }
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            txtFromDate.Text = (Convert.ToDateTime(objCommon.CurrentMonthStartDate())).ToString(Session["MDateFormat"].ToString());
            txtToDate.Text = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Session["MDateFormat"].ToString());
            ddlDesignation.PreRender += LB_PreRender;
            if (Session["parentLevelId"] != null || Convert.ToInt16(Session["parentLevelId"]) != 0)
                Session["parentLevelId"] = null;
        }
        //Check whether the employee is Individual User
        if (ViewState["vs_intIndividualUser"] != null)
            intIndividualUser = Convert.ToInt16(ViewState["vs_intIndividualUser"]);
        else
        {
            intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
            ViewState["vs_intIndividualUser"] = intIndividualUser;
        }
        if (intIndividualUser >= 1)
        {
            PlaceHolderLateEntry.Controls.Clear();
            divEmployeeDetails.Visible = false;
        }
        //Convert date time to MM/dd/YYYY format
        if (Session["MDateFormat"] != null)
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromdate = txtFromDate.Text;
        strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
        strTodate = txtToDate.Text;
        strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
        if (Page.MasterPageFile.ToString() == "TA_Popup_Report_MasterPage.master")
        {
            conHeader.Visible = false;
        }
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        if (ViewState["vs_payrollConfig"] != null)
            payrollConfig = (int)ViewState["vs_payrollConfig"];
        else
        {
            payrollConfig = objCommon.CheckPageExistsInLicense(185);
            ViewState["vs_payrollConfig"] = payrollConfig;
        }
        if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin" && payrollConfig == 1)
        {
            ReportType.Style.Add("display", "none");
            rbtAll.Checked = false;
            rbtlatein.Checked = true;
            ReportType1.Style.Add("display", "none");
        }
        hdnEmpID = Convert.ToString(Session["hdnEmpID"]);
        HdnReportName = Convert.ToString(Session["HdnReportName"]);
        HdnFrom = Convert.ToString(Session["HdnFrom"]);
        HdnTo = Convert.ToString(Session["HdnTo"]);
        if (hdnEmpID != "" & HdnReportName != "" & HdnFrom != "" & HdnTo != "")
        {

            btn_View_Click(sender, e);
        }
        else
        {


        }







    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["Source"] != null)
            this.Page.MasterPageFile = "TA_Popup_Report_MasterPage.master";
    }
    #endregion
    #region User Defined Functions
    /// <summary>
    /// Fills the designation in the drop down
    /// </summary>
    private void FillDesignation()
    {
        DataSet ds_designation = new DataSet();
        if (ViewState["vs_ds_designation"] != null)
            ds_designation = (DataSet)ViewState["vs_ds_designation"];
        else
        {
            ds_designation = objEmployee.select_CommonDesignation();
            ViewState["vs_ds_designation"] = ds_designation;
        }
        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();
            BindDropDownTitle(ddlDesignation);
        }
    }
    private void BindDropDownTitle(DropDownList ddl)
    {
        foreach (ListItem item in ddl.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();
        if (ViewState["vs_dsCategory"] != null)
            dsCategory = (DataSet)ViewState["vs_dsCategory"];
        else
        {
            dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
            ViewState["vs_dsCategory"] = dsCategory;
        }
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
            BindDropDownTitle(ddlEmpCatagory);
        }
        // employee type binding
        DataSet dsType = new DataSet();
        if (ViewState["vs_dsType"] != null)
            dsType = (DataSet)ViewState["vs_dsType"];
        else
        {
            dsType = objEmployee.SelectTypeDetailsEmployee("");
            ViewState["vs_dsType"] = dsType;
        }
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();
            BindDropDownTitle(ddlEmpType);
        }
    }
    /// <summary>
    /// To fill teh shift in the drop down
    /// </summary>
    public void fillShift()
    {
        ShiftEvenData getShift = new ShiftEvenData();
        DataSet ds = new DataSet();
        string strusergroup = string.Empty;
        if (ViewState["vs_Shifts"] != null)
            ds = (DataSet)ViewState["vs_Shifts"];
        else
        {
            ds = getShift.SelectShift(Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["LevelRights"]), 0);
            ViewState["vs_Shifts"] = ds;
        }
        foreach (DataRow drRow in ds.Tables[0].Rows)
        {
            switch (drRow["Shift_Name"].ToString())
            {
                case "No Shift":
                    drRow["Shift_Name"] = rm.GetString("Caption_NoShift", ci);
                    break;
            }
        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            this.ddlShift.DataSource = ds;
            this.ddlShift.DataTextField = "Shift_Name";
            this.ddlShift.DataValueField = "Shift_Id";
            this.ddlShift.DataBind();
        }
        ListItem lstItem = new ListItem();
        lstItem.Value = "0";
        lstItem.Text = rm.GetString("ExportData_All", ci);
        ddlShift.Items.Insert(0, lstItem);
        BindDropDownTitle(ddlShift);
    }
    /// <summary>
    /// Validate the FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateFromDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            if (Session["MDateFormat"] != null)
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            }
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            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
            {
                base.Message(rm.GetString("Alert_EnterValidFromDate", ci));
                e.IsValid = false;
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    /// <summary>
    /// Validate the ToDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateToDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            if (Session["MDateFormat"] != null)
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            }
            strTodate = txtToDate.Text;
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            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
            {
                base.Message(rm.GetString("Alert_EnterValidToDate", ci));
                e.IsValid = false;
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    /// <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;
            if (Session["MDateFormat"] != null)
            {
                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
            {
                base.Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci));
                e.IsValid = false;
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lblFilter.Text = rm.GetString("lblFilter", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblLateEntryReport.Text = rm.GetString("Menu_Reports_Entries", ci);
        lblShift.Text = rm.GetString("Menu_Reports_Shift", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeCL", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeCLId", 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);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Alert_SelectShift", 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);
        btnSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        lblDateFilter.Text = rm.GetString("lbl_DateFilter", ci);
        btn_Export.Text = "&nbsp;&nbsp;" + rm.GetString("btn_ExporttoExcel", ci);
        rbCustom.Text = rm.GetString("rb_Custom", ci);
        rbpreviousMonth.Text = rm.GetString("rb_PreviousMonth", ci);
        rbpreviousweek.Text = rm.GetString("rb_PreviousWeek", ci);
        rbThisMonth.Text = rm.GetString("rb_ThisMonth", ci);
        rbThisweek.Text = rm.GetString("rb_ThisWeek", ci);
        lblReportType.Text = rm.GetString("EmployeeInOutReportType", ci);
        rbtAll.Text = rm.GetString("ExportData_All", ci);
        rbtlatein.Text = rm.GetString("Dashboard_Late", ci);
        rbtEarlyExit.Text = rm.GetString("Report_Early_Exit", ci);
        rbtEarlyEntry.Text = rm.GetString("Report_EarlyEntry", ci);
        rbtLateExit.Text = rm.GetString("Report_Late_Exit", ci);
        rbtNormalReport.Text = rm.GetString("lbl_NormalReport", ci);
        rbtGraphReport.Text = rm.GetString("lbl_GraphReport", ci);
        lblExceptionHrs.Text = rm.GetString("lblExceptionHrs", ci);
    }
    /// <summary>
    /// To get the rights for the logged in user
    /// </summary>
    private void UserRights()
    {
        if (ViewState["vs_Checkuser"] != null)
            ds_Checkuser = (DataSet)ViewState["vs_Checkuser"];
        else
        {
            ds_Checkuser = objCheckUser.checkRights(37, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
            ViewState["vs_Checkuser"] = ds_Checkuser;
        }
        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 Late Entry report
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {

        if (hdnEmpID != "" & HdnReportName == "LateEntry" & HdnFrom != "" & HdnTo != "")
        {
            hdnEmpID = Convert.ToString(Session["hdnEmpID"]);
            HdnReportName = Convert.ToString(Session["HdnReportName"]);
            HdnFrom = Convert.ToString(Session["HdnFrom"]);
            HdnTo = Convert.ToString(Session["HdnTo"]);
            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'>";

            Response.Redirect("TA_UI_Report_LateInGrid.aspx?EmpID=" + hdnEmpID + "&HdnFrom=" + HdnFrom + "&ReportName=" + HdnReportName);

            strScript = strScript + "</script>";
            Response.Write(strScript);

        }
        else if (hdnEmpID != "" & HdnReportName == "Absent" & HdnFrom != "" & HdnTo != "")
        {

            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'>";
            Response.Redirect("TA_UI_Report_LateInGrid.aspx");
            Response.Write(strScript);
        }
        else if (hdnEmpID != "" & HdnReportName == "EarlyExit" & HdnFrom != "" & HdnTo != "")
        {
            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'>";
            Response.Redirect("TA_UI_Report_LateInGrid.aspx");
            Response.Write(strScript);

        }



        try
        {


            if (Page.IsValid == true)
            {
                GetAndSetFieldValues();
                DataSet ds = new DataSet();
                ds = GetData("");
                if (ds.Tables["Table"] == null || ds.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                ParenetLevelid = Convert.ToInt16(Session["parentLevelId"]).ToString();
                strReportType = "Normal";
                Session["Path"] = Server.MapPath(rm.GetString("rptLateEntry", ci));
                if (rbtNormalReport.Checked == true)
                {
                    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'>";
                    if (rbtlatein.Checked)
                        Response.Redirect("TA_UI_Report_LateInGrid.aspx?EmpID=" + empId + "&MinExceptHours=" + MinExceptkHours + "&ReportName=" + ReportName + "&From=" + dtFrom + "&To=" + dtTo + "&EmpName=" + employeeName + "&Shift=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&ReportType=" + strReportType + "&employeeCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&employeeType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelid=" + ParenetLevelid + "&userGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&gradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + empId + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&EmpAutoID=" + Convert.ToInt64(strEmpAutoId));
                    else if (rbtEarlyExit.Checked)
                        Response.Redirect("TA_UI_Report_EarlyExitGrid.aspx?EmpID=" + empId + "&MinExceptHours=" + MinExceptkHours + "&From=" + dtFrom + "&To=" + dtTo + "&EmpName=" + employeeName + "&Shift=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&employeeCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&employeeType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + ParenetLevelid + "&userGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&gradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&ReportType=" + strReportType + "&SwipeCard=" + empId + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue);
                    else if (rbtAll.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=Exception&dtFrom=" + dtFrom + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + empId + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    else if (rbtEarlyEntry.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=EarlyEntry&dtFrom=" + dtFrom + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + empName + "&Level=" + ParenetLevelid + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]) + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&Normal=" + strReportType + "&SwipeCard=" + empId + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    else if (rbtLateExit.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=LateExit&dtFrom=" + dtFrom + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + empId + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    strScript = strScript + "</script>";
                    Response.Write(strScript);
                }
                else
                {
                    DataTable dtLevelName = new DataTable();
                    if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                        dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
                    string strreportHeader = "";
                    if (dtLevelName.Rows.Count > 0)
                        strreportHeader = Convert.ToString(dtLevelName.Rows[0][0]);
                    else
                        strreportHeader = "";
                    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'>";
                    if (rbtlatein.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_Graphical_View.aspx?ReportName=LateEntry&dtFrom=" + Convert.ToString(txtFromDate.Text) + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + Convert.ToString(txtToDate.Text) + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]) + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&ReportHeaderName=" + strreportHeader + "','','left=10px, top=60px, width=1200px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    else if (rbtEarlyExit.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_Graphical_View.aspx?ReportName=EarlyExit&dtFrom=" + Convert.ToString(txtFromDate.Text) + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + Convert.ToString(txtToDate.Text) + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]) + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&ReportHeaderName=" + strreportHeader + "','','left=10px, top=60px, width=1200px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    else if (rbtEarlyEntry.Checked)
                        strScript = strScript + "window.open('TA_UI_Report_Graphical_View.aspx?ReportName=EarlyEntry&dtFrom=" + Convert.ToString(txtFromDate.Text) + "&MinExceptHours=" + MinExceptkHours + "&dtTo=" + Convert.ToString(txtToDate.Text) + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]) + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&ReportHeaderName=" + strreportHeader + "','','left=10px, top=60px, width=1200px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    strScript = strScript + "</script>";
                    Response.Write(strScript);
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                string employeeName = string.Empty;
                string empName = "", empId = "";
                string Level = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = txtEmployeeName.Text.ToString();
                    empId = txtEmployeeId.Text.Trim().ToString();
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                    if (Level.Contains(","))
                    {
                        Level = Level.Replace(",", "~");
                    }
                    if (employeeName.Contains(","))
                    {
                        employeeName = employeeName.Replace(",", "~");
                    }
                    if (empId.Contains(","))
                    {
                        empId = empId.Replace(",", "~");
                    }
                }
                StringBuilder strFilters = new StringBuilder();
                string ReportType = "";
                if (rbtlatein.Checked)
                {
                    ReportType = "LateEntry";
                    Session["LateReportName"] = "LateEntry";
                    strFilters.Append("@FromDate=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeID=" + empId + ",");
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@EmployeeName=" + employeeName + ",");
                    strFilters.Append("@LevelID=" + "0,");
                    strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                    strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                    strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                    strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                    strFilters.Append("@EmpSwipeCard=" + EmployeeId + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]).ToString() + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@ExportType=1,");
                    strFilters.Append("@MINExceptionHOURS=" + Convert.ToString(txtMinExceptionHours.Text) + ",");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0");
                }
                else if (rbtEarlyExit.Checked)
                {
                    ReportType = "EarlyExit";
                    Session["LateReportName"] = "EarlyExit";
                    strFilters.Append("@fromDat=" + " Duration_From " + ",");
                    strFilters.Append("@ToDat=" + " Duration_To " + ",");
                    strFilters.Append("@empId=" + empId + ",");
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@EmployeeName=" + employeeName + ",");
                    strFilters.Append("@LevelID=" + "0,");
                    strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                    strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                    strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                    strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                    strFilters.Append("@EmpSwipeCard=" + EmployeeId + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]).ToString() + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@ExportType=1,");
                    strFilters.Append("@MINExceptionHOURS=" + Convert.ToString(txtMinExceptionHours.Text) + ",");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0");
                }
                else if (rbtEarlyEntry.Checked)
                {
                    ReportType = "EarlyEntry";
                    Session["LateReportName"] = "EarlyEntry";
                    strFilters.Append("@FromDate=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeID=" + empId + ",");
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@EmployeeName=" + employeeName + ",");
                    strFilters.Append("@LevelID=" + Level + ",");
                    strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                    strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                    strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                    strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                    strFilters.Append("@EmpSwipeCard=" + EmployeeId + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]) + ",");
                    strFilters.Append("@DesignationID=0,");
                    strFilters.Append("@ExportType=1,");
                    strFilters.Append("@MINExceptionHOURS=" + Convert.ToString(txtMinExceptionHours.Text) + ",");
                    strFilters.Append("@Gender=Both,");
                    strFilters.Append("@EmpAutoId=0");
                }
                else if (rbtLateExit.Checked)
                {
                    ReportType = "LateExit";
                    Session["LateReportName"] = "LateExit";
                    strFilters.Append("@fromDat=" + " Duration_From " + ",");
                    strFilters.Append("@ToDat=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeId=" + empId + ",");
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@EmployeeName=" + employeeName + ",");
                    strFilters.Append("@LevelID= " + Level + ",");
                    strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                    strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                    strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                    strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                    strFilters.Append("@EmpSwipeCard=" + EmployeeId + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]).ToString() + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@ExportType=1,");
                    strFilters.Append("@MINExceptionHOURS=" + Convert.ToString(txtMinExceptionHours.Text) + ",");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0");
                }
                else
                {
                    ReportType = "All";
                    Session["LateReportName"] = "All";
                    strFilters.Append("@FromDate=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeID=" + empId + ",");
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@EmployeeName=" + employeeName + ",");
                    strFilters.Append("@LevelID= " + Level + ",");
                    strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                    strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                    strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                    strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                    strFilters.Append("@EmpSwipeCard=" + EmployeeId + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]).ToString() + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@ExportType=1,");
                    strFilters.Append("@MINExceptionHOURS=" + Convert.ToString(txtMinExceptionHours.Text) + ",");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0");
                }
                Session["hdnReportFilters"] = string.Empty;
                Session["hdnReportFilters"] = strFilters;
                string strScript = "<script language=\"javascript\">";                //
                strScript = strScript + "{window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnFilters').value='" + strFilters + "'; window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnCompanyId').value='" + Convert.ToInt32(Session["parentLevelId"]).ToString() + "';window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnReportType').value='" + ReportType + "'}";
                //strScript = strScript + "self.close();";
                strScript = strScript + "parent.$('#myModalReport').modal('hide');";
                strScript = strScript + "</script>";
                Response.Write(strScript);
            }
        }
        catch
        {
            //
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string strMsg;
        strMsg = "<script language='javascript'>";
        strMsg = strMsg + "parent.$('#myModalReport').modal('hide');";
        strMsg = strMsg + "</script>";
        Page.RegisterStartupScript("close report window", strMsg);
        return;
    }
    private void GetAndSetFieldValues()
    {
        if (Session["ReportsBasedOn"] != null)
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False")
                strEmpAutoId = "0";
            else
                strEmpAutoId = Convert.ToString(Session["EmpAutoID"]);
        }
        shft = Convert.ToInt16(this.ddlShift.SelectedValue);
        if (txtFromDate.Text != "")
            dtFrom = strFromdate;
        if (txtToDate.Text != "")
            dtTo = strTodate;
        if (intIndividualUser >= 1)
        {
            empName = string.Empty;
            Level = string.Empty;
            empId = Convert.ToString(Session["EmployeeCodeId"]);
        }
        else
        {
            empName = Convert.ToString(txtEmployeeName.Text);
            empId = Convert.ToString(txtEmployeeId.Text).Trim();
            employeeName = this.txtEmployeeName.Text.Replace("'", "''");
            Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
            gStrLevel = Level;
        }
        MinExceptkHours = Convert.ToString(txtMinExceptionHours.Text);
    }
    public void redirectToExportPage(DataSet ds, string reportName)
    {
        Session["Export_ExcelData"] = ds;
        Response.Redirect("Excel_Export.aspx?ReportName=" + reportName + "&FrmDate=" + Convert.ToString(txtFromDate.Text) + "&toDate=" + Convert.ToString(txtToDate.Text) + "");
    }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                GetAndSetFieldValues();
                DataSet ds = new DataSet();
                ds = GetData("Export");
                if (ds.Tables["Table"] == null || ds.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    if (rbtlatein.Checked)
                        redirectToExportPage(ds, "Late Entry");
                    if (rbtEarlyExit.Checked)
                        redirectToExportPage(ds, "Early Exit");
                    if (rbtEarlyEntry.Checked)
                        redirectToExportPage(ds, "Early Entry");
                    if (rbtLateExit.Checked)
                        redirectToExportPage(ds, "Late Exit");
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    private DataSet GetData(string whichbtn)
    {
        DataSet dsEmp = new DataSet();
        if (rbtlatein.Checked)
        {
            dsEmp = rptEmp.SelectLateInstanceReport(empId, Level, dtFrom, dtTo, employeeName, Convert.ToInt16(this.ddlShift.SelectedValue), Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), empId, Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, Convert.ToInt64(strEmpAutoId), 1, MinExceptkHours);
        }
        else if (rbtEarlyExit.Checked)
        {
            dsEmp = rptEmp.SelectEarlyOutReportNew(dtFrom, dtTo, empId, Convert.ToInt16(this.ddlShift.SelectedValue), employeeName, Level, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), empId, Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, 1, MinExceptkHours, Convert.ToInt32(Session["EmpAutoID"]));
        }
        else if (rbtEarlyEntry.Checked)
        {
            dsEmp = rptEmp.SelectEarlyEntryReport(empId, Level, dtFrom, dtTo, employeeName, shft, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), empId, Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, 1, MinExceptkHours, Convert.ToInt32(Session["EmpAutoID"]));
        }
        else if (rbtLateExit.Checked)
        {
            dsEmp = rptEmp.SelectLateExit(dtFrom, dtTo, empId, shft, employeeName, Level, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), empId, Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, MinExceptkHours, Convert.ToInt32(Session["EmpAutoID"]));
        }
        else
        {
            dsEmp = rptEmp.SelectExceptionReport(empId, Level, dtFrom, dtTo, employeeName, shft, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), "", Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, MinExceptkHours, Convert.ToInt32(strEmpAutoId));
        }
        return dsEmp;
    }
    #endregion
    #region Export Excel
    protected void ExportExcel(DataSet dsEmp)
    {
        HSSFWorkbook workbook = new HSSFWorkbook();
        DataTable dtLevelName = new DataTable();
        if (Convert.ToInt16(Session["parentLevelId"]) != 0)
        {
            dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
        }
        if (rbtlatein.Checked)
        {
            SheetName = "Late Entry Report";
            ReportName = "LateEntryReport";
            Cellvalcount = 11;
        }
        else if (rbtEarlyExit.Checked)
        {
            SheetName = "Early Exit Report";
            ReportName = "EarlyExitReport";
            Cellvalcount = 11;
        }
        else if (rbtEarlyEntry.Checked)
        {
            SheetName = "Early Entry Report";
            ReportName = "EarlyEntryReport";
            Cellvalcount = 10;
        }
        else if (rbtLateExit.Checked)
        {
            SheetName = "Late Exit Report";
            ReportName = "LateExitReport";
            Cellvalcount = 10;
        }
        string NewTimeFormat = string.Empty;
        string TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        if (TimeFormat == "HH:mm")
        {
            NewTimeFormat = "HH:mm";
        }
        else
        {
            NewTimeFormat = "hh:mm tt";
        }
        sheet = workbook.CreateSheet(SheetName);
        int rowIndex = 0;
        NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
        HSSFFont hFont = (HSSFFont)workbook.CreateFont();
        hFont.Boldweight = (short)FontBoldWeight.Bold;
        hFont.Color = HSSFColor.Maroon.Index;
        hFont.FontHeightInPoints = 10;
        HSSFCellStyle hStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        hStyle.SetFont(hFont);
        hStyle.FillForegroundColor = IndexedColors.White.Index;
        hStyle.FillPattern = FillPattern.SolidForeground;
        hStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
        HSSFCellStyle MainHStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        MainHStyle.SetFont(hFont);
        MainHStyle.Alignment = HorizontalAlignment.Center;
        HSSFCellStyle IStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        IStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
        if (dtLevelName.Rows.Count > 0)
        {
            row.CreateCell(0).SetCellValue(Convert.ToString(dtLevelName.Rows[0][0]));
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, Cellvalcount));
            row.GetCell(0).CellStyle = MainHStyle;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
        }
        row.CreateCell(0).SetCellValue(SheetName + " From - " + Convert.ToString(txtFromDate.Text) + " - " + " To - " + Convert.ToString(txtToDate.Text));
        row.GetCell(0).CellStyle = MainHStyle;
        sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, Cellvalcount));
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        if (rbtlatein.Checked || rbtEarlyEntry.Checked)
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee ID");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Level");
            row.CreateCell(4).SetCellValue("Designation");
            row.CreateCell(5).SetCellValue("Gender");
            row.CreateCell(6).SetCellValue("Date");
            row.CreateCell(7).SetCellValue("Shift Short Name");
            if (rbtEarlyEntry.Checked)
            {
                row.CreateCell(8).SetCellValue("Shift In Time");
                row.CreateCell(9).SetCellValue("Actual In Time");
                row.CreateCell(10).SetCellValue("Early by Hrs");
            }
            else
            {
                row.CreateCell(8).SetCellValue("Shift Start Time");
                row.CreateCell(9).SetCellValue("Actual In Time");
                row.CreateCell(10).SetCellValue("Late by Hrs");
            }
            if (rbtlatein.Checked)
                row.CreateCell(11).SetCellValue("Reason");
            //row.RowStyle = hStyle;
            for (int i = 0; i <= Cellvalcount; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
            }
            rowIndex++;
            string strPre = string.Empty;
            double ValCount = 0.0;
            int CountDays = 0;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                if (strPre != string.Empty)
                {
                    if (strPre != Convert.ToString(DR["CardNo"]))
                    {
                        row = sheet.CreateRow(rowIndex);
                        row.CreateCell(9).SetCellValue("Sub Total");
                        row.GetCell(9).CellStyle = hStyle;
                        result = TimeSpan.FromMinutes(ValCount);
                        fromTimeString = result.ToString();
                        row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
                        row.GetCell(10).CellStyle = hStyle;
                        if (rbtlatein.Checked)
                        {
                            row.CreateCell(11).SetCellValue("");
                            row.GetCell(11).CellStyle = hStyle;
                        }
                        ValCount = 0.0;
                        CountDays = 0;
                        rowIndex++;
                    }
                }
                row = sheet.CreateRow(rowIndex);
                //row.CreateCell(0).SetCellValue(Convert.ToString(DR["Sl.No"]));
                if (strPre == string.Empty || strPre != Convert.ToString(DR["CardNo"]))
                {
                    SlNo++;
                    row.CreateCell(0).SetCellValue(SlNo);
                }
                else
                {
                    row.CreateCell(0).SetCellValue("");
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["CardNo"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee Name"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["Level Name"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["Designation"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["Date"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["shift_shortName"]));
                if (Convert.ToString(DR["Shift_StartTime"]) == String.Empty)
                    row.CreateCell(8).SetCellValue(Convert.ToString(DR["Shift_StartTime"]));
                else
                {
                    row.CreateCell(8).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["Shift_StartTime"]))).ToString(NewTimeFormat));
                }
                if (Convert.ToString(DR["InTime"]) == String.Empty)
                    row.CreateCell(9).SetCellValue(Convert.ToString(DR["InTime"]));
                else
                {
                    row.CreateCell(9).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["InTime"]))).ToString(NewTimeFormat));
                }
                if (rbtEarlyEntry.Checked)
                    row.CreateCell(10).SetCellValue(Convert.ToString(DR["earlyby"]));
                else
                    row.CreateCell(10).SetCellValue(Convert.ToString(DR["LateBy"]));
                if (rbtlatein.Checked)
                    row.CreateCell(11).SetCellValue(Convert.ToString(DR["Reason"]));
                if (rbtEarlyEntry.Checked)
                    ValCount = ValCount + Convert.ToDouble(DR["earlyInMins"]);
                else
                    ValCount = ValCount + Convert.ToDouble(DR["LateInMins"]);
                CountDays++;
                strPre = Convert.ToString(DR["CardNo"]);
                for (int i = 0; i <= Cellvalcount; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
            }
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(9).SetCellValue("Sub Total");
            row.GetCell(9).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ValCount);
            row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
            row.GetCell(10).CellStyle = hStyle;
            if (rbtlatein.Checked)
            {
                row.CreateCell(11).SetCellValue("");
                row.GetCell(11).CellStyle = hStyle;
            }
            ValCount = 0.0;
            CountDays = 0;
            rowIndex++;
        }
        else if (rbtEarlyExit.Checked)
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee ID");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Level");
            row.CreateCell(4).SetCellValue("Designation");
            row.CreateCell(5).SetCellValue("Gender");
            row.CreateCell(6).SetCellValue("Date");
            row.CreateCell(7).SetCellValue("Shift Short Name");
            row.CreateCell(8).SetCellValue("Shift Out Time");
            row.CreateCell(9).SetCellValue("Actual Shift Out Time");
            row.CreateCell(10).SetCellValue("Early by");
            row.CreateCell(11).SetCellValue("Reason");
            //row.RowStyle = hStyle;
            for (int i = 0; i <= 11; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
            }
            rowIndex++;
            string strPre = string.Empty;
            double ValCount = 0.0;
            int CountDays = 0;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                if (strPre != string.Empty)
                {
                    if (strPre != Convert.ToString(DR["Employee_Code_Id"]))
                    {
                        row = sheet.CreateRow(rowIndex);
                        row.CreateCell(9).SetCellValue("Sub Total");
                        row.GetCell(9).CellStyle = hStyle;
                        result = TimeSpan.FromMinutes(ValCount);
                        row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
                        row.GetCell(10).CellStyle = hStyle;
                        row.CreateCell(11).SetCellValue("");
                        row.GetCell(11).CellStyle = hStyle;
                        ValCount = 0.0;
                        CountDays = 0;
                        rowIndex++;
                    }
                }
                row = sheet.CreateRow(rowIndex);
                //row.CreateCell(0).SetCellValue(Convert.ToString(DR["Sl.No"]));
                if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
                {
                    SlNo++;
                    row.CreateCell(0).SetCellValue(SlNo);
                }
                else
                {
                    row.CreateCell(0).SetCellValue("");
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_FirstName"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["LevelName"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["TitleName"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["Date"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["shift_shortName"]));
                if (Convert.ToString(DR["shiftOut"]) == String.Empty)
                    row.CreateCell(8).SetCellValue(Convert.ToString(DR["shiftOut"]));
                else
                {
                    row.CreateCell(8).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["shiftOut"]))).ToString(NewTimeFormat));
                }
                if (Convert.ToString(DR["OutTime"]) == String.Empty)
                    row.CreateCell(9).SetCellValue(Convert.ToString(DR["OutTime"]));
                else
                {
                    row.CreateCell(9).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["OutTime"]))).ToString(NewTimeFormat));
                }
                row.CreateCell(10).SetCellValue(Convert.ToString(DR["EarlyOut"]));
                row.CreateCell(11).SetCellValue(Convert.ToString(DR["Reason"]));
                ValCount = ValCount + Convert.ToDouble(DR["EarlyOutMins"]);
                CountDays++;
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                for (int i = 0; i <= 11; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
            }
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(9).SetCellValue("Sub Total");
            row.GetCell(9).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ValCount);
            string fromTimeString = result.ToString();
            row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
            row.GetCell(10).CellStyle = hStyle;
            row.CreateCell(11).SetCellValue("");
            row.GetCell(11).CellStyle = hStyle;
            ValCount = 0.0;
            CountDays = 0;
            rowIndex++;
        }
        else if (rbtLateExit.Checked)
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee ID");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Level");
            row.CreateCell(4).SetCellValue("Designation");
            row.CreateCell(5).SetCellValue("Gender");
            row.CreateCell(6).SetCellValue("Date");
            row.CreateCell(7).SetCellValue("Shift Short Name");
            row.CreateCell(8).SetCellValue("Shift Out Time");
            row.CreateCell(9).SetCellValue("Actual Out Time");
            row.CreateCell(10).SetCellValue("Extra Hours");
            //row.RowStyle = hStyle;
            for (int i = 0; i <= 10; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
            }
            rowIndex++;
            string strPre = string.Empty;
            double ValCount = 0.0;
            int CountDays = 0;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                if (strPre != string.Empty)
                {
                    if (strPre != Convert.ToString(DR["Employee_Code_Id"]))
                    {
                        row = sheet.CreateRow(rowIndex);
                        row.CreateCell(9).SetCellValue("Sub Total");
                        row.GetCell(9).CellStyle = hStyle;
                        result = TimeSpan.FromMinutes(ValCount);
                        row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
                        row.GetCell(10).CellStyle = hStyle;
                        ValCount = 0.0;
                        CountDays = 0;
                        rowIndex++;
                    }
                }
                row = sheet.CreateRow(rowIndex);
                //row.CreateCell(0).SetCellValue(Convert.ToString(DR["Sl.No"]));
                if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
                {
                    SlNo++;
                    row.CreateCell(0).SetCellValue(SlNo);
                }
                else
                {
                    row.CreateCell(0).SetCellValue("");
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["empName"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["Level Name"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["TitleName"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["Date"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["shift_shortName"]));
                if (Convert.ToString(DR["shiftOut"]) == String.Empty)
                    row.CreateCell(8).SetCellValue(Convert.ToString(DR["shiftOut"]));
                else
                {
                    row.CreateCell(8).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["shiftOut"]))).ToString(NewTimeFormat));
                }
                if (Convert.ToString(DR["OutTime"]) == String.Empty)
                    row.CreateCell(9).SetCellValue(Convert.ToString(DR["OutTime"]));
                else
                {
                    row.CreateCell(9).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["OutTime"]))).ToString(NewTimeFormat));
                }
                row.CreateCell(10).SetCellValue(Convert.ToString(DR["hrsExtra"]));
                ValCount = ValCount + Convert.ToDouble(DR["ExtraMins"]);
                CountDays++;
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                for (int i = 0; i <= 10; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
            }
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(9).SetCellValue("Sub Total");
            row.GetCell(9).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ValCount);
            string fromTimeString = result.ToString();
            row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes) + " ( " + CountDays + " Days )");
            row.GetCell(10).CellStyle = hStyle;
            ValCount = 0.0;
            CountDays = 0;
            rowIndex++;
        }
        using (MemoryStream exportData = new MemoryStream())
        {
            workbook.Write(exportData);
            string saveAsFileName = string.Format(ReportName + "-{0:d}.xls", DateTime.Now).Replace("/", "-");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
            Response.Clear();
            Response.BinaryWrite(exportData.GetBuffer());
            Response.End();
        }
    }
    #endregion
}
