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.Data;
public partial class Transactions_TA_UI_Transactions_Attendance_OracleExport : Base.BasePage
{
    #region Variable declaration
    DataSet dsAttendanceData = new DataSet();
    AttendanceEntry AttEntry = new AttendanceEntry();
    DataTable dtForPagging = new DataTable();
    #endregion
    #region Page Load Event
    //Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);    
        if (!IsPostBack)
        {
            txtFromDate.Text = "";
            if (Session["IDateFormat"] != null)
            {
                Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            }
        }
    }
    #endregion
    #region Load Grid View
    public void LoadGrid()
    {
        dsAttendanceData = AttEntry.SelectAttendanceReport(Convert.ToDateTime(txtFromDate.Text));
        grv_Attendence_OracleExport.DataSource = dsAttendanceData;
        ViewState["AttendenceData"] = dsAttendanceData.Tables[0];
       grv_Attendence_OracleExport.DataBind();
   }
    #endregion
    #region Grid Events
   protected void grv_Attendence_OracleExport_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dtForPagging = (DataTable)ViewState["AttendenceData"];
        grv_Attendence_OracleExport.DataSource = dtForPagging;
        grv_Attendence_OracleExport.PageIndex = e.NewPageIndex;
        grv_Attendence_OracleExport.DataBind();
    }
    protected void grv_Attendence_OracleExport_Sorting(object sender, GridViewSortEventArgs e)
    {
        try
        {
            if (ViewState["AttendenceData"] != 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)
        {
            // scriptmanager.scriptmanagermessage(this.Page, ex.Message);
        }
    }
    public SortDirection gridviewsortdirection
    {
        get
        {
            if (ViewState["sortdirection"] == null)
            {
                ViewState["sortdirection"] = SortDirection.Ascending;
            }
            return (SortDirection)ViewState["sortdirection"];
        }
        set
        {
            ViewState["sortdirection"] = value;
        }
    }
    public void sortgridview(string sortexpression, string direction)
    {
        DataTable dt = new DataTable();
        dt = ViewState["AttendenceData"] as DataTable;
        DataView dv = new DataView(dt);
        dv.Sort = sortexpression + " " + direction;
        ViewState["AttendenceData"] = dv.ToTable();
        grv_Attendence_OracleExport.DataSource = dv;
        grv_Attendence_OracleExport.DataBind();
    }
   #endregion
    #region button Events
    protected void btn_View_Click(object sender, EventArgs e)
    {
        LoadGrid();
        btnExportToOracle.Visible = true;
    }
    #endregion
}
