protected void Page_Load(object sender, EventArgs e) { if (Session["uid"] == null || Request["orderid"] == null) { Response.Redirect("/login.aspx"); } int OrderID = int.Parse(Request["orderid"]); OrderOnThisPage = OrderBLL.GetOrderByID(OrderID); if (OrderOnThisPage.status != OrderStatus.UnPaid) { Response.Redirect("/login.aspx"); } if ((int)Session["uid"] != OrderOnThisPage.user.id) { Response.Redirect("/login.aspx"); } AddressRowManage.SetAddress(OrderOnThisPage.address); List <AddressModel> AddressModels = AddressBLL.GetAddressesByUserID(OrderOnThisPage.user.id); foreach (AddressModel Address in AddressModels) { AddressRow addressRow = (AddressRow)LoadControl("/Controls/AddressRow.ascx"); addressRow.SetAddress(Address); addressRow.Click += AddressRow_Click; AddressHolder.Controls.Add(addressRow); } if (!IsPostBack) // 需要修改的值 { txtComment.Text = OrderOnThisPage.comment; txtStatus.Text = OrderOnThisPage.GetStatusString(); } // 基本信息 txtDateTime.Text = OrderOnThisPage.dateTime.ToString(); txtOrderID.Text = OrderOnThisPage.id.ToString(); txtUserID.Text = OrderOnThisPage.user.id.ToString(); // 价格信息 OrderPrice = OrderOnThisPage.CalculateTotalPrice(); OrderBLL.SetOrderTotalPrice(OrderOnThisPage); txtOrderPrice.Text = OrderPrice.ToString("F2"); ExtraPrice = 0; txtExtraPrice.Text = ExtraPrice.ToString("F2"); OffPrice = 0; txtOffPrice.Text = OffPrice.ToString("F2"); TotalPrice = OrderPrice + ExtraPrice - OffPrice; txtTotalPrice.Text = TotalPrice.ToString("F2"); // 创建控件 orderBookContent.Controls.Clear(); foreach (BookOrderModel bookOrder in OrderOnThisPage.books) { OrderBookRow bookRow = (OrderBookRow)LoadControl("~/Controls/OrderBookRow.ascx"); bookRow.SetBook(bookOrder, OrderOnThisPage); orderBookContent.Controls.Add(bookRow); bookRow.txtNum.TextChanged += TxtNum_TextChanged; } }
protected void btnPlaceOrder_Click(object sender, EventArgs e) { if (Session["uid"] == null) { Response.Redirect("/login.aspx"); } if (ViewState["selected"] == null) { return; } HashSet <int> seleted = (HashSet <int>)ViewState["selected"]; if (seleted.Count == 0) { return; } int userid = (int)Session["uid"]; AddressModel address = AddressBLL.GetUserDefaultAddress(userid); if (address.id == 0) { Modal.Show(this, "你还没有收货地址,请前往个人中心添加"); return; } CartModel cart = GetCart(); OrderModel order = new OrderModel(); order.address = address; foreach (BookOrderModel orderBook in cart.book) { if (seleted.Contains(orderBook.book.id)) { orderBook.price = orderBook.book.price; order.books.Add(orderBook); } } order.comment = ""; order.dateTime = DateTime.Now; order.status = 0; order.CalculateTotalPrice(); order.user.id = userid; int msg = OrderBLL.AddOrder(order); if (msg != -1) { foreach (BookOrderModel book in order.books) { CartBLL.DeleteBook(userid, book.book.id); } Modal.Show(this, "下单成功,即将前往付款界面", 1000, "/placeorder.aspx?orderid=" + msg); } else { Modal.Show(this, "购买失败", 1000, HttpContext.Current.Request.Url.PathAndQuery); } }
private void TxtNum_TextChanged(object sender, EventArgs e) { string a = ((TextBox)sender).Text; OrderPrice = OrderOnThisPage.CalculateTotalPrice(); OrderBLL.SetOrderTotalPrice(OrderOnThisPage); txtOrderPrice.Text = OrderPrice.ToString("F2"); ExtraPrice = 0; txtExtraPrice.Text = ExtraPrice.ToString("F2"); OffPrice = 0; txtOffPrice.Text = OffPrice.ToString("F2"); TotalPrice = OrderPrice + ExtraPrice - OffPrice; txtTotalPrice.Text = TotalPrice.ToString("F2"); }
protected void btnBuy_Click(object sender, EventArgs e) { if (Session["uid"] == null) { Response.Redirect("/login.aspx"); } int userid = (int)Session["uid"]; AddressModel address = AddressBLL.GetUserDefaultAddress(userid); if (address.id == 0) { Modal.Show(this, "你还没有收货地址,请前往个人中心添加"); return; } OrderModel order = new OrderModel(); order.address = address; BookOrderModel bookOrder = new BookOrderModel(); bookOrder.quantity = int.Parse(txtNum.Text); bookOrder.price = BookOnThisPage.price; bookOrder.book = BookOnThisPage; order.books = new List <BookOrderModel>() { bookOrder }; order.comment = ""; order.dateTime = DateTime.Now; order.status = 0; order.CalculateTotalPrice(); order.user.id = userid; int msg = OrderBLL.AddOrder(order); if (msg != -1) { Modal.Show(this, "下单成功,即将前往付款界面", 1000, "/placeorder.aspx?orderid=" + msg); } else { Modal.Show(this, "购买失败", 1000, HttpContext.Current.Request.Url.PathAndQuery); } }