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 MasterAdmin_BusinessSummery : 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("@From",txtFrmDate.Text.Trim()),
                new SqlParameter("@To",txtToDate.Text.Trim()),
                new SqlParameter("@LoginId",Convert.ToInt64(Session["LOGINID"]))
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "get_transaction_report_admin_dcr", param);
            if (ds.Tables[0].Rows.Count != 0)
            {

                gridview_div.Visible = true;
                gridview_div.DataSource = ds.Tables[0];
                gridview_div.DataBind();
                decimal TotTxnAmount = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("total"));
                int WLCharges = ds.Tables[0].AsEnumerable().Sum(row => row.Field<int>("record"));
                gridview_div.FooterRow.Cells[5].Text = "&#8377; " + TotTxnAmount.ToString("N2");
                gridview_div.FooterRow.Cells[5].HorizontalAlign = HorizontalAlign.Center;
                gridview_div.FooterRow.Cells[4].Text = "Records: " + WLCharges.ToString();
                gridview_div.FooterRow.Cells[4].HorizontalAlign = HorizontalAlign.Center;
            }
            else
            {
                gridview_div.DataSource = null;
                gridview_div.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();
    }
}