locked
how can i put code in LOAD_DATA.cs for send sms using c# RRS feed

  • Question

  • I am using the following code for for pay online and email sending; but how can i put code for sms sending.

    -----------------------------------------------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Net.Mail;

    /// <summary>
    /// Summary description for Load_data
    /// </summary>
    public class Load_data
    {
        public string pay_account_id = "0000";
        public string pay_return_url = "http://www.mydomain.com/pay/Response.aspx?DR={DR}";
        public string pay_mode = "LIVE";
        public string pay_url = "pay/pay_pay.aspx";
        public string home_page = "http://www.mydomain.com/default.aspx";
        public string admin_home_page = "http://www.mydomain.com/Admin";


        public Load_data()
        {
            
        }

        public void send_mail(string to,string message)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("abcd@mydomain.com");
            mail.To.Add(to);
            mail.Subject = "From NAME";
            mail.Body = message;
            mail.IsBodyHtml = true;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("ABCD@mydomain.com", "123456789");
            SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);

        }
       
    }
    -----------------------------------------------------------------------------------------------------------------------

    BELOW THE SMS SENDING CODE IN c#

    using System.IO;
    using System.Net;
    string connectionString = https2.freesmsapi.commessagessendskey=username+password&message=YOUR_MESSAGE&recipient=MOBILE_NUMBER;
    try
    {
            System.IO.Stream SourceStream = null;
            System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString);
            myRequest.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse webResponse = (HttpWebResponse)myRequest.GetResponse();
            SourceStream = webResponse.GetResponseStream();
            StreamReader reader = new StreamReader(webResponse.GetResponseStream());
            string str = reader.ReadLine();
            MessageBox.Show(str);
    }
    catch (Exception ex)
    {
           MessageBox.Show(ex.Message);
    }

    ----------------------------------------------------------------------------------------------------------------------

    MY EMAIL SENDING PAGE SOURCE CODE IS BELOW:

    -----------------------------------------------------------------------------------------------------------------------

    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.Configuration;

    public partial class Admin_Generate_Ticket : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
        SqlCommand cmd = null;
        SqlDataReader dr = null;
        string Status = null, ResponseMessage = null, DateCreatedPaymentID = null, MerchantRefNo = null, PaymentID = null, Amount = null, Mode = null, BillingName = null, BillingAddress = null, BillingCity = null, BillingState = null, BillingPostalCode = null, BillingPhone = null, BillingEmail = null, Description = null, IsFlagged = null, TransactionID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            Check c = new Check();
            c.check_admin_state();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            con.Open();
            if (!IsPostBack)
            {
                if (Request.Form["From"] == "NAME")
                {
                    get_all_details();
                    //insert_into_pg_details();
                    if (Status == "0")
                    {
                        success_stories();
                        show_ticket();
                    }
                    else
                    {
                        failure_stories();
                    }
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('Invalid Request'); </script>");
                    Load_data l = new Load_data();
                    Response.Redirect(l.admin_home_page);
                }
            }
        }


        protected void insert_into_pg_details()
        {
            try
            {
                cmd = new SqlCommand("insert_into_pg_details", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add("Status", System.Data.SqlDbType.Int).Value = Convert.ToInt16(Status);
                cmd.Parameters.Add("MerchantRefNo", System.Data.SqlDbType.BigInt).Value = Convert.ToInt64(MerchantRefNo);
                cmd.Parameters.Add("Amount", System.Data.SqlDbType.Money).Value = Convert.ToDouble(Amount);
                cmd.Parameters.Add("Description", System.Data.SqlDbType.NVarChar).Value = Description;
                cmd.Parameters.Add("BillingName", System.Data.SqlDbType.NVarChar).Value = BillingName;
                cmd.Parameters.Add("BillingAddress", System.Data.SqlDbType.NVarChar).Value = BillingAddress;
                cmd.Parameters.Add("BillingCity", System.Data.SqlDbType.NVarChar).Value = BillingCity;
                cmd.Parameters.Add("BillingState", System.Data.SqlDbType.NVarChar).Value = BillingState;
                cmd.Parameters.Add("BillingPostalCode", System.Data.SqlDbType.NVarChar).Value = BillingPostalCode;
                cmd.Parameters.Add("BillingEmail", System.Data.SqlDbType.NVarChar).Value = BillingEmail;
                cmd.Parameters.Add("BillingPhone", System.Data.SqlDbType.NVarChar).Value = BillingPhone;
                cmd.Parameters.Add("PaymentID", System.Data.SqlDbType.Int).Value = Convert.ToInt64(PaymentID);
                cmd.Parameters.Add("IsFlagged", System.Data.SqlDbType.VarChar).Value = IsFlagged;
                cmd.Parameters.Add("TransactionID", System.Data.SqlDbType.NVarChar).Value = TransactionID;
                cmd.ExecuteNonQuery();
                //Response.Write("<script type='text/javascript'>alert('Inserted'); </script>");

            }
            catch (SqlException sqlex)
            {
                Response.Write("<script type='text/javascript'>alert('Some Sql Exeception'); </script>");
            }
            catch (Exception ex)
            {
                Response.Write("<script type='text/javascript'>alert('Some Exeception'); </script>");
            }
        }

        protected void get_all_details()
        {
            Status = Request.Form["Status"];
            MerchantRefNo = Request.Form["reference_no"];
            /*Amount = Request.Form["amount"];
            Description = Request.Form["description"];
            BillingName = Request.Form["name"];
            BillingAddress = Request.Form["address"];
            BillingCity = Request.Form["city"];
            BillingState = Request.Form["state"];
            BillingPostalCode = Request.Form["postal_code"];
            BillingEmail = Request.Form["email"];
            BillingPhone = Request.Form["phone"];
            PaymentID = Request.Form["PaymentID"];
            IsFlagged = Request.Form["IsFlagged"];
            TransactionID = Request.Form["TransactionID"];*/
            //Label1.Text = Status +        MerchantRefNo +        Amount +        Description +        BillingName +        BillingAddress +        BillingCity +        BillingState +        BillingPostalCode +        BillingEmail +        BillingPhone +        PaymentID +        IsFlagged +        TransactionID;

        }


        protected void success_stories()
        {
            cmd = new SqlCommand("update orderdetails set flag='1' where pnr='" + MerchantRefNo + "'", con);
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            cmd = new SqlCommand("select Seat,BusDetail from orders where Pnr='" + MerchantRefNo + "'", con);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                SqlCommand cmd1 = new SqlCommand("update_seats", con);
                cmd1.CommandType = System.Data.CommandType.StoredProcedure;
                cmd1.Parameters.Add("@seat", System.Data.SqlDbType.VarChar).Value = dr[0].ToString();
                cmd1.Parameters.Add("@bus", System.Data.SqlDbType.VarChar).Value = dr[1].ToString();
                cmd1.ExecuteNonQuery();
                cmd1.Dispose();
            }
        }

        protected void show_ticket()
        {
            string seats = null;
            SqlCommand select_seat = new SqlCommand("select seat from orders where pnr='" + MerchantRefNo + "'", con);
            SqlDataReader select_seat_dr = select_seat.ExecuteReader();

            while (select_seat_dr.Read())
            {
                seats += select_seat_dr[0].ToString() + ",";
            }
            cmd = new SqlCommand("select Pnr,Bookdate,StartPlace,Destination,CONVERT(VARCHAR(8),Departurtime,108),CONVERT(VARCHAR(8),ArrivalTime,108),Passangername,ContactNo,PassangerAddress,Emailid from orders where pnr='" + MerchantRefNo + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                string pnr = dr[0].ToString();
                string bdate = dr[1].ToString();
                string start = dr[2].ToString();
                string dest = dr[3].ToString();
                string start_time = dr[4].ToString();
                string reach_time = dr[5].ToString();
                string name = dr[6].ToString();
                string contact = dr[7].ToString();
                string address = dr[8].ToString();
                string email = dr[9].ToString();

                Label1.Text = "<table width='600'  border='0' cellspacing='0' cellpadding='0'>  <tr>        <td align='right'><a href='#' onClick='PrintDiv();'>Print Ticket</a></td>      </tr></table><div id='divToPrint' ><table width='600'  border='0' cellspacing='0' cellpadding='0'>  <tr>    <td align='center'><table width='600'  border='0' cellpadding='4' cellspacing='0''>      <tr>        <td align='center' class='ticket_font'><strong>Congratulation....!!! You have Sucessfully Booked the Ticket </strong></td>      </tr>               <tr>        <td><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='table1'>          <tr>            <td width='25%' align='right' class='ticket_font'>PNR No : </td>            <td width='25%' align='left' class='ticket_font'>" + dr[0].ToString() + "</td>            <td width='25%' align='right' class='ticket_font'>Booked Date : </td>            <td width='25%' align='left' class='ticket_font'>" + dr[1].ToString() + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Starting Point : </td>            <td align='left' class='ticket_font'>" + dr[2].ToString() + "</td>            <td align='right' class='ticket_font'>Destination</td>            <td align='left' class='ticket_font'>" + dr[3].ToString() + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Boarding Date/Time : </td>            <td align='left' class='ticket_font'>" + dr[4].ToString() + " </td>            <td align='right' class='ticket_font'>Reach Date/Time : </td>            <td align='left' class='ticket_font'>" + dr[5].ToString() + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Name : </td>            <td align='left' class='ticket_font'>" + dr[6].ToString() + "</td>            <td align='right' class='ticket_font'>Mobile No: </td>            <td align='left' class='ticket_font'>" + dr[7].ToString() + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Address : </td>            <td align='left' class='ticket_font'>" + dr[8].ToString() + "</td>            <td align='right' class='ticket_font'>Seats :</td>            <td align='left' class='ticket_font'>" + seats + "</td>          </tr>        <tr>    <td align='right' class='ticket_font'>Boarding Point : </td>    <td align='left' class='ticket_font'>" + get_bp(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>Journey Date : </td>    <td align='left' class='ticket_font'>" + get_jd(MerchantRefNo) + "</td>  </tr>  <tr>    <td align='right' class='ticket_font'>Fare : </td>    <td align='left' class='ticket_font'>" + get_fare(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>&nbsp;</td>    <td align='left' class='ticket_font'>&nbsp;</td>  </tr>             <tr align='center'>            <td colspan='4'><table width='100%'  border='0' cellspacing='0' cellpadding='4'>              <tr class='table1'>                <td class='ticket_font'><strong>Terms &amp; Conditions </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>JGJGJKFVJAGFJVFKJVSADJ MGIGAKSBFK JGI AFIGHI AFIOHBFLKHOBF.</td>              </tr>              <tr class='table1'>                <td class='ticket_font'><strong>Address : </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>Address Comes Here</td>              </tr>            </table></td>            </tr>        </table></td>      </tr>    </table></td>  </tr></table></div>";
                string to_mail = "<table width='600'  border='1' cellspacing='0' cellpadding='0'>  <tr>    <td align='center'><table width='600'  border='0' cellpadding='4' cellspacing='0''>      <tr>        <td align='center' class='ticket_font'><strong>Congratulation....!!! You have Suceesfully Booked the Ticket </strong></td>      </tr>               <tr>        <td><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='table1'>          ";
                to_mail += "<tr> <td width='25%' align='right' class='ticket_font'>PNR No : </td>            <td width='25%' align='left' class='ticket_font'>" + pnr + "</td>            <td width='25%' align='right' class='ticket_font'>Booked Date : </td> ";
                to_mail += "<td width='25%' align='left' class='ticket_font'>" + bdate + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Starting Point : </td>    ";
                to_mail += "<td align='left' class='ticket_font'>" + start + "</td>            <td align='right' class='ticket_font'>Destination</td>        ";
                to_mail += "<td align='left' class='ticket_font'>" + dest + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Boarding Date/Time : </td>  ";
                to_mail += "<td align='left' class='ticket_font'>" + start_time + " </td>            <td align='right' class='ticket_font'>Reach Date/Time : </td>    ";
                to_mail += "<td align='left' class='ticket_font'>" + reach_time + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Name : </td> ";
                to_mail += "<td align='left' class='ticket_font'>" + name + "</td>          ";
                to_mail += "<td align='right' class='ticket_font'>Mobile No: </td>            <td align='left' class='ticket_font'>" + contact + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Address : </td>          ";
                to_mail += "<td align='left' class='ticket_font'>" + address + "</td>            <td align='right' class='ticket_font'>Seats :</td>            <td align='left' class='ticket_font'>" + seats + "</td>          </tr>        <tr>    <td align='right' class='ticket_font'>Boarding Point : </td>    <td align='left' class='ticket_font'>" + get_bp(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>Journey Date : </td>    <td align='left' class='ticket_font'>" + get_jd(MerchantRefNo) + "</td>  </tr>  <tr>    <td align='right' class='ticket_font'>Fare : </td>    <td align='left' class='ticket_font'>" + get_fare(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>&nbsp;</td>    <td align='left' class='ticket_font'>&nbsp;</td>  </tr>             <tr align='center'>            <td colspan='4'><table width='100%'  border='0' cellspacing='0' cellpadding='4'>              <tr class='table1'>                <td class='ticket_font'><strong>Terms &amp; Conditions </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>GJGJFGSAUI GIGAIDF GIGAI DFSHO AFYAOIFHASOIFY OASFY 9AF HGAIOFYAO FOAFYOA OASYF9AD Y98 FAOAYD9 AY</td>              </tr>              <tr class='table1'>                <td class='ticket_font'><strong>Address : </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>Please see contact us </td>              </tr>            </table></td>            </tr>        </table></td>      </tr>    </table></td>  </tr></table>";

                try
                {
                    Load_data l = new Load_data();
                    l.send_mail(email, to_mail);
                }
                catch (Exception ex)
                {
                   // Response.Write("<script type='text/javascript'>alert('There is some Error in Sending the ticket to mail'); </script>");

                }


            }
        }


        protected void failure_stories()
        {
            cmd = new SqlCommand("rollback_on_failure", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("pnr", System.Data.SqlDbType.NVarChar).Value = MerchantRefNo;
            cmd.ExecuteNonQuery();
            Label1.Text = "<div id='printMe'><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='ticket_font' style='border:2px solid #F95C6B'>  <tr>    <td align='center' bgcolor='#F9C8CD'><strong>Sorry...... Your Payment Was Failed </strong></td>  </tr></table></div>";

        }


        protected string get_fare(string pnr)
        {
            cmd = new SqlCommand("select TotalAmount from OrderDetails where Pnr='" + pnr + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }


        protected string get_bp(string pnr)
        {
            cmd = new SqlCommand("select distinct(BoardingPoint) from orders  where Pnr='" + pnr + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }

        protected string get_jd(string pnr)
        {
            cmd = new SqlCommand("SELECT     CONVERT(VARCHAR(10),Bus_Detail.Journey_Date,111) FROM         Bus_Detail INNER JOIN                       Orders ON Bus_Detail.Bus_Sno = Orders.BusDetail where Orders.Pnr =(select distinct(Pnr) from orders   where Pnr='" + pnr + "')", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }
    }
    ---------------------------------------------------------------------------------------------------------------------------

    PLEASE HELP ME FOR BUILD THIS CODE.

    • Changed type Rinku Baruah Tuesday, December 18, 2012 10:10 AM
    • Changed type Rinku Baruah Tuesday, December 18, 2012 10:10 AM
    • Changed type Rinku Baruah Thursday, January 3, 2013 11:08 AM
    Tuesday, December 18, 2012 8:38 AM

All replies

  • I am using the following code for for pay online and email sending; but how can i put code for sms sending.

    -----------------------------------------------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Net.Mail;

    /// <summary>
    /// Summary description for Load_data
    /// </summary>
    public class Load_data
    {
        public string pay_account_id = "0000";
        public string pay_return_url = "http://www.mydomain.com/pay/Response.aspx?DR={DR}";
        public string pay_mode = "LIVE";
        public string pay_url = "pay/pay_pay.aspx";
        public string home_page = "http://www.mydomain.com/default.aspx";
        public string admin_home_page = "http://www.mydomain.com/Admin";


        public Load_data()
        {
            
        }

        public void send_mail(string to,string message)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("abcd@mydomain.com");
            mail.To.Add(to);
            mail.Subject = "From NAME";
            mail.Body = message;
            mail.IsBodyHtml = true;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("ABCD@mydomain.com", "123456789");
            SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);

        }
       
    }
    -----------------------------------------------------------------------------------------------------------------------

    BELOW THE SMS SENDING CODE IN c#

    using System.IO;
    using System.Net;
    string connectionString = https2.freesmsapi.commessagessendskey=username+password&message=YOUR_MESSAGE&recipient=MOBILE_NUMBER;
    try
    {
            System.IO.Stream SourceStream = null;
            System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString);
            myRequest.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse webResponse = (HttpWebResponse)myRequest.GetResponse();
            SourceStream = webResponse.GetResponseStream();
            StreamReader reader = new StreamReader(webResponse.GetResponseStream());
            string str = reader.ReadLine();
            MessageBox.Show(str);
    }
    catch (Exception ex)
    {
           MessageBox.Show(ex.Message);
    }

    ----------------------------------------------------------------------------------------------------------------------

    MY EMAIL SENDING PAGE SOURCE CODE IS BELOW:

    -----------------------------------------------------------------------------------------------------------------------

    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.Configuration;

    public partial class Admin_Generate_Ticket : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
        SqlCommand cmd = null;
        SqlDataReader dr = null;
        string Status = null, ResponseMessage = null, DateCreatedPaymentID = null, MerchantRefNo = null, PaymentID = null, Amount = null, Mode = null, BillingName = null, BillingAddress = null, BillingCity = null, BillingState = null, BillingPostalCode = null, BillingPhone = null, BillingEmail = null, Description = null, IsFlagged = null, TransactionID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            Check c = new Check();
            c.check_admin_state();
            if (con.State == System.Data.ConnectionState.Open)
            {
                con.Close();
            }
            con.Open();
            if (!IsPostBack)
            {
                if (Request.Form["From"] == "NAME")
                {
                    get_all_details();
                    //insert_into_pg_details();
                    if (Status == "0")
                    {
                        success_stories();
                        show_ticket();
                    }
                    else
                    {
                        failure_stories();
                    }
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('Invalid Request'); </script>");
                    Load_data l = new Load_data();
                    Response.Redirect(l.admin_home_page);
                }
            }
        }


        protected void insert_into_pg_details()
        {
            try
            {
                cmd = new SqlCommand("insert_into_pg_details", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add("Status", System.Data.SqlDbType.Int).Value = Convert.ToInt16(Status);
                cmd.Parameters.Add("MerchantRefNo", System.Data.SqlDbType.BigInt).Value = Convert.ToInt64(MerchantRefNo);
                cmd.Parameters.Add("Amount", System.Data.SqlDbType.Money).Value = Convert.ToDouble(Amount);
                cmd.Parameters.Add("Description", System.Data.SqlDbType.NVarChar).Value = Description;
                cmd.Parameters.Add("BillingName", System.Data.SqlDbType.NVarChar).Value = BillingName;
                cmd.Parameters.Add("BillingAddress", System.Data.SqlDbType.NVarChar).Value = BillingAddress;
                cmd.Parameters.Add("BillingCity", System.Data.SqlDbType.NVarChar).Value = BillingCity;
                cmd.Parameters.Add("BillingState", System.Data.SqlDbType.NVarChar).Value = BillingState;
                cmd.Parameters.Add("BillingPostalCode", System.Data.SqlDbType.NVarChar).Value = BillingPostalCode;
                cmd.Parameters.Add("BillingEmail", System.Data.SqlDbType.NVarChar).Value = BillingEmail;
                cmd.Parameters.Add("BillingPhone", System.Data.SqlDbType.NVarChar).Value = BillingPhone;
                cmd.Parameters.Add("PaymentID", System.Data.SqlDbType.Int).Value = Convert.ToInt64(PaymentID);
                cmd.Parameters.Add("IsFlagged", System.Data.SqlDbType.VarChar).Value = IsFlagged;
                cmd.Parameters.Add("TransactionID", System.Data.SqlDbType.NVarChar).Value = TransactionID;
                cmd.ExecuteNonQuery();
                //Response.Write("<script type='text/javascript'>alert('Inserted'); </script>");

            }
            catch (SqlException sqlex)
            {
                Response.Write("<script type='text/javascript'>alert('Some Sql Exeception'); </script>");
            }
            catch (Exception ex)
            {
                Response.Write("<script type='text/javascript'>alert('Some Exeception'); </script>");
            }
        }

        protected void get_all_details()
        {
            Status = Request.Form["Status"];
            MerchantRefNo = Request.Form["reference_no"];
            /*Amount = Request.Form["amount"];
            Description = Request.Form["description"];
            BillingName = Request.Form["name"];
            BillingAddress = Request.Form["address"];
            BillingCity = Request.Form["city"];
            BillingState = Request.Form["state"];
            BillingPostalCode = Request.Form["postal_code"];
            BillingEmail = Request.Form["email"];
            BillingPhone = Request.Form["phone"];
            PaymentID = Request.Form["PaymentID"];
            IsFlagged = Request.Form["IsFlagged"];
            TransactionID = Request.Form["TransactionID"];*/
            //Label1.Text = Status +        MerchantRefNo +        Amount +        Description +        BillingName +        BillingAddress +        BillingCity +        BillingState +        BillingPostalCode +        BillingEmail +        BillingPhone +        PaymentID +        IsFlagged +        TransactionID;

        }


        protected void success_stories()
        {
            cmd = new SqlCommand("update orderdetails set flag='1' where pnr='" + MerchantRefNo + "'", con);
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            cmd = new SqlCommand("select Seat,BusDetail from orders where Pnr='" + MerchantRefNo + "'", con);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                SqlCommand cmd1 = new SqlCommand("update_seats", con);
                cmd1.CommandType = System.Data.CommandType.StoredProcedure;
                cmd1.Parameters.Add("@seat", System.Data.SqlDbType.VarChar).Value = dr[0].ToString();
                cmd1.Parameters.Add("@bus", System.Data.SqlDbType.VarChar).Value = dr[1].ToString();
                cmd1.ExecuteNonQuery();
                cmd1.Dispose();
            }
        }

        protected void show_ticket()
        {
            string seats = null;
            SqlCommand select_seat = new SqlCommand("select seat from orders where pnr='" + MerchantRefNo + "'", con);
            SqlDataReader select_seat_dr = select_seat.ExecuteReader();

            while (select_seat_dr.Read())
            {
                seats += select_seat_dr[0].ToString() + ",";
            }
            cmd = new SqlCommand("select Pnr,Bookdate,StartPlace,Destination,CONVERT(VARCHAR(8),Departurtime,108),CONVERT(VARCHAR(8),ArrivalTime,108),Passangername,ContactNo,PassangerAddress,Emailid from orders where pnr='" + MerchantRefNo + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                string pnr = dr[0].ToString();
                string bdate = dr[1].ToString();
                string start = dr[2].ToString();
                string dest = dr[3].ToString();
                string start_time = dr[4].ToString();
                string reach_time = dr[5].ToString();
                string name = dr[6].ToString();
                string contact = dr[7].ToString();
                string address = dr[8].ToString();
                string email = dr[9].ToString();

                Label1.Text = "<table width='600'  border='0' cellspacing='0' cellpadding='0'>  <tr>        <td align='right'><a href='#' onClick='PrintDiv();'>Print Ticket</a></td>      </tr></table><div id='divToPrint' ><table width='600'  border='0' cellspacing='0' cellpadding='0'>  <tr>    <td align='center'><table width='600'  border='0' cellpadding='4' cellspacing='0''>      <tr>        <td align='center' class='ticket_font'><strong>Congratulation....!!! You have Sucessfully Booked the Ticket </strong></td>      </tr>               <tr>        <td><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='table1'>          <tr>            <td width='25%' align='right' class='ticket_font'>PNR No : </td>            <td width='25%' align='left' class='ticket_font'>" + dr[0].ToString() + "</td>            <td width='25%' align='right' class='ticket_font'>Booked Date : </td>            <td width='25%' align='left' class='ticket_font'>" + dr[1].ToString() + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Starting Point : </td>            <td align='left' class='ticket_font'>" + dr[2].ToString() + "</td>            <td align='right' class='ticket_font'>Destination</td>            <td align='left' class='ticket_font'>" + dr[3].ToString() + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Boarding Date/Time : </td>            <td align='left' class='ticket_font'>" + dr[4].ToString() + " </td>            <td align='right' class='ticket_font'>Reach Date/Time : </td>            <td align='left' class='ticket_font'>" + dr[5].ToString() + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Name : </td>            <td align='left' class='ticket_font'>" + dr[6].ToString() + "</td>            <td align='right' class='ticket_font'>Mobile No: </td>            <td align='left' class='ticket_font'>" + dr[7].ToString() + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Address : </td>            <td align='left' class='ticket_font'>" + dr[8].ToString() + "</td>            <td align='right' class='ticket_font'>Seats :</td>            <td align='left' class='ticket_font'>" + seats + "</td>          </tr>        <tr>    <td align='right' class='ticket_font'>Boarding Point : </td>    <td align='left' class='ticket_font'>" + get_bp(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>Journey Date : </td>    <td align='left' class='ticket_font'>" + get_jd(MerchantRefNo) + "</td>  </tr>  <tr>    <td align='right' class='ticket_font'>Fare : </td>    <td align='left' class='ticket_font'>" + get_fare(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>&nbsp;</td>    <td align='left' class='ticket_font'>&nbsp;</td>  </tr>             <tr align='center'>            <td colspan='4'><table width='100%'  border='0' cellspacing='0' cellpadding='4'>              <tr class='table1'>                <td class='ticket_font'><strong>Terms &amp; Conditions </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>JGJGJKFVJAGFJVFKJVSADJ MGIGAKSBFK JGI AFIGHI AFIOHBFLKHOBF.</td>              </tr>              <tr class='table1'>                <td class='ticket_font'><strong>Address : </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>Address Comes Here</td>              </tr>            </table></td>            </tr>        </table></td>      </tr>    </table></td>  </tr></table></div>";
                string to_mail = "<table width='600'  border='1' cellspacing='0' cellpadding='0'>  <tr>    <td align='center'><table width='600'  border='0' cellpadding='4' cellspacing='0''>      <tr>        <td align='center' class='ticket_font'><strong>Congratulation....!!! You have Suceesfully Booked the Ticket </strong></td>      </tr>               <tr>        <td><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='table1'>          ";
                to_mail += "<tr> <td width='25%' align='right' class='ticket_font'>PNR No : </td>            <td width='25%' align='left' class='ticket_font'>" + pnr + "</td>            <td width='25%' align='right' class='ticket_font'>Booked Date : </td> ";
                to_mail += "<td width='25%' align='left' class='ticket_font'>" + bdate + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Starting Point : </td>    ";
                to_mail += "<td align='left' class='ticket_font'>" + start + "</td>            <td align='right' class='ticket_font'>Destination</td>        ";
                to_mail += "<td align='left' class='ticket_font'>" + dest + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Boarding Date/Time : </td>  ";
                to_mail += "<td align='left' class='ticket_font'>" + start_time + " </td>            <td align='right' class='ticket_font'>Reach Date/Time : </td>    ";
                to_mail += "<td align='left' class='ticket_font'>" + reach_time + " </td>          </tr>          <tr>            <td align='right' class='ticket_font'>Name : </td> ";
                to_mail += "<td align='left' class='ticket_font'>" + name + "</td>          ";
                to_mail += "<td align='right' class='ticket_font'>Mobile No: </td>            <td align='left' class='ticket_font'>" + contact + "</td>          </tr>          <tr>            <td align='right' class='ticket_font'>Address : </td>          ";
                to_mail += "<td align='left' class='ticket_font'>" + address + "</td>            <td align='right' class='ticket_font'>Seats :</td>            <td align='left' class='ticket_font'>" + seats + "</td>          </tr>        <tr>    <td align='right' class='ticket_font'>Boarding Point : </td>    <td align='left' class='ticket_font'>" + get_bp(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>Journey Date : </td>    <td align='left' class='ticket_font'>" + get_jd(MerchantRefNo) + "</td>  </tr>  <tr>    <td align='right' class='ticket_font'>Fare : </td>    <td align='left' class='ticket_font'>" + get_fare(MerchantRefNo) + "</td>    <td align='right' class='ticket_font'>&nbsp;</td>    <td align='left' class='ticket_font'>&nbsp;</td>  </tr>             <tr align='center'>            <td colspan='4'><table width='100%'  border='0' cellspacing='0' cellpadding='4'>              <tr class='table1'>                <td class='ticket_font'><strong>Terms &amp; Conditions </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>GJGJFGSAUI GIGAIDF GIGAI DFSHO AFYAOIFHASOIFY OASFY 9AF HGAIOFYAO FOAFYOA OASYF9AD Y98 FAOAYD9 AY</td>              </tr>              <tr class='table1'>                <td class='ticket_font'><strong>Address : </strong></td>              </tr>              <tr class='table1'>                <td class='ticket_font'>Please see contact us </td>              </tr>            </table></td>            </tr>        </table></td>      </tr>    </table></td>  </tr></table>";

                try
                {
                    Load_data l = new Load_data();
                    l.send_mail(email, to_mail);
                }
                catch (Exception ex)
                {
                   // Response.Write("<script type='text/javascript'>alert('There is some Error in Sending the ticket to mail'); </script>");

                }


            }
        }


        protected void failure_stories()
        {
            cmd = new SqlCommand("rollback_on_failure", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("pnr", System.Data.SqlDbType.NVarChar).Value = MerchantRefNo;
            cmd.ExecuteNonQuery();
            Label1.Text = "<div id='printMe'><table width='100%'  border='0' cellpadding='4' cellspacing='0' class='ticket_font' style='border:2px solid #F95C6B'>  <tr>    <td align='center' bgcolor='#F9C8CD'><strong>Sorry...... Your Payment Was Failed </strong></td>  </tr></table></div>";

        }


        protected string get_fare(string pnr)
        {
            cmd = new SqlCommand("select TotalAmount from OrderDetails where Pnr='" + pnr + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }


        protected string get_bp(string pnr)
        {
            cmd = new SqlCommand("select distinct(BoardingPoint) from orders  where Pnr='" + pnr + "'", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }

        protected string get_jd(string pnr)
        {
            cmd = new SqlCommand("SELECT     CONVERT(VARCHAR(10),Bus_Detail.Journey_Date,111) FROM         Bus_Detail INNER JOIN                       Orders ON Bus_Detail.Bus_Sno = Orders.BusDetail where Orders.Pnr =(select distinct(Pnr) from orders   where Pnr='" + pnr + "')", con);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                return dr[0].ToString();
            }
            else
            {
                return "Error";
            }
        }
    }
    ---------------------------------------------------------------------------------------------------------------------------

    PLEASE HELP ME FOR BUILD THIS CODE.


    Tuesday, December 18, 2012 10:12 AM