Ejemplo n.º 1
0
        /// <summary>
        /// 确认订单按钮
        /// </summary>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public Boolean OrderSubmit(string storeId, List <OrderDetailModel> orderDetails, OrderGoodsMedel storeItem, bool IsEdit)
        {
            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                conn.Open();
                SqlTransaction tr = conn.BeginTransaction();//开启事务

                try
                {
                    if (IsEdit)                                                                                              //如果是修改订单,先删除原来的订单并还原原来的信息
                    {
                        BLL.CommonClass.ChangeLogs cl_h_info = new BLL.CommonClass.ChangeLogs("OrderGoods", "OrderGoodsID"); //实例日志类
                        cl_h_info.AddRecordtran(tr, storeItem.OrderGoodsID);                                                 //添加日志,修改前记录原来数据

                        StoreOrderDAL.DelStoreOrderItemProc(tr, storeItem.OrderGoodsID);
                        //StockDAL.DelStoreOrder(tr, OrderDetailDAL.GetOrderGoodsDetail(storeItem.StoreorderId), storeItem.StoreId);//还原店库存
                        //OrderDetailDAL.DelOrderGoodsDetail(tr, storeItem.StoreorderId);//明细表删除失败回滚
                        //StoreOrderDAL.DelOrderGoods(storeItem.StoreorderId, tr); //订单表删除失败回滚

                        cl_h_info.AddRecordtran(tr, storeItem.OrderGoodsID);                                                                                           //添加日志,修改后记录原来数据
                        cl_h_info.ModifiedIntoLogstran(tr, BLL.CommonClass.ChangeCategory.store10, storeItem.OrderGoodsID, BLL.CommonClass.ENUM_USERTYPE.objecttype2); //插入日志
                    }

                    //插入订单
                    if (new StoreOrderDAL().AddOrderGoods(storeItem, tr))
                    {
                        //订单表插入成功插入明细表
                        foreach (OrderDetailModel orderDetailItem in orderDetails)
                        {
                            if (!OrderDetailDAL.AddOrderGoodsDetail(tr, orderDetailItem, storeItem.OrderGoodsID))
                            {
                                tr.Rollback();
                                return(false);
                            }
                        }
                        //修改库存信息(预订数量)
                        foreach (OrderDetailModel orderDetailItem in orderDetails)
                        {
                            if (!StockDAL.UpdStockHasOrderCount(tr, storeItem.StoreId, orderDetailItem.ProductId, orderDetailItem.Quantity))
                            {
                                tr.Rollback();
                                return(false);
                            }
                        }

                        tr.Commit();//插入订单信息完成
                    }
                    else
                    {//订单插入失败回滚数据
                        tr.Rollback();
                        return(false);
                    }
                }
                catch
                {
                    //订单插入失败回滚数据
                    tr.Rollback();
                    return(false);
                }
                finally
                {
                    conn.Close();
                }
            }
            return(true);
        }