using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Text;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System.IO;
using NPOI.HSSF.Util;
using System.Web;
using NPOI.SS.Util;
public partial class Reports_TA_UI_Report_LessHoursWorked : 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();
    EmployeeEventData objEmployee = new EmployeeEventData();
    ResourceManager rm;
    CultureInfo ci;
    bool ok;
    string dtFrom = "", dtTo = "";
    string empName = "", EmployeeId = "";
    cls_Common objCommon = new cls_Common();
    string strFromdate, gstrDateFormat, strTodate;
    int intIndividualUser = 0;
    string gStrLevel = string.Empty;
    string ParenetLevelid = string.Empty;
    string SummaryOrDetail = string.Empty, strReportType = "Normal", strEmpAutoId = "0", Level = string.Empty, employeeName = string.Empty, empId = string.Empty;
    int shift = 0;
    DataSet dsLesshours = new DataSet();
    #endregion
    #region PageLoad
    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("Exception Reports", "127");
        }
        //get the culture info to set the language        
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_EnterDate", ci) + "','" + rm.GetString("Alert_EnterToDate", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //Set UserRights
        UserRights();
        if (!IsPostBack)
        {
            // Bindings the employee category and type.
            BindingEmployeeCategoryandType();
            BindShift();
            BindDesignation();
            if (Request.QueryString["Source"] != null)
            {
                if (Request.QueryString["Source"].ToString() == "Email")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                    IDTest1.Visible = false;
                    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]["EmployeeId"]);
                                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"]);
                                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"]);
                                Session["EMailParentId"] = Convert.ToString(ds.Tables[0].Rows[0]["ParentID"]);
                                TickCheckbox(Convert.ToString(ds.Tables[0].Rows[0]["TypeOfReport"]));
                            }
                        }
                    }
                    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[5].ToString();
                            ddlEmpType.SelectedValue = strArray1[6].ToString();
                            ddlDesignation.SelectedValue = Convert.ToString(strArray1[11]);
                            ddlGender.SelectedValue = Convert.ToString(strArray1[12]);
                            Session["EMailParentId"] = Convert.ToString(strArray1[10]);
                            TickCheckbox(Convert.ToString(strArray1[13]));
                        }
                    }
                }
            }
            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;
            }
        }
        else
        {
            if (Request.QueryString["Source"] != null)
            {
                if (Request.QueryString["Source"].ToString() == "Email")
                {
                    divdateTime.Visible = false;
                    trView.Visible = false;
                    trSave.Visible = true;
                }
            }
            else
            {
                divdateTime.Visible = true;
                trView.Visible = true;
                trSave.Visible = false;
            }
        }
        //Check whether the employee is Individual User
        intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            PlaceHolderLateEntry.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 (Page.MasterPageFile.ToString() == "TA_Popup_Report_MasterPage.master")
        {
            conHeader.Visible = false;
        }
    }

    private void TickCheckbox(string str)
    {
        switch (str)
        {
            case "s":
                rbtSummary.Checked = true;
                rbtDetail.Checked = false;
                break;
            default:
                rbtSummary.Checked = false;
                rbtDetail.Checked = true;
                break;
        }
    }

    private void LB_PreRender(object sender, System.EventArgs e)
    {
        foreach (ListItem item in ddlDesignation.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["Source"] != null)
            this.Page.MasterPageFile = "TA_Popup_Report_MasterPage.master";
    }
    #endregion

    private void GetAndSetFieldValues()
    {
        if (Session["ReportsBasedOn"] != null)
        {
            if (Convert.ToString(Session["ReportsBasedOn"]) == "False")
                strEmpAutoId = "0";
            else
                strEmpAutoId = Convert.ToString(Session["EmpAutoID"]);
        }
        if (txtFromDate.Text != "")
            dtFrom = strFromdate;
        if (txtToDate.Text != "")
            dtTo = strTodate;
        shift = Convert.ToInt32(ddlShift.SelectedValue);
        if (intIndividualUser >= 1)
        {
            empName = string.Empty;
            Level = string.Empty;
            empId = Convert.ToString(Session["EmployeeCodeId"]);
            EmployeeId = Convert.ToString(Session["EmployeeCodeId"]);
        }
        else
        {
            empName = Convert.ToString(txtEmployeeName.Text);
            empId = Convert.ToString(txtEmployeeId.Text.Trim());
            EmployeeId = Convert.ToString(txtEmployeeId.Text.Trim());
            employeeName = this.txtEmployeeName.Text.Replace("'", "''");
            Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
            gStrLevel = Level;
        }
        SummaryOrDetail = (rbtSummary.Checked == true) ? "s" : "D";
    }

    #region ButtonEvents
    protected void btn_View_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                GetAndSetFieldValues();
                dsLesshours = GetDataSet();
                ParenetLevelid = Convert.ToInt16(Session["parentLevelId"]).ToString();
                if (dsLesshours.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    string strScript = "";
                    strScript = strScript + "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
                    strScript = strScript + "<meta http-equiv='X-UA-Compatible' content='IE=edge' />";
                    strScript = strScript + "<script language='javascript'>";
                    switch (SummaryOrDetail)
                    {
                        case "s":
                            strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=LessHoursWorked&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + shift + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(ParenetLevelid).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + txtSwipeCard.Text.Trim().ToString().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&LessHoursWorked_SummaryOrDetail=" + SummaryOrDetail + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                            break;
                        default:
                            strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=LessHoursWorked&dtFrom=" + dtFrom + "&dtTo=" + dtTo + "&empid=" + empId + "&shft=" + shift + "&EmpName=" + employeeName + "&Level=" + Level + "&EmpCategory=" + Convert.ToInt32(ddlEmpCatagory.SelectedValue) + "&EmpType=" + Convert.ToInt32(ddlEmpType.SelectedValue) + "&ParentLevelId=" + Convert.ToInt16(ParenetLevelid).ToString() + "&UserGroupName=" + Convert.ToString(Session["UserGroupName"]) + "&GradeLevel=" + Convert.ToString(Session["GradeLevel"]) + "&SwipeCard=" + txtSwipeCard.Text.Trim().ToString().Replace("'", "''") + "&Designation=" + Convert.ToInt32(ddlDesignation.SelectedValue) + "&LessHoursWorked_SummaryOrDetail=" + SummaryOrDetail + "&Gender=" + ddlGender.SelectedValue + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                            break;
                    }
                    strScript = strScript + "</script>";
                    Response.Write(strScript);
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }

    private DataSet GetDataSet()
    {
        dsLesshours = rptEmp.SelectLessHoursWorkedReport(EmployeeId, dtFrom, dtTo, employeeName, Convert.ToInt16(this.ddlShift.SelectedValue), Convert.ToInt32(ddlEmpCatagory.SelectedValue), Convert.ToInt32(ddlEmpType.SelectedValue), Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), txtSwipeCard.Text.Trim().ToString().Replace("'", "''"), Convert.ToInt16(Session["parentLevelId"]), Convert.ToInt32(ddlDesignation.SelectedValue), ddlGender.SelectedValue, SummaryOrDetail, Convert.ToInt64(strEmpAutoId));
        return dsLesshours;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                string SummaryOrDetail = string.Empty;
                string ReportType = "";
                if (rbtSummary.Checked == true)
                {
                    SummaryOrDetail = "s";
                    ReportType = "1";
                }
                else
                {
                    SummaryOrDetail = "D";
                    ReportType = "0";
                }
                string employeeName = string.Empty;
                string empName = "", empId = "";
                string Level = string.Empty;
                if (intIndividualUser >= 1)
                {
                    empName = string.Empty;
                    Level = string.Empty;
                    empId = Convert.ToString(Session["EmployeeCodeId"]);
                }
                else
                {
                    empName = Convert.ToString(txtEmployeeName.Text);
                    empId = Convert.ToString(txtEmployeeId.Text.Trim());
                    employeeName = this.txtEmployeeName.Text.Replace("'", "''");
                    Level = rptcommon.getNodes(Convert.ToInt16(Session["parentLevelId"]), Convert.ToString(Session["LevelRights"]));
                    if (Level.Contains(","))
                    {
                        Level = Level.Replace(",", "~");
                    }
                    if (employeeName.Contains(","))
                    {
                        employeeName = employeeName.Replace(",", "~");
                    }
                    if (empId.Contains(","))
                    {
                        empId = empId.Replace(",", "~");
                    }
                }
                StringBuilder strFilters = new StringBuilder();
                strFilters.Append("@fromDat=" + " Duration_From " + ",");
                strFilters.Append("@ToDat=" + " Duration_To " + ",");
                strFilters.Append("@EmployeeId=" + empId + ",");
                strFilters.Append("@shift=" + ddlShift.SelectedValue + ",");
                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("@EmpAutoId=0,");
                strFilters.Append("@TypeOfReport=" + SummaryOrDetail);
                Session["hdnReportFilters"] = string.Empty;
                Session["hdnReportFilters"] = strFilters;
                Session["ReportType"] = ReportType;
                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='" + ReportType + "';}";
                //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
        {
            if (Page.IsValid == true)
            {
                GetAndSetFieldValues();
                dsLesshours = GetDataSet();
                if (dsLesshours.Tables["Table"].Rows.Count == 0)
                {
                    Message(rm.GetString("Alert_Thereisnorecord", ci));
                    return;
                }
                else
                {
                    if (dsLesshours.Tables[0].Columns.Contains("TOTALMINSWORKED"))
                        dsLesshours.Tables[0].Columns.Remove("TOTALMINSWORKED");
                    if (SummaryOrDetail == "D")
                        if (dsLesshours.Tables[0].Columns.Contains("TOTALMINSALLOCATED"))
                            dsLesshours.Tables[0].Columns.Remove("TOTALMINSALLOCATED");
                    if (SummaryOrDetail == "D")
                        if (dsLesshours.Tables[0].Columns.Contains("GENDER"))
                            dsLesshours.Tables[0].Columns.Remove("GENDER");
                    if (dsLesshours.Tables[0].Columns.Contains("TOTALLESSMINS"))
                        dsLesshours.Tables[0].Columns.Remove("TOTALLESSMINS");
                    if (dsLesshours.Tables[0].Columns.Contains("SHIFT_SHORTNAME"))
                        dsLesshours.Tables[0].Columns.Remove("SHIFT_SHORTNAME");
                    if (dsLesshours.Tables[0].Columns.Contains("BRANCHNAME"))
                        dsLesshours.Tables[0].Columns.Remove("BRANCHNAME");

                    Session["Export_ExcelData"] = dsLesshours;
                    string exportReportName = "";
                    exportReportName = (SummaryOrDetail == "D") ? "Less Hours Worked - Detail" : "Less Hours Worked - Summary";
                    Response.Redirect("Excel_Export.aspx?ReportName=" + exportReportName + "&FrmDate=" + Convert.ToString(txtFromDate.Text) + "&toDate=" + Convert.ToString(txtToDate.Text) + "");
                }
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    #endregion
    #region UserDefinedFunctions
    public void BindShift()
    {
        ShiftEvenData getShift = new ShiftEvenData();
        DataSet ds = new DataSet();
        string strusergroup = string.Empty;
        if (ViewState["vs_LHShifts"] != null)
            ds = (DataSet)ViewState["vs_LHShifts"];
        else
            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)
        {
            ViewState["vs_LHShifts"] = ds;
            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 = rm.GetString("ExportData_All", ci);
        ddlShift.Items.Insert(0, lstItem);
        BindDropDowntitle(ddlShift);
    }
    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);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
                e.IsValid = false;
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    public void ValidateToDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = txtToDate.Text;
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            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
                e.IsValid = false;
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    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
                e.IsValid = false;
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lblFilter.Text = rm.GetString("lblFilter", ci);
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        lblLessHrsWorkedReports.Text = rm.GetString("Dash_LessHoursWorked", 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);
        lblEmpSwipe.Text = rm.GetString("TerminalDataType_Card_No", 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);
        lblReportType.Text = rm.GetString("EmployeeInOutReportType", ci);
        rbtSummary.Text = rm.GetString("EmployeeInOutSummary", ci);
        rbtDetail.Text = rm.GetString("EmployeeInOutDetails", 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);

    }
    private void BindDesignation()
    {
        DataSet ds_designation = new DataSet();
        if (ViewState["vs_Designation"] != null)
        {
            ds_designation = (DataSet)ViewState["vs_Designation"];
        }
        else
            ds_designation = objEmployee.select_CommonDesignation();

        if (ds_designation != null)
        {
            if (ds_designation.Tables[0].Rows.Count > 0)
            {
                ViewState["vs_Designation"] = ds_designation;
                ddlDesignation.DataSource = ds_designation;
                ddlDesignation.DataTextField = "TitleName";
                ddlDesignation.DataValueField = "TitleId";
                ddlDesignation.DataBind();
            }
            ds_designation.Dispose();
            BindDropDowntitle(ddlDesignation);
        }
    }

    private void BindingEmployeeCategoryandType()
    {
        // employee category binding
        DataSet dsCategory = new DataSet();
        if (ViewState["vs_Category"] != null)
        {
            dsCategory = (DataSet)ViewState["vs_Category"];
        }
        else
            dsCategory = objEmployee.SelectCategoryDetailsEmployee("");
        if (dsCategory != null)
        {
            if (dsCategory.Tables[0].Rows.Count > 0)
            {
                ViewState["vs_Category"] = dsCategory;
                ddlEmpCatagory.DataSource = dsCategory;
                ddlEmpCatagory.DataTextField = "CategoryName";
                ddlEmpCatagory.DataValueField = "CategoryId";
                ddlEmpCatagory.DataBind();
            }
            dsCategory.Dispose();
            BindDropDowntitle(ddlEmpCatagory);
        }
        // employee type binding
        DataSet dsType = new DataSet();
        if (ViewState["vs_Type"] != null)
        {
            dsType = (DataSet)ViewState["vs_Type"];
        }
        else
            dsType = objEmployee.SelectTypeDetailsEmployee("");
        if (dsType != null)
        {
            if (dsType.Tables[0].Rows.Count > 0)
            {
                ViewState["vs_Type"] = dsType;
                ddlEmpType.DataSource = dsType;
                ddlEmpType.DataTextField = "TypeName";
                ddlEmpType.DataValueField = "TypeId";
                ddlEmpType.DataBind();
            }
            dsType.Dispose();
            BindDropDowntitle(ddlEmpType);
        }
    }

    private void BindDropDowntitle(DropDownList ddl)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }

    private void UserRights()
    {
        if (ViewState["vs_Checkuser"] != null)
            ds_Checkuser = (DataSet)ViewState["vs_Checkuser"];
        else
            ds_Checkuser = objCheckUser.checkRights(127, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            ViewState["vs_Checkuser"] = ds_Checkuser;
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
                btn_View.Visible = true;
            else
                btn_View.Visible = false;
        }
        else
            Response.Redirect("ReportsLandingPage.aspx");
    }
    /// <summary>
    /// Export to excel Functionality operation
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ExportExcel(DataSet dsEmp, DataTable dtLevelName)
    {
        string SheetName = "";
        if (rbtSummary.Checked == true)
        { SheetName = "Less Hours Worked Summary"; }
        else
        { SheetName = "Less Hours Worked Detailed"; }

        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 MainHStyle = (HSSFCellStyle)workbook.CreateCellStyle();
        MainHStyle.SetFont(hFont);
        MainHStyle.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 (rbtSummary.Checked == true)
            {
                sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 8));
            }
            else
            {
                sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 11));
            }
            row.GetCell(0).CellStyle = MainHStyle;
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
        }

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

        if (rbtSummary.Checked == true)
        {
            row.CreateCell(0).SetCellValue("Less Hours Worked Summary Report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text));
            row.GetCell(0).CellStyle = MainHStyle;
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 8));
            rowIndex++;
        }
        else
        {
            row.CreateCell(0).SetCellValue("Less Hours Worked Report From - " + Convert.ToString(txtFromDate.Text) + " To - " + Convert.ToString(txtToDate.Text));
            row.GetCell(0).CellStyle = MainHStyle;
            sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, 11));
            rowIndex++;
        }
        row = sheet.CreateRow(rowIndex);
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        if (rbtSummary.Checked == true)
        {
            row.CreateCell(0).SetCellValue("Sl.No");
            row.CreateCell(1).SetCellValue("Employee Id");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Designation");
            row.CreateCell(4).SetCellValue("Gender");
            row.CreateCell(5).SetCellValue("Total Hours Allocated");
            row.CreateCell(6).SetCellValue("Total Less Hours");
            row.CreateCell(7).SetCellValue("Total Days for Less Hours Taken");
            row.CreateCell(8).SetCellValue("Total Working Days");

            //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_id"]))
                {
                    row.CreateCell(0).SetCellValue(Convert.ToString(EmployeeDatacount));
                    EmployeeDatacount++;
                }
                else
                {
                    row.CreateCell(0).SetCellValue(string.Empty);
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_id"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["empName"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["Designation"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["TotalMinsAllocated"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["TotalLessHrs"]));
                row.CreateCell(7).SetCellValue(Convert.ToString(DR["TotalLessHrsCountDays"]));
                row.CreateCell(8).SetCellValue(Convert.ToString(DR["WorkingDays"]));

                strPre = Convert.ToString(DR["Employee_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("Employee Id");
            row.CreateCell(2).SetCellValue("Employee Name");
            row.CreateCell(3).SetCellValue("Level");
            row.CreateCell(4).SetCellValue("Designation");
            row.CreateCell(5).SetCellValue("Gender");
            row.CreateCell(6).SetCellValue("Date");
            row.CreateCell(7).SetCellValue("InTime");
            row.CreateCell(8).SetCellValue("OutTime");
            row.CreateCell(9).SetCellValue("Hours Worked");
            row.CreateCell(10).SetCellValue("Defined Work Hours");
            row.CreateCell(11).SetCellValue("Total LessHours");

            //row.RowStyle = hStyle;
            for (int i = 0; i <= 11; 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_Id"]))
                {
                    row.CreateCell(0).SetCellValue(Convert.ToString(EmployeeDatacount));
                    EmployeeDatacount++;
                }
                else
                {
                    row.CreateCell(0).SetCellValue(string.Empty);
                }
                row.CreateCell(1).SetCellValue(Convert.ToString(DR["Employee_Id"]));
                row.CreateCell(2).SetCellValue(Convert.ToString(DR["empName"]));
                row.CreateCell(3).SetCellValue(Convert.ToString(DR["BranchName"]));
                row.CreateCell(4).SetCellValue(Convert.ToString(DR["Designation"]));
                row.CreateCell(5).SetCellValue(Convert.ToString(DR["Gender"]));
                row.CreateCell(6).SetCellValue(Convert.ToString(DR["Date"]));
                if (Convert.ToString(DR["InTime"]) == String.Empty)
                    row.CreateCell(7).SetCellValue(Convert.ToString(DR["InTime"]));
                else
                {
                    row.CreateCell(7).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["InTime"]))).ToString(NewTimeFormat));
                }
                if (Convert.ToString(DR["OutTime"]) == String.Empty)
                    row.CreateCell(8).SetCellValue(Convert.ToString(DR["OutTime"]));
                else
                {
                    row.CreateCell(8).SetCellValue((Convert.ToDateTime(Convert.ToString(DR["OutTime"]))).ToString(NewTimeFormat));
                }
                //row.CreateCell(7).SetCellValue(Convert.ToString(DR["InTime"]));
                //row.CreateCell(8).SetCellValue(Convert.ToString(DR["OutTime"]));
                row.CreateCell(9).SetCellValue(Convert.ToString(DR["HrsWork"]));
                row.CreateCell(10).SetCellValue(Convert.ToString(DR["shift_TotalWorkingHours"]));
                row.CreateCell(11).SetCellValue(Convert.ToString(DR["TotalLessHrs"]));

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

        using (MemoryStream exportData = new MemoryStream())
        {
            workbook.Write(exportData);
            string saveAsFileName;
            if (rbtSummary.Checked == true)
            { saveAsFileName = string.Format("LessHoursWorkedSummary-{0:d}.xls", DateTime.Now).Replace("/", "-"); }
            else
            { saveAsFileName = string.Format("LessHoursWorkedDetailed-{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();
        }
    }

    #endregion
}
