//提交订单 protected void btnOK_OnClick(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbxReceiver.Text)) { WebUtil.Alert("请输入收货人!"); return; } if (string.IsNullOrWhiteSpace(tbxAddress.Text)) { WebUtil.Alert("请输入收货地址!"); return; } if (string.IsNullOrWhiteSpace(tbxMobile.Text)) { WebUtil.Alert("请输入收货人地址!"); return; } if (Convert.ToDecimal(hfTotalPrice.Value) <= 0) { WebUtil.Alert("请先选好数量!"); return; } //订单信息 var order = new Ye_Order() { UserID = YeUser.UserID, ShopID = OrderingShop.ShopID, OrderSN = lblOrderSN.Text, OrderDesc = tbxOrderDesc.Text, OrderCreateTime = DateTime.Now, OrderCheckTime = null, OrderPayTime = null, IsUserDeleted = false, IsShopDeleted = false, Receiver = tbxReceiver.Text, ReceiveAddress = tbxAddress.Text, ReceiverMobile = tbxMobile.Text, TotalPrice = Convert.ToDecimal(hfTotalPrice.Value), Tax = Convert.ToDecimal(hfFax.Value), OrderStatus = (int)OrderStatus.已下单 }; if (!string.IsNullOrWhiteSpace(tbxCode.Text)) { var coupon = ShopCouponBll.GetShopCouponsByShopId(OrderingShop.ShopID) .SingleOrDefault( s => s.BeginDate <DateTime.Now && s.EndDate> DateTime.Now && s.CouponCode == tbxCode.Text); if (coupon == null) { WebUtil.Alert("优惠券验证码无效!"); return; } else { var userCoupon = UserCouponBll.GetUserCouponsByUserId(YeUser.UserID) .SingleOrDefault(p => p.CouponId == coupon.CouponID); if (userCoupon == null) { WebUtil.Alert("您没有该验证码的使用权限!"); return; } else { if (userCoupon.IsUsed) { WebUtil.Alert("该验证码已被使用作废!"); return; } else { UserCouponBll.UseCoupon(YeUser.UserID, userCoupon.UserCouponId); order.ShopCouponID = coupon.CouponID; order.UnitCouponCost = coupon.UnitCost; } } } // } var orderDetails = new List <Ye_OrderDetail>();//获取订单详情 rptProduct.Controls.OfType <RepeaterItem>().ToList().ForEach(p => { var lbl = p.FindControl("lblAmount") as Label; var hf = p.FindControl("hfAmount") as HiddenField; orderDetails.Add(new Ye_OrderDetail() { ProductID = Convert.ToInt32(lbl.Attributes["data-pid"]), Quantity = Convert.ToInt32(hf.Value), UnitCost = Convert.ToDecimal(lbl.Attributes["data-unitcost"]) }); }); if (OrderBll.AddOrder(order, orderDetails)) { Response.Cookies["shop_" + OrderingShop.ShopID.ToString()].Expires = DateTime.Now.AddDays(-1);//清空Cookie信息 //WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!","ShopDetail.aspx?shopid="+OrderingShop.ShopID); WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!", "UserOrders.aspx"); } }
/// <summary> /// 添加订单 /// </summary> /// <param name="order">订单详情</param> /// <param name="orderDetails">订单明细</param> /// <returns></returns> public static bool AddOrder(Ye_Order order, List <Ye_OrderDetail> orderDetails) { order.Ye_OrderDetail = orderDetails; _entities.Ye_Order.Add(order); return(_entities.SaveChanges() > 0); }