Files
U8-Import/NX.ERP.U8/AP/APVouch.cs

265 lines
8.5 KiB
C#
Raw Normal View History

2021-05-11 19:35:30 +08:00
using MSXML2;
using NX.ERP.U8.Store;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8MOMAPIFramework;
namespace NX.ERP.U8.AP
{
public class APVouch : VoucherBase
{
public APVouch() : base("应付单", "U8API/APVouch")
{
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
}
protected override string AddUrl
{
get
{
return $"{BaseUrl}/SaveVouch";
}
}
protected override string LoadUrl
{
get
{
return $"{BaseUrl}/GetVouchData";
}
}
protected override string UpdateUrl
{
get
{
return $"{BaseUrl}/SaveVouch";
}
}
protected override void LoadRdVoucher(VoucherParameter para)
{
try
{
U8EnvContext u8EnvContext = new U8EnvContext();
u8EnvContext.U8Login = U8LoginContext.Instance.ClsLogin;
U8ApiAddress apiAddress = new U8ApiAddress(this.LoadUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
2021-05-22 16:37:58 +08:00
u8EnvContext.SetApiContext("VouchType", this.VoucherID);
u8ApiBroker.AssignNormalValue("linkid", "");
2021-05-11 19:35:30 +08:00
if (!u8ApiBroker.Invoke())
{
Exception exception = u8ApiBroker.GetException();
if (exception != null)
{
if (exception is MomSysException)
{
MomSysException ex = exception as MomSysException;
}
else if (exception is MomBizException)
{
MomBizException ex2 = exception as MomBizException;
}
string exceptionString = u8ApiBroker.GetExceptionString();
if (exceptionString.Length != 0)
{
}
}
para.ReturnValue = false;
u8ApiBroker.Release();
return;
}
DOMDocument dOMDocument = u8ApiBroker.GetResult("ohead") as DOMDocument;
if (dOMDocument != null)
{
para.DomHead = new DOMDocumentClass();
para.DomHead.loadXML(dOMDocument.xml);
}
DOMDocument dOMDocument2 = u8ApiBroker.GetResult("obody") as DOMDocument;
if (dOMDocument2 != null)
{
para.DomBody = new DOMDocumentClass();
para.DomBody.loadXML(dOMDocument2.xml);
}
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue());
para.ErrMsg = u8ApiBroker.GetResult("xmlmsg") as string;
u8ApiBroker.Release();
}
catch (Exception err)
{
throw err;
}
}
protected override string AddRdVoucher(VoucherParameter para)
{
try
{
U8EnvContext u8EnvContext = new U8EnvContext();
u8EnvContext.U8Login = U8LoginContext.Instance.ClsLogin;
U8ApiAddress apiAddress = new U8ApiAddress(this.AddUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
u8EnvContext.SetApiContext("VouchType", this.VoucherID);
u8ApiBroker.AssignNormalValue("ohead", para.DomHead);
u8ApiBroker.AssignNormalValue("obody", para.DomBody);
//给普通参数isadd赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示true新增,false修改
2021-05-22 16:37:58 +08:00
u8ApiBroker.AssignNormalValue("isadd", true);
2021-05-11 19:35:30 +08:00
if (para.DOMMsg != null)
{
u8ApiBroker.AssignNormalValue("xmlmsg", para.DOMMsg);
}
else
{
u8ApiBroker.AssignNormalValue("xmlmsg", new DOMDocumentClass());
}
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
// u8ApiBroker.AssignNormalValue("bReMote", para.IsReMote);
if (!u8ApiBroker.Invoke())
{
Exception exception = u8ApiBroker.GetException();
if (exception != null)
{
if (exception is MomSysException)
{
MomSysException ex = exception as MomSysException;
}
else if (exception is MomBizException)
{
MomBizException ex2 = exception as MomBizException;
}
string exceptionString = u8ApiBroker.GetExceptionString();
if (exceptionString.Length != 0)
{
}
}
para.ReturnValue = false;
u8ApiBroker.Release();
}
para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue());
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
para.ErrMsg = u8ApiBroker.GetResult("xmlmsg") as string;
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
u8ApiBroker.Release();
2021-05-22 16:37:58 +08:00
if (!para.ReturnValue)
{
throw new Exception(para.ErrMsg);
}
2021-05-11 19:35:30 +08:00
return "";
}
catch (Exception err)
{
throw err;
}
finally
{
}
}
2021-05-22 16:37:58 +08:00
public string AddVocher(NX.ERP.Model.Request.ApVouch ApVouch)
2021-05-11 19:35:30 +08:00
{
VoucherParameter voucherParameter = new VoucherParameter
{
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);
IXMLDOMElement headXml = domHead.createElement("z:row");
2021-05-22 16:37:58 +08:00
// headXml.setAttribute("cVenAbbName", "无锡市鑫奥");
headXml.setAttribute("cDwCode", ApVouch.supplierCode);
headXml.setAttribute("dVouchDate",ApVouch.Date);
headXml.setAttribute("iExchRate", 1);
headXml.setAttribute("iAmount_f",ApVouch.Amount);
headXml.setAttribute("iRAmount", ApVouch.Amount);
headXml.setAttribute("cVouchType", "P0");
headXml.setAttribute("cTypeName", "其他应付单");
headXml.setAttribute("cCode", "220201");
headXml.setAttribute("cexch_name", "人民币");
headXml.setAttribute("VT_ID", 8056);
headXml.setAttribute("bd_c", false);
headXml.setAttribute("bStartFlag", false);
2021-05-25 13:17:26 +08:00
headXml.setAttribute("cVouchID", "664");
2021-05-22 16:37:58 +08:00
headXml.setAttribute("cFlag", "AP");
headXml.setAttribute("cDeptCode", ApVouch.DeptCode);
headXml.setAttribute("cDigest", ApVouch.Digest);
2021-05-25 13:17:26 +08:00
headXml.setAttribute("cLink", "664");
2021-05-11 19:35:30 +08:00
IXMLDOMElement bodyXml;
2021-05-22 16:37:58 +08:00
2021-05-11 19:35:30 +08:00
//for (var n = 0; n < storeIn.details.Count(); n++)
//{
2021-05-22 16:37:58 +08:00
//var detail = storeIn.details[n];
bodyXml = domBody.createElement("z:row");
bodyXml.setAttribute("cDeptCode", ApVouch.DeptCode);
bodyXml.setAttribute("cCode", "");
bodyXml.setAttribute("iExchRate", 1);
bodyXml.setAttribute("cexch_name", "人民币");
bodyXml.setAttribute("iAmount", ApVouch.Amount);
bodyXml.setAttribute("iAmount_f", ApVouch.Amount);
bodyXml.setAttribute("iAmt_s", 0);
2021-05-25 13:17:26 +08:00
bodyXml.setAttribute("cLink", "664");
2021-05-22 16:37:58 +08:00
headXml.setAttribute("cDwCode", ApVouch.supplierCode);
bodyXml.setAttribute("bd_c", true);
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
2021-05-11 19:35:30 +08:00
//}
domHead.selectSingleNode("//rs:data").appendChild(headXml);
var str = voucherParameter.DomBody.xml;
Console.WriteLine(str);
try
{
return AddRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
}
}