rinku baruah

rinku baruah

  • NA
  • 32
  • 10.9k

how can i send sms when the ticket confirm in asp.net using#

Jul 3 2013 6:38 AM
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;
using System.IO;
using System.Net;

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"] == "mysite")
{
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='650' 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='650' border='0' cellspacing='0' cellpadding='0'> <tr> <td align='center'><table width='650' 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'>Call for Bus No.</td> <td align='left' class='ticket_font'>" + get_cn(MerchantRefNo) + "</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><center>Terms & Conditions </center></strong></td> </tr> <tr class='table1'> <td class='ticket'></td> </tr> <tr class='table1'> <td class='ticket_font'><strong>Address : </strong></td> </tr> <tr class='table1'> <td class='ticket'></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr></table></div>";
string to_mail = "<table width='650' border='1' cellspacing='0' cellpadding='0'> <tr> <td align='center'><table width='650' 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'>call For Bus No.</td> <td align='left' class='ticket_font'>" + get_cn(MerchantRefNo) + "</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><center>Terms & Conditions</center> </strong></td> </tr> <tr class='table1'> <td class='ticket'></td> </tr> <tr class='table1'> <td class='ticket_font'><strong>Address : </strong></td> </tr> <tr class='table1'> <td class='ticket'></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_cn(string pnr)
{
cmd = new SqlCommand("SELECT Bus_facility.facilities FROM Bus_facility INNER JOIN Orders ON Bus_facility.Bus_Ref = 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";
}
}
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";
}
}

}





Answers (1)