From f87905fd06f0fa80decad95fbf47f953323847d6 Mon Sep 17 00:00:00 2001 From: gongxh Date: Fri, 28 May 2021 12:03:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=86=E6=96=99=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NX.ERP.Model/NX.ERP.Model.csproj | 1 + NX.ERP.Model/Request/MaterialApp.cs | 43 ++++ NX.ERP.U8/NX.ERP.U8.csproj | 1 + NX.ERP.U8/Store/MaterialAppDAL.cs | 107 +++++++++- NX.ERP.U8/Store/VoucherBase.cs | 9 +- NX.ERP.U8/U8DbHelper.cs | 201 ++++++++++++++++++ NX.ERP.U8/VoucherParameter.cs | 4 + .../Store/MaterialAppController.cs | 6 +- 8 files changed, 357 insertions(+), 15 deletions(-) create mode 100644 NX.ERP.Model/Request/MaterialApp.cs create mode 100644 NX.ERP.U8/U8DbHelper.cs diff --git a/NX.ERP.Model/NX.ERP.Model.csproj b/NX.ERP.Model/NX.ERP.Model.csproj index 183d32e..71a47a3 100644 --- a/NX.ERP.Model/NX.ERP.Model.csproj +++ b/NX.ERP.Model/NX.ERP.Model.csproj @@ -71,6 +71,7 @@ + diff --git a/NX.ERP.Model/Request/MaterialApp.cs b/NX.ERP.Model/Request/MaterialApp.cs new file mode 100644 index 0000000..37f6fae --- /dev/null +++ b/NX.ERP.Model/Request/MaterialApp.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NX.ERP.Model.Request +{ + + + public class MaterialAppDetail + { + + public string MaterialCode { get; set; } + public decimal Qty { get; set; } + + public DateTime Duedate { get; set; } + + public int SourceDetailId { get; set; } + + + + + } + + + public class MaterialApp + { + /// + /// 生单日期 + /// + public DateTime Date { get; set; } + + public string source { get; set; } + + public string SourceCode { get; set; } + + public IEnumerable MaterialAppDetails = new List(); + + + + + } +} diff --git a/NX.ERP.U8/NX.ERP.U8.csproj b/NX.ERP.U8/NX.ERP.U8.csproj index 76ebdc9..4b12e2b 100644 --- a/NX.ERP.U8/NX.ERP.U8.csproj +++ b/NX.ERP.U8/NX.ERP.U8.csproj @@ -68,6 +68,7 @@ + diff --git a/NX.ERP.U8/Store/MaterialAppDAL.cs b/NX.ERP.U8/Store/MaterialAppDAL.cs index 09a8b5b..48ab38b 100644 --- a/NX.ERP.U8/Store/MaterialAppDAL.cs +++ b/NX.ERP.U8/Store/MaterialAppDAL.cs @@ -16,19 +16,104 @@ namespace NX.ERP.U8.Store } - public string AddVoucher(object param) + public string AddVoucher(NX.ERP.Model.Request.MaterialApp param) { - VoucherParameter voucherParameter = new VoucherParameter + //conn=new AccessViolationException + + U8DbHelper u8DbHelper = new U8DbHelper(NX.ERP.U8.U8LoginContext.Instance.Constr); + u8DbHelper.BeginTrans(); + + try { - VoucherType = this.VoucherID, - DomHead = new DOMDocumentClass(), - DomBody = new DOMDocumentClass() - }; - DOMDocument domHead = voucherParameter.DomHead; - DOMDocument domBody = voucherParameter.DomBody; - voucherParameter.DomHead.loadXML(HeadTemplate); - voucherParameter.DomBody.loadXML(BodyTemplate); - return ""; + + VoucherParameter voucherParameter = new VoucherParameter + { + VoucherType = this.VoucherID, + DomHead = new DOMDocumentClass(), + DomBody = new DOMDocumentClass(), + cnnFrom = u8DbHelper.Conn + }; + DOMDocument domHead = voucherParameter.DomHead; + DOMDocument domBody = voucherParameter.DomBody; + voucherParameter.DomHead.loadXML(HeadTemplate); + voucherParameter.DomBody.loadXML(BodyTemplate); + + IXMLDOMElement headXml = domHead.createElement("z:row"); + + headXml.setAttribute("id", "0"); + headXml.setAttribute("ccode", "AAAAA"); + headXml.setAttribute("ddate", param.Date); + headXml.setAttribute("vt_id", "30718"); + + headXml.setAttribute("csource", param.source); + headXml.setAttribute("cRdCode", "206"); + headXml.setAttribute("cDepCode", "5401"); + + Model.MOM.MomOrder Order = null; + if (param.source == "生产订单") + { + Order = new Mom.MomOrderDAL().GetModel(param.SourceCode); + + } + foreach (var item in param.MaterialAppDetails) + { + var bodyXml = domBody.createElement("z:row"); + bodyXml.setAttribute("autoid", 0); + bodyXml.setAttribute("cinvcode", item.MaterialCode); + bodyXml.setAttribute("iquantity", item.Qty); + bodyXml.setAttribute("dduedate", item.Duedate); + + + if (param.source == "生产订单") + { + var detail = Order.Allocates.FirstOrDefault(m => m.AllocateId == item.SourceDetailId); + + if (detail == null) + { + throw new Exception("未知的明细项"); + } + // + bodyXml.setAttribute("invcode", detail.momDetail.ProductCode); + bodyXml.setAttribute("cmocode", param.SourceCode); + bodyXml.setAttribute("imoseq", detail.momDetail.SortSeq); + bodyXml.setAttribute("iposeq", "000"); + bodyXml.setAttribute("iorderdid", 0); + bodyXml.setAttribute("iMPoIds", item.SourceDetailId); + bodyXml.setAttribute("ipesodid", item.SourceDetailId); + bodyXml.setAttribute("ipesotype", 7); + bodyXml.setAttribute("cpesocode", param.SourceCode); + bodyXml.setAttribute("ipesoseq", detail.momDetail.SortSeq); + ///下面更新 + /// + // var strsql = "update mom_moallocate set RequisitionIssQty=RequisitionIssQty+" + item.Qty + " where AllocateId=" + item.SourceDetailId; + //var row= u8DbHelper.U8ExcuteNoneQuery(strsql); + // if (row==0) + // { + // throw new Exception("未知明细"); + // } + + } + domBody.selectSingleNode("//rs:data").appendChild(bodyXml); + } + domHead.selectSingleNode("//rs:data").appendChild(headXml); + var code = this.AddRdVoucher(voucherParameter); + u8DbHelper.CommitTrans(); + return code; + } + catch (Exception err) + { + u8DbHelper.RollbackTrans(); + throw err; + } + finally + { + u8DbHelper.Dispose(); + } + + + + + } diff --git a/NX.ERP.U8/Store/VoucherBase.cs b/NX.ERP.U8/Store/VoucherBase.cs index 1aa9fd6..02ebf5e 100644 --- a/NX.ERP.U8/Store/VoucherBase.cs +++ b/NX.ERP.U8/Store/VoucherBase.cs @@ -303,7 +303,14 @@ namespace NX.ERP.U8.Store { u8ApiBroker.AssignNormalValue("domPosition", para.DomPosition); } - + if (para.cnnFrom != null) + { + u8ApiBroker.AssignNormalValue("cnnFrom", para.cnnFrom); + } + else + { + u8ApiBroker.AssignNormalValue("cnnFrom", null); + } u8ApiBroker.AssignNormalValue("cnnFrom", null); if (para.DOMMsg != null) { diff --git a/NX.ERP.U8/U8DbHelper.cs b/NX.ERP.U8/U8DbHelper.cs new file mode 100644 index 0000000..c019f18 --- /dev/null +++ b/NX.ERP.U8/U8DbHelper.cs @@ -0,0 +1,201 @@ +using ADODB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NX.ERP.U8 +{ + public class U8DbHelper:IDisposable + { + public string _connstring; + + private string string_0; + + public bool _DbErr; + + public Connection Conn; + + public string ConnectionString + { + get + { + return _connstring; + } + set + { + _connstring = value; + } + } + + public string ErrMsg + { + get + { + return string_0; + } + } + + public U8DbHelper(string connstr) + { + + _connstring = connstr; + if (_connstring != null && !(_connstring == string.Empty)) + { + Conn = new ConnectionClass(); + Conn.ConnectionString = _connstring; + try + { + Conn.Open(); + _DbErr = false; + } + catch (Exception) + { + _DbErr = true; + string_0 = "数据连接配置错误,无法从指定的数据连接字符串打开数据库,请检查WEB.CONFIG文件"; + throw new Exception(ErrMsg); + } + } + else + { + _DbErr = true; + string_0 = "数据连接配置错误,没有配置数据连接"; + } + } + + public U8DbHelper(Connection cnt) + { + + _connstring = cnt.ConnectionString; + Conn = cnt; + try + { + if (Conn.State != 1) + { + Conn.Open(); + _DbErr = false; + } + } + catch (Exception) + { + _DbErr = true; + string_0 = "数据连接配置错误,无法从指定的数据连接字符串打开数据库,请检查WEB.CONFIG文件"; + throw new Exception(ErrMsg); + } + } + + public static bool IsConn(string connectionString) + { + Connection connection = new ConnectionClass(); + try + { + connection.ConnectionString = connectionString; + connection.Open(); + } + catch + { + return false; + } + finally + { + if (connection.State == 1) + { + connection.Close(); + } + connection = null; + } + return true; + } + + public Recordset U8ExcuteRecord(string strSQL) + { + try + { + object RecordsAffected; + return Conn.Execute(strSQL, out RecordsAffected); + } + catch (Exception) + { + throw; + } + } + + public int U8ExcuteNoneQuery(string strSQL) + { + try + { + object RecordsAffected; + Conn.Execute(strSQL, out RecordsAffected); + return (int)RecordsAffected; + } + catch (Exception) + { + throw; + } + } + + public void BeginTrans() + { + try + { + if (Conn != null) + { + Conn.BeginTrans(); + } + } + catch (Exception) + { + throw; + } + } + + public void RollbackTrans() + { + try + { + if (Conn != null) + { + Conn.RollbackTrans(); + } + } + catch (Exception) + { + throw; + } + } + + public void CommitTrans() + { + try + { + if (Conn != null) + { + Conn.CommitTrans(); + } + } + catch (Exception) + { + throw; + } + } + + public void Dispose() + { + try + { + if (Conn != null) + { + if (Conn.State == 1) + { + Conn.Close(); + } + Conn = null; + } + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/NX.ERP.U8/VoucherParameter.cs b/NX.ERP.U8/VoucherParameter.cs index c96331e..4ab10cf 100644 --- a/NX.ERP.U8/VoucherParameter.cs +++ b/NX.ERP.U8/VoucherParameter.cs @@ -46,6 +46,10 @@ namespace NX.ERP.U8 private string sBodyWhere_Order; + + public ADODB.Connection cnnFrom { get; set; } = null; + + public string SBodyWhere_Order { get diff --git a/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs b/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs index fc0dd52..ba73b84 100644 --- a/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs +++ b/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs @@ -77,12 +77,12 @@ namespace NX.ERP.WebAPi.Controllers.Store } [Route("api/MaterialApp/Add")] - [HttpGet] + [HttpPost] - public string Add() + public string Add([FromBody]NX.ERP.Model.Request.MaterialApp param) { var dal = new NX.ERP.U8.Store.MaterialAppDAL(); - return dal.AddVoucher(null); + return dal.AddVoucher(param); }