using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LedgerDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["LOGINID"] == null && Session["USERTYPE"] == null)
            {
                Response.Redirect("../login.aspx");
            }
            if (!IsPostBack)
            {
                txtFrmDate.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
                txtToDate.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
                BindDataAccSummery();
            }
           
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    private void BindDataAccSummery()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@LoginId ",Convert.ToString(Session["LOGINID"])),
                new SqlParameter("@FromDate",txtFrmDate.Text.Trim()),
                new SqlParameter("@ToDate",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetUserLedger", param);
            if (ds.Tables[0].Rows.Count != 0)
            {

                gvAccountReport.DataSource = ds.Tables[0];
                gvAccountReport.DataBind();
            }
            else
            {
                gvAccountReport.DataSource = null;
                gvAccountReport.DataBind();
            }

        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
            return;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if(txtFrmDate.Text.Trim()=="")
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Please Select From Date');"), true);
            return;
        }
        if (txtToDate.Text.Trim() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Please Select To Date');"), true);
            return;
        }
        BindDataAccSummery();
    }
}