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.Text.RegularExpressions;

public partial class MobilePortal_CheckBal : System.Web.UI.Page
{
    string agentid, version, balance;
    string headXML = "<response>";
    string footerXML = "</response>";
    protected void Page_Load(object sender, EventArgs e)
    {
        version = Request.QueryString["version"];
        //version = "1.1";
        agentid = Request.QueryString["agent_Id"];
        //agentid = "1000000040";               
        userdetails();                    
    }

    public void userdetails()
    {
        try
        {
            if (IsNumeric(agentid) == true)
            {
                SqlParameter[] get_user_details = new SqlParameter[]
                {
                    new SqlParameter("@LOGINID",agentid)                
                };
                DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_USERBALANCE", get_user_details);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    balance = Convert.ToString(ds.Tables[0].Rows[0]["balance"]);
                    headXML += "<bal-response>" + balance + "</bal-response>" + footerXML;
                    WriteXML(headXML);
                }
                else
                {
                    headXML += "<bal-response>Invalid Agent ID Request</bal-response>" + footerXML;
                    WriteXML(headXML);
                }
            }
            else
            {
                headXML += "<bal-response>Invalid Agent ID Request</bal-response>" + footerXML;
                WriteXML(headXML);
            }
        }
        catch (Exception ex)
        {
            //string st = ex.Message;
            //CommonFunction.writeToLogFileMApps(Convert.ToString(ex));
        }
    }

    private void WriteXML(string str)
    {
        Response.ClearHeaders();
        Response.AddHeader("content-type", "text/xml");
        Response.Write("<?xml version=\"1.0\" ?>" + str);
        Response.End();
    }

    public static bool IsNumeric(string strToCheck)
    {
        return Regex.IsMatch(strToCheck, "^\\d+(\\.\\d+)?$");
    }
}