/// <summary> /// 获取订单信息 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public OrderInfo GetOrderInfo(string orderId) { OrdersService.OrdersService service = new OrdersService.OrdersService(); DataTable dt = service.GetOrderModel(orderId); OrderInfo model = new OrderInfo(); model.OrderId = orderId; if (dt.Rows.Count > 0) { model.UserId = dt.Rows[0]["UserId"].ToString(); if (dt.Rows[0]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(dt.Rows[0]["CreateDate"].ToString()); } model.Operator = dt.Rows[0]["Operator"].ToString(); if (dt.Rows[0]["State"].ToString() != "") { model.State = int.Parse(dt.Rows[0]["State"].ToString()); } model.Remark = dt.Rows[0]["Remark"].ToString(); model.Address = dt.Rows[0]["Address"].ToString(); model.Contactor = dt.Rows[0]["Contactor"].ToString(); model.Tel = dt.Rows[0]["Tel"].ToString(); model.Email = dt.Rows[0]["Email"].ToString(); return model; } return null; }
/// <summary> /// 更新订单信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateOrders(OrderInfo model) { OrdersService.OrdersService service = new OrdersService.OrdersService(); return service.UpdateOrders(model.OrderId, model.UserId, model.Operator, model.State, model.Remark,model.Address,model.Contactor,model.Tel,model.Email); }
/// <summary> /// 生成订单,并指定订单状态 /// </summary> private string CreateOrder(int orderState) { OrdersBiz biz = new OrdersBiz(); OrderInfo orderModel = new OrderInfo(); GiftBiz giftBiz = new GiftBiz(); //添加订单信息 orderModel.OrderId = biz.GetNewOrderId(); orderModel.UserId = CurrentUser.UserId.ToString(); orderModel.Operator = CurrentUser.OperatorId.ToString(); orderModel.State = orderState; orderModel.Address = address.Text; orderModel.Contactor = Contactor.Text; orderModel.Tel = Tel.Text; orderModel.Email = Email.Text; Orders_DetailInfo[] details = new Orders_DetailInfo[gvShoppingCartList.Rows.Count]; GiftInfo[] giftInfoList = new GiftInfo[gvShoppingCartList.Rows.Count]; int i = 0; //添加订单明细,先检查数量是否足够 foreach (GridViewRow row in gvShoppingCartList.Rows) { Label lblGiftId = row.FindControl("lblGiftId") as Label; TextBox txtCount = row.FindControl("txtCount") as TextBox; TextBox txtUsage = row.FindControl("txtUsage") as TextBox; Orders_DetailInfo detailModel = new Orders_DetailInfo(); detailModel.OrderId = orderModel.OrderId; detailModel.GiftId = lblGiftId.Text; detailModel.GiftCount = int.Parse(txtCount.Text); detailModel.Usage = txtUsage.Text; GiftInfo giftModel = giftBiz.GetModel(detailModel.GiftId); if (giftModel.Quantity < detailModel.GiftCount) { lErrorInfo.Text = "礼品【" + giftModel.Title + "】数量不足,剩余数量为:" + giftModel.Quantity.ToString() + "!"; return string.Empty; } giftInfoList[i] = giftModel; details[i] = detailModel; i++; } //遍历更新 for (i = 0; i < details.Length; i++) { biz.AddOrders_Detail(details[i]); giftInfoList[i].Quantity -= details[i].GiftCount; giftBiz.UpdateGift(giftInfoList[i]); } biz.AddOrders(orderModel); //清除购物车 HttpCookie cookie = Request.Cookies["ShoppingCart"]; cookie.Expires = DateTime.Now.AddHours(-2); Response.Cookies.Add(cookie); return orderModel.OrderId; }