Ejemplo n.º 1
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 long InsertContract(Contract data, List<ContractDeliverPlan> listPlan, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            long nContractId = 0;

            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (ContractDAO dao = new ContractDAO())
                    {
                        //新增合同数据
                        nContractId = dao.InsertContract(data, nOpStaffId, strOpStaffName, out strErrText);
                        if (nContractId <= 0)
                            return 0;

                        //新增合同计划数据
                        foreach (ContractDeliverPlan plan in listPlan)
                        {
                            plan.ContractId = nContractId;

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

                    using (DispatchDAO dao = new DispatchDAO())
                    {
                        //检查调度单数据
                        if (!dao.CheckDispatchBill(data.DispatchBillId, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return 0;
                        }
                    }
                    transScope.Complete();
                }
                return nContractId;
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return 0;
            }
        }