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 System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.Util;
using DevExpress.Web;

public partial class Reports_TA_UI_Report_EmployeeInOut : Base.BasePage
{
    #region Variable Declaration
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    GetReports rptEmp = new GetReports();
    Rpt_Common rptcommon = new Rpt_Common();
    ResourceManager rm;
    cls_Common objCommon = new cls_Common();
    CultureInfo ci;
    int intIndividualUser = 0;
    string strFromdate, gstrDateFormat, strTodate;
    EmployeeEventData objEmployee = new EmployeeEventData();
    HeaderInformation hdrTable = new HeaderInformation();
    int ColCount = 0, EndCount = 0, rowCountval = 0;
    string sheetName, reportName = "";
    NPOI.SS.UserModel.IRow row;
    HSSFFont hFont;
    HSSFCellStyle hStyle;
    HSSFCellStyle MainHStyle;
    HSSFCellStyle IStyle;
    HSSFFont hFont1;
    HSSFCellStyle hStyle1;
    NPOI.SS.UserModel.IRow row1;
    DataSet dsEmp = new DataSet();
    ISheet sheet1;
    HSSFWorkbook workbook;
    ISheet sheet;
    int rowIndex1 = 0, day = 0;
    int employeeCategory = 0, employeeType = 0;
    string empName = "", empId = "", Level = "", strScript = "", strReportType = string.Empty, ParenetLevelid = string.Empty;
    string strSwipeCard = "", strdtFromDate, strdtToDate, SelectedMonth = "", SelectedYear = "";
    DateTime dtFromDate1, dtToDate1;
    string strEmpAutoId = string.Empty;
    TimeSpan diff;
    #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)
    {
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objCommon.menu("Attendance Reports", "105");
        }
        //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"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterDate", ci) + "','" + rm.GetString("Alert_EnterToDate", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //Set UserRights
        gvData.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        gvDataDetailed.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        UserRights();
        if (ViewState["musterSummary"] != null)
        {
            gvData.DataSource = (DataSet)ViewState["musterSummary"];
            gvData.DataBind();
        }
        if (ViewState["musterDetailed"] != null)
        {
            gvDataDetailed.DataSource = (DataSet)ViewState["musterDetailed"];
            gvDataDetailed.DataBind();
        }
        if (!IsPostBack)
        {
            if (Request.QueryString["Source"] != null)
            {
                if (Convert.ToString(Request.QueryString["Source"]) == "Email")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                    lnkbtnGrid.Visible = false;
                }
            }
            else
            {
                string strScript = "";
                divdateTime.Visible = true;
                trView.Visible = true;
                trSave.Visible = false;
                strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "document.getElementById('ctl00_BodyContentPH_Modifylevel').style.display = 'none';";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("Script", strScript);
            }
            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);
                DataSet ds = new DataSet();
                ds = rptEmp.GetEmailSchedulerFilterDetails(Convert.ToInt32(Request.QueryString["ScheduleId"]));
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        txtEmployeeId.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeId"]);
                        txtEmployeeName.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeName"]);
                        ddlEmpCatagory.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeCategory"]);
                        ddlEmpType.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeType"]);
                        txtSwipeCard.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmpSwipeCard"]);
                        ddlDesignation.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["DesignationID"]);
                        ddlGender.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Gender"]);
                        Session["EMailParentId"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentID"]);
                        rbReportType.SelectedValue = Convert.ToString(ds.Tables[1].Rows[0][0]);
                        rbReportType_SelectedIndexChanged(sender, e);
                        //Session["parentLevelId_modify"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentId"]);
                    }
                }
            }
            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];
                    }
                    txtEmployeeName.Text = Convert.ToString(strArray1[3]).Replace("~", ",");
                    txtEmployeeId.Text = Convert.ToString(strArray1[2]).Replace("~", ",");
                    ddlEmpCatagory.SelectedValue = Convert.ToString(strArray1[5]);
                    ddlEmpType.SelectedValue = Convert.ToString(strArray1[6]);
                    ddlDesignation.SelectedValue = Convert.ToString(strArray1[11]);
                    ddlGender.SelectedValue = Convert.ToString(strArray1[12]);
                    Session["EMailParentId"] = Convert.ToInt16(strArray1[10]);
                    rbReportType.SelectedValue = Convert.ToString(Session["ReportTypeID"]);
                    rbReportType_SelectedIndexChanged(sender, e);
                }
            }
            if (Session["parentLevelId"] != null || Convert.ToInt16(Session["parentLevelId"]) != 0)
                Session["parentLevelId"] = null;
            //Included by A.Amsaveni on 18/07/2013
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            txtFromDate.Text = (Convert.ToDateTime(objCommon.CurrentMonthStartDate())).ToString(Convert.ToString(Session["MDateFormat"]));
            txtToDate.Text = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Convert.ToString(Session["MDateFormat"]));
            int ToYear = Convert.ToInt32(DateTime.Now.Year);
            int FromYear = Convert.ToInt32(DateTime.Now.Year) - 20;
            for (int i = ToYear; i >= FromYear; i--)
            {
                ListItem LI = new ListItem();
                LI.Value = Convert.ToString(i);
                LI.Text = Convert.ToString(i);
                ddlYear.Items.Add(LI);
            }
            ListItem liSelect = new ListItem();
            liSelect.Value = "Select";
            liSelect.Text = rm.GetString("Select", ci);
            ddlYear.Items.Insert(0, liSelect);
            ddlMonth.SelectedValue = Convert.ToString(DateTime.Today.Month);
            ddlYear.SelectedValue = Convert.ToString(DateTime.Today.Year);
            BindingEmployeeCategoryandType();
            BindDesignation();
            BindReportBy();
            ddlDesignation.PreRender += LB_PreRender;
        }
        else
        {
            if (Request.QueryString["Source"] != null)
            {
                if (Convert.ToString(Request.QueryString["Source"]) == "Email")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                }
            }
            else
            {
                divdateTime.Visible = true;
                trView.Visible = true;
                trSave.Visible = false;
            }
        }
        //Check whether the employee is Individual User
        if (ViewState["vs_intIndividualUser"] == null)
        {
            intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
            ViewState["vs_intIndividualUser"] = intIndividualUser;
        }
        else
        {
            intIndividualUser = (int)ViewState["vs_intIndividualUser"];
        }
        if (intIndividualUser >= 1)
        {
            PlaceHolderDetailedAttendance.Controls.Clear();
            divEmployeeDetails.Visible = false;
            lblEmpSwipe.Visible = false;
            txtSwipeCard.Visible = false;
        }
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromdate = txtFromDate.Text;
        strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
        strTodate = txtToDate.Text;
        strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
        if (Convert.ToString(Page.MasterPageFile) == "TA_Popup_Report_MasterPage.master")
        {
            conHeader.Visible = false;
        }
    }
    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 BindDesignation()
    {
        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();
            BindTitle(ddlDesignation);
        }
    }
    /// <summary>
    /// Bindings the employee category and type.
    /// </summary>
    private void BindingEmployeeCategoryandType()
    {
        EmployeeEventData objEmployee = new EmployeeEventData();
        // 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();
            BindTitle(ddlEmpCatagory);
        }
        // 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();
            BindTitle(ddlEmpType);
        }
    }
    private void BindTitle(DropDownList ddl)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    /// <summary>
    /// To get the label names according to the language selected.
    /// </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);
        lblReport.Text = rm.GetString("Mustor_roll", 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);
        btnSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        lblTimePeriod.Text = rm.GetString("Reports_TimePeriod", ci);
        lblFrom.Text = rm.GetString("email_FromDate", ci);
        lblTo.Text = rm.GetString("email_ToDate", ci);
        lblreportby.Text = rm.GetString("lblreportby", ci);
        lblReportType.Text = rm.GetString("EmployeeInOutReportType", ci);
        rbReportType.Items[0].Text = rm.GetString("EmployeeInOutSummary", ci);
        rbReportType.Items[1].Text = rm.GetString("EmployeeInOutDetails", 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);
        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);




    }
    /// <summary>
    /// To check the user rights for the logged in user
    /// </summary>
    private void UserRights()
    {
        if (ViewState["vsUserRights"] != null)
            ds_Checkuser = (DataSet)ViewState["vsUserRights"];
        else
            ds_Checkuser = objCheckUser.checkRights(105, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            ViewState["vsUserRights"] = ds_Checkuser;
            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
    private void GetAndSetFieldValues()
    {
        strSwipeCard = Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''");
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strdtFromDate = txtFromDate.Text;
        strdtToDate = txtToDate.Text;
        strdtFromDate = objCommon.DateConvertion(gstrDateFormat, strdtFromDate);
        strdtToDate = objCommon.DateConvertion(gstrDateFormat, strdtToDate);
        if (strdtFromDate != string.Empty && strdtToDate != string.Empty)
        {
            dtFromDate1 = Convert.ToDateTime(strdtFromDate).Date;
            dtToDate1 = DateTime.Parse(strdtToDate);
            diff = dtToDate1.Subtract(dtFromDate1);
            day = diff.Days;
        }
        day = day + 1;
        if (day > 31)
        {
            base.Message("Selected Date range should not exceed 31 Days");
            return;
        }
        if (intIndividualUser >= 1)
        {
            empName = string.Empty;
            empId = Convert.ToString(Session["EmployeeCodeId"]);
        }
        else
        {
            empName = Convert.ToString(txtEmployeeName.Text);
            empId = Convert.ToString(txtEmployeeId.Text).Trim();
            Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
        }
        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;
        SelectedMonth = ddlMonth.SelectedValue;
        SelectedYear = ddlYear.SelectedValue;
        ParenetLevelid = Convert.ToString(Session["parentLevelId"]);
        if (Session["ReportsBasedOn"] != null)
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False")
                strEmpAutoId = "0";
            else
                strEmpAutoId = Convert.ToString(Session["EmpAutoID"]);
        }
    }
    #region Button Events
    protected void btn_View_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                GetAndSetFieldValues();
                DataSet dsEmp = new DataSet();
                dsEmp = GetData();
                if (dsEmp.Tables["Table"] == null || dsEmp.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    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 (rbReportType.SelectedValue == "0")
                    {
                        strReportType = "Summary";
                        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=EmployeeInOut&dtFrom=" + strdtFromDate + "&dtTo=" + strdtToDate + "&dtMonth=" + SelectedMonth + "&dtYear=" + SelectedYear + "&empid=" + empId + "&EmpName=" + empName + "&ReportType=" + strReportType + "&Level=" + Level + "&EmpCategory=" + employeeCategory + "&EmpType=" + employeeType + "&ParentLevelId=" + ParenetLevelid + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + strSwipeCard + "&mon=" + ddlMonth.SelectedValue + "&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>";
                    }
                    else if (rbReportType.SelectedValue == "1")
                    {
                        switch (ddlReportBy.SelectedValue)
                        {
                            case "1":
                                Session["strReportType"] = "First";
                                break;
                            case "2":
                                Session["strReportType"] = "Second";
                                break;
                            default:
                                Session["strReportType"] = "Both";
                                break;
                        }
                        strReportType = "Details";
                        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=EmployeeInOut&dtFrom=" + strdtFromDate + "&dtTo=" + strdtToDate + "&dtMonth=" + SelectedMonth + "&dtYear=" + SelectedYear + "&empid=" + empId + "&EmpName=" + empName + "&ReportType=" + strReportType + "&Level=" + "LevelEmployeeInOut" + "&EmpCategory=" + employeeCategory + "&EmpType=" + employeeType + "&ParentLevelId=" + ParenetLevelid
                            + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + strSwipeCard + "&mon=" + ddlMonth.SelectedItem.Text + "&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)
        {
            Message(ex.ToString());
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                string employeeName = string.Empty;
                string empId = string.Empty;
                string Level = "";
                if (intIndividualUser >= 1)
                {
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empId = Convert.ToString(txtEmployeeId.Text.Trim());
                    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();
                //Summary
                if (rbReportType.SelectedValue == "0")
                {
                    //db_Con.AddInParameter(dbcmd, "@Shift", DbType.Int16, shift);
                    //db_Con.AddInParameter(dbcmd, "@DataLoading", DbType.Int16, DataLoading);
                    strFilters.Append("@FromDate1=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate1=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeId=" + empId + ",");
                    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=" + Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''") + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]) + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0,");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue);
                    Session["ReportTypeID"] = rbReportType.SelectedValue;
                    //strFilters.Append("@ReportType=" + rbReportType.SelectedValue);
                }
                /*
                ReportName=EmployeeInOut&dtFrom=" + strdtFromDate + "&dtTo=" + strdtToDate + 
                 * "&dtMonth=" + SelectedMonth +
                 * "&dtYear=" + SelectedYear + 
                 * "&empid=" + empId + 
                 * "&EmpName=" + employeeName +
                 * "&ReportType=" + strReportType +
                 * "&Level=" + Level + 
                 * "&EmpCategory=" + iemployeeCategory +
                 * "&EmpType=" + iemployeeType +
                 * "&ParentLevelId=" + ParenetLevelid + 
                 * "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) +
                 * "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + 
                 * "&SwipeCard=" + strSwipeCard +
                 * "&mon=" + ddlMonth.SelectedValue + 
                 * "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + 
                 * "&Gender=" + ddlGender.SelectedValue + "'
                 */
                else if (rbReportType.SelectedValue == "1")
                {
                    if (ddlReportBy.SelectedValue == "1")
                    {
                        Session["strReportType"] = "First";
                    }
                    else if (ddlReportBy.SelectedValue == "2")
                    {
                        Session["strReportType"] = "Second";
                    }
                    else
                    {
                        Session["strReportType"] = "Both";
                    }
                    strFilters.Append("@FromDate1=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate1=" + " Duration_To " + ",");
                    strFilters.Append("@EmployeeId=" + empId + ",");
                    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=" + Convert.ToString(txtSwipeCard.Text).Trim().Replace("'", "''") + ",");
                    strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]) + ",");
                    strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                    strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                    strFilters.Append("@EmpAutoId=0,");
                    strFilters.Append("@Type=" + Convert.ToString(Session["strReportType"]));
                    Session["ReportTypeID"] = rbReportType.SelectedValue;
                }
                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"]) + "';window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnReportType').value='" + rbReportType.SelectedValue + "'}";
                strScript = strScript + "parent.$('#myModalReport').modal('hide');";
                strScript = strScript + "</script>";
                Response.Write(strScript);
            }
        }
        catch
        {
            //
        }
    }
    protected void IDTest1_Click(object senser, EventArgs e)
    {
        if (hdnReportFilters.Value != "")
        {
            string strhdnParameters = hdnReportFilters.Value;
            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 = Convert.ToString(strArray1[2]);
            // ddlShift.SelectedValue = strArray1[3].ToString();
            txtEmployeeName.Text = Convert.ToString(strArray1[4]).Trim().Replace("''", "'");
            txtEmployeeName.Text = Convert.ToString(strArray1[4]).Trim().Replace("%", " ");
            ddlEmpCatagory.SelectedValue = Convert.ToString(strArray1[6]);
            ddlEmpType.SelectedValue = Convert.ToString(strArray1[7]);
            txtSwipeCard.Text = Convert.ToString(strArray1[10]);
            ucOrganizationLevel.Visible = false;
            Session["parentLevelId_modify"] = hdnCompanyId1.Value;
            ddlDesignation.SelectedValue = Convert.ToString(strArray1[12]);
            ddlGender.SelectedValue = Convert.ToString(strArray1[13]);
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "document.getElementById('ctl00_TA_uc_MainMenu1_divMenu').style.display = 'none';";
            strScript = strScript + "document.getElementById('ctl00_TA_uc_MainMenu1_Div1').style.display = 'none';";
            strScript = strScript + "document.getElementById('ctl00_TA_uc_MainMenu1_Div2').style.display = 'none';";
            strScript = strScript + "document.getElementById('ctl00_TA_uc_MainMenu1_Div3').style.display = 'none';";
            strScript = strScript + "document.getElementById('trView').style.display = 'none';";
            strScript = strScript + "document.getElementById('trSave').style.display = 'block';";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("Script", strScript);
        }
    }
    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 DataSet GetData()
    {
        DataSet dsEmp = new DataSet();
        if (ParenetLevelid == "") ParenetLevelid = "0";
        if (rbReportType.SelectedValue == "0")
        {
            strReportType = "Summary";
            sheetName = "Muster Roll Summary";
            reportName = "MusterRollSummary";
            dsEmp = rptEmp.SelectInOutEmployeeSummary(empId, empName, Level, Convert.ToString(employeeCategory), Convert.ToString(employeeType), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipeCard, Convert.ToInt16(ParenetLevelid), strdtFromDate, strdtToDate, Convert.ToInt32(ddlDesignation.SelectedValue), Convert.ToString(ddlGender.SelectedValue), Convert.ToInt32(Session["EmpAutoID"]));
            ViewState["musterSummary"] = dsEmp;
        }
        else if (rbReportType.SelectedValue == "1")
        {
            strReportType = "Details";
            sheetName = "Muster Roll Detailed";
            reportName = "MusterRollDetailed";
            dsEmp = rptEmp.SelectInOutEmployeeNew(empId, empName, Level, Convert.ToString(employeeCategory), Convert.ToString(employeeType), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strSwipeCard, Convert.ToInt16(ParenetLevelid), strdtFromDate, strdtToDate, Convert.ToInt32(ddlDesignation.SelectedValue), Convert.ToString(ddlGender.SelectedValue), Convert.ToInt32(Session["EmpAutoID"]));
            ViewState["musterDetailed"] = dsEmp;
        }
        Session["Ses_MusterRollData"] = dsEmp;
        return dsEmp;
    }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            GetAndSetFieldValues();
            DataSet dsEmp = new DataSet();
            dsEmp = GetData();
            if (dsEmp.Tables["Table"] == null || dsEmp.Tables["Table"].Rows.Count == 0)
            {
                Message(rm.GetString("Alert_Thereisnorecord", ci));
                return;
            }
            else
            {
                string strHead = "";
                strHead = "<HTML xmlns:x='urn:schemas-microsoft-com:office:excel'>";
                strHead += "<HEAD><meta charset='utf-8'><style type=\"text/css\">  <!--table";
                strHead += "  @page {mso-header-data:'&CMultiplication Table\\000ADate\\: &D\\000APage &P';mso-page-orientation:landscape;}";
                strHead += "br{mso-data-placement:same-cell;}";
                strHead += ".xl67{mso-style-parent:style0;text-align:center;white-space:normal;mso-pattern:auto none;background:#9BC2E6;color:#F2F2F2;font-size:10.0pt;font-weight:700;font-family:Arial Unicode MS;mso-font-charset:134;border:.5pt solid windowtext;}";
                strHead += ".xl68{mso-style-parent:style0;text-align:left;white-space:normal;mso-pattern:auto none;background:#9BC2E6;color:#F2F2F2;font-size:10.0pt;font-weight:700;font-family:Arial Unicode MS;mso-font-charset:134;border:.5pt solid windowtext;}";
                strHead += ".xl69{mso-style-parent:style0;text-align:center;white-space:normal;mso-pattern:auto none;background:#9BC2E6;color:#F2F2F2;font-size:10.0pt;font-weight:700;font-family:Arial Unicode MS;mso-font-charset:134;border:.5pt solid windowtext;}";
                strHead += ".xl72{ mso - style - parent:style0; text - align:center; white - space:normal; mso - font - charset:134; border: .5pt solid windowtext; }";
                strHead += ".xl80{ mso - style - parent:style0; text - align:center; white - space:normal; mso - pattern:auto none; background:#AEAAAA;color:#F2F2F2;font-size:10.0pt;font-weight:700;font-family:Arial;mso-font-charset:134;border:.5pt solid windowtext;}";
                strHead += "--></style>";
                strHead += "<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>";
                strHead += "<x:Name>" + sheetName + "</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo/>";
                strHead += "</x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>";
                strHead += "</xml><![endif]--></HEAD><body><table>";
                dsEmp.Tables[0].TableName = "Sheet 1";
                DataTable dt = dsEmp.Tables[0];
                DataTable dt1 = dsEmp.Tables[1];
                dt.TableName = "Sheet 1";
                string attachment = "attachment; filename=" + reportName + ".xls";
                Response.ClearContent();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "application/vnd.ms-excel";
                Response.Write(strHead);
                DataTable dtLevelName = new DataTable();
                if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                {
                    dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
                    if (dtLevelName.Rows.Count > 0)
                    {
                        Response.Write("<tr>");
                        Response.Write("<td  class='header' height='20' width='3470.53' colspan='40' style='height:15.00pt;width:2602.90pt;border-right:none;border-bottom:none;' x:str>" + Convert.ToString(dtLevelName.Rows[0][0]) + "</td>");
                        Response.Write("</tr>");
                    }
                }
                Response.Write("<tr>");
                Response.Write("<td  class='header' height='20' width='3470.53' colspan='40' style='text-align:center;height:15.00pt;width:2602.90pt;border-right:none;border-bottom:none;' x:str>" + sheetName + " " + Convert.ToString(txtFromDate.Text) + " To " + Convert.ToString(txtToDate.Text) + "</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                int increment = 1;

                if (rbReportType.SelectedValue == "0")
                {
                    if (dsEmp.Tables[0].Columns.Contains("FatherName"))
                        dsEmp.Tables[0].Columns.Remove("FatherName");
                    if (dsEmp.Tables[0].Columns.Contains("Present"))
                        dsEmp.Tables[0].Columns.Remove("Present");
                    if (dsEmp.Tables[0].Columns.Contains("Absent"))
                        dsEmp.Tables[0].Columns.Remove("Absent");
                    if (dsEmp.Tables[0].Columns.Contains("Leave"))
                        dsEmp.Tables[0].Columns.Remove("Leave");
                    if (dsEmp.Tables[0].Columns.Contains("Holiday"))
                        dsEmp.Tables[0].Columns.Remove("Holiday");
                    if (dsEmp.Tables[0].Columns.Contains("TotalOT"))
                        dsEmp.Tables[0].Columns.Remove("TotalOT");
                    if (dsEmp.Tables[0].Columns.Contains("DesignationID"))
                        dsEmp.Tables[0].Columns.Remove("DesignationID");
                    if (dsEmp.Tables[0].Columns.Contains("Grade_Level"))
                        dsEmp.Tables[0].Columns.Remove("Grade_Level");
                    if (dsEmp.Tables[0].Columns.Contains("OrderBy"))
                        dsEmp.Tables[0].Columns.Remove("OrderBy");
                    foreach (DataColumn dc in dt.Columns)
                    {
                        if (dc.ColumnName.Contains("A_Day") || dc.ColumnName.Contains("AFDay"))
                            break;
                        increment = GenerateHeaders(dt1, increment, dc);
                    }
                    Response.Write("</tr><tr>");
                    foreach (DataRow dr in dt.Rows)
                    {
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            if (i == 35)
                            {
                                Response.Write("</tr><tr><td></td><td></td><td></td><td></td>");
                            }
                            else if (i == 66)
                            {
                                break;
                            }
                            switch (i)
                            {
                                case 1:
                                case 2:
                                case 3:
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                    break;
                                default:
                                    Response.Write("<td>" + dr[i].ToString().Replace("#", " ") + "</td>");
                                    break;
                            }
                        }
                        Response.Write("</tr>");
                    }
                    if (rbReportType.SelectedValue == "100")
                        SubTotalRowCreation(dt1);
                    Response.Write("</BODY></HTML>");
                    Response.End();
                    return;
                }
                else
                {
                    foreach (DataColumn dc in dt.Columns)
                    {
                        if (increment == 32)
                            break;
                        increment = GenerateHeaders(dt1, increment, dc);
                    }
                    Response.Write("</tr><tr>");
                    foreach (DataRow dr in dt.Rows)
                    {
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            if (i == 35)
                                break;
                            switch (i)
                            {
                                case 1:
                                case 2:
                                case 3:
                                    Response.Write("<td>" + dr[i].ToString() + "</td>");
                                    break;
                                default:
                                    Response.Write("<td>" + dr[i].ToString().Replace("#", " ") + "</td>");
                                    break;
                            }
                        }
                        Response.Write("</tr>");
                    }
                    if (rbReportType.SelectedValue == "100")
                        SubTotalRowCreation(dt1);
                    Response.Write("</BODY></HTML>");
                    Response.End();
                    return;
                }
            }
        }
    }
    private void SubTotalRowCreation(DataTable dt1)
    {
        int increment_New = 1;
        string subTotalHtml = string.Empty;
        foreach (DataColumn dc in dt1.Columns)
        {
            if (dc.ColumnName != "id")
            {
                string[] splittedString = Convert.ToString(dt1.Rows[0]["Day" + increment_New]).Split('#');
                if (increment_New == 1)
                {
                    subTotalHtml += "<tr>";
                    subTotalHtml += "<td class='xl80' colspan='4' style='text-align:right;height:15.00pt;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;' x:str>Total Present</td>";
                    subTotalHtml += "<td class='xl80' x:num>" + splittedString[1] + "</td>" + "cell1";
                    subTotalHtml += "</tr>";
                    subTotalHtml += "<tr>";
                    subTotalHtml += "<td class='xl80'  colspan='4' style='text-align:right;height:15.00pt;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;' x:str>Total Absent</td>";
                    subTotalHtml += "<td class='xl80' x:num>" + splittedString[2] + "</td>" + "cell2";
                    subTotalHtml += "</tr>";
                    subTotalHtml += "<tr>";
                    subTotalHtml += "<td class='xl80'  colspan='4' style='text-align:right;height:15.00pt;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;' x:str>Total Leave</td>";
                    subTotalHtml += "<td class='xl80' x:num>" + splittedString[3] + "</td>" + "cell3";
                    subTotalHtml += "</tr>";
                }
                else
                {
                    if (subTotalHtml.Contains("cell1"))
                        subTotalHtml = subTotalHtml.Replace("cell1", "<td class='xl80'>" + splittedString[1] + "</td>" + "cell1");
                    if (subTotalHtml.Contains("cell2"))
                        subTotalHtml = subTotalHtml.Replace("cell2", "<td class='xl80'>" + splittedString[2] + "</td>" + "cell2");
                    if (subTotalHtml.Contains("cell3"))
                        subTotalHtml = subTotalHtml.Replace("cell3", "<td class='xl80'>" + splittedString[3] + "</td>" + "cell3");
                }
                increment_New += 1;
            }
        }
        Response.Write(subTotalHtml.Replace("cell1", "").Replace("cell2", "").Replace("cell3", ""));
    }
    private int GenerateHeaders(DataTable dt1, int increment, DataColumn dc)
    {
        switch (dc.ColumnName)
        {
            case "SlNo":
                Response.Write("<td class='xl67' > Sl.No.</td>");
                break;
            case "Name":
                Response.Write("<td class='xl68' > Employee Name</td>");
                break;
            case "Employee_Code_Id":
                Response.Write("<td class='xl67' > Employee ID</td>");
                break;
            case "Designation":
                Response.Write("<td class='xl67' > Designation</td>");
                break;
            case "CLAvailed":
                Response.Write("<td class='xl67' > CLAvailed</td>");
                break;
            default:
                if (dt1.Rows.Count > 0 && increment <= 31)
                {
                    string[] splittedString = Convert.ToString(dt1.Rows[0]["Day" + increment]).Split('#');
                    Response.Write("<td class='xl69' >" + splittedString[0] + "</td>");
                    increment++;
                }
                else
                    Response.Write("<td class='xl69' >" + dc.ColumnName + "</td>");
                break;
        }

        return increment;
    }
    #endregion
    #region Export Excel
    protected void ExportExcel(DataSet dsEmp)
    {
        workbook = new HSSFWorkbook();
        ISheet sheet;
        sheet = workbook.CreateSheet(sheetName);
        DataTable dtLevelName = new DataTable();
        if (Convert.ToInt16(Session["parentLevelId"]) != 0)
        {
            dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
        }
        GetColumnCount();
        sheet.IsPrintGridlines = true;
        sheet.VerticallyCenter = true;
        int rowIndex = 0;
        row = sheet.CreateRow(rowIndex);
        hFont = (HSSFFont)workbook.CreateFont();
        hStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        MainHStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        IStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        hFont.Boldweight = (short)FontBoldWeight.Bold;
        hFont.Color = HSSFColor.Maroon.Index;
        hFont.FontHeightInPoints = 10;
        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;
        MainHStyle.SetFont(hFont);
        MainHStyle.Alignment = HorizontalAlignment.Center;
        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;
        IStyle.VerticalAlignment = VerticalAlignment.Center;
        if (dtLevelName.Rows.Count > 0)
        {
            row.CreateCell(0).SetCellValue(Convert.ToString(dtLevelName.Rows[0][0]));
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, rowCountval));
            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, rowCountval));
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        if (rbReportType.SelectedValue == "0")
        {
            #region Summary
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee Name");
            row.CreateCell(2).SetCellValue("Employee ID");
            row.CreateCell(3).SetCellValue("Number of CL Availed");
            row.CreateCell(4).SetCellValue("Session");
            //Dynamic Row Create
            for (int i = 5; i <= Convert.ToInt32(dsEmp.Tables[1].Columns.Count) + 3; i++)
            {
                row.CreateCell(i).SetCellValue(Convert.ToString(dsEmp.Tables[1].Rows[0][i - 4]));
            }
            row.CreateCell(36).SetCellValue("Remarks");
            //Header Style Added Here
            for (int i = 0; i <= 36; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
            }
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 3, 4));
            rowIndex++;
            string strPre = string.Empty;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                row = sheet.CreateRow(rowIndex);
                row.Height = 300;
                SlNo++;
                row.CreateCell(0).SetCellValue(SlNo);
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Name"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                if (Convert.ToString(DR["CLAvailed"]) == String.Empty)
                    row.CreateCell(3).SetCellValue(Convert.ToString(DR["CLAvailed"]));
                else
                {
                    row.CreateCell(3).SetCellValue(Convert.ToDouble(DR["CLAvailed"]));
                }
                row.CreateCell(4).SetCellValue("FN");
                for (int i = 5; i <= 35; i++)
                {
                    row.CreateCell(i).SetCellValue(Convert.ToString(DR["F_Day" + Convert.ToString(i - 4)]));
                }
                row.CreateCell(36).SetCellValue("");
                for (int i = 0; i <= 36; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
                row = sheet.CreateRow(rowIndex);
                row.CreateCell(0).SetCellValue("");
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Name"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                if (Convert.ToString(DR["CLAvailed"]) == String.Empty)
                    row.CreateCell(3).SetCellValue(Convert.ToString(DR["CLAvailed"]));
                else
                {
                    row.CreateCell(3).SetCellValue(Convert.ToDouble(DR["CLAvailed"]));
                }
                sheet.AddMergedRegion(new CellRangeAddress(rowIndex - 1, rowIndex, 3, 3));
                row.CreateCell(4).SetCellValue("AN");
                for (int i = 5; i <= 35; i++)
                {
                    row.CreateCell(i).SetCellValue(Convert.ToString(DR["A_Day" + Convert.ToString(i - 4)]));
                }
                row.CreateCell(36).SetCellValue("");
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                for (int i = 0; i <= 36; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                sheet.AddMergedRegion(new CellRangeAddress(rowIndex - 1, rowIndex, 36, 36));
                rowIndex++;
            }
            #endregion
            CreateLegendDetails(1);
        }
        else
        {
            #region Detailed
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee Name");
            row.CreateCell(2).SetCellValue("Employee Id");
            row.CreateCell(3).SetCellValue("Designation");
            GetColumnCount();
            for (int i = 4; i <= EndCount; i++)
            {
                ColCount++;
                if (ddlReportBy.SelectedValue == "1" || ddlReportBy.SelectedValue == "2")
                {
                    row.CreateCell(i).SetCellValue(Convert.ToString(dsEmp.Tables[1].Rows[0][ColCount]));
                }
                else
                {
                    row.CreateCell(i).SetCellValue(Convert.ToString(dsEmp.Tables[1].Rows[0][i - 3]));
                }
            }
            if (ddlReportBy.SelectedValue == "2" || ddlReportBy.SelectedValue == "0")
            {
                row.CreateCell(EndCount + 1).SetCellValue("WD");
                row.CreateCell(EndCount + 2).SetCellValue("NFH");
                for (int i = 0; i <= EndCount + 2; i++)
                {
                    row.GetCell(i).CellStyle = hStyle;
                }
            }
            else
            {
                for (int i = 0; i <= EndCount; i++)
                {
                    row.GetCell(i).CellStyle = hStyle;
                }
            }
            //sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 2, 3));
            rowIndex++;
            string strPre = string.Empty;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                row = sheet.CreateRow(rowIndex);
                row.Height = 300;
                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["Name"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["Designation"]));
                GetColumnCount();
                for (int i = 4; i <= EndCount; i++)
                {
                    ColCount++;
                    row.CreateCell(i).SetCellValue(Convert.ToString(DR["F_Day" + Convert.ToString(ColCount)]));
                }
                if (ddlReportBy.SelectedValue == "2" || ddlReportBy.SelectedValue == "0")
                {
                    if (Convert.ToString(DR["CountDays"]) == String.Empty)
                        row.CreateCell(EndCount + 1).SetCellValue(Convert.ToString(DR["CountDays"]));
                    else
                    {
                        row.CreateCell(EndCount + 1).SetCellValue(Convert.ToDouble(DR["CountDays"]));
                    }
                    if (Convert.ToString(DR["Holiday"]) == String.Empty)
                        row.CreateCell(EndCount + 2).SetCellValue(Convert.ToString(DR["Holiday"]));
                    else
                    {
                        row.CreateCell(EndCount + 2).SetCellValue(Convert.ToDouble(DR["Holiday"]));
                    }
                    for (int i = 0; i <= EndCount + 2; i++)
                    {
                        row.GetCell(i).CellStyle = IStyle;
                        sheet.AutoSizeColumn(i);
                    }
                }
                else
                {
                    for (int i = 0; i <= EndCount; i++)
                    {
                        row.GetCell(i).CellStyle = IStyle;
                        sheet.AutoSizeColumn(i);
                    }
                }
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                rowIndex++;
            }
            CreateLegendDetails(0);
            #endregion
        }
        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();
        }
    }
    protected void CreateLegendDetails(int SumDet)
    {
        sheet1 = workbook.CreateSheet("Legends");
        sheet1.IsPrintGridlines = true;
        sheet1.VerticallyCenter = true;
        hFont1 = (HSSFFont)workbook.CreateFont();
        hStyle1 = (HSSFCellStyle)workbook.CreateCellStyle();
        hFont1.Boldweight = (short)FontBoldWeight.Bold;
        hFont1.Color = HSSFColor.Red.Index;
        hFont1.FontHeightInPoints = 10;
        hStyle1.FillForegroundColor = IndexedColors.White.Index;
        hStyle1.FillPattern = FillPattern.SolidForeground;
        hStyle1.SetFont(hFont1);
        if (SumDet == 0)
        {
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("A - Absent");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("P - Present");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("L - Leave");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("I* - Late In");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("O* - Early Out");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("C - Comp Off");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("H - Holiday");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("Off - Weekly Off");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**Off - Weekly Off Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**H - Holiday Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**RH - Restricted Holiday Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("OD - On Duty");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
        }
        else
        {
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("P - Present");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("A - Absent");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("H - Holiday");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("Off - Weekly off");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("C - Comp Off");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("RH - Restricted Holiday");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("OD - On Duty");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**o - Weekly Off Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**H - Holiday Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("*P - Late In / Early Exit");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("**R - Restricted Holiday Worked");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
            row1 = sheet1.CreateRow(rowIndex1);
            row1.CreateCell(0).SetCellValue("");
            row1.CreateCell(1).SetCellValue("# - Manual Time Entry");
            row1.GetCell(1).CellStyle = hStyle1;
            rowIndex1++;
        }
    }
    protected void GetColumnCount()
    {
        if (ddlReportBy.SelectedValue == "1")
        {
            ColCount = 0;
            EndCount = 18;
            rowCountval = 18;
        }
        else if (ddlReportBy.SelectedValue == "2")
        {
            ColCount = 15;
            EndCount = 19;
            rowCountval = 21;
        }
        else
        {
            EndCount = 34;
            ColCount = 0;
            rowCountval = 36;
        }
    }
    #endregion
    #region *** UserdefinedFunctions ***
    /// <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("Select valid date compare with Fromdate");
                base.Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", 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 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
        {
            //
        }
    }
    /// <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 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
        {
            //
        }
    }
    /// <summary>
    /// Reporttype selected index changed 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rbReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbReportType.SelectedValue == "0")
        {
            lblreportby.Visible = false;
            ddlReportBy.SelectedIndex = 0;
            ddlReportBy.Visible = false;
            Session["strReportType"] = string.Empty;
        }
        else if (rbReportType.SelectedValue == "1")
        {
            lblreportby.Visible = true;
            ddlReportBy.Visible = true;
        }
        clearControls();
    }
    private void BindReportBy()
    {
        try
        {
            ddlReportBy.Items.Clear();
            ddlReportBy.Items.Add(new ListItem(rm.GetString("Caption_Both", ci), "0"));
            ddlReportBy.Items.Add(new ListItem(rm.GetString("First15Days", ci), "1"));
            ddlReportBy.Items.Add(new ListItem(rm.GetString("Next15Days", ci), "2"));
        }
        catch (Exception ex)
        {
            throw;
        }
    }
    #endregion
    private void clearControls()
    {
        ViewState["musterSummary"] = null;
        ViewState["musterDetailed"] = null;
        gvData.DataSource = null;
        gvData.DataBind();
        gvData.Visible = false;
        gvDataDetailed.DataSource = null;
        gvDataDetailed.DataBind();
        gvDataDetailed.Visible = false;
        lnbtnClear.Visible = false;
        lnkbtnpdf.Visible = false;
        lnktbnexcel.Visible = false;
        btnCustWindow.Visible = false;
    }
    protected void lnkbtnGrid_Click(object sender, EventArgs e)
    {
        clearControls();
        GetAndSetFieldValues();
        dsEmp = GetData();
        lnktbnexcel.Visible = true;
        btnCustWindow.Visible = true;
        lnkbtnpdf.Visible = true;
        lnbtnClear.Visible = true;
        if (rbReportType.SelectedValue == "0")
        {
            gvData.SettingsText.Title = "Muster Roll Summary Report - " + txtFromDate.Text + " To " + txtToDate.Text;
            gvData.Visible = true;
            gvData.DataSource = dsEmp;
            gvData.DataBind();
        }
        else
        {
            gvDataDetailed.SettingsText.Title = "Muster Roll Detailed Report - " + txtFromDate.Text + " To " + txtToDate.Text;
            gvDataDetailed.Visible = true;
            gvDataDetailed.DataSource = dsEmp;
            gvDataDetailed.DataBind();
        }
        if (rbReportType.SelectedValue == "0")
        {
            if (dsEmp != null)
            {
                if (dsEmp.Tables.Count > 0)
                {
                    if (dsEmp.Tables[1].Rows.Count > 0)
                    {
                        gvData.Columns[2].Caption = dsEmp.Tables[1].Rows[0][1].ToString();
                        gvData.Columns[3].Caption = dsEmp.Tables[1].Rows[0][2].ToString();
                        gvData.Columns[4].Caption = dsEmp.Tables[1].Rows[0][3].ToString();
                        gvData.Columns[5].Caption = dsEmp.Tables[1].Rows[0][4].ToString();
                        gvData.Columns[6].Caption = dsEmp.Tables[1].Rows[0][5].ToString();
                        gvData.Columns[7].Caption = dsEmp.Tables[1].Rows[0][6].ToString();
                        gvData.Columns[8].Caption = dsEmp.Tables[1].Rows[0][7].ToString();
                        gvData.Columns[9].Caption = dsEmp.Tables[1].Rows[0][8].ToString();
                        gvData.Columns[10].Caption = dsEmp.Tables[1].Rows[0][9].ToString();
                        gvData.Columns[11].Caption = dsEmp.Tables[1].Rows[0][10].ToString();
                        gvData.Columns[12].Caption = dsEmp.Tables[1].Rows[0][11].ToString();
                        gvData.Columns[13].Caption = dsEmp.Tables[1].Rows[0][12].ToString();
                        gvData.Columns[14].Caption = dsEmp.Tables[1].Rows[0][13].ToString();
                        gvData.Columns[15].Caption = dsEmp.Tables[1].Rows[0][14].ToString();
                        gvData.Columns[16].Caption = dsEmp.Tables[1].Rows[0][15].ToString();
                        gvData.Columns[17].Caption = dsEmp.Tables[1].Rows[0][16].ToString();
                        gvData.Columns[18].Caption = dsEmp.Tables[1].Rows[0][17].ToString();
                        gvData.Columns[19].Caption = dsEmp.Tables[1].Rows[0][18].ToString();
                        gvData.Columns[20].Caption = dsEmp.Tables[1].Rows[0][19].ToString();
                        gvData.Columns[21].Caption = dsEmp.Tables[1].Rows[0][20].ToString();
                        gvData.Columns[22].Caption = dsEmp.Tables[1].Rows[0][21].ToString();
                        gvData.Columns[23].Caption = dsEmp.Tables[1].Rows[0][22].ToString();
                        gvData.Columns[24].Caption = dsEmp.Tables[1].Rows[0][23].ToString();
                        gvData.Columns[25].Caption = dsEmp.Tables[1].Rows[0][24].ToString();
                        gvData.Columns[26].Caption = dsEmp.Tables[1].Rows[0][25].ToString();
                        gvData.Columns[27].Caption = dsEmp.Tables[1].Rows[0][26].ToString();
                        gvData.Columns[28].Caption = dsEmp.Tables[1].Rows[0][27].ToString();
                        gvData.Columns[29].Caption = dsEmp.Tables[1].Rows[0][28].ToString();
                        gvData.Columns[30].Caption = dsEmp.Tables[1].Rows[0][29].ToString();
                        gvData.Columns[31].Caption = dsEmp.Tables[1].Rows[0][30].ToString();
                        gvData.Columns[32].Caption = dsEmp.Tables[1].Rows[0][31].ToString();
                    }
                }
            }
        }
        else
        {
            if (dsEmp != null)
            {
                if (dsEmp.Tables.Count > 0)
                {
                    if (dsEmp.Tables[1].Rows.Count > 0)
                    {
                        gvDataDetailed.Columns[2].Caption = dsEmp.Tables[1].Rows[0][1].ToString();
                        gvDataDetailed.Columns[3].Caption = dsEmp.Tables[1].Rows[0][2].ToString();
                        gvDataDetailed.Columns[4].Caption = dsEmp.Tables[1].Rows[0][3].ToString();
                        gvDataDetailed.Columns[5].Caption = dsEmp.Tables[1].Rows[0][4].ToString();
                        gvDataDetailed.Columns[6].Caption = dsEmp.Tables[1].Rows[0][5].ToString();
                        gvDataDetailed.Columns[7].Caption = dsEmp.Tables[1].Rows[0][6].ToString();
                        gvDataDetailed.Columns[8].Caption = dsEmp.Tables[1].Rows[0][7].ToString();
                        gvDataDetailed.Columns[9].Caption = dsEmp.Tables[1].Rows[0][8].ToString();
                        gvDataDetailed.Columns[10].Caption = dsEmp.Tables[1].Rows[0][9].ToString();
                        gvDataDetailed.Columns[11].Caption = dsEmp.Tables[1].Rows[0][10].ToString();
                        gvDataDetailed.Columns[12].Caption = dsEmp.Tables[1].Rows[0][11].ToString();
                        gvDataDetailed.Columns[13].Caption = dsEmp.Tables[1].Rows[0][12].ToString();
                        gvDataDetailed.Columns[14].Caption = dsEmp.Tables[1].Rows[0][13].ToString();
                        gvDataDetailed.Columns[15].Caption = dsEmp.Tables[1].Rows[0][14].ToString();
                        gvDataDetailed.Columns[16].Caption = dsEmp.Tables[1].Rows[0][15].ToString();
                        gvDataDetailed.Columns[17].Caption = dsEmp.Tables[1].Rows[0][16].ToString();
                        gvDataDetailed.Columns[18].Caption = dsEmp.Tables[1].Rows[0][17].ToString();
                        gvDataDetailed.Columns[19].Caption = dsEmp.Tables[1].Rows[0][18].ToString();
                        gvDataDetailed.Columns[20].Caption = dsEmp.Tables[1].Rows[0][19].ToString();
                        gvDataDetailed.Columns[21].Caption = dsEmp.Tables[1].Rows[0][20].ToString();
                        gvDataDetailed.Columns[22].Caption = dsEmp.Tables[1].Rows[0][21].ToString();
                        gvDataDetailed.Columns[23].Caption = dsEmp.Tables[1].Rows[0][22].ToString();
                        gvDataDetailed.Columns[24].Caption = dsEmp.Tables[1].Rows[0][23].ToString();
                        gvDataDetailed.Columns[25].Caption = dsEmp.Tables[1].Rows[0][24].ToString();
                        gvDataDetailed.Columns[26].Caption = dsEmp.Tables[1].Rows[0][25].ToString();
                        gvDataDetailed.Columns[27].Caption = dsEmp.Tables[1].Rows[0][26].ToString();
                        gvDataDetailed.Columns[28].Caption = dsEmp.Tables[1].Rows[0][27].ToString();
                        gvDataDetailed.Columns[29].Caption = dsEmp.Tables[1].Rows[0][28].ToString();
                        gvDataDetailed.Columns[30].Caption = dsEmp.Tables[1].Rows[0][29].ToString();
                        gvDataDetailed.Columns[31].Caption = dsEmp.Tables[1].Rows[0][30].ToString();
                        gvDataDetailed.Columns[32].Caption = dsEmp.Tables[1].Rows[0][31].ToString();
                    }
                }
            }
        }
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = (LinkButton)sender;
        if (rbReportType.SelectedValue == "0")
        {
            ASPxGridViewExporter1.Landscape = true;
            ASPxGridViewExporter1.LeftMargin = 10;
            ASPxGridViewExporter1.RightMargin = 10;
            ASPxGridViewExporter1.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
            ASPxGridViewExporter1.MaxColumnWidth = 400;
            //ASPxGridViewExporter1.GridViewID = "gvData";
            //DataSet ds = (DataSet)ASPxGridViewExporter1.GridView.DataSource;
            string saveAsFileName = string.Format("Muster Roll Summary Report -{0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
            ASPxGridViewExporter1.FileName = saveAsFileName;
            ASPxGridViewExporter1.PaperKind = System.Drawing.Printing.PaperKind.A3;
            ASPxGridViewExporter1.PageHeader.Center = "Muster Roll Summary report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text);
            switch (lnkbtn.CommandName)
            {
                case "excel":
                    ASPxGridViewExporter1.WriteXlsxToResponse();
                    break;
                case "pdf":
                    ASPxGridViewExporter1.WritePdfToResponse();
                    break;
            }
        }
        else
        {
            ASPxgve2.Landscape = true;
            ASPxgve2.LeftMargin = 10;
            ASPxgve2.RightMargin = 10;
            ASPxgve2.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
            ASPxgve2.MaxColumnWidth = 100;
            string saveAsFileName = string.Format("Muster Roll Detailed Report -{0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
            ASPxgve2.FileName = saveAsFileName;
            ASPxgve2.PaperKind = System.Drawing.Printing.PaperKind.A3;
            ASPxgve2.PageHeader.Center = "Muster Roll Detailed report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text);
            switch (lnkbtn.CommandName)
            {
                case "excel":
                    ASPxgve2.WriteXlsxToResponse();
                    break;
                case "pdf":
                    ASPxgve2.WritePdfToResponse();
                    break;
            }

        }
    }

    protected void lnbtnClear_Click(object sender, EventArgs e)
    {
        clearControls();
    }

    protected void gvDataDetailed_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == GridViewRowType.Data)
        {
            //string fday1 = (string)e.GetValue("F_Day1");
            //if (fday1 != null)
            //{
            //    e.Row.Cells[2].Text = fday1.Replace("#####", "<br>").Replace("#", "<br>");
            //}
            //string fday2 = (string)e.GetValue("F_Day2");
            //if (fday2 != null)
            //{
            //    e.Row.Cells[3].Text = fday2.Replace("#####", "<br>").Replace("#", "<br>");
            //}
            //string fday3 = (string)e.GetValue("F_Day3");
            //if (fday3 != null)
            //{
            //    e.Row.Cells[4].Text = fday3.Replace("#####", "<br>").Replace("#", "<br>");
            //}
            //string fday4 = (string)e.GetValue("F_Day4");
            //if (fday4 != null)
            //{
            //    e.Row.Cells[5].Text = fday4.Replace("#####", "<br>").Replace("#", "<br>");
            //}

            //string fday5 = (string)e.GetValue("F_Day5");
            //if (fday5 != null)
            //{
            //    e.Row.Cells[6].Text = fday5.Replace("#####", "<br>").Replace("#", "<br>");
            //}

            //string fday6 = (string)e.GetValue("F_Day6");
            //if (fday6 != null)
            //{
            //    e.Row.Cells[7].Text = fday6.Replace("#####", "<br>").Replace("#", "<br>");
            //}
        }
    }
}
