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 EzyTapTxnDetails : 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("@FromDate",txtFrmDate.Text.Trim()),
                new SqlParameter("@ToDate",txtToDate.Text.Trim()),
                new SqlParameter("@UserName",Convert.ToString(Session["LOGINID"])),
                new SqlParameter("@Status",ddlStatus.SelectedValue=="0"?null:ddlStatus.SelectedValue.ToString()),
                new SqlParameter("@Mode",ddlMode.SelectedValue=="0"?null:ddlMode.SelectedValue.ToString()),
                new SqlParameter("@ServiceType",ddlService.SelectedValue=="0"?null:ddlService.SelectedValue.ToString()),
                new SqlParameter("@LoginType","MDS")
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.SBBConnectionString, CommandType.StoredProcedure, "usp_getEzyTapTxn", param);
            if (ds.Tables[0].Rows.Count != 0)
            {

                gvAccountReport.DataSource = ds.Tables[0];
                gvAccountReport.DataBind();
                
                if(ds.Tables[1].Rows.Count>0)
                {
                    lblTotCount.Text = "Total Transaction Count : " + ds.Tables[1].Rows[0]["TotCount"];
                    lblTotAmount.Text = "Total Transaction Amount : " + ds.Tables[1].Rows[0]["TotAmount"];
                }

            }
            else
            {
                gvAccountReport.DataSource = null;
                gvAccountReport.DataBind();

                lblTotCount.Text = "Total Transaction Count : NA";
                lblTotAmount.Text = "Total Transaction Amount : NA";
            }

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