using System;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Reports_TA_UI_Report_LateInGrid : Base.BasePage
{
    #region Varaiable Declaration
    GetReports rptEmp = new GetReports();
    Rpt_Common rptcommon = new Rpt_Common();
    ResourceManager rm;
    CultureInfo ci;
    string EmpID = string.Empty;
    int shiftID = 0;
    string levelID = string.Empty;
    string from = string.Empty;
    string to = string.Empty;
    string Empname = string.Empty;
    int employeeCategory = 0;
    int employeeType = 0;
    string userGroupName = string.Empty;
    string gradeLevel = string.Empty;
    string strReportType = string.Empty;
    string ParentLevelid = string.Empty;
    string strSwipeCard = string.Empty;
    string Designation = string.Empty;
    string Gender = string.Empty;
    string source_Language;
    Int64 EmpAutoID = 0;
    #endregion
    #region Page Load Events
    /// <summary>
    /// On page loading
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        grv_LateIn.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        //get the culture info to set the 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);
        EmpID = Convert.ToString(Request.QueryString["EmpID"]);
        shiftID = Convert.ToInt32(Request.QueryString["Shift"]);
        from = Convert.ToString(Request.QueryString["From"]);
        to = Convert.ToString(Request.QueryString["To"]);
        Empname = Convert.ToString(Request.QueryString["EmpName"]);
        ParentLevelid = Convert.ToString(Request.QueryString["ParentLevelId"]);
        levelID = rptcommon.getNodes(Convert.ToInt16(ParentLevelid), Convert.ToString(Session["LevelRights"]));
        employeeCategory = Convert.ToInt32(Request.QueryString["employeeCategory"]);
        employeeType = Convert.ToInt32(Request.QueryString["employeeType"]);
        userGroupName = Convert.ToString(Request.QueryString["userGroupName"]);
        gradeLevel = Convert.ToString(Request.QueryString["gradeLevel"]);
        strReportType = Convert.ToString(Request.QueryString["ReportType"]);
        strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
        Designation = Convert.ToString(Request.QueryString["Designation"]);
        Gender = Convert.ToString(Request.QueryString["Gender"]);
        EmpAutoID = Convert.ToInt64(Request.QueryString["EmpAutoID"]);
    }
    #endregion
    #region Button Events
    /// <summary>
    /// To view the crystal report
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid == true)
            {
                //Redirect the page to the report viewer
                string strScript = "";
                //strScript = "TA_UI_Report_ReportViewer.aspx";
                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'>";
                strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=LateEntry&dtFrom="
                    + from + "&dtTo=" + to + "&empid=" + EmpID + "&shft=" + shiftID + "&EmpName=" + Empname +
                    "&Level=" + ParentLevelid + "&EmpCategory=" + employeeCategory + "&EmpType=" + employeeType +
                    "&ParentLevelId=" + ParentLevelid + "&UserGroupName=" + userGroupName + "&GradeLevel=" + gradeLevel +
                    "&Normal=" + strReportType + "&SwipeCard=" + strSwipeCard + "&Designation=" + Convert.ToInt32(Designation) + "&Gender=" + Gender + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
                strScript = strScript + "</script>";
                Response.Write(strScript);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #endregion
    #region User Defined Function
    /// <summary>
    /// Getting Information from resource file and display it in label
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        btn_View.Text = "&nbsp;&nbsp;" + rm.GetString("btn_View", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblLateEntry.Text = rm.GetString("Reports_LateEntry_Report", ci);
        grv_LateIn.Columns[0].Caption = rm.GetString("email_EmployeeId", ci);
        grv_LateIn.Columns[1].Caption = rm.GetString("email_EmployeeName", ci);
        grv_LateIn.Columns[2].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grv_LateIn.Columns[3].Caption = rm.GetString("Master_Designation", ci);
        grv_LateIn.Columns[4].Caption = rm.GetString("EmployeeMaster_Gender", ci);
        grv_LateIn.Columns[5].Caption = rm.GetString("Reports_Date", ci);
        grv_LateIn.Columns[6].Caption = rm.GetString("ManualTimeEntry_In_Time", ci);
        grv_LateIn.Columns[7].Caption = rm.GetString("Late_Entry_LateBy", ci);        
        grv_LateIn.Columns[8].Caption = rm.GetString("email_Reason", ci);
    }
    #endregion
    #region Grid Events    
    protected void grv_LateIn_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
    }
    #endregion

    protected void btnExport_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = (LinkButton)sender;
        ASPxGridViewExporter1.Landscape = true;
        ASPxGridViewExporter1.LeftMargin = 10;
        ASPxGridViewExporter1.RightMargin = 10;
        ASPxGridViewExporter1.ExportedRowType = DevExpress.Web.GridViewExportedRowType.All;
        ASPxGridViewExporter1.MaxColumnWidth = 400;
        ASPxGridViewExporter1.GridViewID = "grv_LateIn";
        string saveAsFileName = string.Format("Late Entry Report -{0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
        ASPxGridViewExporter1.FileName = saveAsFileName;
        ASPxGridViewExporter1.PaperKind = System.Drawing.Printing.PaperKind.A3;
        ASPxGridViewExporter1.PageHeader.Center = "Late Entry report From - " + Convert.ToString(from) + " To - " + Convert.ToString(to);
        switch (lnkbtn.CommandName)
        {
            case "excel":
                ASPxGridViewExporter1.WriteXlsxToResponse();
                break;
            case "pdf":
                ASPxGridViewExporter1.WritePdfToResponse();
                break;
        }
    }
}
