public bool AddOrderDetail(int idOrder, int idProduct, int quantity, decimal price) { OrderDetail odt = new OrderDetail(); odt.OrderID = idOrder; odt.ProductID = idProduct; odt.Quantity = quantity; odt.Price = price; return(orderDetailDAL.AddOrderDetail(odt)); }
public bool AddOrderDetail(OrderDetail orderDetail) { return(orderDetailDAL.AddOrderDetail(orderDetail)); }
/// <summary> /// 我要发货,订单生成 /// </summary> /// <param name="storeId">店铺编号</param> /// <param name="orderDetails">发货单明细</param> /// <param name="storeItem">发货单信息</param> /// <returns></returns> public Boolean ApplyGoodsSubmit(StoreOrderModel storeorder, string orders) { string orderId = OrderGoodsBLL.GetNewOrderID(); int maxqishu = CommonDataBLL.GetMaxqishu(); //总金额,积分,数量,重量 decimal totalmoney = 0; decimal totalpv = 0; int totalQuantity = 0; decimal totalWeight = 0; string remark = ""; //保存合并后订单明细 IList <OrderDetailModel> orderDetails = new List <OrderDetailModel>(); //获取要合并的订单列表 IList <OrderGoodsMedel> storeorders = StoreOrderDAL.GetOrderGoodsByOrders(orders); //遍历要合并的订单列表 foreach (OrderGoodsMedel order in storeorders) { //获取要合并的订单列表明细并且进行遍历 foreach (OrderDetailModel detail in OrderDetailDAL.GetGoodsDetailModelList(order.OrderGoodsID)) { //判断是否已经有了该产品 int ct = 0; //遍历合并后的订单列表,是否有和要合并的订单重复的产品 foreach (OrderDetailModel orderdetail in orderDetails) { if (orderdetail.ProductId == detail.ProductId) { orderdetail.Quantity += detail.Quantity; ct++;//有重复的累加 } } //没有重复添加新的明细 if (ct == 0) { //生成一条订单明细 OrderDetailModel detailNew = new OrderDetailModel(); detailNew.StoreorderId = orderId; detailNew.ProductId = detail.ProductId; detailNew.Quantity = detail.Quantity; detailNew.Price = detail.Price; detailNew.Pv = detail.Pv; detailNew.StoreId = detail.StoreId; detailNew.ProductName = detail.ProductName; detailNew.ExpectNum = maxqishu; //添加订单明细,到订单明细列表 orderDetails.Add(detailNew); } } //累加总金额,总积分,数量 totalmoney += order.TotalMoney; totalpv += order.TotalPv; totalQuantity += order.GoodsQuantity; totalWeight += order.Weight; remark += order.OrderGoodsID + ";"; } //保存合并后订单 StoreOrderModel storeItem = new StoreOrderModel(); storeItem.StoreId = storeorder.StoreId; //店铺ID storeItem.StoreorderId = orderId; //订单号 storeItem.TotalMoney = totalmoney; //订单总金额 storeItem.TotalPv = totalpv; //订单总积分 storeItem.InceptAddress = storeorder.InceptAddress; //收货人地址 storeItem.InceptPerson = storeorder.InceptPerson; //收货人姓名 storeItem.PostalCode = storeorder.PostalCode; //收货人邮编 storeItem.Telephone = storeorder.Telephone; //收货人电话 storeItem.OrderDatetime = DateTime.Now.ToUniversalTime(); //订单时间 storeItem.ExpectNum = CommonDataBLL.GetMaxqishu(); //获取期数 storeItem.TotalCommision = 0; //手续费 storeItem.GoodsQuantity = totalQuantity; //货物件数 storeItem.Carriage = 0; //运费 storeItem.Weight = totalWeight; //重量 storeItem.City.Country = storeorder.City.Country; //国家 storeItem.City.Province = storeorder.City.Province; //省份 storeItem.City.City = storeorder.City.City; //城市 storeItem.City.Xian = storeorder.City.Xian; storeItem.IscheckOut = "Y"; //是否支付 storeItem.IsAuditing = "Y"; storeItem.SendWay = storeorder.SendWay; storeItem.OperateIP = System.Web.HttpContext.Current.Request.UserHostAddress; //用户IP storeItem.Description = remark; //描述 storeItem.ConsignmentDatetime = DateTime.Now.ToUniversalTime(); //申请发货日期 storeItem.OrderType = storeorder.OrderType; using (SqlConnection conn = new SqlConnection(DBHelper.connString)) { conn.Open(); SqlTransaction tr = conn.BeginTransaction();//开启事务 try { //插入订单 if (new StoreOrderDAL().AddStoreOrder(storeItem, tr)) { //DBHelper.ExecuteNonQuery(tr, "insert into ApplygoodsTb select '" + storeItem.Description + "',1"); //订单表插入成功插入明细表 foreach (OrderDetailModel orderDetailItem in orderDetails) { if (!OrderDetailDAL.AddOrderDetail(tr, orderDetailItem, storeItem.StoreorderId)) { tr.Rollback(); return(false); } } //修改库存信息 foreach (OrderDetailModel orderDetailItem in orderDetails) { if (!StockDAL.UpdStockSendTotalNumber(tr, storeItem.StoreId, orderDetailItem.ProductId, orderDetailItem.Quantity)) { tr.Rollback(); return(false); } } //更新订单发货状态 StoreOrderDAL.UpdateDeliveryFlag(orders, orderId); //if (storeItem.SendType == 2) //{ // string strSql = @"Update memberorder Set sendType = 2 Where OrderId in (Select OutStorageOrderID from OrderGoods where storeorderid in (" + orders + "))"; // DBHelper.ExecuteNonQuery(tr, strSql, null, CommandType.Text); //} tr.Commit();//插入订单信息完成 } else {//订单插入失败回滚数据 tr.Rollback(); return(false); } } catch { //订单插入失败回滚数据 tr.Rollback(); return(false); } finally { conn.Close(); } } return(true); }