using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Admin_VendorAnalysis : System.Web.UI.Page
{
    decimal Success, Pending, Refund, Fail, Total;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            vendoranalysis();
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    public void vendoranalysis()
    {
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_dashboardVendorAnalys");
        for(int i=0;i<ds.Tables.Count;i++)
        {
            ds.Tables[0].Merge(ds.Tables[i]);
        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "abc", string.Format("alert('No Data Availabel');"), true);
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Success += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Success"));
                Pending += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Pending"));
                Refund += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Refunded"));
                Fail += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Fail"));
                Total += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Total"));
            }
            else if(e.Row.RowType==DataControlRowType.Footer)
            {
                e.Row.Cells[0].Text = "Total";
                e.Row.Cells[1].Text = Success.ToString();
                e.Row.Cells[2].Text = Pending.ToString();
                e.Row.Cells[3].Text = Refund.ToString();
                e.Row.Cells[4].Text = Refund.ToString();
                e.Row.Cells[5].Text = Total.ToString();
            }
        }
        catch (Exception ex)
        {
            //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "abc", string.Format("alert('There is some problem please try again');"),true);
            throw (ex);
        }
    }
}
