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;
using System.Drawing;
using System.IO;
using System.Text;
using System.Net.Mail;
using System.Net.Sockets;
using System.Xml;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;

public partial class MobilePortal_MobileAppSearchTransaction : System.Web.UI.Page
{
    string headXML = "<?xml version=\"1.0\" encoding='UTF-8' standalone='no' ?><response-Statement>";
    string footerXML = "</response-Statement>";
    string agent_Id, mobileno,url;

    protected void Page_Load(object sender, EventArgs e)
    {
        url = HttpContext.Current.Request.Url.AbsoluteUri;
        agent_Id = Request.QueryString["agent_Id"];
        mobileno = Request.QueryString["mobileno"];
        //agent_Id = "1000008041";
        //mobileno = "9761777949";
        if (agent_Id != null)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlParameter[] get_user_last_five_transaction = new SqlParameter[]
                {
                    new SqlParameter("@agentid",agent_Id),
                    new SqlParameter("@mobileno",mobileno)
                };
                ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_TxnMobilePortal", get_user_last_five_transaction);              
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables["Table"].Copy();
                    DataView dv = new DataView(dt);
                    dv.Sort = "TRANSACTION_DATETIME ASC";
                    string dataXML = string.Empty;
                    int count = 0;
                    foreach (DataRow row in ds.Tables[0].Rows) // Loop over the rows.
                    {
                        dataXML += "<transaction_detail><Id_No>" + count + "</Id_No><Tran_Id>" + row["TRANSACTIONID"].ToString() +
                            "</Tran_Id><Service>" + row["SERVICE_NAME"] + "</Service><Optr>" + row["OperatorName"] + "</Optr><Mob_Num>" + row["MobileDTHNumber"] +
                            "</Mob_Num><Action>" + row["Action_on_amount"] + "</Action> <Status>" + row["Status"] + "</Status><Amt>" + row["NET_AMOUNT"] +
                            "</Amt><Net_Amt>" + row["REQUEST_AMOUNT"] + "</Net_Amt><DOT>" + row["Txn_Date"] +
                            "</DOT><TOT>" + row["Txn_Time"] + "</TOT><Open_Bal>" + row["AMOUNT_BEFORE_DUE_DATE"] + "</Open_Bal><Close_Bal>" + row["AMOUNT_AFTER_DEU_DATE"] +
                            "</Close_Bal></transaction_detail>";
                        count++;
                    }
                    headXML += dataXML + footerXML;
                    WriteXML(headXML);
                }
                else
                {
                    string dataXML = string.Empty;
                    dataXML += "<transaction_detail><Id_No>" + "0" + "</Id_No><Tran_Id>" + "0" +
                            "</Tran_Id><Service>" + "Null" + "</Service><Optr>" + "Null" + "</Optr><Mob_Num>" + "0" +
                            "</Mob_Num><Action>" + "D/C" + "</Action> <Status>" + "S" + "</Status><Amt>" + "0" +
                            "</Amt><Net_Amt>" + "0" + "</Net_Amt><DOT>" + "Null" +
                            "</DOT><TOT>13:12:00</TOT><Open_Bal>" + "0" + "</Open_Bal><Close_Bal>" + "0" +
                            "</Close_Bal></transaction_detail>";
                    headXML += dataXML + footerXML;
                    WriteXML(headXML);
                }
            }
            catch (Exception ex)
            {
                string st = ex.Message;
            }
        }
        else
        {
            headXML += "<trans-response-code>1</trans-response-code><trans-response-message>Invalid request!</trans-response-message>" + footerXML;
            WriteXML(headXML);
        }

    }

    private void WriteXML(string str)
    {        
        Response.ClearHeaders();
        Response.AddHeader("content-type", "text/xml");
        Response.Write(str);
        Response.End();
    }    
}
