protected void btnSavePermissions_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (GridViewRow row in gvstopservices.Rows)
            {
                _objmasters = new clsMasters();
                Label lblScrnID = (Label)row.FindControl("lblScreenID");
                Label lblScrnName = (Label)row.FindControl("lblScreenName");
                CheckBox ChkAdd1 = (CheckBox)row.FindControl("ChkAdd");
                _objmasters.ScreenInd = Masters.Getservices;
                _objmasters.ID = Convert.ToInt32(lblScrnID.Text.Trim());
                if (ChkAdd1.Checked == true)
                {
                    _objmasters.Status = "1";
                }
                else
                {
                    _objmasters.Status = "0";
                }
                if (_objmasters.fnUpdateRecord() == true)
                {
                    lblmsg.Text = "Selected services Stopped succesfully";
                    lblmsg.Visible = true;
                    lblmsg.ForeColor = System.Drawing.Color.Green;
                }
            }

        }
        catch (Exception ex)
        {
        }
    }
 protected void AddAmountoUserswhenRechargefailed()
 {
     try
     {
         _objMaster = new clsMasters();
         _objMaster.ScreenInd = Masters.AddAmounttoUsersRechargeFailed;
         _objMaster.amountewallet = Convert.ToDecimal(Session["RRechargeAmount"].ToString());
         _objMaster.UserID = Convert.ToInt32(Session["UserID"].ToString());
         _objMaster.fnUpdateRecord();
     }
     catch (Exception ex)
     {
       //  LogError("redirect.aspx", "AddAmountoUserswhenRechargefailed", DateTime.Now, ex.Message.ToString());
     }
 }
        protected void mobilerecharge()
        {
            getip();
            string MobileNumber, Provider, balance, Email;
            _objMaster = new clsMasters();
            _objMaster.ScreenInd = Masters.getrecharge;
            _objMaster.Parameter = "RequestID";
            _objMaster.RequestID = Session["Order_Id"].ToString();
            _objDataSet = new DataSet();
            _objDataSet = (DataSet)_objMaster.fnGetData();

            if (_objDataSet != null)
            {
                if (_objDataSet.Tables[0].Rows.Count > 0)
                {
                    MobileNumber = _objDataSet.Tables[0].Rows[0]["MobileNo"].ToString();
                    Provider = _objDataSet.Tables[0].Rows[0]["Provider_Name"].ToString();
                    balance = _objDataSet.Tables[0].Rows[0]["Amount"].ToString();
                    Email = _objDataSet.Tables[0].Rows[0]["E_Mail"].ToString();

                    ViewState["Mobile"] = MobileNumber.ToString();
                    ViewState["provider"] = Provider.ToString();
                    ViewState["balance"] = balance.ToString();
                    ViewState["Email"] = Email.ToString();

                    # region Mobile code
                    lblRequestID.Text = "KAA" + GenerateRandomNumber(11);

                    string URL = "http://www.bulksel.com/api_reach_bulksel.php?user=kass9378&pass=bus80111&mobileno=918008419101&newid=" + Session["Order_Id"] + "&message=BS " +
             Provider + " " + MobileNumber + " " + balance;

                    HttpWebRequest oReq = null;
                    HttpWebResponse oRes = null;
                    StreamReader oStream = null;
                    oReq = (HttpWebRequest)WebRequest.Create(URL);
                    oReq.Method = "GET";
                    oReq.Timeout = 10000;
                    oRes = (HttpWebResponse)oReq.GetResponse();
                    oStream = new StreamReader(oRes.GetResponseStream(), Encoding.GetEncoding(1252));

                    string strMessage = oStream.ReadToEnd().ToString();

                    Session["strMessage"] = strMessage.ToString();
                    string[] s = strMessage.Split('d');
                    if (s[0].ToString() == "Request Accepte")
                    {
                        #region Insert Data into Database

                        _objMaster = new clsMasters();

                        _objMaster.ScreenInd = Masters.getrecharge1;
                        _objMaster.Parameter = "update";
                        _objMaster.RequestID = Session["Order_Id"].ToString();
                        _objMaster.TransactionID = Convert.ToString(s[1].ToString());
                        Session["TransactionID"] = Convert.ToString(s[1].ToString());
                        _objMaster.IP = ipaddr;

                        _objMaster.Status = "SUCCESS";
                        // _objMaster.fnUpdateRecord();
                        if (_objMaster.fnUpdateRecord() == true)
                        {

                            Mpe1.Show();

                            //if (_objMaster.fnInsertRecord() == true)
                            //{
                            lblMessage.Text = "Recharge has Been Success";

                            try
                            {
                                string body = "<html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body>" +
                       "<table width='700' border='0' cellspacing='0' cellpadding='0' style='font-family: Verdana;font-size: smaller; margin-left: 1px; margin-right: 1px; padding-bottom: 10px;'><tr>" +
                       "<td valign='top' width='100%'>" +
                       "<table width='100%'><tr><td valign='top'" +
                      " &nbsp;<img src='http://paytopups.com/images/ban.jpg' /></td> </tr></table> </td></tr>" + " <tr><td align='left' valign='top' style='height: 0px; background-color: #860f2b;'></td></tr>" +
                      "<tr><td align='left' valign='top' style='padding-left: 10px;'>Dear User, </td></tr>" +
                      "<tr><td align='left' valign='top' style='padding-left: 10px;'>Your TransactionID .<span style='font-weight: 600;'>" + Session["TransactionID"] + " </span></td></tr>" +
                      "<tr><td><table><tr><td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'> Mobile Number:</span>" + MobileNumber + "</td>" +
                      "<td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'>Amount:</span>" + balance + "</td></tr></table></td></tr>" +
                       "<tr><td align='left' width='100%' valign='top'><table><tr><td align='center' width='100%' valign='top' style='background-color: #860f2b; color: White;' colspan='2'><b>Contact Us</b></td></tr>" +
                       "<tr><td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='right' valign='top'><span style='color: #860f2b;'>Support</span> </td>  " + "<td align='left' valign='top'>  &nbsp;Visit our Knowledge Base / FAQs for quick answers Log a query or problem at  My Helpdesk </td></tr> " +
                       "<tr><td align='right' valign='top'></td>&quot;</tr></table></td>" +
                     "<td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='left' valign='top'> <span style='color: #860f2b;'>Sales Support</span></td> " +
                     "<td align='left' valign='top'> <p>Kassp Technologies f101, Rainbow residency, plot- 1000 and 1001,Pragathi Nagar, Kukatpally </p> Hyderabad - 90</td></tr>" +
                      "<tr><td align='left' valign='top' style='padding-left: 20px;'></td></tr>" +
                      "<tr><td align='left' valign='top' style='padding-left: 20px; background-color: #860f2b color: White;'></td></tr>" +
                      "</table></body></html>" +
                      "<br />Again, we thank you for registering with <b>www.paytopups.com</b> and please " +
                       "do not hesitate to write to us at <a href='mailto:[email protected]'>Mail</a>" + "if you have any questions.<br /><br />Best Regards,<br /><a href='http://www.paytopups.com'>paytopups.com</a> " + "<br /><br />";

                                MailSender.SendEmail(Email, "*****@*****.**", "*****@*****.**", "Paytopups-Recharge", body);

                            }
                            catch (Exception ex)
                            {
                                //LogError("redirect.aspx", "Mail", DateTime.Now, ex.Message.ToString());
                                //Response.Redirect("Error.aspx", false);

                            }

                            try
                            {
                                //string strUrl = "http://sms.i2space.in/WebServiceSMS.aspx?User=i2space1&passwd=smsc&mobilenumber=" + MobileNumber +
                                //"&message= Thank You for usingpaytopups.com to Recharge Mobile no" + MobileNumber + " for Rs" + " " + balance + "& your order Num is" + "" + Session["TransactionID"] + "" + "for Queries ,Email us at [email protected]" +
                                //"&sid=Paytopups&mtype=N";
                                //HttpWebRequest oReq1 = null;
                                //HttpWebResponse oRes1 = null;
                                //StreamReader oStream1 = null;
                                //oReq1 = (HttpWebRequest)WebRequest.Create(strUrl);
                                //oReq1.Method = "GET";
                                //oReq1.Timeout = 10000;
                                //oRes1 = (HttpWebResponse)oReq1.GetResponse();
                                //oStream1 = new StreamReader(oRes1.GetResponseStream(), Encoding.GetEncoding(1252));
                                //string strMessage1 = oStream1.ReadToEnd().ToString();
                            }
                            catch (ArgumentException ex)
                            {
                                // LogError("redirect.aspx", "sms", DateTime.Now, ex.Message.ToString());
                                //Response.Redirect("Error.aspx", false);
                            }
                            //}
                            Response.Redirect("Success.aspx", false);
                        #endregion
                        }
                    }
                    else
                    {
                        Response.Redirect("RechargeFailure.aspx", false);
                        // LogError("redirect.aspx", "API", DateTime.Now, Session["strMessage"].ToString());
                        _objMaster = new clsMasters();
                        _objMaster.ScreenInd = Masters.Mobilenew;
                        _objMaster.Mobile_Num = Convert.ToString(MobileNumber); //txtMobile.Text.Trim();
                        _objMaster.Provider_Name = Convert.ToString(Provider);
                        _objMaster.E_Mail = Convert.ToString(Email);
                        _objMaster.Amount = Convert.ToDouble(balance);
                        _objMaster.Payment = Convert.ToString("Deposited");
                        _objMaster.RequestID = lblRequestID.Text.Trim();
                        _objMaster.TransactionID = Convert.ToString(Session["strMessage"]);

                        _objMaster.IP = ipaddr;
                        _objMaster.Status = "Failure";//strMessage.Substring(strMessage.IndexOf("<status>") + 8, 7);
                        _objMaster.CreatedBy = "NA";
                        _objMaster.ModifiedBy = "NA";
                        _objMaster.ModifiedDate = "NA";
                        _objMaster.fnInsertRecord();
                        Response.Redirect("Error.aspx", false);
                    }
                }
                else
                {
                    Response.Redirect("RechargeFailure.aspx", false);
                    // LogError("redirect.aspx", "API", DateTime.Now, Session["strMessage"].ToString());
                    _objMaster = new clsMasters();
                    _objMaster.ScreenInd = Masters.Mobilenew;
                    _objMaster.Mobile_Num = Convert.ToString(ViewState["Mobile"]); //txtMobile.Text.Trim();
                    _objMaster.Provider_Name = Convert.ToString(ViewState["provider"]);
                    _objMaster.E_Mail = Convert.ToString(ViewState["balance"]);
                    _objMaster.Amount = Convert.ToDouble(ViewState["Email"]);
                    _objMaster.Payment = Convert.ToString("Deposited");
                    _objMaster.RequestID = lblRequestID.Text.Trim();
                    _objMaster.TransactionID = Convert.ToString(Session["strMessage"]);
                    _objMaster.IP = ipaddr;
                    _objMaster.Status = "Failure";//strMessage.Substring(strMessage.IndexOf("<status>") + 8, 7);
                    _objMaster.CreatedBy = "NA";
                    _objMaster.ModifiedBy = "NA";
                    _objMaster.ModifiedDate = "NA";
                    _objMaster.fnInsertRecord();
                    Response.Redirect("Error.aspx", false);
                }
            }
            else
            {
                Mpe1.Show();
                lblMessage.Text = "Recharge Has Been Failed Please Try Again Later";
            }
                    #endregion
        }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            _objMasters = new clsMasters();
            _objMasters.ScreenInd = Masters.AgentCommission;
            _objMasters.RefID = Convert.ToInt32(lblID.Text);

            _objMasters.OperatorType = ddloperators.SelectedValue;
            _objMasters.NetworkName = ddlProvider.SelectedValue;
            _objMasters.AgentCommission = Convert.ToDecimal(txtRechargeAmount.Text);

            if (_objMasters.fnUpdateRecord() == true)
            {
                lblmessage.ForeColor = Color.Green;
                lblmessage.Text = "Record Updated successfully.";
                ddlProvider.SelectedIndex = 0;
                txtRechargeAmount.Text = string.Empty;

                ddloperators.SelectedIndex = 0;
                fnLoadPage1();
            }
            else
            {
                lblmessage.Text = "Insertion Failed";
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void DataCardRecharge()
    {
        try
        {
            getip();
            string MobileNumber, Provider, balance, Email;
            _objMasters = new clsMasters();
            _objMasters.ScreenInd = Masters.getagentDatacardrecharge;
            _objMasters.Parameter = "RequestID";
            _objMasters.RequestID = Session["Order_Id"].ToString();
            _objDataSet = new DataSet();
            _objDataSet = (DataSet)_objMasters.fnGetData();

            if (_objDataSet != null)
            {
                if (_objDataSet.Tables.Count > 0)
                {
                    if (_objDataSet.Tables[0].Rows.Count > 0)
                    {
                        MobileNumber = _objDataSet.Tables[0].Rows[0]["MobileNo"].ToString();
                        Provider = _objDataSet.Tables[0].Rows[0]["Provider_Name"].ToString();
                        balance = _objDataSet.Tables[0].Rows[0]["Amount"].ToString();
                        Email = _objDataSet.Tables[0].Rows[0]["E_Mail"].ToString();

                        //-----------Gettinh the commission of agent for a network-----

                        // _objMaster = new clsMasters();
                        _objMaster.ScreenInd = Masters.GetCommisionByNetwork;
                        _objMaster.NetworkName = Session["NetWorkName"].ToString();
                        if (Session["Role"].ToString() == "Agent")
                        {
                            _objMaster.Type = "AG";
                        }
                        _objMaster.UserID = Convert.ToInt32(Session["UserID"].ToString());
                        _objDataSet = (DataSet)_objMaster.fnGetData();
                        if (_objDataSet.Tables.Count > 0)
                        {
                            if (_objDataSet.Tables[0].Rows.Count > 0)
                            {
                                Commission = Convert.ToDecimal(_objDataSet.Tables[0].Rows[0]["AgentCommission"].ToString());
                            }
                        }

                        decimal rechargeAmount = Convert.ToDecimal(Session["RRechargeAmount"]);
                        decimal DeductAmountOnCommission = (rechargeAmount * Commission) / (100);
                        decimal deductamount = rechargeAmount - DeductAmountOnCommission;

                        //----------end-------
                        # region Mobile code

                        string all = "10118" + Session["Order_Id"] + Session["RProviderName"] + "|" + Session["RMobileNumber"] + "|" + Session["RRechargeAmount"] + "A8JW8FX7KQ7PY5ZT2S1V";

                        string pwhash = FormsAuthentication.HashPasswordForStoringInConfigFile(all, "sha1");

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.payintegra.com/RechargeService");
                        request.Method = "POST";
                        request.ContentType = "application/x-www-form-urlencoded";
                        string postData = "PartnerId=10118&TransId=" + Session["Order_Id"] + "&Message=" + Session["RProviderName"] + "|" + Session["RMobileNumber"] + "|" + Session["RRechargeAmount"] + "&Hash=" + pwhash;
                        byte[] bytes = Encoding.UTF8.GetBytes(postData);
                        request.ContentLength = bytes.Length;

                        Stream requestStream = request.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);

                        WebResponse response = request.GetResponse();
                        Stream stream = response.GetResponseStream();
                        StreamReader reader = new StreamReader(stream);

                        var result = reader.ReadToEnd();

                        string[] s = result.Split('|');

                        stream.Dispose();
                        reader.Dispose();

                        if (s[0].ToString().Trim() == "100" && s[4].ToString().Trim() == "Transaction Successful")
                        {
                            #region Insert Data into Database
                            //getstatus();
                            //if (Session["GetStatus"].ToString() == "Success ")
                            //{
                            AdminiBalance();
                            Session["TranscationId"] = s[1].ToString();
                            _objMasters = new clsMasters();

                            _objMasters.ScreenInd = Masters.getrecharge3;
                            _objMasters.Parameter = "update";
                            _objMasters.RequestID = Session["Order_Id"].ToString();
                            _objMasters.TransactionID = Convert.ToString(s[1].ToString());
                            Session["TransactionID"] = Convert.ToString(s[1].ToString());

                            _objMasters.Amount = Convert.ToDouble(balance);
                            _objMasters.UserID = Convert.ToInt32(Session["UserID"]);

                            _objMasters.AgentCommission = DeductAmountOnCommission;

                            _objMasters.Status = "SUCCESS";
                            Session["Status"] = "Recharge successfully";
                            _objMasters.IP = ipaddr;

                            _objMasters.A_Amount = Convert.ToDecimal(Session["FinalAdminBalance"].ToString());

                            if (_objMasters.fnUpdateRecord() == true)
                            {

                                Mpe1.Show();

                                lblMessage.Text = "Recharge has Been Success";

                                try
                                {
                                    string body = "<html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body>" +
                           "<table width='700' border='0' cellspacing='0' cellpadding='0' style='font-family: Verdana;font-size: smaller; margin-left: 1px; margin-right: 1px; padding-bottom: 10px;'><tr>" +
                           "<td valign='top' width='100%'>" +
                           "<table width='100%'><tr><td valign='top'" +
                          " &nbsp;<img src='http://lovejourney.in/images/ban.jpg' /></td> </tr></table> </td></tr>" + " <tr><td align='left' valign='top' style='height: 0px; background-color: #860f2b;'></td></tr>" +
                          "<tr><td align='left' valign='top' style='padding-left: 10px;'>Dear User, </td></tr>" +
                          "<tr><td align='left' valign='top' style='padding-left: 10px;'>Your TransactionID .<span style='font-weight: 600;'>" + Session["TransactionID"] + " " + "& Your request Id is " + "" + Session["Order_Id"] + " </span></td></tr>" +
                          "<tr><td><table><tr><td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'> Mobile Number:</span>" + MobileNumber + "</td>" +
                          "<td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'>Amount:</span>" + balance + "</td></tr></table></td></tr>" +
                           "<tr><td align='left' width='100%' valign='top'><table><tr><td align='center' width='100%' valign='top' style='background-color: #860f2b; color: White;' colspan='2'><b>Contact Us</b></td></tr>" +
                           "<tr><td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='right' valign='top'><span style='color: #860f2b;'>Support</span> </td>  " + "<td align='left' valign='top'>  &nbsp;Visit our Knowledge Base / FAQs for quick answers Log a query or problem at  My Helpdesk </td></tr> " +
                           "<tr><td align='right' valign='top'></td>&quot;</tr></table></td>" +
                         "<td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='left' valign='top'> <span style='color: #860f2b;'>Sales Support</span></td> " +
                         "<td align='left' valign='top'> </td></tr>" +
                          "<tr><td align='left' valign='top' style='padding-left: 20px;'></td></tr>" +
                          "<tr><td align='left' valign='top' style='padding-left: 20px; background-color: #860f2b color: White;'></td></tr>" +
                          "</table></body></html>" +
                          "<br />Again, we thank you for registering with <b>www.lovejourney.in</b> and please " +
                           "do not hesitate to write to us at <a href='mailto:[email protected]'>Mail</a>" + "if you have any questions.<br /><br />Best Regards,<br /><a href='http://www.lovejourney.in'>lovejourney.in</a> " + "<br /><br />";

                                    MailSender.SendEmail("*****@*****.**", "*****@*****.**", "*****@*****.**", "LoveJourney-Recharge", body);

                                }
                                catch (Exception ex)
                                {
                                    //LogError("redirect.aspx", "Mail", DateTime.Now, ex.Message.ToString());
                                   // Response.Redirect("Error.aspx", false);

                                }

                                try
                                {
                                    //string strUrl = "http://sms.i2space.in/WebServiceSMS.aspx?User=i2space1&passwd=smsc&mobilenumber=" + MobileNumber +
                                    //"&message= Thank You for using lovejourney.in to Recharge Mobile no" + MobileNumber + " for Rs" + " " + balance + "& your order Num is" + "" + Session["TransactionID"] + "" + "for Queries ,Email us at [email protected]" +
                                    //"&sid=LoveJourney&mtype=N";
                                    //HttpWebRequest oReq1 = null;
                                    //HttpWebResponse oRes1 = null;
                                    //StreamReader oStream1 = null;
                                    //oReq1 = (HttpWebRequest)WebRequest.Create(strUrl);
                                    //oReq1.Method = "GET";
                                    //oReq1.Timeout = 10000;
                                    //oRes1 = (HttpWebResponse)oReq1.GetResponse();
                                    //oStream1 = new StreamReader(oRes1.GetResponseStream(), Encoding.GetEncoding(1252));
                                    //string strMessage1 = oStream1.ReadToEnd().ToString();
                                }
                                catch (ArgumentException ex)
                                {
                                    //LogError("redirect.aspx", "sms", DateTime.Now, ex.Message.ToString());
                                  //  Response.Redirect("Error.aspx", false);
                                }

                                //_objMaster = new clsMasters();
                                //_objMaster.ScreenInd = Masters.deductagentbalance;
                                //_objMaster.UserID = Convert.ToInt32(Session["UserID"]);
                                //_objMaster.A_Amount = deductamount;
                                //_objMaster.fnUpdateRecord();

                                DeductAgentBalance(Convert.ToInt32(Session["AgentId_Agent"].ToString()), Convert.ToDouble(deductamount),
                                      Convert.ToInt32(Session["UserID"].ToString()), Session["TransactionID"].ToString().Trim(), Convert.ToDouble(Session["RRechargeAmount"].ToString()),
                                      Convert.ToDouble(DeductAmountOnCommission), Convert.ToInt32(Session["CommisionPercentage_Agent"].ToString()));

                                objBAL = new ClsBAL();
                                DataSet dsBalanceA = objBAL.GetAgentByUserId(Convert.ToInt32(Session["UserID"].ToString()));

                                string balanceAgent = dsBalanceA.Tables[0].Rows[0]["Balance"].ToString();
                                Label lbl = (Label)this.Master.FindControl("lblBalance");
                                lbl.Text = balanceAgent;
                                Session["Balance"] = balanceAgent;

                                Response.Redirect("~/Agent/Recharge/RechargeSucces.aspx", false);

                            #endregion
                            }
                            // }

                        }
                        else
                        {
                            AdminiBalance();

                            _objMasters = new clsMasters();

                            _objMasters.ScreenInd = Masters.getrecharge3;
                            _objMasters.Parameter = "update";
                            _objMasters.RequestID = Session["Order_Id"].ToString();
                            _objMasters.TransactionID = Convert.ToString(s[1].ToString());
                            Session["TransactionID"] = Convert.ToString(s[1].ToString());

                            _objMasters.Amount = Convert.ToDouble(balance);
                            _objMasters.UserID = Convert.ToInt32(Session["UserID"]);
                            _objMasters.Status = "Failure";
                            Session["Status"] = "Recharge Failure";

                            _objMasters.A_Amount = Convert.ToDecimal(Session["FinalAdminBalance"].ToString());

                            _objMasters.IP = ipaddr;

                            Session["errorcode"] = s[0].ToString();
                            Session["errorDecsription"] = s[4].ToString();

                            _objMasters.fnUpdateRecord();

                            Response.Redirect("~/Agent/Recharge/Failure.aspx", false);
                        }
                    }
                }

                else
                {
                    Mpe1.Show();
                    lblMessage.Text = "Recharge Has Been Failed Please Try Again Later";

                }
                        #endregion
            }
            else
            {
                Mpe1.Show();
                lblMessage.Text = "Recharge Has Been Failed Please Try Again Later";

            }
        }
        catch (Exception ex)
        {
            //LogError("Masters/Recharge.aspx", "DataCardRecharge", DateTime.Now, ex.Message.ToString());
            throw ex;
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            _objMasters = new clsMasters();
            _objMasters.ScreenInd = Masters.ListOfAmounts;
            _objMasters.RefID =Convert.ToInt32(lblID.Text);

            _objMasters.OperatorType = ddloperators.SelectedValue;
            _objMasters.NetworkName = ddlProvider.SelectedValue;
            _objMasters.A_Amount = Convert.ToDecimal(txtRechargeAmount.Text);
            //_objMasters.TalkTime = Convert.ToDecimal(txtTalkTime.Text);

            _objDataSet = (DataSet)_objMasters.fnGetData();
            if (_objDataSet.Tables[0].Rows.Count > 0)
            {
                _objDataSet = (DataSet)_objMasters.fnGetData();
                DataView dv = _objDataSet.Tables[0].DefaultView;
                dv.RowFilter = "NetworkName ='" + ddlProvider.SelectedValue + "' and RechargeAmount='" + txtRechargeAmount.Text.ToString() + "'";
                if (dv.Count > 0)
                {
                    lblmessage.Visible = true;
                    lblmessage.Text = "Already You have added This amount for this network";
                    lblmessage.ForeColor = Color.Red;
                }
                else
                {
                    if (_objMasters.fnUpdateRecord() == true)
                    {
                        lblmessage.ForeColor = Color.Green;
                        lblmessage.Text = "Record Updated successfully.";
                        ddlProvider.SelectedIndex = 0;
                        txtRechargeAmount.Text = string.Empty;
                        //txtTalkTime.Text = string.Empty;
                        ddlProvider.SelectedIndex = 0;
                        ddloperators.SelectedIndex = 0;
                        fnLoadPage1();
                    }
                    else
                    {
                        lblmessage.Text = "Insertion Failed";
                    }
                }
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void UserDataCardRecharge()
    {
        try
        {
            getip();
            string MobileNumber, Provider, balance, Email;
            _objMasters = new clsMasters();
            _objMasters.ScreenInd = Masters.getagentDatacardrecharge;
            _objMasters.Parameter = "RequestID";
            _objMasters.RequestID = Session["Order_Id"].ToString();
            _objDataSet = new DataSet();
            _objDataSet = (DataSet)_objMasters.fnGetData();

            if (_objDataSet != null)
            {
                if (_objDataSet.Tables.Count > 0)
                {
                    if (_objDataSet.Tables[0].Rows.Count > 0)
                    {
                        MobileNumber = _objDataSet.Tables[0].Rows[0]["MobileNo"].ToString();
                        Provider = _objDataSet.Tables[0].Rows[0]["Provider_Name"].ToString();
                        balance = _objDataSet.Tables[0].Rows[0]["Amount"].ToString();
                        Email = _objDataSet.Tables[0].Rows[0]["E_Mail"].ToString();

                        # region Mobile code
                         string all = "10118" + Session["Order_Id"] + Session["RProviderName"] + "|" + Session["RMobileNumber"] + "|" + Session["RRechargeAmount"] + "A8JW8FX7KQ7PY5ZT2S1V";

                        string pwhash = FormsAuthentication.HashPasswordForStoringInConfigFile(all, "sha1");

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.payintegra.com/RechargeService");
                        request.Method = "POST";
                        request.ContentType = "application/x-www-form-urlencoded";
                        string postData = "PartnerId=10118&TransId=" + Session["Order_Id"] + "&Message=" + Session["RProviderName"] + "|" + Session["RMobileNumber"] + "|" + Session["RRechargeAmount"] + "&Hash=" + pwhash;
                        byte[] bytes = Encoding.UTF8.GetBytes(postData);
                        request.ContentLength = bytes.Length;

                        Stream requestStream = request.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);

                        WebResponse response = request.GetResponse();
                        Stream stream = response.GetResponseStream();
                        StreamReader reader = new StreamReader(stream);

                        var result = reader.ReadToEnd();

                        string[] s = result.Split('|');

                        stream.Dispose();
                        reader.Dispose();

                        if (s[0].ToString().Trim() == "100" && s[4].ToString().Trim() == "Transaction Successful")
                        {
                                #region Show Loading

                                //Response.Write("<div id=\"loading\" style=\"position:absolute; width:100%; text-align:center; top:300px;\">In Process...<img src=\"images/loading123.gif\" border=0></div>");
                                //Response.Flush();
                                #endregion

                              //  getstatus();

                                //if (Session["GetStatus"].ToString() == "Success ")
                                //{
                                    AdminiBalance();
                                    #region Insert Data into Database

                                    _objMasters = new clsMasters();

                                    _objMasters.ScreenInd = Masters.getrecharge3;
                                    _objMasters.Parameter = "update";
                                    _objMasters.RequestID = Session["Order_Id"].ToString();
                                    _objMasters.TransactionID = Convert.ToString(s[1].ToString());
                                    Session["TransactionID"] = Convert.ToString(s[1].ToString());

                                    _objMasters.Amount = Convert.ToDouble(balance);
                                    _objMasters.UserID = Convert.ToInt32(Session["UserID"]);

                                    _objMasters.Status = "SUCCESS";
                                    Session["Status"] = "Successfully Recharge";
                                    _objMasters.IP = ipaddr;
                                    _objMasters.A_Amount = Convert.ToDecimal(Session["FinalAdminBalance"].ToString());
                                    if (_objMasters.fnUpdateRecord() == true)
                                    {

                                        //Mpe1.Show();

                                        //lblMessage.Text = "Recharge has Been Success";

                                        try
                                        {
                                            string body = "<html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body>" +
                                   "<table width='700' border='0' cellspacing='0' cellpadding='0' style='font-family: Verdana;font-size: smaller; margin-left: 1px; margin-right: 1px; padding-bottom: 10px;'><tr>" +
                                   "<td valign='top' width='100%'>" +
                                   "<table width='100%'><tr><td valign='top'" +
                                  " &nbsp;<img src='http://lovejourney.in/images/ban.jpg' /></td> </tr></table> </td></tr>" + " <tr><td align='left' valign='top' style='height: 0px; background-color: #860f2b;'></td></tr>" +
                                  "<tr><td align='left' valign='top' style='padding-left: 10px;'>Dear User, </td></tr>" +
                                  "<tr><td align='left' valign='top' style='padding-left: 10px;'>Your TransactionID .<span style='font-weight: 600;'>" + Session["TransactionID"] + " " + "& Your request Id is " + "" + Session["Order_Id"] + " </span></td></tr>" +
                                  "<tr><td><table><tr><td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'> Mobile Number:</span>" + MobileNumber + "</td>" +
                                  "<td align='right' valign='top' style='padding-right: 100px; background-color: #F1F1F1'><span style='color: #860f2b; font-weight: 600;'>Amount:</span>" + balance + "</td></tr></table></td></tr>" +
                                   "<tr><td align='left' width='100%' valign='top'><table><tr><td align='center' width='100%' valign='top' style='background-color: #860f2b; color: White;' colspan='2'><b>Contact Us</b></td></tr>" +
                                   "<tr><td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='right' valign='top'><span style='color: #860f2b;'>Support</span> </td>  " + "<td align='left' valign='top'>  &nbsp;Visit our Knowledge Base / FAQs for quick answers Log a query or problem at  My Helpdesk </td></tr> " +
                                   "<tr><td align='right' valign='top'></td>&quot;</tr></table></td>" +
                                 "<td align='left' valign='top' style='background-color: #EFEFEF;'><table><tr><td align='left' valign='top'> <span style='color: #860f2b;'>Sales Support</span></td> " +
                                 "<td align='left' valign='top'> <p> Kassp Technologies f101, Rainbow residency, plot- 1000 and 1001,Pragathi Nagar, Kukatpally </p> Hyderabad - 90</td></tr>" +
                                  "<tr><td align='left' valign='top' style='padding-left: 20px;'></td></tr>" +
                                  "<tr><td align='left' valign='top' style='padding-left: 20px; background-color: #860f2b color: White;'></td></tr>" +
                                  "</table></body></html>" +
                                  "<br />Again, we thank you for registering with <b>www.lovejourney.in</b> and please " +
                                   "do not hesitate to write to us at <a href='mailto:[email protected]'>Mail</a>" + "if you have any questions.<br /><br />Best Regards,<br /><a href='http://www.lovejourney.in'>lovejourney.in</a> " + "<br /><br />";

                                            MailSender.SendEmail(Email, "*****@*****.**", "*****@*****.**", "LoveJourney-Recharge", body);

                                        }
                                        catch (Exception ex)
                                        {
                                            //LogError("redirect.aspx", "Mail", DateTime.Now, ex.Message.ToString());
                                            //Response.Redirect("Error.aspx", false);

                                        }

                                        try
                                        {
                                            //string strUrl = "http://sms.i2space.in/WebServiceSMS.aspx?User=i2space1&passwd=smsc&mobilenumber=" + MobileNumber +
                                            //"&message= Thank You for using lovejourney.in to Recharge Mobile no" + MobileNumber + " for Rs" + " " + balance + "& your order Num is" + "" + Session["TransactionID"] + "" + "for Queries ,Email us at [email protected]" +
                                            //"&sid=LoveJourney&mtype=N";
                                            //HttpWebRequest oReq1 = null;
                                            //HttpWebResponse oRes1 = null;
                                            //StreamReader oStream1 = null;
                                            //oReq1 = (HttpWebRequest)WebRequest.Create(strUrl);
                                            //oReq1.Method = "GET";
                                            //oReq1.Timeout = 20000;
                                            //oRes1 = (HttpWebResponse)oReq1.GetResponse();
                                            //oStream1 = new StreamReader(oRes1.GetResponseStream(), Encoding.GetEncoding(1252));
                                            //string strMessage1 = oStream1.ReadToEnd().ToString();
                                        }
                                        catch (ArgumentException ex)
                                        {
                                            //LogError("redirect.aspx", "sms", DateTime.Now, ex.Message.ToString());
                                            //Response.Redirect("Error.aspx", false);
                                        }
                                        //Response.Write("<script>document.getElementById('loading').style.display='none';</script>");
                                        //ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "window.location = 'Masters/RechargeSucces.aspx';", true);

                                        Response.Redirect("~/SuccessRecharge.aspx", false);

                                    #endregion
                                    }
                                }
                                else
                                {
                                  //  Response.Write("<script>document.getElementById('loading').style.display='none';</script>");
                                    AdminiBalance();

                                    _objMasters = new clsMasters();

                                    _objMasters.ScreenInd = Masters.getrecharge3;
                                    _objMasters.Parameter = "update";
                                    _objMasters.RequestID = Session["Order_Id"].ToString();
                                    _objMasters.TransactionID = Convert.ToString(s[1].ToString());
                                    Session["TransactionID"] = Convert.ToString(s[1].ToString());

                                    _objMasters.Amount = Convert.ToDouble(balance);
                                    _objMasters.UserID = Convert.ToInt32(Session["UserID"]);
                                    _objMasters.Status = "Failure";
                                    Session["Status"] = "Recharge Failure";

                                    _objMasters.A_Amount = Convert.ToDecimal(Session["FinalAdminBalance"].ToString());

                                    _objMasters.IP = ipaddr;

                                    _objMasters.fnUpdateRecord();

                            Session["errorcode"] = s[0].ToString();
                            Session["errorDecsription"] = s[4].ToString();
                                    AddAmountoUserswhenRechargefailed();

                                    Response.Redirect("~/SuccessRecharge.aspx", false);
                                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "window.location = 'Masters/RechargeSucces.aspx';", true);

                                }
                            }

                       // }
                    //    else
                    //    {
                    //        Message.Text = strMessage.ToString();
                    //    }
                    //}
                }
            }
            else
            {
                //Mpe1.Show();
                //lblMessage.Text = "Recharge Has Been Failed Please Try Again Later";

            }
                        #endregion

        }

        catch (Exception ex)
        {
           // LogError("redirect.aspx", "UserDataCardRecharge", DateTime.Now, ex.Message.ToString());
        }
    }