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;
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 = "";
    DataSet dsEmp = new DataSet();
    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 = GetDataset();
                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 GetDataset()
    {
        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 = GetDataset();
            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 == 43)
                            {
                                Response.Write("</tr><tr>");
                            }
                            else if (i == 74)
                            {
                                break;
                            }
                            switch (i)
                            {
                                case 0:
                                case 1:
                                case 2:
                                case 3:
                                    Response.Write("<td rowspan='2' style='width:120px;border:1px solid black;'>" + dr[i].ToString() + "</td>");
                                    break;
                                case 35:
                                case 36:
                                case 37:
                                case 38:
                                case 39:
                                case 40:
                                case 41:
                                case 42:
                                    Response.Write("<td rowspan='2' style='border:1px solid black;'>" + dr[i].ToString() + "</td>");
                                    break;
                                default:
                                    Response.Write("<td style='width:5px;border:1px solid black;'>" + 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 *** 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 = GetDataset();
        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;
            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)
    {
    }
}