예제 #1
0
        /// <summary>
        /// 新增调度单数据
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="listDeliverPlan"></param>
        /// <param name="listGoods"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public long InsertDispatchBill(DispatchBill bill, List <DispatchBillDeliverPlan> listDeliverPlan, List <DispatchBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            long nDispatchBillId = 0;

            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (DispatchDAO dao = new DispatchDAO())
                    {
                        //新增计划数据
                        nDispatchBillId = dao.InsertDispatchBill(bill, nOpStaffId, strOpStaffName, out strErrText);
                        if (nDispatchBillId <= 0)
                        {
                            return(0);
                        }

                        //新增计划数据
                        foreach (DispatchBillDeliverPlan deliverPlan in listDeliverPlan)
                        {
                            deliverPlan.DispatchBillId = nDispatchBillId;

                            if (!dao.InsertDispatchBillDeliverPlan(deliverPlan, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(0);
                            }
                        }

                        //新增货物数据
                        foreach (DispatchBillGoods goods in listGoods)
                        {
                            goods.DispatchBillId = nDispatchBillId;

                            if (!dao.InsertDispatchBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(0);
                            }
                        }

                        //校验调度单数据
                        if (!dao.CheckDispatchBill(nDispatchBillId, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(0);
                        }
                    }
                    transScope.Complete();
                }
                return(nDispatchBillId);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(0);
            }
        }