Пример #1
0
        /// <summary>
        /// 确认订单按钮
        /// </summary>
        /// <returns></returns>
        public Boolean CheckOutStoreOrder(IList <StoreOrderModel> orders, string storeid)
        {
            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                conn.Open();                                 //打开连接
                SqlTransaction tr = conn.BeginTransaction(); //开启事务

                try
                {
                    decimal ordermoney = 0;
                    decimal turnmoney  = 0;
                    string  orderids   = "";
                    foreach (StoreOrderModel order in orders)
                    {
                        if (!StoreOrderDAL.GetIsCheckOut(tr, order.StoreorderId))            //判断该订单是否已经支付
                        {
                            if (StoreOrderDAL.UpdateOrderGoodsState(tr, order.StoreorderId)) //更改订单成已支付状态
                            {
                                orderids += order.StoreorderId + ";";
                                if (order.OrderType == 0)
                                {
                                    ordermoney += order.TotalMoney;
                                }
                                else if (order.OrderType == 1)
                                {
                                    turnmoney += order.TotalMoney;
                                }
                                if (!StockDAL.UpdateInWayCount(tr, OrderDetailDAL.GetOrderGoodsDetail(order.StoreorderId), storeid))//跟新店库存,添加在途数量,去除预定数量
                                {
                                    tr.Rollback();
                                    return(false);
                                }
                                if (!LogicProductInventoryDAL.UpdateToatlOut(tr, CommonDataBLL.GetNewOrderDetail(OrderDetailDAL.GetOrderGoodsDetail(order.StoreorderId))))//更新公司 逻辑库存
                                {
                                    tr.Rollback();
                                    return(false);
                                }
                            }
                            else
                            {
                                tr.Rollback();
                                return(false);
                            }
                        }
                    }

                    //添加对账单
                    D_AccountBLL.AddAccount(storeid, Convert.ToDouble(ordermoney), D_AccountSftype.StoreType, D_AccountKmtype.StoreOrderout, DirectionEnum.AccountReduced, "店铺【" + storeid + "】在线订货,订货款扣除额,订单号为【" + orderids + "】", tr);
                    //跟新店货款
                    if (!StoreInfoDAL.UpdateSomeMoney(tr, ordermoney, turnmoney, storeid))
                    {
                        tr.Rollback();
                        return(false);
                    }

                    tr.Commit();
                }
                catch
                {
                    tr.Rollback();
                    return(false);
                }
                finally
                {
                    conn.Close();
                }
            }
            return(true);
        }