-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayment.aspx.cs
159 lines (147 loc) · 6.77 KB
/
Payment.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace DC
{
public partial class Payment : System.Web.UI.Page
{
SqlConnection CONN = new SqlConnection(ConfigurationManager.AppSettings["webconn"]);
//SqlCommand CMD;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("SN");
dt.Columns.Add("VaccineName");
dt.Columns.Add("VaccinePrice");
dt.Columns.Add("VaccinationCharge");
if (Request.QueryString["id"] != null)
{
if (Session["Buyitems"] == null)
{
dr = dt.NewRow();
String mycon = "Data Source=DESKTOP-V7UTR4K;Initial Catalog = DataDictionary; Integrated Security = True";
SqlConnection scon = new SqlConnection(mycon);
String myquery = "select * from VaccineDetails where VaccineId=" + Request.QueryString["id"];
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = scon;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
// dr["SN"] = 1;
// dr["VaccineName"] = ds.Tables[0].Rows[0]["VaccineName"].ToString();
dr["VaccinationCharge"] = ds.Tables[0].Rows[0]["VaccinationCharge"].ToString();
dr["VaccinePrice"] = ds.Tables[0].Rows[0]["VaccinePrice"].ToString();
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
Session["buyitems"] = dt;
GridView1.FooterRow.Cells[5].Text = "Total Amount";
GridView1.FooterRow.Cells[6].Text = grandtotal().ToString();
Response.Redirect("WhenWhere.aspx");
}
else
{
dt = (DataTable)Session["buyitems"];
int sr;
sr = dt.Rows.Count;
dr = dt.NewRow();
String mycon = "Data Source=DESKTOP-V7UTR4K;Initial Catalog = DataDictionary; Integrated Security = True";
SqlConnection scon = new SqlConnection(mycon);
String myquery = "select * from VaccineDetails where VaccineId=" + Request.QueryString["id"];
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = scon;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
// dr["SN"] = 1;
// dr["VaccineName"] = ds.Tables[0].Rows[0]["VaccineName"].ToString();
dr["VaccinationCharge"] = ds.Tables[0].Rows[0]["VaccinationCharge"].ToString();
dr["VaccinePrice"] = ds.Tables[0].Rows[0]["VaccinePrice"].ToString();
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
Session["buyitems"] = dt;
GridView1.FooterRow.Cells[0].Text = "Total Amount";
GridView1.FooterRow.Cells[1].Text = grandtotal().ToString();
Response.Redirect("WhenWhere.aspx");
}
}
else
{
dt = (DataTable)Session["buyitems"];
GridView1.DataSource = dt;
GridView1.DataBind();
if (GridView1.Rows.Count > 0)
{
GridView1.FooterRow.Cells[0].Text = "Total Amount";
GridView1.FooterRow.Cells[1].Text = grandtotal().ToString();
}
}
}
Label4.Text = DateTime.Now.ToShortDateString();
findorderid();
}
public int grandtotal()
{
DataTable dt = new DataTable();
dt = (DataTable)Session["buyitems"];
int nrow = dt.Rows.Count;
int i = 0;
int gtotal = 0;
while (i < nrow)
{
gtotal = gtotal + Convert.ToInt32(dt.Rows[i]["VaccinePrice"].ToString())+ Convert.ToInt32(dt.Rows[i]["VaccinationCharge"].ToString());
i= i + 1;
}
return gtotal;
}
public void findorderid()
{
String pass = "abcdefghijklmnopqrstuvwxyz123456789";
Random r = new Random();
char[] mypass = new char[5];
for (int i = 0; i < 5; i++)
{
mypass[i] = pass[(int)(35 * r.NextDouble())];
}
String PaymentId;
PaymentId = "Payment" + DateTime.Now.Hour.ToString() +
DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() +
DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() +
DateTime.Now.Year.ToString() + new string(mypass);
Label3.Text = PaymentId;
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt;
dt = (DataTable)Session["buyitems"];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
String updatepass = "insert into PaymentDetails(PaymentId, TotalAmount, PaymentMode, PaymentDate) values('" + Label3.Text + "'," + GridView1.FooterRow.Cells[1].Text + ",'" + RadioButton1.Text + "','" + Label4.Text + "')";
String mycon1 = "Data Source=DESKTOP-V7UTR4K;Initial Catalog = DataDictionary; Integrated Security = True";
SqlConnection s = new SqlConnection(mycon1);
s.Open();
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = updatepass;
cmd1.Connection = s;
cmd1.ExecuteNonQuery();
s.Close();
}
Response.Redirect("Successfully.aspx");
}
}
}