using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;

public partial class AepsService_Transaction : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //try
        //{
        //venusrecharge.in/AepsService/Transaction.aspx?AG=AG02260&TxnDate=2018-11-19&wid=1000202239
            if (Request.QueryString.Count > 0)
            {
                string AG = Convert.ToString(Request.QueryString["AG"]);
                string FromTxnDate = Convert.ToString(Request.QueryString["TxnDate"]);
                string ToTxnDate = Convert.ToString(Request.QueryString["TxnDate2"]);
                string wl = Convert.ToString(Request.QueryString["wid"]);
                string sb = string.Empty; ;
                string header = "<Data>";
                string footer = "</Data>";
                SqlParameter[] param = new SqlParameter[] 
                {         
                   new SqlParameter("@AgentID",AG),
                   new SqlParameter("@WL",wl),
                   new SqlParameter("@FromTxnDate",FromTxnDate),
                   new SqlParameter("@ToTxnDate",ToTxnDate)
                };
                DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_getAgentAEPSTransactionService", param);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        sb = sb + @"<Detail>";
                        sb = sb + @"<RefID>" + Convert.ToString(dr["RefID"]) + "</RefID>";
                        sb = sb + @"<TxnDate>" + Convert.ToString(dr["TxnDate"]) + "</TxnDate>";
                        sb = sb + @"<Service>" + Convert.ToString(dr["Service"]) + "</Service>";
                        sb = sb + @"<OpeningBal>" + Convert.ToString(dr["OpeningBal"]) + "</OpeningBal>";
                        sb = sb + @"<ReqAmount>" + Convert.ToString(dr["ReqAmount"]) + "</ReqAmount>";
                        sb = sb + @"<Commission>" + Convert.ToString(dr["Commission"]) + "</Commission>";
                        sb = sb + @"<ServiceCharge>" + Convert.ToString(dr["ServiceCharge"]) + "</ServiceCharge>";
                        sb = sb + @"<NetAmount>" + Convert.ToString(dr["NetAmount"]) + "</NetAmount>";
                        sb = sb + @"<ClosingBal>" + Convert.ToString(dr["ClosingBal"]) + "</ClosingBal>";
                        sb = sb + @"<Status>" + Convert.ToString(dr["STATUS"]) + "</Status>";
                        sb = sb + @"<TxnType>" + Convert.ToString(dr["TxnType"]) + "</TxnType>";
                        sb = sb + @"<BankRefID>" + Convert.ToString(dr["BankRefID"]) + "</BankRefID>";
                        sb = sb + @"<AgentID>" + Convert.ToString(dr["agentId"]) + "</AgentID>";
                        sb = sb + @"</Detail>";
                    }
                    WriteXML(header + sb + footer);
                }
                else
                {
                    string abc = "<Data><Detail><Error>No Record Found</Error></Detail></Data>";
                    WriteXML(abc);
                }
               
            }
            else
            {
                string abc = "<Data><Detail><Error>Parameter Error</Error></Detail></Data>";
                WriteXML(abc);
            }
       // }
        //catch (Exception ex)
        //{
        //    string abc = "<Data><Detail><Error>Exception</Error></Detail></Data>";
        //    WriteXML(abc);
        //}
    }

    private void WriteXML(string str)
    {

        Response.Clear();
        Response.ContentType = "text/xml; charset=utf-8";
        Response.ContentEncoding = Encoding.UTF8;
        Response.Write(str);
        Response.End();
    }
}