-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checkout_Order.aspx.cs
executable file
·306 lines (275 loc) · 10.3 KB
/
Checkout_Order.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Checkout_Order : System.Web.UI.Page
{
Clsconnection cls = new Clsconnection();
clsAddToCart clsCart;
BillingShippingDetails clsBSD;
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Session["MemberInfo"] != null)
{
if (HttpContext.Current.Session["Cart"] != null)
{
clsCart = new clsAddToCart();
if (clsCart.TotalItems() <= 0)
{
Response.Redirect("Checkout_Login.aspx");
}
}
if (!IsPostBack)
{
BindCart();
BindFinalAmt();
BindOrderSummary();
BindShippingSummary();
setCoupoCodePanel();
}
}
else
{
HttpContext.Current.Session["CameFrom"] = "CheckOut_Login";
Response.Redirect("Checkout_Login.aspx");
}
}
protected void BindCart()
{
clsCart = new clsAddToCart();
rptrCart.DataSource = clsCart.BindCart();
rptrCart.DataBind();
}
protected void BindShippingSummary()
{
clsBSD = new BillingShippingDetails();
rptShipping.DataSource = clsBSD.BindBillShip();
rptShipping.DataBind();
}
protected void BindFinalAmt()
{
//double ftotal = 0;
//foreach (RepeaterItem rptitem in dlMail.Items)
//{
// Label lblamt = (Label)rptitem.FindControl("lblfprice");
// ftotal = ftotal + Convert.ToDouble(lblamt.Text);
//}
Control footer = rptrCart.Controls[rptrCart.Controls.Count - 1].Controls[0];
Label lblFinalTotal = (Label)footer.FindControl("lblFinalTotal");
clsCart = new clsAddToCart();
lblFinalTotal.Text = Math.Round(clsCart.TotalPriceWithoutDiscount()).ToString();
}
protected void BindTopCartItems()
{
Label lblTopNoItems = (Label)this.Page.Master.FindControl("lblTopNoItems");
Label lblTopTotal = (Label)this.Page.Master.FindControl("lblTopTotal");
if (Session["Cart"] != null)
{
clsCart = new clsAddToCart();
lblTopNoItems.Text = clsCart.TotalItems().ToString();
if (clsCart.TotalItems() != 0)
{
lblTopTotal.Text = Math.Round(clsCart.TotalPrice()).ToString();
}
else
{
lblTopTotal.Text = "0";
}
}
else
{
lblTopNoItems.Text = "0";
lblTopTotal.Text = "0";
}
}
protected void rptrCart_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string ProductId = e.CommandArgument.ToString();
Label lblProPrice = (Label)e.Item.FindControl("lblProPrice");
TextBox txtQty = (TextBox)e.Item.FindControl("txtQty");
Label lblSize = (Label)e.Item.FindControl("lblSize");
Label lblColor = (Label)e.Item.FindControl("lblColor");
Control footer = rptrCart.Controls[rptrCart.Controls.Count - 1].Controls[0];
TextBox txtCoupon = (TextBox)footer.FindControl("txtCoupon");
string amount;
amount = ValidateCoupon(txtCoupon.Text.Trim());
if (e.CommandName == "UpdateCart")
{
if (amount == "") // coupon code not applicable
{
RemoveDiscountSession();
}
clsCart = new clsAddToCart();
clsCart.SetQtyAndPriceWithSizeColor(ProductId, Convert.ToDouble(txtQty.Text), Convert.ToDouble(lblProPrice.Text), lblSize.Text, lblColor.Text);
//BindCart();
//setCoupoCodePanel();
}
else if (e.CommandName == "Remove")
{
if (amount == "") // coupon code not applicable
{
RemoveDiscountSession();
}
clsCart = new clsAddToCart();
clsCart.RemoveItem(e.Item.ItemIndex);
// BindCart();
// setCoupoCodePanel();
}
else if (e.CommandName == "Coupon")
{
if (amount != "")//coupon code applicable
{
Session["Discount"] = Convert.ToDouble(amount);
Session["CouponCode"] = txtCoupon.Text;
}
else
{
MsgBox("Coupon not Applicable");
return;
}
}
BindCart();
BindFinalAmt();
BindTopCartItems();
BindOrderSummary();
setCoupoCodePanel();
}
protected void btnContinue_Click(object sender, EventArgs e)
{
Response.Redirect("Checkout_Payment.aspx");
}
protected void BindOrderSummary()
{
clsCart = new clsAddToCart();
lblTotalItems.Text = clsCart.TotalItems().ToString();
lblTotalAmount.Text = "Rs. " + Math.Round(clsCart.TotalPrice()).ToString();
}
protected void lnkChange_OnClick(object sender, EventArgs e)
{
Session["CameAgain"] = "1";
Response.Redirect("Checkout_Shipping.aspx");
}
protected void setCoupoCodePanel()
{
if (Session["Discount"] != null)
{
Control footer = rptrCart.Controls[rptrCart.Controls.Count - 1].Controls[0];
Panel pnlCoupon = (Panel)footer.FindControl("pnlCoupon");
pnlCoupon.Visible = false;
Panel pnlCouponapplied = (Panel)footer.FindControl("pnlCouponapplied");
pnlCouponapplied.Visible = true;
Label lblGrandTotal = (Label)footer.FindControl("lblGrandTotal");
Label lblDiscount = (Label)footer.FindControl("lblDiscount");
Label lblDiscountPer = (Label)footer.FindControl("lblDiscountPer");
Label lblCoupon = (Label)footer.FindControl("lblCoupon");
Label lblFinalTotal = (Label)footer.FindControl("lblFinalTotal");
clsCart = new clsAddToCart();
lblGrandTotal.Text = Math.Round(clsCart.TotalPrice()).ToString();
lblCoupon.Text = Session["CouponCode"].ToString();
lblDiscount.Text = Math.Round((Convert.ToDouble(lblFinalTotal.Text) - Convert.ToDouble(lblGrandTotal.Text))).ToString();
lblDiscountPer.Text = "(" + Session["Discount"].ToString() + "%) Discount";
Session["DiscountValue"] = Convert.ToDouble(lblDiscount.Text);
}
else
{
Control footer = rptrCart.Controls[rptrCart.Controls.Count - 1].Controls[0];
Panel pnlCoupon = (Panel)footer.FindControl("pnlCoupon");
pnlCoupon.Visible = true;
Panel pnlCouponapplied = (Panel)footer.FindControl("pnlCouponapplied");
pnlCouponapplied.Visible = false;
}
}
protected void RemoveDiscountSession()
{
Session["Discount"] = null;
Session["CouponCode"] = null;
}
//protected int checkCoupon(string CouponName)
//{
// int flag = 1;
// int a, b, c;
// if (Session["MemberInfo"] != null)
// {
// a = 1;
// DataTable dtUser;
// dtUser = new DataTable();
// dtUser = (DataTable)Session["MemberInfo"];
// if (dtUser.Rows[0]["memberId"].ToString() == "0")
// {
// a = 2;
// }
// }
// else
// {
// a = 2;
// }
// clsBSD = new BillingShippingDetails();
// DataTable dtbilship1 = new DataTable();
// dtbilship1 = clsBSD.BindBillShip();
// if (cls.CheckExistField("CheckExistField", "InvoiceBillingShipping", "ColourName", txtcolourname.Text, "and IsActive = 1"))
// {
// }
// DataTable dt = new DataTable();
// dt = cls.ReturnDataTable("Select_CouponOnName", new SqlParameter("@CouponName", CouponName));
// if (dt.Rows.Count > 0)
// {
// }
// else
// {
// flag = 2; // coupon not exist
// }
// return flag;
//}
protected string ValidateCoupon(string CouponName)
{
string amount = "";
int memberid;
double orderval;
string email;
string couponname;
if (Session["MemberInfo"] != null)
{
DataTable dtUser;
dtUser = new DataTable();
dtUser = (DataTable)Session["MemberInfo"];
memberid = Convert.ToInt32(dtUser.Rows[0]["memberId"].ToString()); // set memberid
}
else
{
memberid = 0;
}
clsCart = new clsAddToCart();
orderval = clsCart.TotalPriceWithoutDiscount(); // set ordervalue
clsBSD = new BillingShippingDetails();
DataTable dtbilship1 = new DataTable();
dtbilship1 = clsBSD.BindBillShip();
email = dtbilship1.Rows[0]["SEmail"].ToString(); // set email
couponname = CouponName; // set couponname
amount = cls.ReturnScalerObject("GetDiscountOnCoupon", new SqlParameter("@CouponName", couponname), new SqlParameter("@MemberId", memberid), new SqlParameter("@Email", email), new SqlParameter("@OrderValue", orderval)).ToString();
return amount;
}
public void MsgBox(string message)
{
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
message = message.Replace("'", "'");
ScriptManager.RegisterStartupScript(page, page.GetType(), "MessageThenRedirect", "alert('" + message + "')", true);
}
}
public void ShowMessageThenRedirectTo(string message, string pageName)
{
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
message = message.Replace("'", "\'");
ScriptManager.RegisterStartupScript(page, page.GetType(),
"MessageThenRedirect", "alert('" + message +
"');window.location='" + pageName + ".aspx';", true);
}
}
}