using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Reports_TA_UI_Report_Employee : Base.BasePage
{
    #region Variable Declaration
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    HeaderInformation hdrTable = new HeaderInformation();
    GetReports rptEmp = new GetReports();
    Rpt_Common rptcommon = new Rpt_Common();
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    string strFromdate, gstrDateFormat, strTodate;
    int intIndividualUser = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language        
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objCommon.menu("EmployeeReports", "42");
        }
        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"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterToDate", ci) + "');";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", 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 (!Page.IsPostBack)
        {
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();
            FillDesignation();
            ddlDesignation.PreRender += LB_PreRender;
            //txtFromDate.Text = (Convert.ToDateTime(objCommon.CurrentMonthStartDate())).ToString(Convert.ToString(Session["MDateFormat"]));
            txtToDate.Text = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Convert.ToString(Session["MDateFormat"]));
            if (Session["parentLevelId"] != null || Convert.ToInt16(Session["parentLevelId"]) != 0)
            {
                Session["parentLevelId"] = null;
            }
        }
        //Check whether the employee is Individual User
        intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            PlaceHolderEmployees.Controls.Clear();
            divEmployeeDetails.Visible = false;
            lblEmpSwipeCard.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);
    }
    #endregion
    #region User Defined function
    /// <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>
    /// 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
            {
                // base.Message("Select valid From Date");  
                base.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
            {
                // base.Message("Select valid To Date");  
                base.Message(rm.GetString("Alert_SelectvalidToDate", 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
            {
                base.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)
    {
        lblFilter.Text = rm.GetString("lblFilter", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblEmployeeDetailsReport.Text = rm.GetString("Report_Employee_Details", ci);
        lblStatus.Text = rm.GetString("EmployeeMaster_EmployeeStatus", 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);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblEmpSwipeCard.Text = rm.GetString("TerminalDataType_Card_No", ci);
        ddlStatus.Items[0].Text = rm.GetString("ExportData_All", ci);
        ddlStatus.Items[1].Text = rm.GetString("rbtn_EmployeeMaster_Active", ci);
        ddlStatus.Items[2].Text = rm.GetString("rbtn_EmployeeMaster_InActive", ci);
        ddlSwipeOpt.Items[0].Text = rm.GetString("Select", ci);
        ddlSwipeOpt.Items[1].Text = rm.GetString("ExportData_All", ci);
        ddlSwipeOpt.Items[2].Text = rm.GetString("Report_Exists", ci);
        ddlSwipeOpt.Items[3].Text = rm.GetString("Report_NotExists", 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);
        lblDateFilter.Text = rm.GetString("lbl_DateFilter", 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);
        btn_Export.Text = "&nbsp;&nbsp;" + rm.GetString("btn_ExporttoExcel", ci);
    }
    /// <summary>
    /// To check rights for the logged in user
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(42, 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 Event
    /// <summary>
    /// Load the Employee report
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {
        int employeeCategory = 0, employeeType = 0;
        try
        {
            if (Page.IsValid == true)
            {
                //Create the datatable ,that holds the header information
                DataTable dtHdr = new DataTable();
                dtHdr = hdrTable.CreateHeader();
                dtHdr.TableName = "Header";
                //Add the Header information
                DataRow drHdr = dtHdr.NewRow();
                drHdr["Link"] = 1;
                drHdr["Hdr1"] = "Neuland Laboratories Limited";
                drHdr["Hdr2"] = "NEULAND";
                drHdr["Address1"] = "HeadOffice";
                drHdr["Address2"] = "Hyderabad";
                drHdr["ReportName"] = "Early Exit Report";
                if (txtFromDate.Text != "")
                {
                    DateTime tmpFrom = DateTime.Parse(strFromdate);
                    drHdr["FromDate"] = tmpFrom.ToString("dd-MMM-yyyy");
                }
                else
                    drHdr["FromDate"] = "";
                if (txtToDate.Text != "")
                {
                    DateTime tmpTo = DateTime.Parse(strTodate);
                    drHdr["ToDate"] = tmpTo.ToString("dd-MMM-yyyy");
                }
                else
                    drHdr["ToDate"] = "";
                dtHdr.Rows.Add(drHdr);
                string dtFrom = "", dtTo = "";
                if (txtFromDate.Text != "")
                    dtFrom = strFromdate;
                if (txtToDate.Text != "")
                    dtTo = strTodate;
                // 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;
                }
                //Get the Report source from the Server and load this into the report table
                DataSet dsEmp = new DataSet();
                //this is new report
                int shft = 0;
                string Level = string.Empty;
                string employeeName = string.Empty;
                string empName = string.Empty;
                string empId = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    shft = 0;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = Convert.ToString(txtEmployeeName.Text);
                    empId = Convert.ToString(txtEmployeeId.Text.Trim());
                    //shft = Convert.ToInt16(this.ddlShift.SelectedValue);
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    employeeName = employeeName.Replace(' ', '%');
                    //if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                    //{
                    //Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]));
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                    //}
                }
                string EmployeeStatus = Convert.ToString(ddlStatus.SelectedValue);
                string strSwipOpt = "";
                if (ddlSwipeOpt.SelectedIndex != 0)
                {
                    strSwipOpt = ddlSwipeOpt.SelectedValue;
                }
                string strSwipeCard = "";
                strSwipeCard = Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''");
                //dsEmp = rptEmp.SelectEmployee(dtFrom, dtTo, empId, shft, employeeName, Level, employeeCategory, employeeType, EmployeeStatus, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipOpt, strSwipeCard);
                //DataTable dtEmp = new DataTable();
                ////Check the Empty table
                //if (dsEmp.Tables["Table"] == null || dsEmp.Tables["Table"].Rows.Count == 0)
                //{
                //    string strMsg;
                //    strMsg = "<script language='javascript'>";
                //    strMsg = strMsg + "alert('There is no record ');";
                //    strMsg = strMsg + "</script>";
                //    Page.RegisterStartupScript("Display Message", strMsg);
                //    return;
                //}
                //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=edge' />";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=EmployeeDetails&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + shft + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + employeeCategory + "&EmpType=" + employeeType + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]) + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&EmpStatus=" + EmployeeStatus + "&SwipOpt=" + strSwipOpt + "&SwipeCard=" + strSwipeCard + "&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);
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex);
            //
        }
    }
    #endregion

    protected void btn_Export_Click(object sender, EventArgs e)
    {
        int employeeCategory = 0, employeeType = 0;
        try
        {
            if (Page.IsValid == true)
            {
                //Create the datatable ,that holds the header information
                DataTable dtHdr = new DataTable();
                dtHdr = hdrTable.CreateHeader();
                dtHdr.TableName = "Header";
                //Add the Header information
                DataRow drHdr = dtHdr.NewRow();
                drHdr["Link"] = 1;
                drHdr["Hdr1"] = "Neuland Laboratories Limited";
                drHdr["Hdr2"] = "NEULAND";
                drHdr["Address1"] = "HeadOffice";
                drHdr["Address2"] = "Hyderabad";
                drHdr["ReportName"] = "Early Exit Report";
                if (txtFromDate.Text != "")
                {
                    DateTime tmpFrom = DateTime.Parse(strFromdate);
                    drHdr["FromDate"] = tmpFrom.ToString("dd-MMM-yyyy");
                }
                else
                    drHdr["FromDate"] = "";
                if (txtToDate.Text != "")
                {
                    DateTime tmpTo = DateTime.Parse(strTodate);
                    drHdr["ToDate"] = tmpTo.ToString("dd-MMM-yyyy");
                }
                else
                    drHdr["ToDate"] = "";
                dtHdr.Rows.Add(drHdr);
                string dtFrom = "", dtTo = "";
                if (txtFromDate.Text != "")
                    dtFrom = strFromdate;
                if (txtToDate.Text != "")
                    dtTo = strTodate;
                // 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;
                }
                //Get the Report source from the Server and load this into the report table
                DataSet dsEmp = new DataSet();
                //this is new report
                int shft = 0;
                string Level = string.Empty;
                string employeeName = string.Empty;
                string empName = string.Empty;
                string empId = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    shft = 0;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = Convert.ToString(txtEmployeeName.Text);
                    empId = Convert.ToString(txtEmployeeId.Text.Trim());
                    //shft = Convert.ToInt16(this.ddlShift.SelectedValue);
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    employeeName = employeeName.Replace(' ', '%');
                    //if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                    //{
                    //Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]));
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                    //}
                }
                string EmployeeStatus = Convert.ToString(ddlStatus.SelectedValue);
                string strSwipOpt = "";
                if (ddlSwipeOpt.SelectedIndex != 0)
                {
                    strSwipOpt = ddlSwipeOpt.SelectedValue;
                }
                string strSwipeCard = "";
                strSwipeCard = Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''");
                dsEmp = rptEmp.SelectEmployee
                    (
                        dtFrom,
                        dtTo,
                        empId,
                        shft,
                        employeeName,
                        Level,
                        employeeCategory,
                        employeeType,
                        EmployeeStatus,
                        Convert.ToString(Session["UserGroupName"]),
                        Convert.ToString(Session["GradeLevel"]),
                        strSwipOpt,
                        strSwipeCard,
                        Convert.ToInt16(Session["parentLevelId"]),
                        Convert.ToInt32(ddlDesignation.SelectedValue),
                        ddlGender.SelectedValue,
                        Convert.ToInt32(Session["EmpAutoID"])
                     );
                if (dsEmp.Tables["Table"] == null || dsEmp.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    Session["Export_ExcelData"] = dsEmp;
                    if (dsEmp.Tables[0].Columns.Contains("empname"))
                        dsEmp.Tables[0].Columns["empname"].ColumnName = "Employee Name";
                    if (dsEmp.Tables[0].Columns.Contains("employee_id"))
                        dsEmp.Tables[0].Columns["employee_id"].ColumnName = "Employee ID";
                    if (dsEmp.Tables[0].Columns.Contains("TitleName"))
                        dsEmp.Tables[0].Columns["TitleName"].ColumnName = "Designation";
                    if (dsEmp.Tables[0].Columns.Contains("name"))
                        dsEmp.Tables[0].Columns["name"].ColumnName = "Organization Levels";
                    if (dsEmp.Tables[0].Columns.Contains("dateJoin"))
                        dsEmp.Tables[0].Columns["dateJoin"].ColumnName = "Date of Joining";
                    if (dsEmp.Tables[0].Columns.Contains("dateOfBirth"))
                        dsEmp.Tables[0].Columns["dateOfBirth"].ColumnName = "Date of Birth";
                    if (dsEmp.Tables[0].Columns.Contains("Visa_No"))
                        dsEmp.Tables[0].Columns["Visa_No"].ColumnName = "Visa No.";
                    if (dsEmp.Tables[0].Columns.Contains("Visa_expirydate"))
                        dsEmp.Tables[0].Columns["Visa_expirydate"].ColumnName = "Visa Expiry Date";
                    if (dsEmp.Tables[0].Columns.Contains("Passport_No"))
                        dsEmp.Tables[0].Columns["Passport_No"].ColumnName = "Passport No.";
                    if (dsEmp.Tables[0].Columns.Contains("Passport_expirydate"))
                        dsEmp.Tables[0].Columns["Passport_expirydate"].ColumnName = "Passport Expiry Date";
                    if (dsEmp.Tables[0].Columns.Contains("CustomField1"))
                        dsEmp.Tables[0].Columns.Remove("CustomField1");
                    if (dsEmp.Tables[0].Columns.Contains("CustomField2"))
                        dsEmp.Tables[0].Columns.Remove("CustomField2");
                    if (dsEmp.Tables[0].Columns.Contains("empAutoId"))
                        dsEmp.Tables[0].Columns.Remove("empAutoId");
                    if (dsEmp.Tables[0].Columns.Contains("department"))
                        dsEmp.Tables[0].Columns.Remove("department");
                    if (dsEmp.Tables[0].Columns.Contains("Report_Exclude"))
                        dsEmp.Tables[0].Columns.Remove("Report_Exclude");
                    Response.Redirect("Excel_Export.aspx?ReportName=Employee Detail&FrmDate=" + Convert.ToString(txtFromDate.Text) + "&toDate=" + Convert.ToString(txtToDate.Text) + "");
                    //ExportExcel(dsEmp);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex);
            //
        }
    }
}
