Files
U8-Import/NX.ERP.U8/Store/OtherStoreInDAL.cs

171 lines
6.0 KiB
C#
Raw Normal View History

2021-01-12 16:10:37 +08:00
using MSXML2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NX.ERP.U8.Store
{
public class OtherStoreInDAL : VoucherBase
{
2021-01-13 12:37:27 +08:00
public OtherStoreInDAL() : base("08", "U8API/otherin")
2021-01-12 16:10:37 +08:00
{
}
2021-01-15 10:22:35 +08:00
public string AddVocher(Model.Request.OtherStoreInOut storeIn)
2021-01-12 16:10:37 +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");
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);
2021-03-15 11:24:16 +08:00
headXml.setAttribute("cmaker", storeIn.Maker);
2021-01-12 16:10:37 +08:00
headXml.setAttribute("cvouchtype", this.VoucherID);
2021-03-15 11:24:16 +08:00
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("0301"));
2021-01-12 16:10:37 +08:00
headXml.setAttribute("editprop", "A");
headXml.setAttribute("cdepcode", "");
headXml.setAttribute("cpersoncode", "");
headXml.setAttribute("crdcode", "");
2021-01-13 09:02:37 +08:00
headXml.setAttribute("csource", "库存");
2021-01-12 16:10:37 +08:00
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);
2021-01-13 09:02:37 +08:00
bodyXml.setAttribute("irowno", n + 1);
2021-01-12 16:10:37 +08:00
bodyXml.setAttribute("cbatch", "");
bodyXml.setAttribute("cposition", detail.Position);
2021-01-13 09:02:37 +08:00
bodyXml.setAttribute("cvmivencode", "");
2021-01-12 16:10:37 +08:00
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
{
2021-01-13 13:30:24 +08:00
return AddRdVoucher(voucherParameter);
2021-01-12 16:10:37 +08:00
}
catch (Exception err)
{
throw err;
}
}
2021-03-15 11:24:16 +08:00
2021-03-15 16:32:40 +08:00
public string SaveVoucher(Model.Request.OtherStoreInOut storeIn)
2021-03-15 11:24:16 +08:00
{
2021-03-15 16:32:40 +08:00
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("保存错误");
}
}
}
2021-03-15 11:24:16 +08:00
2021-03-15 16:32:40 +08:00
public bool UpdateVocher(Model.Request.OtherStoreInOut storeIn, VoucherParameter voucherParameter = null)
{
if (voucherParameter == null)
{
voucherParameter = base.LoadVoucher($" id={storeIn.Id}");
}
2021-03-15 11:24:16 +08:00
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;
}
}
2021-01-12 16:10:37 +08:00
}
}