using System;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI.WebControls;
public partial class Reports_TA_UI_Report_EarlyExitGrid : Base.BasePage
{
    #region Variable Declaration
    GetReports rptEmp = new GetReports();
    ResourceManager rm;
    CultureInfo ci;
    Rpt_Common rptcommon = new Rpt_Common();
    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;
    string MinExceptkHours = "";
    #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_Earlyout.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;
        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"]);
        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"]);
        ParentLevelId = Convert.ToString(Request.QueryString["ParentLevelId"]);
        strSwipeCard = Convert.ToString(Request.QueryString["SwipeCard"]);
        Designation = Convert.ToString(Request.QueryString["Designation"]);
        Gender = Convert.ToString(Request.QueryString["Gender"]);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        if (Request.QueryString["MinExceptHours"] != null)
            MinExceptkHours = Convert.ToString(Request.QueryString["MinExceptHours"]);
        if (!IsPostBack)
        {
            LoadStrings(ci);
            if (strReportType == "Graph")
            {
                Session["Path"] = Server.MapPath(rm.GetString("rptEarlyExitGraph", ci));
            }
            else
            {
                Session["Path"] = Server.MapPath(rm.GetString("rptEarlyExit", ci));
            }
        }
    }
    #endregion
    #region Button Events
    /// <summary>
    /// To pass the filter parameters to the report viewer page
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_View_Click(object sender, EventArgs e)
    {
        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'>";
        strScript = strScript + "window.open('TA_UI_Report_ReportViewer.aspx?ReportName=EarlyExit&dtFrom="
            + from + "&dtTo=" + to + "&empid=" + EmpID + "&MinExceptHours=" + MinExceptkHours + "&shft=" + shiftID + "&EmpName=" + Empname +
            "&Level=" + ParentLevelId + "&EmpCategory=" + employeeCategory + "&EmpType=" + employeeType +
            "&ParentLevelId=" + ParentLevelId + "&UserGroupName=" +
            userGroupName + "&GradeLevel=" + gradeLevel +
            "&Normal=" + strReportType + "&SwipeCard=" + strSwipeCard + "&Designation=" + Designation + "&Gender=" + Gender + "','','left=10px, top=60px, width=1000px, height=600px, scrollbars=yes, status=no, resizable=yes');";
        strScript = strScript + "</script>";
        Response.Write(strScript);
    }
    #endregion
    #region User Defined Functions
    /// <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);
        lblEarlyOut.Text = rm.GetString("Dash_EarlyExit", ci);
        grv_Earlyout.Columns[0].Caption = rm.GetString("email_EmployeeId", ci);
        grv_Earlyout.Columns[1].Caption = rm.GetString("email_EmployeeName", ci);
        grv_Earlyout.Columns[2].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grv_Earlyout.Columns[3].Caption = rm.GetString("Master_Designation", ci);
        grv_Earlyout.Columns[4].Caption = rm.GetString("EmployeeMaster_Gender", ci);
        grv_Earlyout.Columns[5].Caption = rm.GetString("Reports_Date", ci);
        grv_Earlyout.Columns[6].Caption = rm.GetString("ManualTimeEntry_Out_Time", ci);
        grv_Earlyout.Columns[7].Caption = rm.GetString("Early_Exit_EarlyBy", ci);
        grv_Earlyout.Columns[8].Caption = rm.GetString("email_Reason", ci);
    }
    #endregion
    #region Grid Events
    ///// <summary>
    ///// To change grid data according to the language selected
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void grv_Earlyout_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        Label lbl = (Label)e.Row.Cells[5].FindControl("lblDate");
    //        if (lbl.Text != "")
    //        {
    //            lbl.Text = (Convert.ToDateTime(lbl.Text.ToString())).ToString(Session["MDateFormat"].ToString());
    //            //e.Row.Cells[5].Controls.Add(lbl);
    //        }
    //        Label lblGender = (Label)e.Row.FindControl("lblGender");
    //        if (lblGender.Text.Trim() == "Male" || lblGender.Text.Trim() == "MALE")
    //        {
    //            lblGender.Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
    //        }
    //        else if (lblGender.Text.Trim() == "Female" || lblGender.Text.Trim() == "FEMALE")
    //        {
    //            lblGender.Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
    //        }
    //        LinkButton lbEdit = new LinkButton();
    //        lbEdit = (LinkButton)e.Row.Cells[0].Controls[0];
    //        if (lbEdit.Text == "Edit")
    //        {
    //            lbEdit.Text = rm.GetString("Grid_Edit", ci);
    //        }
    //        else if (lbEdit.Text == "Update")
    //        {
    //            lbEdit.Text = rm.GetString("Grid_Update", ci);
    //            LinkButton lbCancel = new LinkButton();
    //            lbCancel = (LinkButton)e.Row.Cells[0].Controls[2];
    //            if (lbCancel.Text == "Cancel")
    //            {
    //                lbCancel.Text = rm.GetString("btn_Cancel", ci);
    //            }
    //        }
    //    }
    //}
    #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_Earlyout";
        string saveAsFileName = string.Format("Early Exit Report -{0:d}", DateTime.Now).Replace("/", "-").Replace(" ", "");
        ASPxGridViewExporter1.FileName = saveAsFileName;
        ASPxGridViewExporter1.PaperKind = System.Drawing.Printing.PaperKind.A3;
        ASPxGridViewExporter1.PageHeader.Center = "Early Exit report From - " + Convert.ToString(from) + " To - " + Convert.ToString(to);
        switch (lnkbtn.CommandName)
        {
            case "excel":
                ASPxGridViewExporter1.WriteXlsxToResponse();
                break;
            case "pdf":
                ASPxGridViewExporter1.WritePdfToResponse();
                break;
        }
    }
    protected void grv_Earlyout_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            //Label lbl = (Label)grv_Earlyout.FindRowCellTemplateControl(e.VisibleIndex, null, "lblDate");
            //if (lbl.Text != "")
            //{
            //    lbl.Text = (Convert.ToDateTime(lbl.Text.ToString())).ToString(Session["MDateFormat"].ToString());
            //    e.Row.Cells[5].Text = lbl.Text;
            //}
            //Label lblGender = (Label)grv_Earlyout.FindRowCellTemplateControl(e.VisibleIndex, null, "lblGender");
            //if (lblGender.Text.Trim() == "Male" || lblGender.Text.Trim() == "MALE")
            //{
            //    lblGender.Text = rm.GetString("rbtn_EmployeeMaster_Male", ci);
            //}
            //else if (lblGender.Text.Trim() == "Female" || lblGender.Text.Trim() == "FEMALE")
            //{
            //    lblGender.Text = rm.GetString("rbtn_EmployeeMaster_Female", ci);
            //}
            //LinkButton lbEdit = new LinkButton();
            //lbEdit = (LinkButton)grv_Earlyout.FindEditRowCellTemplateControl(
            //    //e.Row.Cells[0].Controls[0];
            //if (lbEdit.Text == "Edit")
            //{
            //    lbEdit.Text = rm.GetString("Grid_Edit", ci);
            //}
            //else if (lbEdit.Text == "Update")
            //{
            //    lbEdit.Text = rm.GetString("Grid_Update", ci);
            //    LinkButton lbCancel = new LinkButton();
            //    lbCancel = (LinkButton)e.Row.Cells[0].Controls[2];
            //    if (lbCancel.Text == "Cancel")
            //    {
            //        lbCancel.Text = rm.GetString("btn_Cancel", ci);
            //    }
            //}
        }
    }
}
