ASP. net e-commerce system development-3 (orders), asp.net-3
I. Preface
This is the third article after the last shopping cart. Record the order function. When this function was implemented, it was a detour, and it was very brainless. Because the idea was not straightened out, the database design was not very good, and only half of it found the problem, and then the database was re-designed, after clarifying our ideas, we finally finished it.
Ii. Start
1. Let's take a look at the initial error.
Click "place order" in the shopping cart and go to the order page:
Protected void Button3_Click (object sender, EventArgs e) {int num; // submit the DataTable getGoodsid = bllShopCar. getList ("[ShopUser] = '" + Request. cookies ["ShopUser"]. value + "'"). tables [0]; DataSet getnumway = bllShopCar. getnum (Request. cookies ["ShopUser"]. value); num = Int32.Parse (getnumway. tables [0]. rows [0] ["Num"]. toString (); for (I = 0; I <num; I ++) {Goodsid = Int32.Parse (getGoodsid. rows [I] ["Goods _ ID "]. toString (); // get Godos_ID molOrderinfo. goods_ID = Goodsid; // submit the item ID to Orderinfo Goods_Num = getGoodsid. rows [I] ["Goods_Num"]. toString (); molOrderinfo. goods_Num = Int32.Parse (Goods_Num); // submit the number of items to Orderinfo DataSet getprice = bllgoods. getList ("Goods_ID =" + Goodsid); In_Storeprice = getprice. tables [0]. rows [0] ["In_store_price"]. toString (); // get the unit price s = Int32.Parse (In_Storeprice) * Int32.Parse (Goods _ Num); molOrderinfo. goods_Money = s; // submit the subtotal to Orderinfo DataSet getallprice = bllShopCar. getAllprice (Request. cookies ["ShopUser"]. value); a = getallprice. tables [0]. rows [0] [0]. toString (); molOrderinfo. goods_Name = getprice. tables [0]. rows [0] [1]. toString (); // submit the product name to Orderinfo molOrderinfo. u_ID = Int32.Parse (sj); // generate an order number to Oredrinfo bllOrderinfo. add (molOrderinfo);} molOrder. money_Sum = Int32.Parse (); // Submit the total price of this Order to Order molOrder. user_Name = Request. cookies ["Username"]. value; // submit the Order primary User_name to Order molOrder. order_status = "submitted"; molOrder. method = method. value; molOrder. style = "coming soon"; molOrder. u_ID = Int32.Parse (sj); // generate an order number to Oredr DateTime dt = DateTime. now; molOrder. order_time = dt; bllorder. add (molOrder); // submit the address molAddress. user_Name = Request. cookies ["Username"]. value; molAddress. address_info = TextArea1.Value; molAddress. zipcode = TextBox3.Text; molAddress. get_Name = TextBox1.Text; molAddress. email = TextBox4.Text; molAddress. phone = TextBox2.Text; molAddress. method = method. value; // string sj2 = DateTime. now. day. toString () + DateTime. now. timeOfDay. hours. toString () + DateTime. now. timeOfDay. minutes. toString () + DateTime. now. timeOfDay. milliseconds. toString (); molAddress. u_ID = Int32.P Arse (sj); bllAddress. Add (molAddress); Page. ClientScript. RegisterStartupScript (this. GetType (), "alert", "<script> alert ('submitted successfully! '); Location. href = 'personcenter. aspx' </script> "); bllShopCar. DeleteShopCar (Request. Cookies [" ShopUser "]. Value );}
First, let's look at the first row. Getlist method: Obtain the item ID in the ShopCar table based on the ShopUser mentioned in the previous article. Second, getnum method gets the number of items under the same ShopUser, that is, select count (*); the third row gives the number to the variable set in advance: num. Next, let's go to the most critical point: add all the items in the shopping cart, note that they are all, not a single item, as we have said before, at the beginning, the wrong idea was to use the for loop to traverse all the items in the shopping cart. Therefore, only one item can be submitted to the order. Then I wrote a for, tried several times, and found that there was no problem. The first row in for, condition: the number of cycles must be smaller than num; then the third row in for gets the number of items, followed by getGoods_id. row [I], not. row [1], because it has multiple data records and needs to be traversed, not only one data entry. Then there are comments below. At the end of the for statement, place the order details in the for loop, that is, add (molOrderinfo) in the last row of the for statement, so that you can submit multiple items in the shopping cart. After for, you do not need to submit some information such as the order total price and the order person and the final address cyclically. There is also a U_ID:
string sj = DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
This is the order number. Three tables are associated. Only one order is generated at a time and no duplicates are generated.
4. effect after implementation
Let's take a look at what data is added to the database:
Public void dataload1 () {molOrder = bllOrder. getModel1 (int. parse (Request ["ID"]); lblorderid_text.Text = molOrder. u_ID.ToString (); lblordertime. text = molOrder. order_time.ToString (); moladdress = blladdress. getModel2 (int. parse (Request ["ID"]); lblperson. text = moladdress. get_Name; orderway. text = molOrder. method; lbladderss. text = moladdress. address_info; lblmoney. text = molOrder. money_Sum.ToString (); SqlDataSource1.SelectCommand = "select * from [Orderinfo] where U_ID = '" + lblorderid_text.Text + "'"; // DataSet ds = bllOrderinfo. getList ("U_ID = '" + Request. queryString ["ID"] + "'"); // RadListView1.DataSource = ds; // RadListView1.DataBind ();}
Lblorderid_text is the previous order number.
After you click "Payment", a message is displayed, indicating that the payment is successful:
Protected void button#click (object sender, EventArgs e) {molOrder = bllOrder. getModel1 (int. parse (Request ["ID"]); molOrder. style = "paid"; bllOrder. update (molOrder); Page. clientScript. registerStartupScript (this. getType (), "alert", "<script> alert ('payment successful! '); Location. href = 'personalorder. aspx'; </script> ");}
Of course, you can manage orders in the background. The effect is as follows:
Click View order to go to this page:
After you select "delivered", you can see the following in the personal center:
The status is delivered.
Finally, after the order process is complete, the shopping cart should be in the clear state.
Well, this is all about the order. I hope it will help you in the future.
Ps: This is the third article. It will continue to be updated tomorrow. Thank you for your patience!