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

                gvAccountReport.DataSource = ds.Tables[0];
                gvAccountReport.DataBind();
                decimal TotTxnAmount = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("TotTxnAmount"));
                decimal WLCharges = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("WLCharges"));
                decimal WLCommission = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("WLCommission"));
                decimal DSCommission = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("DSCommission"));
                decimal AGCharges = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("AGCharges"));
                decimal AGCommission = ds.Tables[0].AsEnumerable().Sum(row => row.Field<decimal>("AGCommission"));
                gvAccountReport.FooterRow.Cells[3].Text = "&#8377; " + TotTxnAmount.ToString("N2");
                gvAccountReport.FooterRow.Cells[3].HorizontalAlign = HorizontalAlign.Center;
                gvAccountReport.FooterRow.Cells[4].Text = "&#8377; " + WLCharges.ToString("N2");
                gvAccountReport.FooterRow.Cells[4].HorizontalAlign = HorizontalAlign.Center;
                gvAccountReport.FooterRow.Cells[5].Text = "&#8377; " + WLCommission.ToString("N2");
                gvAccountReport.FooterRow.Cells[5].HorizontalAlign = HorizontalAlign.Center;
                gvAccountReport.FooterRow.Cells[6].Text = "&#8377; " + DSCommission.ToString("N2");
                gvAccountReport.FooterRow.Cells[6].HorizontalAlign = HorizontalAlign.Center;
                gvAccountReport.FooterRow.Cells[7].Text = "&#8377; " + AGCharges.ToString("N2");
                gvAccountReport.FooterRow.Cells[7].HorizontalAlign = HorizontalAlign.Center;
                gvAccountReport.FooterRow.Cells[8].Text = "&#8377; " + AGCommission.ToString("N2");
                gvAccountReport.FooterRow.Cells[8].HorizontalAlign = HorizontalAlign.Center;
                //gvAccountReport.FooterRow.Cells[9].Text = "Total Commission : " + totalCom.ToString("N2");
                //gvAccountReport.FooterRow.Cells[9].HorizontalAlign = HorizontalAlign.Center;

            }
            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();
    }
}