Beispiel #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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 修改调度单
        /// </summary>
        /// <param name="data"></param>
        /// <param name="listPlan"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateDispatchBill(DispatchBill data, List <DispatchBillDeliverPlan> listPlan, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (DispatchDAO dao = new DispatchDAO())
                    {
                        #region 修改调度单数据
                        DispatchBill oldData = dao.LoadDispatchBill(data.Id, nOpStaffId, strOpStaffName, out strErrText);
                        if (oldData == null)
                        {
                            return(false);
                        }
                        data.TotalPackages         = oldData.TotalPackages;
                        data.TotalTunnages         = oldData.TotalTunnages;
                        data.TotalPiles            = oldData.TotalPiles;
                        data.TotalTenThousands     = oldData.TotalTenThousands;
                        data.TotalTransportCharges = oldData.TotalTransportCharges;

                        if (!dao.UpdateDispatchBill(data, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }
                        #endregion

                        #region 修改调度计划数据
                        List <DispatchBillDeliverPlan> listOldPlan = dao.LoadDispatchBillDeliverPlans(data.Id, nOpStaffId, strOpStaffName, out strErrText);
                        if (listOldPlan == null)
                        {
                            return(false);
                        }
                        if (!dao.DeleteDispatchBillDeliverPlans(data.Id, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }
                        foreach (DispatchBillDeliverPlan oldPlan in listOldPlan)
                        {
                            DispatchBillDeliverPlan newPlan = listPlan.Find(delegate(DispatchBillDeliverPlan p) { return(p.PlanId == oldPlan.PlanId); });
                            if (newPlan != null)
                            {
                                oldPlan.ReceiveType = newPlan.ReceiveType;
                            }

                            if (!dao.InsertDispatchBillDeliverPlan(oldPlan, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                        #endregion

                        #region 修改调度货物数据
                        List <DispatchBillGoods> listOldGoods = dao.LoadDispatchBillAllGoods(data.Id, nOpStaffId, strOpStaffName, out strErrText);
                        if (listOldGoods == null)
                        {
                            return(false);
                        }
                        if (!dao.DeleteDispatchBillAllGoods(data.Id, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }
                        foreach (DispatchBillGoods goods in listOldGoods)
                        {
                            if (!dao.InsertDispatchBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                        #endregion

                        #region 校验调度单数据
                        if (!dao.CheckDispatchBill(data.Id, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }
                        #endregion
                    }
                    transScope.Complete();
                }
                return(true);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(false);
            }
        }