using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Agent_electricity : System.Web.UI.Page
{
    #region Declare private variable
    private string _loginID;
    #endregion
    AirEpointSupport _objTransaction = new AirEpointSupport();
    WBMobile_Noverification _ObjWBMNverify = new WBMobile_Noverification();
    DataSet ds = new DataSet();
    public string LoginID
    {
        get
        {
            return _loginID;
        }
        set
        {
            _loginID = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["LOGINID"])) && string.IsNullOrEmpty(Convert.ToString(Session["USERNAME"])))
            {
                Response.Redirect("../login.aspx");
            }
            else
            {

                LoginID = Convert.ToString(Session["LOGINID"]);
                 if (!GetServiceActivation(LoginID))
                {
                   string message = "Electricity Bill Payment Service Coming Soon.";
                    string url = "Billpayment.aspx";
                    string script = "window.onload = function(){ alert('";
                    script += message;
                    script += "');";
                    script += "window.location = '";
                    script += url;
                    script += "'; }";
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", script, true);
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Electricity Bill Payment Service Coming Soon. ');"), true);
                    //return;
                }
                if (!IsPostBack)
                {
                    BindElecticityBoard();
                }
            }
            lblerror.Text = Request.QueryString["error"];
            if (lblerror.Text == "Successfully completed.")
            {
                lblerror.ForeColor = Color.Blue;
            }
            else
            {
                lblerror.ForeColor = Color.Red;
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
     public bool GetServiceActivation(string LoginID)
    {
        bool status = false;
        status = SqlHelper.checkExistance(SqlHelper.mainConnectionString, CommandType.Text, "select LoginID from UtilityServiceActivation where LoginID='" + LoginID + "'");
        return status;
    }
    public void BindElecticityBoard()
    {
        try
        {

            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.Text, "select MobileDthOperatorDetailsID,OperatorName,Operator_Code,Imagename from MOBILE_DTH_OPERATOR_DETAILS where Type='ELECTRICITY' order by OperatorName");
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlEleOpt.DataSource = ds.Tables[0];
                ddlEleOpt.DataTextField = "OperatorName";
                ddlEleOpt.DataValueField = "Operator_Code";
                ddlEleOpt.DataBind();
                ddlEleOpt.Items.Insert(0, new ListItem("--Select Electricity Board--", "0"));
                ddlEleOpt.SelectedIndex = 0;
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void ddlEleOpt_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (ddlEleOpt.SelectedValue != "0")
            {
               
                //DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.Text, "select MobileDthOperatorDetailsID,OperatorName,Operator_Code,Imagename from MOBILE_DTH_OPERATOR_DETAILS where Type='ELECTRICITY'");
                //if (ds.Tables[0].Rows.Count > 0)
                //{
                //    ddlEleOpt.DataSource = ds.Tables[0];
                //    ddlEleOpt.DataTextField = "OperatorName";
                //    ddlEleOpt.DataValueField = "Operator_Code";
                //    ddlEleOpt.DataBind();
                //    ddlEleOpt.Items.Insert(0, new ListItem("--Select Electricity Board--", "0"));
                //    ddlEleOpt.SelectedIndex = 0;
                //}
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        if (ddlEleOpt.SelectedValue != "0" && txtConsumerNo.Text != "" && txtMobileNo.Text.Trim() != "" && txtAmount.Text.Trim() != "")
        {
            string RefID = _objTransaction.Generate_TID();
            ViewState["RefId"] = RefID;
            if (ddlEleOpt.SelectedValue != "WBSE" && ddlEleOpt.SelectedValue != "CWE")
            {

                string json = new JavaScriptSerializer().Serialize(new
                   {
                       Key = "7ef37a4185480cebda9430277939c47ce93b4183",
                       AgentID = "3890",
                       OP = Convert.ToString(ddlEleOpt.SelectedValue),
                       REQUEST_ID = RefID,
                       Amount = txtAmount.Text.Trim(),
                       Account = txtConsumerNo.Text.Trim(),
                       Customermobile = txtMobileNo.Text.Trim(),
                       Optional1 = "",
                       Optional2 = "",
                       Optional3 = "",
                       Optional4 = "",
                       Optional5 = "",
                       Optional6 = "",
                       Optional7 = "",
                       Optional8 = "Live",
                       Optional9 = "28.6207,77.3818|201301",//"22.572645,‎88.363892|700050",//"28.6207,77.3818|201301",
                       Outlet_ID = "3669"//"3702"//"3669"
                   });
                string Result = PostRequest("http://api.softsolutionzone.in/resources/SKIPDMR/ValidatePayment", json);
                 InsrtLog(RefID,Result,"ValidatePayment");
                if (Result != "")
                {
                    JObject jsonResponse = JObject.Parse(Result);
                    if (jsonResponse["statuscode"].ToString() == "TXN" || jsonResponse["statuscode"].ToString() == "IRA")
                    {
                        ViewState["ResponseStatus"] = jsonResponse["statuscode"].ToString();
                        JObject objResponse = (JObject)jsonResponse["particulars"];
                        if (objResponse.Count > 0)
                        {
                            //ViewState["BILLDETAILS"] = objResponse;
                            JValue billnumber = (JValue)objResponse["billnumber"];
                            JValue duedate = (JValue)objResponse["duedate"];
                            JValue dueamount = (JValue)objResponse["dueamount"];
                            JValue billperiod = (JValue)objResponse["billperiod"];
                            JValue customername = (JValue)objResponse["customername"];

                            lblBillNo.Text = Convert.ToString(billnumber);
                            lblConsumerName.Text = Convert.ToString(customername);
                            lblBillDueDate.Text = Convert.ToString(duedate);
                            lblDueAmount.Text = Convert.ToString(dueamount);
                            ViewState["BillAmount"] = Convert.ToString(dueamount);
                            if (jsonResponse["statuscode"].ToString() == "IRA")
                            {
                                chkboxpricediffernce.Visible = true;
                                chkboxpricediffernce.Text = "YOUR REQUEST AMOUNT IS DIFFER FROM ACTUAL DUE AMOUNT. DO YOU WANT TO PAY THIS ACTUAL BILL AMOUNT.";
                            }
                            ModalPopupExtender1.Show();
                        }


                    }
                    else
                    {
                        reset();
                        lblerror.Visible = true;
                        lblerror.Text = jsonResponse["status"].ToString();
                    }
                }
                else
                {
                    reset();
                    lblerror.Visible = true;
                    lblerror.Text = "Server Error! Please try after some time.";
                }

            }
            else if (ddlEleOpt.SelectedValue == "WBSE" || ddlEleOpt.SelectedValue == "CWE")
            {
                PaymentBill_Other(txtAmount.Text.Trim());
            }
        }
        else
        {
            string message = "Please Fill all details";
            string url = "#";
            string script = "window.onload = function(){ alert('";
            script += message;
            script += "');";
            script += "window.location = '";
            script += url;
            script += "'; }";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", script, true);
        }
        
    }
    public void InsrtLog(string RefId,string Log,string Service)
    {
        SqlParameter[] TxnResponce = new SqlParameter[]
                    {
                         new SqlParameter("@RefID",RefId),
                        new SqlParameter("@Log",Log),
                        new SqlParameter("@Service",Service)
                    };
        SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "InserLog", TxnResponce);
    }
    public void reset()
    {
        lblBillNo.Text = "";
        lblConsumerName.Text = "";
        lblBillDueDate.Text = "";
        lblDueAmount.Text = "";
        txtAmount.Text = "";
        txtConsumerNo.Text = "";
        txtMobileNo.Text = "";
        ddlEleOpt.SelectedValue = "0";
    }
    private string PostRequest(string url, string json)
    {
        string result = "";
        try
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                result = streamReader.ReadToEnd();
            }
            return result;
        }
        catch (Exception ex)
        {
            return result;
        }
    }
    protected void btnTxnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string BillAmount = string.Empty;
            //JObject BillDetails = (JObject)ViewState["BILLDETAILS"];
            if (Convert.ToString(ViewState["ResponseStatus"]) == "IRA")
            {
                if (chkboxpricediffernce.Checked == true)
                {
                    BillAmount = Convert.ToString(ViewState["BillAmount"]);
                }
                else
                {
                    reset();
                    lblerror.Visible = true;
                    lblerror.Text = "Invalid Bill Amount.";
                    return;
                }
            }
            else if (Convert.ToString(ViewState["ResponseStatus"]) == "TXN")
            {
                BillAmount = txtAmount.Text.Trim();
            }
            PaymentBill(BillAmount);

        }
        catch(Exception ex)
        {
        }
    }
    public decimal WLAmount()
    {
        decimal WLbalance=0;
        try
        {
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@LOGINID",Session["WhitelabelId"].ToString())
            };

            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getavailablebalance", get_user_details);
            if (dr.Read())
            {
                WLbalance = Convert.ToInt32(dr["balance"]);
            }
            return WLbalance;
        }
        catch (Exception ex)
        {
            return WLbalance;
        }
       
    }
    public decimal userdetails()
    {
        decimal balance = 0;
        try
        {
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@LOGINID",LoginID)
            };
            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getavailablebalance", get_user_details);
            if (dr.Read())
            {
                balance = Convert.ToDecimal(dr["balance"]);
            }
            return balance;
        }
        catch (Exception ex)
        {
            return balance;
        }
    }
    public decimal UserCutOffDetails()
    {
        decimal cutoffBalance = 0;
        try
        {
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@LOGINID",LoginID)
            };

            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getcutoffbalance", get_user_details);
            if (dr.Read())
            {
                cutoffBalance = Convert.ToInt32(dr["CuttOffAmount"]);
            }
            return cutoffBalance;
        }
        catch (Exception ex)
        {
            return cutoffBalance;
        }
    }
    public void GetOperatorID(string Operator)
    {
        SqlParameter[] ONLINEOFFLINEOPERATOR = new SqlParameter[]
        {
            new SqlParameter("@opname", Operator),
            new SqlParameter("@OperatorType","ELECTRICITY")
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_GETONLINEOFFLINEOPERATOR", ONLINEOFFLINEOPERATOR);
        if (ds.Tables[0].Rows.Count != 0)
        {
            ViewState["OperatorID"] = ds.Tables[0].Rows[0]["MobileDthOperatorDetailsID"];

        }

    }
    public void PaymentBill(string BillAmount)
    {
        try
        {
            decimal WLbalance = WLAmount();
            decimal ReqBalance = Convert.ToDecimal(BillAmount);
            decimal AgBalance = userdetails();
            decimal cutoffBalance = UserCutOffDetails();
            string RefNumber = string.Empty;
            string TXNID = string.Empty;
            string IPAdd = HttpContext.Current.Request.UserHostAddress.ToString();
            GetOperatorID(ddlEleOpt.SelectedValue.ToString());
            if (WLbalance > ReqBalance)
            {
                if (AgBalance > cutoffBalance)
                {
                    if (AgBalance > ReqBalance)
                    {
                        RefNumber = Convert.ToString(ViewState["RefId"]);
                        int status1 = CommonFunction.InsertTransactionWithPendingStatus(Session["WhitelabelId"].ToString(), IPAdd, RefNumber, LoginID, "ELECTRICITY", ddlEleOpt.SelectedItem.Text,
                                Convert.ToString(ViewState["OperatorID"]), "ALL", txtConsumerNo.Text, BillAmount, " ", "SoftZone", Session["PortalName"].ToString(), "Bill Payment");

                        if (status1 == 1)
                        {
                            reset();
                            lblerror.Visible = true;
                            lblerror.Text = "There is some technical problem .Please try again.";
                        }
                        else if (status1 == 2)
                        {
                            
                          string json = new JavaScriptSerializer().Serialize(new
                           {
                               Key = "7ef37a4185480cebda9430277939c47ce93b4183",
                               AgentID = "3890",
                               OP = Convert.ToString(ddlEleOpt.SelectedValue),
                               REQUEST_ID = RefNumber,
                               Amount = ReqBalance,
                               Account = txtConsumerNo.Text.Trim(),
                               Customermobile = txtMobileNo.Text.Trim(),
                               Optional1 = "",
                               Optional2 = "",
                               Optional3 = "",
                               Optional4 = "",
                               Optional5 = "",
                               Optional6 = "",
                               Optional7 = "",
                               Optional8 = "Live",
                               Optional9 = "28.6207,77.3818|201301",//"22.572645,‎88.363892|700050",//"28.6207,77.3818|201301",
                               Outlet_ID = "3669"//"3702"//"3669"
                           });
                            string Result = PostRequest("http://api.softsolutionzone.in/resources/SKIPDMR/Payment", json);
                            SqlParameter[] TxnResponce = new SqlParameter[]
                            {
                                 new SqlParameter("@TXNRESPONCE",Result),
                                new SqlParameter("@REFRENCENO",RefNumber)
                            };
                            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "USP_INSERTTXNRESPONCEFIRSTTIME", TxnResponce);

                            string res = Result;

                            if (res.Contains("res_code"))
                            {
                                JObject jsonResponse = JObject.Parse(res);
                                if (jsonResponse["res_code"].ToString() == "TXN")
                                {
                                    ViewState["OrderId"] = Convert.ToString(jsonResponse["ipay_id"]);
                                    ViewState["Status"] = Convert.ToString(jsonResponse["status"]);
                                    TXNID = Convert.ToString(jsonResponse["opr_id"]);
                                   
                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, Convert.ToString(ReqBalance), "Success", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TXNID);
                                    reset();
                                    lblerror.Text="Successfully Completed";
                                    lblerror.Visible=true;
                                }
                                else if (jsonResponse["res_code"].ToString() == "TUP")
                                {
                                    ViewState["OrderId"] = Convert.ToString(jsonResponse["ipay_id"]);
                                    ViewState["Status"] = "Pending";
                                    TXNID = Convert.ToString(jsonResponse["opr_id"]);
                                   
                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, Convert.ToString(ReqBalance), "Pending", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TXNID);
                                    reset();
                                    lblerror.Text="Transaction Under Process";
                                    lblerror.Visible=true;
                                }
                                else{
                                    ViewState["OrderId"] = Convert.ToString(jsonResponse["ipay_id"]);
                                    ViewState["Status"] = "Failed";
                                    TXNID = Convert.ToString(jsonResponse["opr_id"]);
                                   
                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, Convert.ToString(ReqBalance), "Fail", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TXNID);
                                    reset();
                                    lblerror.Text="Transaction Failed.";
                                    lblerror.Visible=true;
                                }
                             }
                            else if (res.Contains("statuscode"))
                            {
                                JObject jsonResponse = JObject.Parse(res);
                                if (jsonResponse["statuscode"].ToString() == "TXN")
                                {
                                    ViewState["OrderId"] = Convert.ToString(jsonResponse["ipay_id"]);
                                    ViewState["Status"] = Convert.ToString(jsonResponse["status"]);
                                    TXNID = Convert.ToString(jsonResponse["opr_id"]);

                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, Convert.ToString(ReqBalance), "Success", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TXNID);
                                    reset();
                                    lblerror.Text = "Successfully Completed";
                                    lblerror.Visible = true;
                                }
                                 else if (jsonResponse["statuscode"].ToString() == "TUP")
                                {
                                    ViewState["OrderId"] = Convert.ToString(jsonResponse["ipay_id"]);
                                    ViewState["Status"] = "Pending";
                                    TXNID = Convert.ToString(jsonResponse["opr_id"]);

                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, Convert.ToString(ReqBalance), "Pending", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TXNID);
                                    reset();
                                    lblerror.Text = "Transaction Under Process";
                                    lblerror.Visible = true;
                                }
                                else
                                {
                                    _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID.ToString(), RefNumber, Convert.ToString(ReqBalance), "Fail", "Failed", "", RefNumber, "");
                                    reset();
                                    lblerror.Text = jsonResponse["status"].ToString();
                                    lblerror.Visible = true;
                                }
                            }
                            else
                            {
                                _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID.ToString(), RefNumber, Convert.ToString(ReqBalance), "Fail", "Failed", "", RefNumber, "");
                                reset();
                                lblerror.Text = "Transaction Failed.";
                                lblerror.Visible = true;
                            }
                           }
                            
                                
                        
                    }
                    else
                    {
                        reset();
                        lblerror.Text = "You don’t have enough balance to do this transaction. Please take balance in your login.";
                        lblerror.Visible = true;
                    }
                }
                else
                {
                    reset();
                    lblerror.Text = "Your balance is low from cutoff balance. Please take balance in your login.";
                    lblerror.Visible = true;
                }
            }
            else
            {
                reset();
                lblerror.Text = "Your Administrator don’t have enough balance to do this transaction.";
                lblerror.Visible = true;
            }
        }
        catch (Exception ex)
        {
        }
    }

    public void PaymentBill_Other(string BillAmount)
    {
        try
        {
            string TxnID = string.Empty;
            decimal WLbalance = WLAmount();
            decimal ReqBalance = Convert.ToDecimal(BillAmount);
            decimal AgBalance = userdetails();
            decimal cutoffBalance = UserCutOffDetails();
            string RefNumber = string.Empty;
            string TXNID = string.Empty;
            string IPAdd = HttpContext.Current.Request.UserHostAddress.ToString();
            GetOperatorID(ddlEleOpt.SelectedValue.ToString());
            if (WLbalance > ReqBalance)
            {
                if (AgBalance > cutoffBalance)
                {
                    if (AgBalance > ReqBalance)
                    {
                        RefNumber = Convert.ToString(ViewState["RefId"]);
                        int status1 = CommonFunction.InsertTransactionWithPendingStatus(Session["WhitelabelId"].ToString(), IPAdd, RefNumber, LoginID, "ELECTRICITY", ddlEleOpt.SelectedItem.Text,
                                Convert.ToString(ViewState["OperatorID"]), "ALL", txtConsumerNo.Text, BillAmount, " ", "VenusAPI", Session["PortalName"].ToString(), "Bill Payment");

                        if (status1 == 1)
                        {
                            reset();
                            lblerror.Visible = true;
                            lblerror.Text = "There is some technical problem .Please try again.";
                        }
                        else if (status1 == 2)
                        {

                            string json = CommonFunction.eGenAPIRecharge("Bill Payment", ddlEleOpt.SelectedValue.ToString(), "EB", txtConsumerNo.Text, BillAmount, RefNumber, txtMobileNo.Text, LoginID);
                            SqlParameter[] TxnResponce = new SqlParameter[]
                            {
                                 new SqlParameter("@TXNRESPONCE",json),
                                new SqlParameter("@REFRENCENO",RefNumber)
                            };
                            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "USP_INSERTTXNRESPONCEFIRSTTIME", TxnResponce);

                            string res = json;
                            if (!(res.Contains("error") || res.Contains("Error")))
                            {
                                ds.ReadXml(new StringReader(res));
                                if (ds.Tables["Response"].Rows.Count > 0)
                                {
                                    ViewState["Status"] = Convert.ToString(ds.Tables["Response"].Rows[0]["ResponseStatus"]);
                                    if (ds.Tables[0].Columns.Contains("OrderNo"))
                                    {
                                        ViewState["OrderId"] = Convert.ToString(ds.Tables["Response"].Rows[0]["OrderNo"]);
                                        TxnID = Convert.ToString(ds.Tables["Response"].Rows[0]["OperatorTxnID"]);
                                        if (ViewState["Status"].Equals("FAILED") || ViewState["Status"].Equals("FAILURE"))
                                        {
                                            _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, txtAmount.Text.Trim(), "Fail", ViewState["Status"].ToString(), res, Convert.ToString(ViewState["OrderId"]), TxnID);
                                            reset();
                                            lblerror.Text = ViewState["Status"].ToString();
                                            lblerror.Visible = true;
                                        }
                                        else if (ViewState["Status"].Equals("Pending") || ViewState["Status"].Equals("PENDING"))
                                        {
                                            _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, txtAmount.Text.Trim(), "Pending", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TxnID);
                                            reset();
                                            lblerror.Text = "Transaction Under Process";
                                            lblerror.Visible = true;
                                           
                                        }
                                        else
                                        {
                                            _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID, RefNumber, txtAmount.Text.Trim(), "Success", ViewState["Status"].ToString(), res, ViewState["OrderId"].ToString(), TxnID);
                                            reset();
                                            lblerror.Text = "Successfully Completed";
                                            lblerror.Visible = true;
                                        }
                                    }
                                    else
                                    {
                                        _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID.ToString(), RefNumber, Convert.ToString(ReqBalance), "Fail", ViewState["Status"].ToString(), res, RefNumber, "");
                                        reset();
                                        lblerror.Text = "Transaction Failed.";
                                        lblerror.Visible = true;
                                    }

                                }
                            }
                            else
                            {
                                _ObjWBMNverify.FinalUpdate(Session["WhitelabelId"].ToString(), LoginID.ToString(), RefNumber, Convert.ToString(ReqBalance), "Fail", ViewState["Status"].ToString(), res, RefNumber, "");
                                reset();
                                lblerror.Text = ViewState["Status"].ToString();
                                lblerror.Visible = true;
                            }
                            
                        }



                    }
                    else
                    {
                        reset();
                        lblerror.Text = "You don’t have enough balance to do this transaction. Please take balance in your login.";
                        lblerror.Visible = true;
                    }
                }
                else
                {
                    reset();
                    lblerror.Text = "Your balance is low from cutoff balance. Please take balance in your login.";
                    lblerror.Visible = true;
                }
            }
            else
            {
                reset();
                lblerror.Text = "Your Administrator don’t have enough balance to do this transaction.";
                lblerror.Visible = true;
            }
        }
        catch (Exception ex)
        {
        }
    }
}