using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Reports_TA_UI_PayRoll_Report : 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();
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    DataSet dsEmp = new DataSet();
    int rowIndex1 = 0, day = 0;
    ResourceManager rm;
    CultureInfo ci;
    string strFromdate, gstrDateFormat, strTodate;
    int intIndividualUser = 0;
    string empName = "", empId = "", Level = "", strScript = "", strReportType = string.Empty, ParenetLevelid = string.Empty;
    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;
    TimeSpan diff;
    string strEmpAutoId = string.Empty;
    #endregion
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        gvData.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
       
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objCommon.menu("Payroll Report", "320");
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_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);
        Page.RegisterStartupScript("GethiddenValue", "<script language='javascript'>GethiddenValue();</script>");
        //Set UserRights
        UserRights();
    }

    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(320, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                btn_View.Visible = true;
            }
            else
            {
                btn_View.Visible = false;
            }
        }
        else
        {
            Response.Redirect("ReportsLandingPage.aspx");
        }
    }

    private void LoadStrings(CultureInfo ci)
    {
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        btn_Export.Text = "&nbsp;&nbsp;" + rm.GetString("btn_ExporttoExcel", ci);
        lblPayrollData.Text = rm.GetString("Payroll_Report", ci);
        lblEmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        lblTimePeriod.Text = rm.GetString("Reports_TimePeriod", ci);
        lblFrom.Text = rm.GetString("email_FromDate", ci);
        lblTo.Text = rm.GetString("email_ToDate", ci);
    }
    protected void ExportExcel(DataSet dsEmp, DataTable dtLevelName)
    {
        string SheetName = "";
        //if (Convert.ToString(rblReportType.SelectedValue) == "1")
        //{ SheetName = "Raw Data Report Recent Punches "; }
        //else
        //{ SheetName = "Raw Data Report Detailed Punches"; }

        string NewTimeFormat = string.Empty;
        string TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        if (TimeFormat == "HH:mm")
        {
            NewTimeFormat = "HH:mm";
        }
        else
        {
            NewTimeFormat = "hh:mm tt";
        }

        HSSFWorkbook workbook = new HSSFWorkbook();
        ISheet sheet = workbook.CreateSheet(SheetName);
        int rowIndex = 0;

        NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
        HSSFFont hFont = (HSSFFont)workbook.CreateFont();
        hFont.Boldweight = (short)FontBoldWeight.Bold;
        hFont.Color = HSSFColor.Maroon.Index;
        hFont.FontHeightInPoints = 10;
        HSSFCellStyle hStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        hStyle.SetFont(hFont);
        hStyle.FillForegroundColor = IndexedColors.White.Index;
        hStyle.FillPattern = FillPattern.SolidForeground;
        hStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
        HSSFCellStyle MainStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        MainStyle.SetFont(hFont);
        MainStyle.Alignment = HorizontalAlignment.Center;
        HSSFCellStyle hStyle2 = (HSSFCellStyle)workbook.CreateCellStyle();
        hStyle2.SetFont(hFont);
        HSSFCellStyle IStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        IStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;

        if (dtLevelName.Rows.Count > 0)
        {
            //row.CreateCell(0).SetCellValue(Convert.ToString(dtLevelName.Rows[0][0]));
            //if (Convert.ToString(rblReportType.SelectedValue) == "1")
            //{
            //    sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 7));
            //}
            //else
            //{
            //    sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 7));
            //}
            row.GetCell(0).CellStyle = MainStyle;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
        }
        //if (Convert.ToString(rblReportType.SelectedValue) == "1")
        //{
        //    row.CreateCell(0).SetCellValue("Raw Data Recent Punches Report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text));
        //    row.GetCell(0).CellStyle = MainStyle;
        //    sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 7));
        //    rowIndex++;
        //}
        //else
        //{
        //    row.CreateCell(0).SetCellValue("Raw Data Detailed Report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text));
        //    row.GetCell(0).CellStyle = MainStyle;
        //    sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 7));
        //    rowIndex++;
        //}
        row = sheet.CreateRow(rowIndex);
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        //if (Convert.ToString(rblReportType.SelectedValue) == "1")
        //{
        //    row.CreateCell(0).SetCellValue("Sl.No");
        //    row.CreateCell(1).SetCellValue("Card Id");
        //    row.CreateCell(2).SetCellValue("Employee Name");
        //    row.CreateCell(3).SetCellValue("Punch Date");
        //    row.CreateCell(4).SetCellValue("Terminal ID");
        //    row.CreateCell(5).SetCellValue("Punch Time");
        //    row.CreateCell(6).SetCellValue("Punch Type (Value)");
        //    row.CreateCell(7).SetCellValue("Status");
        //    row.CreateCell(8).SetCellValue("Remedy");

        //    //row.RowStyle = hStyle;
        //    for (int i = 0; i <= 8; i++)
        //    {
        //        row.GetCell(i).CellStyle = hStyle;
        //    }
        //    rowIndex++;
        //    string strPre = string.Empty; int EmployeeDatacount = 1;
        //    //string OldEmployeeId = "0";
        //    //string PreviousEmployeeId = "-1";
        //    //Int64 Total = 0;
        //    //string column = "";
        //    foreach (DataRow DR in dsEmp.Tables[0].Rows)
        //    {
        //        row = sheet.CreateRow(rowIndex);

        //        if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
        //        {
        //            row.CreateCell(0).SetCellValue(Convert.ToString(EmployeeDatacount));
        //            EmployeeDatacount++;
        //        }
        //        else
        //        {
        //            row.CreateCell(0).SetCellValue(string.Empty);
        //        }
        //        row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
        //        row.CreateCell(2).SetCellValue(Convert.ToString(DR["EmployeeName"]));
        //        row.CreateCell(3).SetCellValue(Convert.ToString(DR["PunchDate"]));
        //        row.CreateCell(4).SetCellValue(Convert.ToString(DR["Terminal_Name"]));
        //        if (Convert.ToString(DR["PunchTime"]) == String.Empty)
        //            row.CreateCell(5).SetCellValue(Convert.ToString(DR["PunchTime"]));
        //        else
        //        {
        //            row.CreateCell(5).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["PunchTime"]))).ToString(NewTimeFormat));
        //        }
        //        row.CreateCell(6).SetCellValue(Convert.ToString(DR["PunchType"]));
        //        row.CreateCell(7).SetCellValue(Convert.ToString(DR["Process"]));
        //        if (Convert.ToString(DR["Resolution"]) == "Processed")
        //            row.CreateCell(8).SetCellValue(Convert.ToString(""));
        //        else
        //        { row.CreateCell(8).SetCellValue(Convert.ToString(DR["Resolution"])); }

        //        strPre = Convert.ToString(DR["Employee_Code_Id"]);
        //        for (int i = 0; i <= 8; i++)
        //        {
        //            row.GetCell(i).CellStyle = IStyle;
        //            sheet.AutoSizeColumn(i);
        //        }
        //        rowIndex++;
        //    }
        //}
        //else
        //{
        //    row.CreateCell(0).SetCellValue("Sl.No");
        //    row.CreateCell(1).SetCellValue("Card Id");
        //    row.CreateCell(2).SetCellValue("Employee Name");
        //    row.CreateCell(3).SetCellValue("Terminal Name(Terminal ID)");
        //    row.CreateCell(4).SetCellValue("Punch Date");
        //    row.CreateCell(5).SetCellValue("Punch Type (Value)");
        //    row.CreateCell(6).SetCellValue("Punch Time");
        //    row.CreateCell(7).SetCellValue("Status");
        //    row.CreateCell(8).SetCellValue("Remedy");

        //    //row.RowStyle = hStyle;
        //    for (int i = 0; i <= 8; i++)
        //    {
        //        row.GetCell(i).CellStyle = hStyle;
        //    }
        //    rowIndex++;
        //    string strPre = string.Empty; int EmployeeDatacount = 1;
        //    //string OldEmployeeId = "0";
        //    //string PreviousEmployeeId = "-1";
        //    //Int64 Total = 0;
        //    //string column = "";
        //    foreach (DataRow DR in dsEmp.Tables[0].Rows)
        //    {
        //        row = sheet.CreateRow(rowIndex);

        //        if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
        //        {
        //            row.CreateCell(0).SetCellValue(Convert.ToString(EmployeeDatacount));
        //            EmployeeDatacount++;
        //        }
        //        else
        //        {
        //            row.CreateCell(0).SetCellValue(string.Empty);
        //        }
        //        row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
        //        row.CreateCell(2).SetCellValue(Convert.ToString(DR["EmployeeName"]));
        //        row.CreateCell(3).SetCellValue(Convert.ToString(DR["Terminal_Name"]));
        //        row.CreateCell(4).SetCellValue(Convert.ToString(DR["PunchDate"]));
        //        row.CreateCell(5).SetCellValue(Convert.ToString(DR["PunchType"]));
        //        //row.CreateCell(6).SetCellValue(Convert.ToString(DR["PunchTime"]));
        //        if (Convert.ToString(DR["PunchTime"]) == String.Empty)
        //            row.CreateCell(6).SetCellValue(Convert.ToString(DR["PunchTime"]));
        //        else
        //        {
        //            row.CreateCell(6).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["PunchTime"]))).ToString(NewTimeFormat));
        //        }
        //        row.CreateCell(7).SetCellValue(Convert.ToString(DR["Process"]));
        //        if (Convert.ToString(DR["Resolution"]) == "Processed")
        //            row.CreateCell(8).SetCellValue(Convert.ToString(""));
        //        else
        //        { row.CreateCell(8).SetCellValue(Convert.ToString(DR["Resolution"])); }

        //        strPre = Convert.ToString(DR["Employee_Code_Id"]);
        //        for (int i = 0; i <= 8; i++)
        //        {
        //            row.GetCell(i).CellStyle = IStyle;
        //            sheet.AutoSizeColumn(i);
        //        }
        //        rowIndex++;
        //    }
        //}

        using (MemoryStream exportData = new MemoryStream())
        {
            workbook.Write(exportData);
            string saveAsFileName=string.Empty;
            //if (Convert.ToString(rblReportType.SelectedValue) == "1")
            //{ saveAsFileName = string.Format("RawDataReportRecentPunches-{0:d}.xls", DateTime.Now).Replace("/", "-"); }
            //else
            //{ saveAsFileName = string.Format("RawDataReportDetailedPunches-{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();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
    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 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 btn_View_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                string dtFrom = strFromdate;
                string dtTo = strTodate;
                string Level = string.Empty;
                string employeeName = string.Empty;
                string empName = string.Empty;
                string empId = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = txtEmployeeName.Text.ToString();
                    empId = txtEmployeeId.Text.Trim().ToString();
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    employeeName = employeeName.Replace(' ', '%');
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                }

               // string DeviceId = ddlDeviceIds.SelectedValue.ToString();

                //if (Convert.ToString(rblReportType.SelectedValue) == "1")
                //{
                //    //this is for Recent Raw Punches
                //    string strScript = "";
                //    strScript = strScript + "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
                //    strScript = strScript + "<meta http-equiv='X-UA-Compatible' content='IE=document.documentMode;' />";
                //    strScript = strScript + "<script language='javascript'>";
                //    strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=RawData_Latest&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&EmpName=" + employeeName + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&RawDataDashboard=" + 1 + "&ProcessType=" + rblProcessType.SelectedValue + "&DeviceId=" + DeviceId + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                //    strScript = strScript + "</script>";
                //    Response.Write(strScript);
                ////}
                //else
                //{
                    //this is for Detailed Raw Punches
                    string strScript = "";
                    strScript = strScript + "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
                    strScript = strScript + "<meta http-equiv='X-UA-Compatible' content='IE=document.documentMode;' />";
                    strScript = strScript + "<script language='javascript'>";
                    //strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=RawData&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&EmpName=" + employeeName + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "&RawDataDashboard=" + 1 + "&ProcessType=" + rblProcessType.SelectedValue + "&DeviceId=" + DeviceId + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                    strScript = strScript + "</script>";
                    Response.Write(strScript);
                //}

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                DataSet dsRawData = new DataSet();
                string dtFrom = strFromdate;
                string dtTo = strTodate;
                string Level = string.Empty;
                string employeeName = string.Empty;
                string empName = string.Empty;
                string empId = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = txtEmployeeName.Text.ToString();
                    empId = txtEmployeeId.Text.Trim().ToString();
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    employeeName = employeeName.Replace(' ', '%');
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                }
                //string DeviceId = ddlDeviceIds.SelectedValue.ToString();
                //if (Convert.ToString(rblReportType.SelectedValue) == "1")
                //{
                //    dsRawData = rptEmp.RawData(dtFrom, dtTo, empId, employeeName, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt16(ddlEmpCatagory.SelectedValue), Convert.ToInt16(ddlEmpType.SelectedValue), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, Convert.ToInt16(rblProcessType.SelectedValue), Convert.ToInt32(Session["EmpAutoID"]), DeviceId);
                //}
                //else
                //{
                //    dsRawData = rptEmp.RawData(dtFrom, dtTo, empId, employeeName, Convert.ToString(Session["UserGroupName"]), Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt16(ddlEmpCatagory.SelectedValue), Convert.ToInt16(ddlEmpType.SelectedValue), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, Convert.ToInt16(rblProcessType.SelectedValue), Convert.ToInt32(Session["EmpAutoID"]), DeviceId);
                //}

                DataTable dtLevelName = new DataTable();
                if (Convert.ToInt16(Session["parentLevelId"]) != 0)
                {
                    dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
                }

                if (dsRawData.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    ExportExcel(dsRawData, dtLevelName);
                    //Session["Export_ExcelData"] = dsRawData;
                    //Response.Redirect("Excel_Export.aspx?ReportName=Raw Data&FrmDate=" + Convert.ToString(txtFromDate.Text) + "&toDate=" + Convert.ToString(txtToDate.Text) + "");
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void ValidateFromDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            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
        {
        }
    }
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            strTodate = txtToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            DateTime dtToDate = DateTime.Parse(strTodate);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
            {
                base.Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }
    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;
    }
    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"]);
        }
    }
    protected void gvDataDetailed_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
    }
}