using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
public partial class Transactions_TA_UI_Transactions_MonthClosurePreview : Base.BasePage
{
    ResourceManager objResourceManager;
    CultureInfo objCultureInfo;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    // Create object for the Class MonthClosureEventData to use the methods that are used to interact with the Payroll Process 
    // related Tables in the Timecheck Database
    MonthClosureEventData objMonthClosure = new MonthClosureEventData();
    EmployeeEventData objEmployeeEventData = new EmployeeEventData();
    DataSet ds_Checkuser = new DataSet();
    Int32 gintMonthClosureId = 0;
    cls_Common objClassCommon = new cls_Common();
    protected override void Page_Load(object sender, EventArgs e)
    {
        // Session Checking
        base.Page_Load(sender, e);
        // Get the culture info to set the language        
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objClassCommon.menu("ExportTran", "27");
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        objResourceManager = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        objCultureInfo = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(objCultureInfo);
        // Set UserRights
        UserRights();
        // Get the Month Closure ID 
        gintMonthClosureId = Convert.ToInt32(Request.QueryString["MonthClose_Id"]);
    }
    protected void btn_View_Click(object sender, EventArgs e)
    {
        DataSet dsPayrollDetails = new DataSet();
        string strEmployeeName = string.Empty;
        string strEmployeeId = string.Empty;
        string strLevelIds = string.Empty;
        strEmployeeId = txtEmployeeId.Text.Trim().ToString();
        strEmployeeName = this.txtEmployeeName.Text.Replace("'", "''");
        strEmployeeName = strEmployeeName.Replace(' ', '%');
        dsPayrollDetails = objMonthClosure.SelectTempPayrollDetails(gintMonthClosureId,  strEmployeeId, strEmployeeName);
        grvPayrollProcessDetails.DataSource = dsPayrollDetails;
        ViewState["DataPayroll"] = dsPayrollDetails.Tables[0];
        grvPayrollProcessDetails.DataBind();
    }
    protected void grvPayrollProcessDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvPayrollProcessDetails.PageIndex = e.NewPageIndex;
        DataTable dtSrch = new DataTable();
        DataView dvSearch = new DataView();
        dtSrch = (DataTable)ViewState["DataPayroll"];
        dvSearch.Table = dtSrch;
        grvPayrollProcessDetails.DataSource = dvSearch;
        grvPayrollProcessDetails.DataBind();
    }
    protected void grvPayrollProcessDetails_PageIndexChanged(object sender, EventArgs e)
    {
        try
        {
            // To display the sorted records in the new page if the Vendor has Sorted the Gridview by clicking any header
            if ((ViewState["SortExpression"]) != null)
            {
                string SortColumn = Convert.ToString(ViewState["SortExpression"]);
                string SortOrder = Convert.ToString(Session["SortOrderPayroll"]);
                SortGrid(SortColumn, SortOrder);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void grvPayrollProcessDetails_Sorting(object sender, GridViewSortEventArgs e)
    {
        ViewState["SortExpression"] = e.SortExpression;
        if (Convert.ToString(Session["SortOrderPayroll"]) == string.Empty)
        {
            Session["SortOrderPayroll"] = "Asc";
        }
        else if (Convert.ToString(Session["SortOrderPayroll"]) == "Asc")
        {
            Session["SortOrderPayroll"] = "Desc";
        }
        else
        {
            Session["SortOrderPayroll"] = "Asc";
        }
        SortGrid(e.SortExpression, Convert.ToString(Session["SortOrderPayroll"]));
    }
    public void SortGrid(string SortColumn, string SortOrder)
    {
        DataTable dtSrch = new DataTable();
        DataView dvSearch = new DataView();
        dtSrch = (DataTable)ViewState["DataPayroll"];
        dvSearch.Table = dtSrch;
        dvSearch.Sort = SortColumn + " " + SortOrder;
        grvPayrollProcessDetails.DataSource = dvSearch;
        grvPayrollProcessDetails.DataBind();
    }
    private void LoadStrings(CultureInfo ci)
    {
        lblMonthClosure.Text = objResourceManager.GetString("UserGroups_MonthClosure", ci);
        lblEmployeeName.Text = objResourceManager.GetString("email_EmployeeName", ci);
        lblEmployeeId.Text = objResourceManager.GetString("email_EmployeeId", ci);
        btn_View.Text = "&nbsp;&nbsp;" + objResourceManager.GetString("btn_View", ci);
        btnBack.Text = "&nbsp;&nbsp;" + objResourceManager.GetString("btn_Back", ci);
        grvPayrollProcessDetails.Columns[0].HeaderText = objResourceManager.GetString("email_EmployeeId", ci);
        grvPayrollProcessDetails.Columns[1].HeaderText = objResourceManager.GetString("email_EmployeeName", ci);
        grvPayrollProcessDetails.Columns[2].HeaderText = objResourceManager.GetString("MonthClosure_HoursWorked", ci);
        grvPayrollProcessDetails.Columns[3].HeaderText = objResourceManager.GetString("NormalOT", ci);
        grvPayrollProcessDetails.Columns[4].HeaderText = objResourceManager.GetString("OTSanction_WeeklyoffOt", ci);
        grvPayrollProcessDetails.Columns[5].HeaderText = objResourceManager.GetString("OTSanction_HolidayOt", ci);
        grvPayrollProcessDetails.Columns[6].HeaderText = objResourceManager.GetString("MonthClosure_LateInHours", ci);
        grvPayrollProcessDetails.Columns[7].HeaderText = objResourceManager.GetString("MonthClosure_EarlyOutHours", ci);
        grvPayrollProcessDetails.Columns[8].HeaderText = objResourceManager.GetString("MonthClosure_PresentDays", ci);
        grvPayrollProcessDetails.Columns[9].HeaderText = objResourceManager.GetString("MonthClosure_LeaveDays", ci);
        grvPayrollProcessDetails.Columns[10].HeaderText = objResourceManager.GetString("Menu_Masters_Holidays", ci);
        grvPayrollProcessDetails.Columns[11].HeaderText = objResourceManager.GetString("MonthClosure_AbsentDays", ci);
        grvPayrollProcessDetails.Columns[12].HeaderText = objResourceManager.GetString("MonthClosure_LOPDays", ci);
        grvPayrollProcessDetails.Columns[13].HeaderText = objResourceManager.GetString("MonthClosurePermissionHours", ci);
    }
    private void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(27, Convert.ToInt32(Session["userGroup_Id"]), string.Empty);
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Transactions_MonthClosure.aspx");
            }
        }
        catch
        {
            //
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transactions_MonthClosure.aspx");
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = objResourceManager.GetString("Alert_Norecordsfound", objCultureInfo);
    }
}
