using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.Util;
using System.Web;
public partial class Reports_TA_UI_Report_OverTime : 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();
    EmployeeEventData objEmployee = new EmployeeEventData();
    string strFromdate, gstrDateFormat, strTodate;
    CultureInfo ci;
    int intIndividualUser = 0;
    double HrsOT, OffOT, HolOT, ActHrsOT, ActOffOT, ActHolOT, ApprovedOT, RejectOT = 0;
    TimeSpan result;
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFFont hFont;
    ISheet sheet;
    HSSFCellStyle hStyle;
    HSSFCellStyle MainHStyle;
    HSSFCellStyle IStyle;
    NPOI.SS.UserModel.IRow row;
    int rowIndex = 0;
    string dtFrom = "", dtTo = "";
    string employeeName = string.Empty;
    string empName = "", empId = "";
    string Level = string.Empty;
    string strStatus = "All";
    string SanctionType = string.Empty;
    string strEmpAutoId = "0";
    string SheeetName, ReportName = "";
    int columnCount = 0;
    int shft;
    #endregion
    #region Page Load Event
    /// <summary>
    /// On page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            ddlShift.Focus();
            objCommon.menu("OverTime", "36");
            rbCustom.Checked = true;
        }
        // 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"]);
        GettingControlsTextFrmResourceFile(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
        UserRights();
        if (!IsPostBack)
        {
            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();
            fillShift();
            FillDesignation();
            if (Request.QueryString["Source"] != null)
            {
                if (Request.QueryString["Source"].ToString() == "Email")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                    IDTest1.Visible = false;
                    lblShift.Style.Add("margin-right", "84px");
                    if (Request.QueryString["ScheduleId"] != null)
                    {
                        DataSet ds = new DataSet();
                        ds = rptEmp.GetEmailSchedulerFilterDetails(Convert.ToInt32(Request.QueryString["ScheduleId"]));
                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                Session["parentLevelId_modify"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentId"]);
                                txtEmployeeId.Text = Convert.ToString(ds.Tables[0].Rows[0]["empId"]);
                                txtEmployeeName.Text = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeName"]);
                                ddlDesignation.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["DesignationID"]);
                                ddlGender.SelectedItem.Text = Convert.ToString(ds.Tables[0].Rows[0]["Gender"]);
                                if (Convert.ToString(ds.Tables[1].Rows[0][0]) == "OTCompOff")
                                {
                                    //OTCompOff
                                    ddlShift.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["ShiftID"]);
                                }
                                else
                                {
                                    ddlShift.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["shift"]);
                                }
                                ddlEmpCatagory.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeCategory"]);
                                ddlEmpType.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["EmployeeType"]);
                                ddlOTStatus.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Status"]);
                                Session["EMailParentId"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentID"]);
                                if (Convert.ToString(ds.Tables[0].Rows[0]["SanctionType"]) == "CompOff")
                                {
                                    rbtnCompoff.Checked = true;
                                    rbtnOTCompOff.Checked = false;
                                    rbtnOverTime.Checked = false;
                                }
                                else if (Convert.ToString(ds.Tables[0].Rows[0]["SanctionType"]) == "OverTime")
                                {
                                    rbtnCompoff.Checked = false;
                                    rbtnOTCompOff.Checked = false;
                                    rbtnOverTime.Checked = true;
                                }
                                else if (Convert.ToString(ds.Tables[0].Rows[0]["SanctionType"]) == "OTCompOff")
                                {
                                    rbtnCompoff.Checked = false;
                                    rbtnOTCompOff.Checked = true;
                                    rbtnOverTime.Checked = false;
                                }
                            }
                        }
                    }
                    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];
                            }
                            ddlShift.SelectedValue = strArray1[3].ToString();
                            txtEmployeeName.Text = strArray1[4].ToString().Replace("~", ",");
                            txtEmployeeId.Text = strArray1[2].ToString().Replace("~", ",");
                            ddlEmpCatagory.SelectedValue = strArray1[6].ToString();
                            ddlEmpType.SelectedValue = strArray1[7].ToString();
                            ddlDesignation.SelectedValue = Convert.ToString(strArray1[12]);
                            ddlGender.SelectedValue = Convert.ToString(strArray1[13]);
                            ddlOTStatus.SelectedValue = strArray1[14].ToString();
                            Session["EMailParentId"] = Convert.ToString(strArray1[11]);
                            if (Convert.ToString(Session["SanctionType"]) == "CompOff")
                            {
                                rbtnCompoff.Checked = true;
                                rbtnOTCompOff.Checked = false;
                                rbtnOverTime.Checked = false;
                            }
                            else if (Convert.ToString(Session["SanctionType"]) == "OverTime")
                            {
                                rbtnCompoff.Checked = false;
                                rbtnOTCompOff.Checked = false;
                                rbtnOverTime.Checked = true;
                            }
                            else if (Convert.ToString(Session["SanctionType"]) == "OTCompOff")
                            {
                                rbtnCompoff.Checked = false;
                                rbtnOTCompOff.Checked = true;
                                rbtnOverTime.Checked = false;
                            }
                        }
                    }
                }
            }
            else
            {
                divdateTime.Visible = true;
                trView.Visible = true;
                trSave.Visible = false;
                IDTest1.Visible = false;
            }
            if (Request.QueryString["ScheduleId"] != null)
            {
                string strGet = hdnReportFilters.Value;
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "GethiddenValue();";
                strScript += " </script>";
                this.RegisterStartupScript("setScript", strScript);
                IDTest1.Visible = false;
            }
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            ddlDesignation.PreRender += LB_PreRender;
            txtFromDate.Text = (Convert.ToDateTime(objCommon.CurrentMonthStartDate())).ToString(Session["MDateFormat"].ToString());
            txtToDate.Text = (Convert.ToDateTime(System.DateTime.Now.ToShortDateString())).ToString(Session["MDateFormat"].ToString());
            if (Session["parentLevelId"] != null || Convert.ToInt16(Session["parentLevelId"]) != 0)
            {
                Session["parentLevelId"] = null;
            }
        }
        //Check whether the employee is Individual User
        intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            PlaceHolderOverTime.Controls.Clear();
            divEmployeeDetails.Visible = false;
            lblEmpSwipe.Visible = false;
            txtSwipeCard.Visible = false;
        }
        // Convert date time to MM/dd/YYYY format
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        strFromdate = txtFromDate.Text;
        strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
        strTodate = txtToDate.Text;
        strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
        ////if Standar Edition set the visibility to false
        //if (Session["Edition"].ToString() == "1")
        //{
        //    trStatus.Visible = false;
        //}
        int otApprovalExists = 0;
        otApprovalExists = objCommon.CheckPageExistsInLicense(97);
        if (otApprovalExists == 0)
        {
            trStatus.Visible = false;
        }
        if (Page.MasterPageFile.ToString() == "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 FillDesignation()
    {
        DataSet ds_designation = new DataSet();
        ds_designation = objEmployee.select_CommonDesignation();
        if (ds_designation != null)
        {
            if (ds_designation.Tables[0].Rows.Count > 0)
            {
                ddlDesignation.DataSource = ds_designation;
                ddlDesignation.DataTextField = "TitleName";
                ddlDesignation.DataValueField = "TitleId";
                ddlDesignation.DataBind();
            }
            ds_designation.Dispose();
            foreach (ListItem item in ddlDesignation.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    /// <summary>
    /// Bindings the employee category and type.
    /// </summary>
    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
            foreach (ListItem item in ddlEmpCatagory.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
        // employee type binding
        DataSet dsType = new DataSet();
        dsType = objEmployee.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();
            foreach (ListItem item in ddlEmpType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
        }
    }
    /// <summary>
    /// To fill the shift in the drop down
    /// </summary>
    public void fillShift()
    {
        ShiftEvenData getShift = new ShiftEvenData();
        DataSet ds = new DataSet();
        string strusergroup = string.Empty;
        ds = getShift.SelectShift(Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["LevelRights"]), 0);
        foreach (DataRow drRow in ds.Tables[0].Rows)
        {
            switch (drRow["Shift_Name"].ToString())
            {
                case "No Shift":
                    drRow["Shift_Name"] = rm.GetString("Caption_NoShift", ci);
                    break;
            }
        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            this.ddlShift.DataSource = ds;
            this.ddlShift.DataTextField = "Shift_Name";
            this.ddlShift.DataValueField = "Shift_Id";
            this.ddlShift.DataBind();
        }
        ListItem lstItem = new ListItem();
        lstItem.Value = "0";
        //lstItem.Text = "All";
        lstItem.Text = rm.GetString("ExportData_All", ci);
        ddlShift.Items.Insert(0, lstItem);
        //Added By Moorthi.A.K.T Reg : Bug No 0021285 On 13-Jan-2014
        ddlShift.Items.Insert(1, new ListItem(rm.GetString("List_Item_Week_Off", ci), "-1"));
        foreach (ListItem item in ddlShift.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    /// <summary>
    /// Validate the FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateFromDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            //strCurrentDate = objCommon.DateConvertion(gstrDateFormat,DateTime.Today.Date.ToString());
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            //strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            //DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date.ToString("MM/dd/yyyy")); ;
            DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
            {
                //base.Message("Select valid From Date");
                base.Message(rm.GetString("Alert_SelectvalidFromDate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }
    /// <summary>
    /// Validate the ToDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void ValidateToDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            //strCurrentDate = objCommon.DateConvertion(gstrDateFormat, DateTime.Today.Date.ToString());
            strTodate = txtToDate.Text;
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            //DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date.ToString("MM/dd/yyyy"));
            DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
            DateTime dtFromDate = DateTime.Parse(strTodate);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
            {
                //base.Message("Enter Valid To Date");
                base.Message(rm.GetString("Alert_EnterValidToDate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }
    /// <summary>
    /// Compare ToDate with FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txtFromDate.Text;
            strTodate = txtToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            DateTime dtToDate = DateTime.Parse(strTodate);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
            {
                //base.Message("Select valid date compare with Fromdate");
                base.Message(rm.GetString("Msg_SelectvaliddatecomparewithFromdate", ci));
                e.IsValid = false;
            }
        }
        catch
        {
            //
        }
    }
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void GettingControlsTextFrmResourceFile(CultureInfo ci)
    {
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblOverTimeReport.Text = rm.GetString("Reports_OverTime_OverTimeReport", ci);
        lblShift.Text = rm.GetString("Menu_Reports_Shift", 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);
        lblStatus.Text = rm.GetString("email_Status", ci);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", ci);
        ddlOTStatus.Items[0].Text = rm.GetString("ExportData_All", ci);
        ddlOTStatus.Items[1].Text = rm.GetString("btn_Approved", ci);
        ddlOTStatus.Items[2].Text = rm.GetString("btn_Forwarded", ci);
        ddlOTStatus.Items[3].Text = rm.GetString("btn_Pending", ci);
        ddlOTStatus.Items[4].Text = rm.GetString("btn_Reject", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Alert_SelectShift", ci);
        reqFromDate.ErrorMessage = rm.GetString("Alert_PleaseselectFromDate", ci);
        reqToDate.ErrorMessage = rm.GetString("Alert_PleaseselectToDate", ci);
        ddlEmpCatagory.Items[0].Text = rm.GetString("Select", ci);
        ddlEmpType.Items[0].Text = rm.GetString("Select", ci);
        lblDesignation.Text = rm.GetString("EmployeeMaster_Designation", ci);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        ddlGender.Items[0].Text = rm.GetString("Caption_Both", ci);
        ddlGender.Items[1].Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
        ddlGender.Items[2].Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
        ddlDesignation.Items[0].Text = rm.GetString("ExportData_All", ci);
        lblSanctionType.Text = rm.GetString("EmployeeInOutReportType", ci);
        rbtnOverTime.Text = rm.GetString("Menu_Reports_OverTime", ci);
        rbtnCompoff.Text = rm.GetString("Caption_CompOff", ci);
        rbtnOTCompOff.Text = rm.GetString("rbtn_OTCompOff", ci);
        btnSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        lblDateFilter.Text = rm.GetString("lbl_DateFilter", ci);
        btn_Export.Text = "&nbsp;&nbsp;" + rm.GetString("btn_ExporttoExcel", ci);
        rbCustom.Text = rm.GetString("rb_Custom", ci);
        rbpreviousMonth.Text = rm.GetString("rb_PreviousMonth", ci);
        rbpreviousweek.Text = rm.GetString("rb_PreviousWeek", ci);
        rbThisMonth.Text = rm.GetString("rb_ThisMonth", ci);
        rbThisweek.Text = rm.GetString("rb_ThisWeek", ci);
        lbl_Filters.Text = rm.GetString("lblFilter", ci);
    }
    /// <summary>
    /// To check the rights for the logged in user
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(36, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                btn_View.Visible = true;
            }
            else
            {
                btn_View.Visible = false;
            }
        }
        else
        {
            Response.Redirect("ReportsLandingPage.aspx");
        }
    }
    /// <summary>
    /// To apply tooltip for the designation in the drop down
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void LB_PreRender(object sender, System.EventArgs e)
    {
        foreach (ListItem item in ddlDesignation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region Button Events
    /// <summary>
    /// Load the Over Time report
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                GetFilter(0);
                //Redirect the page to the report viewer
                StringBuilder strScript = new StringBuilder();
                strScript.Append("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
                strScript.Append("<meta http-equiv='X-UA-Compatible' content='IE=edge' />");
                strScript.Append("<script language='javascript'>");
                strScript.Append("window.open('TA_UI_Report_ReportViewer.aspx?ReportName=OverTime&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&SanctionType=" + SanctionType + "&empid=" + empId + "&shft=" + Convert.ToInt16(this.ddlShift.SelectedValue) + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(Session["parentLevelId"]).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) +"&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&Status=" + strStatus + "&SwipeCard=" + txtSwipeCard.Text.ToString().Trim().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');");
                strScript.Append("</script>");
                Response.Write(strScript);
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                GetFilter(1);
                StringBuilder strFilters = new StringBuilder();
                strFilters.Append("@empId=" + empId + ",");
                if (SanctionType == "OTCompOff")
                {
                    strFilters.Append("@Shiftid=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@fromDate=" + " Duration_From " + ",");
                    strFilters.Append("@ToDate=" + " Duration_To " + ",");
                    strFilters.Append("@EmpAutoId=0" + ",");
                }
                else
                {
                    strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                    strFilters.Append("@fromDat=" + " Duration_From " + ",");
                    strFilters.Append("@ToDat=" + " Duration_To " + ",");
                    strFilters.Append("@EmpAutoId=0" + ",");
                }
                strFilters.Append("@EmployeeName=" + employeeName + ",");
                strFilters.Append("@LevelID=" + "0,");
                strFilters.Append("@EmployeeCategory=" + ddlEmpCatagory.SelectedValue + ",");
                strFilters.Append("@EmployeeType=" + ddlEmpType.SelectedValue + ",");
                strFilters.Append("@UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + ",");
                strFilters.Append("@GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + ",");
                strFilters.Append("@EmpSwipeCard=" + txtSwipeCard.Text.ToString().Trim().Replace("'", "''") + ",");
                strFilters.Append("@ParentId=" + Convert.ToInt32(Session["parentLevelId"]).ToString() + ",");
                strFilters.Append("@DesignationID=" + ddlDesignation.SelectedValue + ",");
                strFilters.Append("@Gender=" + ddlGender.SelectedValue + ",");
                strFilters.Append("@Status=" + strStatus + ",");
                strFilters.Append("@SanctionType=" + SanctionType);
                Session["hdnReportFilters"] = string.Empty;
                Session["hdnReportFilters"] = strFilters;
                Session["SanctionType"] = SanctionType;
                string strScript = "<script language=\"javascript\">";
                strScript = strScript + "{window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnFilters').value='" + strFilters + "'; window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnCompanyId').value='" + Convert.ToInt32(Session["parentLevelId"]).ToString() + "';window.top.parent.document.getElementById('ctl00_BodyContentPH_hdnReportType').value='" + Session["SanctionType"] + "';}";
                //strScript = strScript + "self.close();";
                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 = strArray1[2].ToString();
            ddlShift.SelectedValue = strArray1[3].ToString();
            txtEmployeeName.Text = Convert.ToString(strArray1[4].ToString()).Trim().Replace("''", "'");
            txtEmployeeName.Text = Convert.ToString(strArray1[4].ToString()).Trim().Replace("%", " ");
            ddlEmpCatagory.SelectedValue = strArray1[6].ToString();
            ddlEmpType.SelectedValue = strArray1[7].ToString();
            txtSwipeCard.Text = strArray1[10].ToString();
            ucOrganizationLevel.Visible = false;
            Session["parentLevelId_modify"] = hdnCompanyId1.Value;
            ddlDesignation.SelectedValue = strArray1[12].ToString();
            ddlGender.SelectedValue = strArray1[13].ToString();
            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('ctl00_TA_uc_Header1_RptLogoHeader').style.display = 'none';";
            //strScript = strScript + "document.getElementById('ctl00_BodyContentPH_TimePeriod').style.display = 'none';";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("Script", strScript);
            btnSave.Visible = true;
            btn_View.Visible = false;
            btnBack.Visible = true;
            IDTest1.Visible = false;
        }
    }
    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;
    }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dsEmp = new DataSet();
            if (Page.IsValid == true)
            {
                GetFilter(0);
                if (SanctionType == "OTCompOff")
                {
                    dsEmp = rptEmp.SelectOverTimeCompOff(dtFrom, dtTo, empId, shft, employeeName, Level, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strStatus, txtSwipeCard.Text.ToString().Trim().Replace("'", "''"), Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, Convert.ToInt32(Session["EmpAutoID"]));
                }
                else
                {
                    dsEmp = rptEmp.SelectOverTime(dtFrom, dtTo, empId, shft, employeeName, Level, Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), strStatus, txtSwipeCard.Text.ToString().Trim().Replace("'", "''"), Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, SanctionType, Convert.ToInt32(strEmpAutoId));
                }
                if (dsEmp.Tables["Table"] == null || dsEmp.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    if (SanctionType == "CompOff")
                    {
                        ReportName = "Compensationreport";
                        SheeetName = "Compensation report";
                        columnCount = 11;
                    }
                    else
                    {
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_NormOT1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_NormOT1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_NormOTHrs1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_NormOTHrs1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_NormOT2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_NormOT2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_NormOTHrs2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_NormOTHrs2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_OffOT1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_OffOT1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_OffOTHrs1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_OffOTHrs1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_OffOT2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_OffOT2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_OffOTHrs2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_OffOTHrs2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_HOLOT1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_HOLOT1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_HolOTHrs1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_HolOTHrs1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_HOLOT2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_HOLOT2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_HolOTHrs2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_HolOTHrs2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_NormOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_NormOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_NormOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_NormOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_OffOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_OffOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_OffOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_OffOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_HOLOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_HOLOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SPEC_HOLOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SPEC_HOLOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_NormOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_NormOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_NormOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_NormOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_OffOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_OffOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_OffOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_OffOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_HolOTMins1"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_HolOTMins1");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("Modified_Spec_HolOTMins2"))
                        {
                            dsEmp.Tables[0].Columns.Remove("Modified_Spec_HolOTMins2");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("shift_id"))
                        {
                            dsEmp.Tables[0].Columns.Remove("shift_id");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ShiftName"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ShiftName");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("OtMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("OtMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("NormOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("NormOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("WeekOffOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("WeekOffOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("HolidayOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("HolidayOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ActNormOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ActNormOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ActWeekOffOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ActWeekOffOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ActHolidayOTMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ActHolidayOTMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ApprovedOTHours"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ApprovedOTHours");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("RejectOTHours"))
                        {
                            dsEmp.Tables[0].Columns.Remove("RejectOTHours");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SelectedRecords"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SelectedRecords");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("SwipeCardNo"))
                        {
                            dsEmp.Tables[0].Columns.Remove("SwipeCardNo");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("ActOtMins"))
                        {
                            dsEmp.Tables[0].Columns.Remove("ActOtMins");
                        }
                        if (dsEmp.Tables[0].Columns.Contains("HrsWork"))
                        {
                            dsEmp.Tables[0].Columns["HrsWork"].ColumnName = "Worked Hours";
                        }
                        if (dsEmp.Tables[0].Columns.Contains("HrsWork"))
                        {
                            dsEmp.Tables[0].Columns["HrsWork"].ColumnName = "Worked Hours";
                        }
                        ReportName = "Over Time";
                        Session["Export_ExcelData"] = dsEmp;
                        Response.Redirect("Excel_Export.aspx?ReportName=" + ReportName + "&FrmDate=" + Convert.ToString(txtFromDate.Text) + "&toDate=" + Convert.ToString(txtToDate.Text) + "");
                        return;
                    }
                    ExportExcel(dsEmp);
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    #endregion
    #region Export Excel
    protected void ExportExcel(DataSet dsEmp)
    {
        DataTable dtLevelName = new DataTable();
        if (Convert.ToInt16(Session["parentLevelId"]) != 0)
        {
            dtLevelName = rptEmp.getHeader(Convert.ToInt16(Session["parentLevelId"]));
        }
        string NewTimeFormat = string.Empty;
        string TimeFormat = Convert.ToString(Session["ITimeFormat"]);
        if (TimeFormat == "HH:mm")
        {
            NewTimeFormat = "HH:mm";
        }
        else
        {
            NewTimeFormat = "hh:mm tt";
        }
        //Val
        hFont = (HSSFFont)workbook.CreateFont();
        hStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        MainHStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        IStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        sheet = workbook.CreateSheet(SheeetName);
        NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
        hFont.Boldweight = (short)FontBoldWeight.Bold;
        hFont.Color = HSSFColor.Maroon.Index;
        hFont.FontHeightInPoints = 10;
        hStyle.SetFont(hFont);
        hStyle.FillForegroundColor = IndexedColors.White.Index;
        hStyle.FillPattern = FillPattern.SolidForeground;
        hStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        hStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
        MainHStyle.SetFont(hFont);
        MainHStyle.Alignment = HorizontalAlignment.Center;
        IStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
        IStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
        if (dtLevelName.Rows.Count > 0)
        {
            row.CreateCell(0).SetCellValue(Convert.ToString(dtLevelName.Rows[0][0]));
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, columnCount));
            row.GetCell(0).CellStyle = MainHStyle;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
        }
        row.CreateCell(0).SetCellValue(SheeetName + " From - " + Convert.ToString(txtFromDate.Text) + " - " + "To - " + Convert.ToString(txtToDate.Text));
        row.GetCell(0).CellStyle = MainHStyle;
        sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, columnCount));
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        if (SanctionType == "CompOff")
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee ID");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Gender");
            row.CreateCell(4).SetCellValue("Shift");
            row.CreateCell(5).SetCellValue("Date");
            row.CreateCell(6).SetCellValue("Worked Hours");
            row.CreateCell(7).SetCellValue("Extra Worked Hrs");
            row.CreateCell(8).SetCellValue("Weekly Off Worked OT");
            row.CreateCell(9).SetCellValue("Holiday Worked Hrs");
            row.CreateCell(10).SetCellValue("Status");
            row.CreateCell(11).SetCellValue("Expiry Date");
            //row.RowStyle = hStyle;
            for (int i = 0; i <= 11; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
                sheet.AutoSizeColumn(i);
            }
            rowIndex++;
            string strPre = string.Empty;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                if (strPre != string.Empty)
                {
                    if (strPre != Convert.ToString(DR["Employee_Code_Id"]))
                    {
                        subtotal();
                    }
                }
                row = sheet.CreateRow(rowIndex);
                if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
                {
                    SlNo++;
                    row.CreateCell(0).SetCellValue(SlNo);
                    row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                    row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_FirstName"]));
                    row.CreateCell(3).SetCellValue(Convert.ToString(DR["Gender"]));
                }
                else
                {
                    row.CreateCell(0).SetCellValue("");
                    row.CreateCell(1).SetCellValue("");
                    row.CreateCell(2).SetCellValue("");
                    row.CreateCell(3).SetCellValue("");
                }
                
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["ShiftName"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Date"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["HrsWork"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["HrsOT"]));
                row.CreateCell(8).SetCellValue(Convert.ToString(DR["OffOT"]));
                row.CreateCell(9).SetCellValue(Convert.ToString(DR["HolOT"]));
                row.CreateCell(10).SetCellValue(Convert.ToString(DR["OverTimeStatus"]));
                row.CreateCell(11).SetCellValue(Convert.ToString(DR["Expiry Date"]));
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                HrsOT = HrsOT + Convert.ToDouble(DR["NormOTMins"]);
                OffOT = OffOT + Convert.ToDouble(DR["WeekOffOTMins"]);
                HolOT = HolOT + Convert.ToDouble(DR["HolidayOTMins"]);
                //Style Added the created Headers.
                for (int i = 0; i <= 11; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
            }
        }
        else
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee ID");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Gender");
            row.CreateCell(4).SetCellValue("Shift");
            row.CreateCell(5).SetCellValue("Date");
            row.CreateCell(6).SetCellValue("Worked Hours");
            row.CreateCell(7).SetCellValue("Actual Week day OT");
            row.CreateCell(8).SetCellValue("Modified Week Day OT");
            row.CreateCell(9).SetCellValue("Actual Week Off OT");
            row.CreateCell(10).SetCellValue("Modified Week Off Day OT");
            row.CreateCell(11).SetCellValue("Actual Holiday OT");
            row.CreateCell(12).SetCellValue("Modified Holiday OT");
            row.CreateCell(13).SetCellValue("Status");
            //row.RowStyle = hStyle;
            for (int i = 0; i <= 13; i++)
            {
                row.GetCell(i).CellStyle = hStyle;
                sheet.AutoSizeColumn(i);
            }
            rowIndex++;
            string strPre = string.Empty;
            Int32 SlNo = 0;
            foreach (DataRow DR in dsEmp.Tables[0].Rows)
            {
                if (strPre != string.Empty)
                {
                    if (strPre != Convert.ToString(DR["Employee_Code_Id"]))
                    {
                        subtotal();
                    }
                }
                row = sheet.CreateRow(rowIndex);
                if (strPre == string.Empty || strPre != Convert.ToString(DR["Employee_Code_Id"]))
                {
                    SlNo++;
                    row.CreateCell(0).SetCellValue(SlNo);
                }
                else
                {
                    row.CreateCell(0).SetCellValue("");
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Code_Id"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["Employee_FirstName"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["shiftName"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Date"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["HrsWork"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["ActHrsOT"]));
                row.CreateCell(8).SetCellValue(Convert.ToString(DR["HrsOT"]));
                row.CreateCell(9).SetCellValue(Convert.ToString(DR["ActOffOT"]));
                row.CreateCell(10).SetCellValue(Convert.ToString(DR["OffOT"]));
                row.CreateCell(11).SetCellValue(Convert.ToString(DR["ActHolOT"]));
                row.CreateCell(12).SetCellValue(Convert.ToString(DR["HolOT"]));
                row.CreateCell(13).SetCellValue(Convert.ToString(DR["OverTimeStatus"]));
                strPre = Convert.ToString(DR["Employee_Code_Id"]);
                HrsOT = HrsOT + Convert.ToDouble(DR["NormOTMins"]);
                OffOT = OffOT + Convert.ToDouble(DR["WeekOffOTMins"]);
                HolOT = HolOT + Convert.ToDouble(DR["HolidayOTMins"]);
                ActHrsOT = ActHrsOT + Convert.ToDouble(DR["ActNormOTMins"]);
                ActOffOT = ActOffOT + Convert.ToDouble(DR["ActWeekOffOTMins"]);
                ActHolOT = ActHolOT + Convert.ToDouble(DR["ActHolidayOTMins"]);
                if (Convert.ToString(DR["OverTimeStatus"]) == "Approved")
                {
                    if (Convert.ToDouble(DR["NormOTMins"]) != 0)
                        ApprovedOT = ApprovedOT + Convert.ToDouble(DR["NormOTMins"]);
                    else if (Convert.ToDouble(DR["WeekOffOTMins"]) != 0)
                        ApprovedOT = ApprovedOT + Convert.ToDouble(DR["WeekOffOTMins"]);
                    else
                        ApprovedOT = ApprovedOT + Convert.ToDouble(DR["HolidayOTMins"]);
                }
                RejectOT = RejectOT + Convert.ToDouble(DR["RejectOTHours"]);
                //Style Added the created Headers.
                for (int i = 0; i <= 13; i++)
                {
                    row.GetCell(i).CellStyle = IStyle;
                    sheet.AutoSizeColumn(i);
                }
                rowIndex++;
            }
        }
        subtotal();
        using (MemoryStream exportData = new MemoryStream())
        {
            workbook.Write(exportData);
            string saveAsFileName = string.Format(ReportName + "-{0:d}.xls", DateTime.Now).Replace("/", "-");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
            Response.Clear();
            Response.BinaryWrite(exportData.GetBuffer());
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
    protected void subtotal()
    {
        if (SanctionType == "CompOff")
        {
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(6).SetCellValue("Sub Total");
            row.GetCell(6).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(HrsOT);
            row.CreateCell(7).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(7).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(OffOT);
            row.CreateCell(8).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(8).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(HolOT);
            row.CreateCell(9).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(9).CellStyle = hStyle;
            row.CreateCell(10).SetCellValue("");
            row.GetCell(10).CellStyle = hStyle;
            HrsOT = 0.0;
            OffOT = 0.0;
            HolOT = 0.0;
        }
        else
        {
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(6).SetCellValue("Sub Total");
            row.GetCell(6).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ActHrsOT);
            row.CreateCell(7).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(7).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(HrsOT);
            row.CreateCell(8).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(8).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ActOffOT);
            row.CreateCell(9).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(9).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(OffOT);
            row.CreateCell(10).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(10).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(ActHolOT);
            row.CreateCell(11).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(11).CellStyle = hStyle;
            result = TimeSpan.FromMinutes(HolOT);
            row.CreateCell(12).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(12).CellStyle = hStyle;
            row.CreateCell(13).SetCellValue("");
            row.GetCell(13).CellStyle = hStyle;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
            row.CreateCell(6).SetCellValue("Total OT Hours - Worked : ");
            row.GetCell(6).CellStyle = hStyle;
            sheet.AutoSizeColumn(6);
            result = TimeSpan.FromMinutes(ActHrsOT + ActOffOT + ActHolOT);
            row.CreateCell(7).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(7).CellStyle = hStyle;
            row.CreateCell(8).SetCellValue("Total Approved OT Hours : ");
            row.GetCell(8).CellStyle = hStyle;
            sheet.AutoSizeColumn(8);
            result = TimeSpan.FromMinutes(ApprovedOT);
            row.CreateCell(9).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(9).CellStyle = hStyle;
            row.CreateCell(10).SetCellValue("Total OT Hrs - Deducted : ");
            row.GetCell(10).CellStyle = hStyle;
            sheet.AutoSizeColumn(10);
            result = TimeSpan.FromMinutes(RejectOT);
            row.CreateCell(11).SetCellValue(string.Format("{0:00}:{1:00}", (int)result.TotalHours, result.Minutes));
            row.GetCell(11).CellStyle = hStyle;
            row.CreateCell(12).SetCellValue("");
            row.GetCell(12).CellStyle = hStyle;
            row.CreateCell(13).SetCellValue("");
            row.GetCell(13).CellStyle = hStyle;
            HrsOT = 0.0;
            OffOT = 0.0;
            HolOT = 0.0;
            ActHrsOT = 0.0;
            ActOffOT = 0.0;
            ActHolOT = 0.0;
            ApprovedOT = 0.0;
            RejectOT = 0.0;
        }
        rowIndex++;
    }
    protected void GetFilter(int val)
    {
        if (Session["ReportsBasedOn"] != null)
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False")
            {
                strEmpAutoId = "0";
            }
            else
            {
                strEmpAutoId = Convert.ToString(Session["EmpAutoID"]);
            }
        }
        shft = Convert.ToInt16(this.ddlShift.SelectedValue);
        if (txtFromDate.Text != "")
            dtFrom = strFromdate;
        if (txtToDate.Text != "")
            dtTo = strTodate;
        if (ddlOTStatus.SelectedValue == "Approved")
        {
            strStatus = "Approved";
        }
        else if (ddlOTStatus.SelectedValue == "Forwarded")
        {
            strStatus = "Forwarded";
        }
        else if (ddlOTStatus.SelectedValue == "Pending")
        {
            strStatus = "Pending";
        }
        else if (ddlOTStatus.SelectedValue == "Rejected")
        {
            strStatus = "Rejected";
        }
        else
        {
            strStatus = "All";
        }
        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"]));
            if (val == 1)
            {
                if (Level.Contains(","))
                {
                    Level = Level.Replace(",", "~");
                }
                if (employeeName.Contains(","))
                {
                    employeeName = employeeName.Replace(",", "~");
                }
                if (empId.Contains(","))
                {
                    empId = empId.Replace(",", "~");
                }
            }
        }
        if (rbtnCompoff.Checked == true)
        {
            SanctionType = "CompOff";
        }
        else if (rbtnOverTime.Checked == true)
        {
            SanctionType = "OverTime";
        }
        else if (rbtnOTCompOff.Checked == true)
        {
            SanctionType = "OTCompOff";
        }
    }
    #endregion
}
