Order-Related Modules for an ASP.NET AJAX Server-Centric Based Online Shopping Website - Page Initialization
(Page 7 of 7 )
At the start of the initialization of the "order.aspx," related data are bound to the ProductView control, i.e. displaying the products within the cart, then continue to show the detailed info about the user and the order. The following code corresponds to the initializing process.
protected void Page_Load(object sender,EventArgs e){
if(!Page.IsPostBack){
///get the info about the cart
ShowCartInfo();
if(Session["UserID"]!=null)
BindUserData(Int32.Parse(Session["UserID"].ToString()));
}
}
private void BindUserData(int nUserID){
///Get the data
User user = new User();
SqlDataReader recr = user.GetSingleUser(nUserID);
///Read the data
if(recr.Read()){
///display data
UserName.Text = recr["UserName"].ToString();
RealName.Text = recr["RealName"].ToString();
Address.Text = recr["Address"].ToString();
Email.Text = recr["Email"].ToString();
Phone.Text = recr["Phone"].ToString();
Mobile.Text = recr["Mobile"].ToString();
Remark.Text = recr["Remark"].ToString();
}
recr.Close();///Close the data source
}
private void ShowCartInfo(){
///judge if there are data in the cart
if(Session[Session.SessionID + OrderForm.Cart] == null) {
return;
}
OrderInfo order = (OrderInfo)Session[Session.SessionID + OrderForm.Cart];
ProductView.DataSource = order.OrderItemList;
ProductView.DataBind();
ProductView.FooterRow.Cells[0].Text = "Total amount: " +
order.TotalNumber.ToString() + ", Total price: " +
order.TotalMoney.ToString();
}
Notwithstanding the fact that it is pretty long, the inner logic is rather easy. The key sentence is 'SqlDataReader recr = user.GetSingleUser(nUserID);' while the key variable still lies in Session. OK, by calling the two helper functions, namedShowCartInfoand BindUserData, all the required info is displayed on the screen.
Submitting the Order
The following shows the click event handler for the "Confirm the shopping info and commit the order" in the above Figure 18.
protected void CommitBtn_Click(object sender,EventArgs e){
///judge if there are data in the cart
if(Session[Session.SessionID + OrderForm.Cart] == null) {
return;
}
OrderInfo order = (OrderInfo)Session[Session.SessionID + OrderForm.Cart];
OrderForm orderform = new OrderForm();
int nOrderFormID = orderform.AddOrderForm(Int32.Parse(Session
["UserID"].ToString()),
order.TotalNumber,
order.TotalMoney);
if(nOrderFormID > -1) {
OrderItem orderItem = new OrderItem();
foreach(OrderItemInfo item in order.OrderItemList) {
orderItem.AddOrderItem(item.ProductID,item.Number,nOrderFormID);
}
}
///display the hint message
Response.Write("<script>alert("You have succeeded in committing the
order!")</script>");
}
Here, we first obtain the order info out of the Session variable, then submit it to the remote SQL Server database, and at last create an order. That's it.
Author's Note: First, because this is just a demonstration application, we have not attached all the order-related info to the popular online payment systems, such as PayPal or any other famous system. Thus, in practical development, you will have to do this by yourself. Second, to grasp all the data relations introduced in the above several modules you should carefully study the relationships between some classes such as OrderForm, OrderInfo, and OrderItemInfo.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |