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_TopupTxnDetail : System.Web.UI.Page
{
    decimal ColumnAmount;
    int RowCount;
    decimal ColumnNetAmount;
    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("@FromDate",txtFrmDate.Text.Trim()),
                new SqlParameter("@ToDate",txtToDate.Text.Trim()),
                new SqlParameter("@LoginId",Convert.ToInt32(Session["LOGINID"]))
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetEzytapTopUpDetail", 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();
    }

    protected void gvAccountReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ColumnAmount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "TxnAmount"));
                RowCount += 1;
                //ColumnNetAmount = (ColumnAmount - ColumnMargin);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[1].Text = "Total Record:";
                e.Row.Cells[2].Text = RowCount.ToString();
                e.Row.Cells[4].Text = "Total Rs:";
                e.Row.Cells[5].Text = ColumnAmount.ToString();
                e.Row.Cells[5].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Font.Bold = true;
                lblRecords.Text= RowCount.ToString();
                lblTotAmount.Text= ColumnAmount.ToString();
            }
        }
        catch (Exception ex)
        {
            //lblerror.Text = "error=" + ex;
        }
    }
}