Files
U8-Import/NX.ERP.U8/AP/APVouch.cs
杰 朱 615368f90e 1
2022-05-20 14:26:02 +08:00

341 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
using Dapper;
namespace NX.ERP.U8.AP
{
public class APVouch : STVoucherBase
{
public APVouch() : base("应付单", "U8API/APVouch")
{
}
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(STVoucherParameter para)
{
try
{
U8EnvContext u8EnvContext = new U8EnvContext();
u8EnvContext.U8Login = U8LoginContext.Instance.ClsLogin;
U8ApiAddress apiAddress = new U8ApiAddress(this.LoadUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
u8EnvContext.SetApiContext("VouchType", this.VoucherID);
u8ApiBroker.AssignNormalValue("linkid", "");
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);
}
para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue());
para.ErrMsg = u8ApiBroker.GetResult("xmlmsg") as string;
u8ApiBroker.Release();
}
catch (Exception err)
{
throw err;
}
}
protected override string AddRdVoucher(STVoucherParameter para)
{
U8EnvContext u8EnvContext = new U8EnvContext
{
U8Login = U8LoginContext.Instance.ClsLogin
};
U8ApiAddress apiAddress = new U8ApiAddress(this.AddUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
try
{
u8EnvContext.SetApiContext("VouchType", this.VoucherID);
u8ApiBroker.AssignNormalValue("ohead", para.DomHead);
u8ApiBroker.AssignNormalValue("obody", para.DomBody);
//给普通参数isadd赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示true新增,false修改
u8ApiBroker.AssignNormalValue("isadd", true);
if (para.DOMMsg != null)
{
u8ApiBroker.AssignNormalValue("xmlmsg", para.DOMMsg);
}
else
{
u8ApiBroker.AssignNormalValue("xmlmsg", new DOMDocumentClass());
}
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;
}
para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue());
para.ErrMsg = u8ApiBroker.GetResult("xmlmsg") as string;
if (!para.ReturnValue)
{
throw new Exception(para.ErrMsg);
}
return "";
}
catch (Exception err)
{
throw err;
}
finally
{
u8ApiBroker.Release();
}
}
public string AddVocher(NX.ERP.Model.Request.ApVouch ApVouch)
{
var id = Guid.NewGuid().ToString().Replace("-", "");
var vhobj = new NX.ERP.U8.VoucherHistory();
var maxnumber = vhobj.ApVouchGetNumber(ApVouch.Date.ToString("yyyyMM"));
if (maxnumber == null)
{
maxnumber = "1";
}
else
{
maxnumber = (int.Parse(maxnumber) + 1).ToString();
}
string temp = "";
//补足0
for (int i = 0; i < 5 - maxnumber.Length; i++)
{
temp += "0";
}
var mouthstr = ApVouch.Date.ToString("yyyyMM").Substring(2, 4);
string cVouchID = "QTYF" + mouthstr + temp + maxnumber;
STVoucherParameter voucherParameter = new STVoucherParameter
{
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");
// 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);
headXml.setAttribute("cVouchID", cVouchID);
headXml.setAttribute("cFlag", "AP");
headXml.setAttribute("cDeptCode", ApVouch.DeptCode);
headXml.setAttribute("cDigest", ApVouch.Digest);
var user = new NX.ERP.U8.User.UserDal().GetModel(ApVouch.UserCode);
if (user != null)
{
// headXml.setAttribute("cCheckMan", user.UserName);
headXml.setAttribute("cOperator", user.Name);
} else
{
// headXml.setAttribute("cCheckMan", ApVouch.UserCode);
headXml.setAttribute("cOperator", ApVouch.UserCode);
}
headXml.setAttribute("cDefine10", id);
var supplier = new SupplierDAL().GetModel(ApVouch.supplierCode);
if (supplier==null)
{
throw new Exception($"未知供应商(${ApVouch.supplierCode})");
}
var per = new NX.ERP.U8.User.UserDal().GetModel(supplier.VenPPerson);
headXml.setAttribute("cPerson", supplier.VenPPerson);
if (per != null)
{
headXml.setAttribute("cPersonName", per.Name);
}
// headXml.setAttribute("cLink", "");
IXMLDOMElement bodyXml;
//for (var n = 0; n < storeIn.details.Count(); n++)
//{
//var detail = storeIn.details[n];
bodyXml = domBody.createElement("z:row");
bodyXml.setAttribute("cDeptCode", ApVouch.DeptCode);
bodyXml.setAttribute("cCode", "");
bodyXml.setAttribute("iExchRate", 1);
bodyXml.setAttribute("cPerson", supplier.VenPPerson);
if (per != null)
{
headXml.setAttribute("cPersonName", per.Name);
}
bodyXml.setAttribute("cexch_name", "人民币");
bodyXml.setAttribute("iAmount", ApVouch.Amount);
bodyXml.setAttribute("iAmount_f", ApVouch.Amount);
bodyXml.setAttribute("iAmt_s", 0);
// bodyXml.setAttribute("cLink", "");
headXml.setAttribute("cDwCode", ApVouch.supplierCode);
bodyXml.setAttribute("bd_c", true);
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
//}
domHead.selectSingleNode("//rs:data").appendChild(headXml);
try
{
AddRdVoucher(voucherParameter);
var number = new NX.ERP.U8.VoucherHistory();
number.ApVouchIncNumber(maxnumber, ApVouch.Date.ToString("yyyyMM"));
var strsql = "select Auto_ID from AP_ApVouch where cDefine10=@id";
string code = "";
using (var conn = NX.ERP.U8.U8LoginContext.Instance.Connection)
{
code = conn.ExecuteScalar<string>(strsql, new { id }, null, 30, System.Data.CommandType.Text);
}
return code;
}
catch (Exception err)
{
throw err;
}
}
}
}