Files
U8-Import/NX.ERP.U8/Store/STVoucherBase.cs
2021-05-29 10:18:22 +08:00

434 lines
13 KiB
C#

using MSXML2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8MOMAPIFramework;
namespace NX.ERP.U8.Store
{
/// <summary>
/// 库存模板基础类
/// </summary>
public abstract class STVoucherBase
{
private string voucherID;
protected string BaseUrl;
private static string BasePath;
private const string FLODER_NAME = "xml";
static STVoucherBase()
{
BasePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FLODER_NAME);
if (!Directory.Exists(BasePath))
{
Directory.CreateDirectory(BasePath);
}
}
private string BodyFile
{
get
{
return System.IO.Path.Combine(BasePath, $"XMLDomBody{this.voucherID}.xml");
}
}
private string HeadFile
{
get
{
return System.IO.Path.Combine(BasePath, $"XMLDomHead{this.voucherID}.xml");
}
}
protected virtual string LoadUrl
{
get
{
return $"{BaseUrl}/Load";
}
}
protected virtual string AddUrl
{
get
{
return $"{BaseUrl}/Add";
}
}
protected virtual string UpdateUrl
{
get
{
return $"{BaseUrl}/Update";
}
}
protected string VoucherID
{
get
{
return this.voucherID;
}
}
public STVoucherBase(string voucherID, string Url)
{
this.voucherID = voucherID;
this.BaseUrl = Url;
}
protected string HeadTemplate
{
get
{
return this.GetHeadTemplate();
}
}
protected string BodyTemplate
{
get
{
return this.GetBodyTemplate();
}
}
private string GetHeadTemplate()
{
var strTemlate = FileHelp.ReadFile(HeadFile);
if (strTemlate == string.Empty)
{
this.LoadTemplate();
strTemlate = GetHeadTemplate();
}
return strTemlate;
}
private string GetBodyTemplate()
{
var strTemlate = FileHelp.ReadFile(BodyFile);
if (strTemlate == string.Empty)
{
this.LoadTemplate();
strTemlate = GetBodyTemplate();
}
return strTemlate;
}
protected virtual 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);
u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType);
u8ApiBroker.AssignNormalValue("sWhere", para.StrWhere);
u8ApiBroker.AssignNormalValue("domPos", new DOMDocumentClass());
u8ApiBroker.AssignNormalValue("bGetBlank", para.IsGetBlank);
u8ApiBroker.AssignNormalValue("sBodyWhere_Order", para.SBodyWhere_Order);
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("DomHead") as DOMDocument;
if (dOMDocument != null)
{
para.DomHead = new DOMDocumentClass();
para.DomHead.loadXML(dOMDocument.xml);
}
DOMDocument dOMDocument2 = u8ApiBroker.GetResult("domBody") as DOMDocument;
if (dOMDocument2 != null)
{
para.DomBody = new DOMDocumentClass();
para.DomBody.loadXML(dOMDocument2.xml);
}
DOMDocument dOMDocument3 = u8ApiBroker.GetResult("domPos") as DOMDocument;
if (dOMDocument3 != null)
{
para.DomPosition = new DOMDocumentClass();
para.DomPosition.loadXML(dOMDocument3.xml);
}
para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue());
para.ErrMsg = u8ApiBroker.GetResult("errMsg") as string;
u8ApiBroker.Release();
}
catch (Exception err)
{
throw err;
}
}
protected bool UpdateRdVoucher(STVoucherParameter para)
{
try
{
U8EnvContext u8EnvContext = new U8EnvContext();
u8EnvContext.U8Login = U8LoginContext.Instance.ClsLogin;
U8ApiAddress apiAddress = new U8ApiAddress(this.UpdateUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType);
u8ApiBroker.AssignNormalValue("DomHead", para.DomHead);
u8ApiBroker.AssignNormalValue("domBody", para.DomBody);
if (para.DomPosition != null && para.DomPosition.selectNodes("//z:row").length != 0)
{
u8ApiBroker.AssignNormalValue("domPosition", para.DomPosition);
}
u8ApiBroker.AssignNormalValue("cnnFrom", null);
if (para.DOMMsg != null)
{
u8ApiBroker.AssignNormalValue("domMsg", para.DOMMsg);
}
else
{
u8ApiBroker.AssignNormalValue("domMsg", new DOMDocumentClass());
}
u8ApiBroker.AssignNormalValue("bCheck", para.IsCheck);
u8ApiBroker.AssignNormalValue("bBeforCheckStock", para.IsBeforCheckStock);
u8ApiBroker.AssignNormalValue("bIsRedVouch", para.IsRedVouch);
u8ApiBroker.AssignNormalValue("sAddedState", para.AddedState);
u8ApiBroker.AssignNormalValue("bUpdateNeedEas", true);
// 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());
para.DOMMsg = u8ApiBroker.GetResult("domMsg") as DOMDocument;
para.ErrMsg = u8ApiBroker.GetResult("errMsg") as string;
if (!para.ReturnValue)
{
throw new Exception(para.ErrMsg);
}
u8ApiBroker.Release();
return true;
}
catch (Exception err)
{
throw err;
}
finally
{
}
}
protected virtual string AddRdVoucher(STVoucherParameter para)
{
string VoucherId;
try
{
U8EnvContext u8EnvContext = new U8EnvContext();
u8EnvContext.U8Login = U8LoginContext.Instance.ClsLogin;
U8ApiAddress apiAddress = new U8ApiAddress(this.AddUrl);
U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext);
u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType);
u8ApiBroker.AssignNormalValue("DomHead", para.DomHead);
u8ApiBroker.AssignNormalValue("domBody", para.DomBody);
if (para.DomPosition != null && para.DomPosition.selectNodes("//z:row").length != 0)
{
u8ApiBroker.AssignNormalValue("domPosition", para.DomPosition);
}
if (para.cnnFrom!=null)
{
u8ApiBroker.AssignNormalValue("cnnFrom", para.cnnFrom);
} else
{
u8ApiBroker.AssignNormalValue("cnnFrom",null);
}
if (para.DOMMsg != null)
{
u8ApiBroker.AssignNormalValue("domMsg", para.DOMMsg);
}
else
{
u8ApiBroker.AssignNormalValue("domMsg", new DOMDocumentClass());
}
u8ApiBroker.AssignNormalValue("bCheck", para.IsCheck);
u8ApiBroker.AssignNormalValue("bBeforCheckStock", para.IsBeforCheckStock);
u8ApiBroker.AssignNormalValue("bIsRedVouch", para.IsRedVouch);
u8ApiBroker.AssignNormalValue("sAddedState", para.AddedState);
// 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());
para.DOMMsg = u8ApiBroker.GetResult("domMsg") as DOMDocument;
para.ErrMsg = u8ApiBroker.GetResult("errMsg") as string;
if (para.ReturnValue)
{
para.VoucherId = u8ApiBroker.GetResult("VouchId") as string;
VoucherId = para.VoucherId;
}
else
{
throw new Exception(para.ErrMsg);
}
u8ApiBroker.Release();
return VoucherId;
}
catch (Exception err)
{
throw err;
}
finally
{
}
}
protected STVoucherParameter LoadVoucher(string where)
{
var rdVoucherParameter = new STVoucherParameter
{
VoucherType = this.VoucherID,
IsGetBlank = false,
StrWhere = where
};
this.LoadRdVoucher(rdVoucherParameter);
return rdVoucherParameter;
}
private void LoadTemplate()
{
STVoucherParameter rdVoucherParameter = null;
try
{
rdVoucherParameter = new STVoucherParameter
{
VoucherType = this.VoucherID,
IsGetBlank = true
};
this.LoadRdVoucher(rdVoucherParameter);
if (rdVoucherParameter.ReturnValue)
{
FileHelp.WriteFile(rdVoucherParameter.DomHead.xml, HeadFile);
FileHelp.WriteFile(rdVoucherParameter.DomBody.xml, BodyFile);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}