using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
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;

public partial class Transactions_PopUp_LeaveAvailedQuota : Base.BasePage
{
    string Employee_code_Id = string.Empty;
    CultureInfo ci;
    ResourceManager rm;
    LeaveApplicationEventData_Angler objLeaveApplication = new LeaveApplicationEventData_Angler();
    DataSet dsLeaveAvailed = new DataSet();
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        loadcss();
        if (!IsPostBack)
        {
            Employee_code_Id = Request.QueryString["EmployeeId"].ToString();
            LoadAvailedLeaveofEmployees(Employee_code_Id);

        }
    }

    public void LoadAvailedLeaveofEmployees(string EmployeeId)
    {

        dsLeaveAvailed = objLeaveApplication.LoadEmployeeLeaveAvailed(EmployeeId);
        grv_LeaveAvailed.DataSource = dsLeaveAvailed.Tables[0];
        ViewState["LeaveAvailed"] = dsLeaveAvailed.Tables[0];
        grv_LeaveAvailed.DataBind();

    }
    protected void grv_LeaveAvailed_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataTable dtLeaveAvailedPagging = new DataTable();
        dtLeaveAvailedPagging = ViewState["LeaveAvailed"] as DataTable;
        grv_LeaveAvailed.DataSource = dtLeaveAvailedPagging;
        grv_LeaveAvailed.PageIndex = e.NewPageIndex;
        grv_LeaveAvailed.DataBind();
    }
    #region sorting
    public SortDirection gridviewsortdirection
    {
        get
        {
            if (ViewState["sortdirection"] == null)
            {
                ViewState["sortdirection"] = SortDirection.Ascending;
            }
            return (SortDirection)ViewState["sortdirection"];
        }
        set
        {
            ViewState["sortdirection"] = value;
        }
    }


    protected void grv_LeaveAvailed_Sorting(object sender, GridViewSortEventArgs e)
    {
        try
        {
            if (ViewState["LeaveAvailed"] != null)
            {
                string sort = e.SortExpression;


                if (gridviewsortdirection == SortDirection.Ascending)
                {
                    gridviewsortdirection = SortDirection.Descending;
                    sortgridview(sort, "DESC");
                }
                else
                {
                    gridviewsortdirection = SortDirection.Ascending;
                    sortgridview(sort, "ASC");
                }
            }
        }
        catch (Exception ex)
        {
           
        }
    }

    public void sortgridview(string sortexpression, string direction)
    {
        DataTable dt = new DataTable();
        dt = ViewState["LeaveAvailed"] as DataTable;


        DataView dv = new DataView(dt);
        dv.Sort = sortexpression + " " + direction;

        ViewState["LeaveAvailed"] = dv.ToTable();
        grv_LeaveAvailed.DataSource = dv;
        grv_LeaveAvailed.DataBind();
    }
    #endregion

    double dblTotalDays = 0;
    protected void grv_LeaveAvailed_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblNumberofDays = (Label)e.Row.FindControl("lbl_NumberofDays");

            if (lblNumberofDays != null)
            {
                if (lblNumberofDays.Text != "")
                {
                    dblTotalDays += Convert.ToDouble(lblNumberofDays.Text);
                }
            }
        
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lblLeaveinYear=(Label)e.Row.FindControl("lblNumeberofDaysinYear");
            lblLeaveinYear.Text = dblTotalDays.ToString();
        }
    }

    private void loadcss()
    {
        CultureInfo ci;
        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;
        //if Standard Demo
        htmlLeaveQuota.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
            styleselect2.Href = "../plugins/select2/select2.min-rtl.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew-rtl.css";
        }
        else
        {
            //htmlLeaveQuota.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            //styleselect2.Href = "../plugins/select2/select2.min-rtl.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
            styleselect2.Href = "../plugins/select2/select2.min.css";
            styleAutocomp.Href = "../bootstrap/css/autoCompleteNew.css";
        }
    }

}
