public ResultModel Create(UserModel user, Model.Document doc, List<Model.DocumentStock> docStocks, bool isSubmitAudit) { ResultModel result = new ResultModel(); try { //新增制单主表 //新增制单库存明细表 //新增制单发票明细表 //新增发票 //提交审核 DAL.DocumentOrderDAL orderDAL = new DocumentOrderDAL(); DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL(); DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL(); DAL.DocumentStockDAL docStockDAL = new DocumentStockDAL(); DAL.DocumentInvoiceDAL docInvoiceDAL = new DocumentInvoiceDAL(); Invoice.DAL.BusinessInvoiceDAL invoiceDAL = new Invoice.DAL.BusinessInvoiceDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (doc == null || doc.OrderId <= 0) { result.ResultStatus = -1; result.Message = "制单信息错误"; return result; } if (docStocks == null || docStocks.Count == 0) { result.ResultStatus = -1; result.Message = "未选择任何制单库存"; return result; } //获取指令 result = orderDAL.Get(user, doc.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrder order = result.ReturnValue as Model.DocumentOrder; if (order == null || order.OrderId <= 0) { result.ResultStatus = -1; result.Message = "制单指令不存在"; return result; } //判断指令状态 if (order.OrderStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "制单指令非已生效状态,不能进行制单"; return result; } //新增制单 //doc.AcceptanceDate = DefaultValue.DefaultTime; //doc.PresentDate = DefaultValue.DefaultTime; doc.DocEmpId = user.EmpId; doc.DocumentStatus = DocumentStatusEnum.已录入; result = this.documentDAL.Insert(user, doc); if (result.ResultStatus != 0) return result; int documentId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out documentId) || documentId <= 0) { result.ResultStatus = -1; result.Message = "制单新增失败"; return result; } doc.DocumentId = documentId; //获取当前指令所有库存明细 result = orderStockDAL.Load(user, order.OrderId); if (result.ResultStatus != 0) return result; List<Model.DocumentOrderStock> orderStocks = result.ReturnValue as List<Model.DocumentOrderStock>; if (orderStocks == null || orderStocks.Count == 0) { result.ResultStatus = -1; result.Message = "制单指令库存明细获取失败"; return result; } //明细新增 foreach (Model.DocumentStock docStock in docStocks) { //验证选择明细是否在指令中 Model.DocumentOrderStock orderStock = orderStocks.FirstOrDefault(temp => temp.DetailId == docStock.DetailId); if (orderStock == null || orderStock.DetailId<=0) { result.ResultStatus = -1; result.Message = "制单指令库存不存在"; return result; } //新增制单库存明细 Model.DocumentStock addDocStock = new DocumentStock(); addDocStock.DetailStatus = StatusEnum.已生效; addDocStock.DocumentId = documentId; addDocStock.OrderId = order.OrderId; addDocStock.OrderStockDetailId = orderStock.DetailId; addDocStock.RefNo = orderStock.RefNo; addDocStock.StockId = orderStock.StockId; addDocStock.StockNameId = orderStock.StockNameId; result = docStockDAL.Insert(user, addDocStock); if (result.ResultStatus != 0) return result; int docStockDetailId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out docStockDetailId) || docStockDetailId <= 0) { result.ResultStatus = -1; result.Message = "制单库存明细新增失败"; return result; } addDocStock.DetailId = docStockDetailId; //获取指令发票明细 result = orderInvoiceDAL.GetByStockDetailId(user,orderStock.DetailId); if (result.ResultStatus != 0) return result; Model.DocumentOrderInvoice orderInvoice = result.ReturnValue as Model.DocumentOrderInvoice; if (orderInvoice == null || orderInvoice.DetailId <= 0) { result.ResultStatus = -1; result.Message = "制单指令发票明细不存在"; return result; } Model.DocumentInvoice docInvoice = new DocumentInvoice(); docInvoice.DetailStatus = StatusEnum.已生效; docInvoice.DocumentId = doc.DocumentId; docInvoice.InvoiceNo = orderInvoice.InvoiceNo; docInvoice.InvoiceBala =orderInvoice.InvoiceBala; docInvoice.OrderId = order.OrderId; docInvoice.OrderInvoiceDetailId = orderInvoice.DetailId; docInvoice.StockDetailId = addDocStock.DetailId; result = docInvoiceDAL.Insert(user, docInvoice); if (result.ResultStatus != 0) return result; } if (isSubmitAudit) { NFMT.WorkFlow.AutoSubmit submit = new WorkFlow.AutoSubmit(); NFMT.WorkFlow.ITaskProvider taskProvider = new TaskProvider.DocumentTaskProvider(); result = submit.Submit(user, doc, taskProvider, WorkFlow.MasterEnum.制单审核); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = doc; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Update(UserModel user, Model.Document doc, List<Model.DocumentStock> docStocks) { ResultModel result = new ResultModel(); try { DAL.DocumentOrderDAL orderDAL = new DocumentOrderDAL(); DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL(); DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL(); DAL.DocumentStockDAL docStockDAL = new DocumentStockDAL(); DAL.DocumentInvoiceDAL docInvoiceDAL = new DocumentInvoiceDAL(); Invoice.DAL.BusinessInvoiceDAL invoiceDAL = new Invoice.DAL.BusinessInvoiceDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (doc == null || doc.DocumentId <= 0) { result.ResultStatus = -1; result.Message = "制单信息错误"; return result; } if (docStocks == null || docStocks.Count == 0) { result.ResultStatus = -1; result.Message = "未选择任何制单库存"; return result; } //获取制单 result = this.documentDAL.Get(user, doc.DocumentId); if (result.ResultStatus != 0) return result; Model.Document resultDoc = result.ReturnValue as Model.Document; if (resultDoc == null || resultDoc.DocumentId <= 0) { result.ResultStatus = -1; result.Message = "制单不存在"; return result; } //获取指令 result = orderDAL.Get(user, resultDoc.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrder order = result.ReturnValue as Model.DocumentOrder; if (order == null || order.OrderId <= 0) { result.ResultStatus = -1; result.Message = "制单指令不存在"; return result; } //判断指令状态 if (order.OrderStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "制单指令非已生效状态,不能进行制单"; return result; } //新增制单 resultDoc.DocEmpId = user.EmpId; resultDoc.DocumentDate = doc.DocumentDate; resultDoc.Meno = doc.Meno; result = this.documentDAL.Update(user, resultDoc); if (result.ResultStatus != 0) return result; //获取当前指令所有库存明细 result = orderStockDAL.Load(user, order.OrderId); if (result.ResultStatus != 0) return result; List<Model.DocumentOrderStock> orderStocks = result.ReturnValue as List<Model.DocumentOrderStock>; if (orderStocks == null || orderStocks.Count == 0) { result.ResultStatus = -1; result.Message = "制单指令库存明细获取失败"; return result; } //获取当前制单所有库存明细与发票明细并作废 result = docStockDAL.Load(user, resultDoc.DocumentId); if (result.ResultStatus != 0) return result; List<Model.DocumentStock> resultDocStocks = result.ReturnValue as List<Model.DocumentStock>; if (resultDocStocks == null) { result.ResultStatus = -1; result.Message = "制单库存明细获取失败"; return result; } foreach (Model.DocumentStock docStock in resultDocStocks) { result = docStockDAL.Invalid(user, docStock); if (result.ResultStatus != 0) return result; } result = docInvoiceDAL.Load(user,resultDoc.DocumentId); if(result.ResultStatus!=0) return result; List<Model.DocumentInvoice> resultDocInvoices = result.ReturnValue as List<Model.DocumentInvoice>; if (resultDocInvoices == null) { result.ResultStatus = -1; result.Message = "制单发票明细获取失败"; return result; } foreach (Model.DocumentInvoice docInvoice in resultDocInvoices) { result = docInvoiceDAL.Invalid(user, docInvoice); if (result.ResultStatus != 0) return result; } //明细新增 foreach (Model.DocumentStock docStock in docStocks) { //验证选择明细是否在指令中 Model.DocumentOrderStock orderStock = orderStocks.FirstOrDefault(temp => temp.DetailId == docStock.DetailId); if (orderStock == null || orderStock.DetailId <= 0) { result.ResultStatus = -1; result.Message = "制单指令库存不存在"; return result; } //新增制单库存明细 Model.DocumentStock addDocStock = new DocumentStock(); addDocStock.DetailStatus = StatusEnum.已生效; addDocStock.OrderId = resultDoc.OrderId; addDocStock.OrderStockDetailId = orderStock.DetailId; addDocStock.RefNo = orderStock.RefNo; addDocStock.StockId = orderStock.StockId; addDocStock.StockNameId = orderStock.StockNameId; addDocStock.DocumentId = resultDoc.DocumentId; result = docStockDAL.Insert(user, addDocStock); if (result.ResultStatus != 0) return result; int docStockDetailId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out docStockDetailId) || docStockDetailId <= 0) { result.ResultStatus = -1; result.Message = "制单库存明细新增失败"; return result; } addDocStock.DetailId = docStockDetailId; //获取指令发票明细 result = orderInvoiceDAL.GetByStockDetailId(user, orderStock.DetailId); if (result.ResultStatus != 0) return result; Model.DocumentOrderInvoice orderInvoice = result.ReturnValue as Model.DocumentOrderInvoice; if (orderInvoice == null || orderInvoice.DetailId <= 0) { result.ResultStatus = -1; result.Message = "制单指令发票明细不存在"; return result; } Model.DocumentInvoice docInvoice = new DocumentInvoice(); docInvoice.DetailStatus = StatusEnum.已生效; docInvoice.DocumentId = resultDoc.DocumentId; docInvoice.InvoiceNo = orderInvoice.InvoiceNo; docInvoice.InvoiceBala = orderInvoice.InvoiceBala; docInvoice.OrderId = resultDoc.OrderId; docInvoice.OrderInvoiceDetailId = orderInvoice.DetailId; docInvoice.StockDetailId = addDocStock.DetailId; result = docInvoiceDAL.Insert(user, docInvoice); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = resultDoc; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public override IModel CreateModel(SqlDataReader dr) { DocumentInvoice documentinvoice = new DocumentInvoice(); int indexDetailId = dr.GetOrdinal("DetailId"); documentinvoice.DetailId = Convert.ToInt32(dr[indexDetailId]); int indexDocumentId = dr.GetOrdinal("DocumentId"); if (dr["DocumentId"] != DBNull.Value) { documentinvoice.DocumentId = Convert.ToInt32(dr[indexDocumentId]); } int indexOrderId = dr.GetOrdinal("OrderId"); if (dr["OrderId"] != DBNull.Value) { documentinvoice.OrderId = Convert.ToInt32(dr[indexOrderId]); } int indexStockDetailId = dr.GetOrdinal("StockDetailId"); if (dr["StockDetailId"] != DBNull.Value) { documentinvoice.StockDetailId = Convert.ToInt32(dr[indexStockDetailId]); } int indexOrderInvoiceDetailId = dr.GetOrdinal("OrderInvoiceDetailId"); if (dr["OrderInvoiceDetailId"] != DBNull.Value) { documentinvoice.OrderInvoiceDetailId = Convert.ToInt32(dr[indexOrderInvoiceDetailId]); } int indexInvoiceNo = dr.GetOrdinal("InvoiceNo"); if (dr["InvoiceNo"] != DBNull.Value) { documentinvoice.InvoiceNo = Convert.ToString(dr[indexInvoiceNo]); } int indexInvoiceId = dr.GetOrdinal("InvoiceId"); if (dr["InvoiceId"] != DBNull.Value) { documentinvoice.InvoiceId = Convert.ToInt32(dr[indexInvoiceId]); } int indexInvoiceBala = dr.GetOrdinal("InvoiceBala"); if (dr["InvoiceBala"] != DBNull.Value) { documentinvoice.InvoiceBala = Convert.ToDecimal(dr[indexInvoiceBala]); } int indexDetailStatus = dr.GetOrdinal("DetailStatus"); if (dr["DetailStatus"] != DBNull.Value) { documentinvoice.DetailStatus = (StatusEnum)Convert.ToInt32(dr[indexDetailStatus]); } int indexCreatorId = dr.GetOrdinal("CreatorId"); if (dr["CreatorId"] != DBNull.Value) { documentinvoice.CreatorId = Convert.ToInt32(dr[indexCreatorId]); } int indexCreateTime = dr.GetOrdinal("CreateTime"); if (dr["CreateTime"] != DBNull.Value) { documentinvoice.CreateTime = Convert.ToDateTime(dr[indexCreateTime]); } int indexLastModifyId = dr.GetOrdinal("LastModifyId"); if (dr["LastModifyId"] != DBNull.Value) { documentinvoice.LastModifyId = Convert.ToInt32(dr[indexLastModifyId]); } int indexLastModifyTime = dr.GetOrdinal("LastModifyTime"); if (dr["LastModifyTime"] != DBNull.Value) { documentinvoice.LastModifyTime = Convert.ToDateTime(dr[indexLastModifyTime]); } return documentinvoice; }