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.Data.SqlClient;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources; 
public partial class Transactions_TA_UI_Transactions_ManualTimeEntrySanctionView : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    ManualEntryEventData objManualEntryEventData = new ManualEntryEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    cls_Common objcls_Common = new cls_Common();
    Rpt_Common rptcommon = new Rpt_Common();
    DataTable dtManualEntrySanctionView = new DataTable();
    DataSet dsYearSetting = new DataSet();
    DataSet ds_Checkuser = new DataSet();
    int vmonthValue;
    string startDate;
    string endDate, gstrDateFormat, LevelId, Status, From_Date, To_Date, StartMonth, EndMonth, StartYear, EndYear;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        // 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;
        LoadStrings(ci);
        //Set UserRights
        UserRights();
        //To check the user is in SuperAdmin Group
        // Check the dropdownlist are filled or not
        LevelId = Request.QueryString["LevelId"].ToString();
        LevelId = rptcommon.getNodes(Convert.ToInt16(LevelId), Convert.ToString(Session["LevelRights"]));
        Status = Request.QueryString["Status"].ToString();
        //Checking and Convert to Date Format MM/dd/yyyy
        gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
        From_Date = Request.QueryString["From_Date"].ToString();
        To_Date = Request.QueryString["To_Date"].ToString();
        if (From_Date != string.Empty)
        {
            From_Date = objcls_Common.DateConvertion(gstrDateFormat, From_Date);
        }
        if (To_Date != string.Empty)
        {
            To_Date = objcls_Common.DateConvertion(gstrDateFormat, To_Date);
        }
        dsYearSetting = objYearSettingsEventData.GetActiveYearSettings();
        if (dsYearSetting.Tables[0].Rows.Count <= 0)
        {
            return;
        }
        else
        {
            StartMonth = dsYearSetting.Tables[0].Rows[0]["StartMonth"].ToString();
            StartYear = dsYearSetting.Tables[0].Rows[0]["StartYear"].ToString();
            vmonthValue = MonthValue(StartMonth);
            startDate = vmonthValue.ToString() + "/1/" + StartYear;
            EndMonth = dsYearSetting.Tables[0].Rows[0]["EndMonth"].ToString();
            EndYear = dsYearSetting.Tables[0].Rows[0]["EndYear"].ToString();
            vmonthValue = MonthValue(EndMonth);
            endDate = vmonthValue.ToString() + "/31/" + EndYear;
        }
        if (LevelId == "0")
        {
            LevelId = null;
        }
        if (Status == "-Select Status-")
        {
            Status = null;
        }
        else if (Status == "All")
        {
            Status = null;
        }
        if (From_Date == string.Empty)
        {
            From_Date = startDate;
        }
        if (To_Date == string.Empty)
        {
            To_Date = endDate;
        }
        // Fill Manual Time Entry Sanction Details in Grid
        BindManualEntrySanctionDetails();
    }
    public void BindManualEntrySanctionDetails()
    {
        // To check the user is in SuperAdmin Group
        //DataSet dsEmployeeGroup = new DataSet();
        //dsEmployeeGroup = objLeaveApplicationEventData.GetEmployeeGroupName(Convert.ToInt32(Session["EmpAutoId"]));
        //if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
        //{
        //    dtManualEntrySanctionView = objManualEntryEventData.GetManualEntrySanctionDetailsForSuperAdmin(LevelId, Status, From_Date, To_Date);
        //    gdManualEntrySanctionView.DataSource = dtManualEntrySanctionView;
        //    ViewState["DataManualEntrySanction"] = dtManualEntrySanctionView;
        //    gdManualEntrySanctionView.DataBind();
        //}
        //else
        //{
        //    dtManualEntrySanctionView = objManualEntryEventData.GetManualEntrySanctionDetails(Convert.ToInt32(Session["EmpAutoId"]), LevelId, Status, Convert.ToDateTime(From_Date), Convert.ToDateTime(To_Date));
        //    gdManualEntrySanctionView.DataSource = dtManualEntrySanctionView;
        //    ViewState["DataManualEntrySanction"] = dtManualEntrySanctionView;
        //    gdManualEntrySanctionView.DataBind();
        //}
    }
    public int MonthValue(string monthName)
    {
        if (monthName == "January")
            return 1;
        else if (monthName == "February")
            return 2;
        else if (monthName == "March")
            return 3;
        else if (monthName == "April")
            return 4;
        else if (monthName == "May")
            return 5;
        else if (monthName == "June")
            return 6;
        else if (monthName == "July")
            return 7;
        else if (monthName == "August")
            return 8;
        else if (monthName == "September")
            return 9;
        else if (monthName == "October")
            return 10;
        else if (monthName == "November")
            return 11;
        else if (monthName == "December")
            return 12;
        else
            return 0;
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Transactions_ManualTimeEntrySanction.aspx");
    }
    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualTimeEntrySanction", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        gdManualEntrySanctionView.Columns[0].HeaderText = rm.GetString("email_EmployeeName", ci);
        gdManualEntrySanctionView.Columns[1].HeaderText = rm.GetString("ManualTimeEntry_ManualTimeEntryDate", ci);
        gdManualEntrySanctionView.Columns[2].HeaderText = rm.GetString("ManualTimeEntrySanction_InEntry", ci);
        gdManualEntrySanctionView.Columns[3].HeaderText = rm.GetString("ManualTimeEntrySanction_OutEntry", ci);
        gdManualEntrySanctionView.Columns[4].HeaderText = rm.GetString("email_Status", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(98, Convert.ToInt32(Session["userGroup_Id"]), "viewPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("TransactionLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    protected void gdManualEntrySanctionView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdManualEntrySanctionView.PageIndex = e.NewPageIndex;
        BindManualEntrySanctionDetails();
    }
    protected void gdManualEntrySanctionView_Sorting(object sender, GridViewSortEventArgs e)
    {
        ViewState["SortExpression"] = e.SortExpression;
        if (Convert.ToString(Session["SortOrderManualEntrySanction"]) == string.Empty)
        {
            Session["SortOrderManualEntrySanction"] = "Asc";
        }
        else if (Convert.ToString(Session["SortOrderManualEntrySanction"]) == "Asc")
        {
            Session["SortOrderManualEntrySanction"] = "Desc";
        }
        else
        {
            Session["SortOrderManualEntrySanction"] = "Asc";
        }
        SortGrid(e.SortExpression, Convert.ToString(Session["SortOrderManualEntrySanction"]));
    }
    public void SortGrid(string SortColumn, string SortOrder)
    {
        DataTable dtSrch = new DataTable();
        DataView dvSearch = new DataView();
        dtSrch = (DataTable)ViewState["DataManualEntrySanction"];
        dvSearch.Table = dtSrch;
        dvSearch.Sort = SortColumn + " " + SortOrder;
        gdManualEntrySanctionView.DataSource = dvSearch;
        gdManualEntrySanctionView.DataBind();
    }
    protected void gdManualEntrySanctionView_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["SortOrderManualEntrySanction"]);
                SortGrid(SortColumn, SortOrder);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
}
