protected void btnCheck_Click(object sender, EventArgs e) { List <CShoppingCart> cartList = Session["cart"] as List <CShoppingCart>; CBookFactory bookfactory = new CBookFactory(); COrdersFactory orderfactory = new COrdersFactory(); int bookId, bookPrice, count, subtotal; DateTime orderDate; string note; try { foreach (CShoppingCart c in cartList) { bookId = bookfactory.getbookId(c.書名); bookPrice = Convert.ToInt32(c.單價); count = Convert.ToInt32(c.數量); subtotal = Convert.ToInt32(c.小計); orderDate = Convert.ToDateTime(c.訂購日期); note = "收件人姓名" + tboxName1.Text + "電話" + tboxPhone1.Text + "地址" + tboxAddress1.Text + "email" + tboxEmail1.Text + "信用卡號碼" + tboxCardID.Text + "信用卡有效日期" + tboxCardMonth.Text + tboxCardYear.Text + "信用卡安全碼" + tboxSecurityID.Text; COrders order = new COrders() { book_id = bookId, bookPrice = bookPrice, count = count, subtotal = subtotal, orderDate = orderDate, note = note }; orderfactory.insertOrder(order); } } catch (Exception) { Response.Write("<script>alert('" + orderfactory.message + "')</script>"); } (Session["cart"] as List <CShoppingCart>).Clear(); Response.Write("<script>alert('" + orderfactory.message + "')</script>"); Response.Redirect("redirect.aspx"); }
protected void Button1_Click(object sender, EventArgs e) { COrdersFactory factory = new COrdersFactory(); COrders order = new COrders() { book_id = 10002, bookPrice = 1200, count = 2, subtotal = 2400, orderDate = Convert.ToDateTime("2015/6/17"), note = "test" }; factory.insertOrder(order); }