/// <summary> /// 新增出库单数据 /// </summary> /// <param name="bill"></param> /// <param name="listGoods"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public long InsertOutWarehouseBill(OutWarehouseBill bill, List <OutWarehouseBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText) { long nOutWarehouseBillId = 0; try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (StockDAO dao = new StockDAO()) { //新增出库单数据 nOutWarehouseBillId = dao.InsertOutWarehouseBill(bill, nOpStaffId, strOpStaffName, out strErrText); if (nOutWarehouseBillId <= 0) { return(0); } //新增出库货物数据 foreach (OutWarehouseBillGoods goods in listGoods) { goods.OutWarehouseBillId = nOutWarehouseBillId; if (!dao.InsertOutWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText)) { return(0); } } } using (CustomerDAO dao = new CustomerDAO()) { //修改上力支费价格数据 List <CustomerForceFeePrice> listForceFeePrice = dao.LoadCustomerForceFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText); if (listForceFeePrice.Count == 0) { //新增力支费价格数据 CustomerForceFeePrice data = new CustomerForceFeePrice(); data.CustomerId = bill.CustomerId; data.StartTime = bill.CreateTime; data.EndTime = DateTime.Parse("9999-12-31"); data.LoadingForceFeePrice = bill.LoadingForceFeePrice; data.UnloadingForceFeePrice = 0; if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText)) { return(0); } } else { int i = 0; while (i < listForceFeePrice.Count) { if (bill.CreateTime.Date >= listForceFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listForceFeePrice[i].EndTime.Date) { break; } i++; } if (i < listForceFeePrice.Count) { //修改力支费价格数据 listForceFeePrice[i].LoadingForceFeePrice = bill.LoadingForceFeePrice; if (!dao.UpdateCustomerForceFeePrice(listForceFeePrice[i], nOpStaffId, strOpStaffName, out strErrText)) { return(0); } } else { //新增力支费价格数据 CustomerForceFeePrice data = new CustomerForceFeePrice(); data.CustomerId = bill.CustomerId; data.StartTime = bill.CreateTime; data.LoadingForceFeePrice = bill.LoadingForceFeePrice; data.UnloadingForceFeePrice = 0; //计算截止时间 i = 0; while (i < listForceFeePrice.Count) { if (bill.CreateTime.Date < listForceFeePrice[i].StartTime.Date) { break; } i++; } if (i < listForceFeePrice.Count) { data.EndTime = listForceFeePrice[i].StartTime.Date.AddDays(-1); } else { data.EndTime = DateTime.Parse("9999-12-31"); } if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText)) { return(0); } } } } transScope.Complete(); } return(nOutWarehouseBillId); } catch (Exception e) { strErrText = e.Message; return(0); } }