Files
U8-Import/NX.ERP.U8/Store/OtherStoreInDAL.cs
2021-03-15 16:32:40 +08:00

171 lines
6.0 KiB
C#

using MSXML2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NX.ERP.U8.Store
{
public class OtherStoreInDAL : VoucherBase
{
public OtherStoreInDAL() : base("08", "U8API/otherin")
{
}
public string AddVocher(Model.Request.OtherStoreInOut storeIn)
{
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");
headXml.setAttribute("bpufirst", "0");
headXml.setAttribute("bisstqc", "0");
headXml.setAttribute("bomfirst", "0");
headXml.setAttribute("biafirst", "0");
headXml.setAttribute("brdflag", 1);
headXml.setAttribute("ccode", storeIn.Code);
headXml.setAttribute("ddate", storeIn.Date);
headXml.setAttribute("cmaker", storeIn.Maker);
headXml.setAttribute("cvouchtype", this.VoucherID);
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("0301"));
headXml.setAttribute("editprop", "A");
headXml.setAttribute("cdepcode", "");
headXml.setAttribute("cpersoncode", "");
headXml.setAttribute("crdcode", "");
headXml.setAttribute("csource", "库存");
headXml.setAttribute("cwhcode", storeIn.WhCode);
headXml.setAttribute("cbustype", "其他入库");
headXml.setAttribute("cmemo", "");
IXMLDOMElement bodyXml;
for (var n = 0; n < storeIn.details.Count(); n++)
{
var detail = storeIn.details[n];
bodyXml = domBody.createElement("z:row");
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
bodyXml.setAttribute("irowno", n + 1);
bodyXml.setAttribute("cbatch", "");
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("cvmivencode", "");
bodyXml.setAttribute("dmadedate", "");
bodyXml.setAttribute("dvdate", "");
bodyXml.setAttribute("iexpiratdatecalcu", "");
bodyXml.setAttribute("cmassunit", "");
bodyXml.setAttribute("imassdate", "");
bodyXml.setAttribute("cexpirationdate", "");
bodyXml.setAttribute("dexpirationdate", "");
bodyXml.setAttribute("citem_class", "");
bodyXml.setAttribute("citemcode", "");
bodyXml.setAttribute("cbmemo", "");
bodyXml.setAttribute("editprop", "A");
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
}
domHead.selectSingleNode("//rs:data").appendChild(headXml);
var str = voucherParameter.DomBody.xml;
Console.WriteLine(str);
try
{
return AddRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
public string SaveVoucher(Model.Request.OtherStoreInOut storeIn)
{
var voucherParameter = this.LoadVoucher($"id='{storeIn.Id}'");
if (voucherParameter.DomHead.selectSingleNode("//rs:data").childNodes.length == 0)
{
return this.AddVocher(storeIn);
}
else
{
if (this.UpdateVocher(storeIn, voucherParameter))
{
return storeIn.Id.ToString();
}
else
{
throw new Exception("保存错误");
}
}
}
public bool UpdateVocher(Model.Request.OtherStoreInOut storeIn, VoucherParameter voucherParameter = null)
{
if (voucherParameter == null)
{
voucherParameter = base.LoadVoucher($" id={storeIn.Id}");
}
DOMDocument domBody = voucherParameter.DomBody;
for (var n = 0; n < storeIn.details.Count(); n++)
{
var detail = storeIn.details[n];
var bodyXml = domBody.createElement("z:row");
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
bodyXml.setAttribute("cbatch", "");
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("cvmivencode", "");
bodyXml.setAttribute("dmadedate", "");
bodyXml.setAttribute("dvdate", "");
bodyXml.setAttribute("iexpiratdatecalcu", "");
bodyXml.setAttribute("cmassunit", "");
bodyXml.setAttribute("imassdate", "");
bodyXml.setAttribute("cexpirationdate", "");
bodyXml.setAttribute("dexpirationdate", "");
bodyXml.setAttribute("citem_class", "");
bodyXml.setAttribute("citemcode", "");
bodyXml.setAttribute("cbmemo", "");
bodyXml.setAttribute("editprop", "A");
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
}
var str = voucherParameter.DomBody.xml;
Console.WriteLine(str);
try
{
return base.UpdateRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
}
}