comparison Demo/Asp.Net/Web/CheckOut.aspx.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Web.UI.WebControls;
3
4 using PetShop.BusinessLogic;
5 using PetShop.ObjectModel;
6
7 namespace PetShop.Web
8 {
9 public partial class CheckOut : System.Web.UI.Page
10 {
11 protected void Page_Load(object sender, EventArgs e)
12 {
13 if (billingForm.Address == null)
14 billingForm.Address = Profile.AccountInfo;
15 }
16
17 /// <summary>
18 /// Process the order
19 /// </summary>
20 protected void wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e)
21 {
22 if (Profile.ShoppingCart.Items.Count > 0)
23 {
24 if (Profile.ShoppingCart.Count > 0)
25 {
26 // display ordered items
27 CartListOrdered.Bind(Profile.ShoppingCart.Items);
28
29 // display total and credit card information
30 ltlTotalComplete.Text = ltlTotal.Text;
31 ltlCreditCardComplete.Text = ltlCreditCard.Text;
32
33 // create order
34 Order order = new Order();
35
36 order.UserID = User.Identity.Name;
37 order.OrderDate = DateTime.Now;
38 order.TotalPrice = Profile.ShoppingCart.Total;
39 order.ShippingAddress = shippingForm.Address;
40 order.BillingAddress = billingForm.Address;
41 order.Lines = Profile.ShoppingCart.GetOrderLineItems();
42 order.CreditCard = GetCreditCardInfo();
43
44 new OrderManager().InsertOrder(order);
45
46 // destroy cart
47 Profile.ShoppingCart.Clear();
48 Profile.Save();
49 }
50 }
51 else
52 {
53 lblMsg.Text = "<p><br>Can not process the order. Your cart is empty.</p><p class=SignUpLabel><a class=linkNewUser href=Default.aspx>Continue shopping</a></p>";
54 wzdCheckOut.Visible = false;
55 }
56 }
57
58 /// <summary>
59 /// Create CreditCardInfo object from user input
60 /// </summary>
61 private CreditCard GetCreditCardInfo()
62 {
63 CreditCard cc = new CreditCard();
64
65 cc.Type = WebUtility.InputText(listCCType.SelectedValue, 40);
66 cc.Expiration = WebUtility.InputText(txtExpDate.Text, 7);
67 cc.Number = WebUtility.InputText(txtCCNumber.Text, 20);
68
69 return cc;
70 }
71
72 /// <summary>
73 /// Changing Wiszard steps
74 /// </summary>
75 protected void wzdCheckOut_ActiveStepChanged(object sender, EventArgs e)
76 {
77 if (wzdCheckOut.ActiveStepIndex == 3)
78 {
79 billingConfirm. Address = billingForm.Address;
80 shippingConfirm.Address = shippingForm.Address;
81 ltlTotal.Text = Profile.ShoppingCart.Total.ToString("c");
82
83 if (txtCCNumber.Text.Length > 4)
84 ltlCreditCard.Text = txtCCNumber.Text.Substring(txtCCNumber.Text.Length - 4, 4);
85 }
86 }
87
88 /// <summary>
89 /// Handler for "Ship to Billing Addredd" checkbox.
90 /// Prefill/Clear shipping address form.
91 /// </summary>
92 protected void chkShipToBilling_CheckedChanged(object sender, EventArgs e)
93 {
94 if (chkShipToBilling.Checked)
95 shippingForm.Address = billingForm.Address;
96 }
97
98 /// <summary>
99 /// Custom validator to check CC expiration date
100 /// </summary>
101 protected void ServerValidate(object source, ServerValidateEventArgs value)
102 {
103 DateTime dt;
104
105 if (DateTime.TryParse(value.Value, out dt))
106 value.IsValid = dt > DateTime.Now;
107 else
108 value.IsValid = false;
109 }
110 }
111 }