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

183 lines
5.5 KiB
C#
Raw Normal View History

2021-01-13 15:02:56 +08:00
using MSXML2;
2021-01-18 15:07:20 +08:00
using NX.ERP.Model.Request;
2021-01-13 15:02:56 +08:00
using System;
2021-01-13 13:30:24 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NX.ERP.U8.Store
{
2021-05-29 10:18:22 +08:00
public class SaleOutDAL : STVoucherBase
2021-01-13 13:30:24 +08:00
{
public SaleOutDAL() : base("32", "U8API/saleout")
2021-01-13 14:02:33 +08:00
{
2021-01-13 13:30:24 +08:00
}
2021-01-13 15:02:56 +08:00
public string AddVoucher(SaleStoreOut storeOut)
2021-01-13 14:02:33 +08:00
{
2021-01-13 13:30:24 +08:00
2021-05-29 10:18:22 +08:00
STVoucherParameter voucherParameter = new STVoucherParameter
2021-01-13 15:02:56 +08:00
{
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("cvouchtype", this.VoucherID);//DomHead[0]["cvouchtype"] = ""; //单据类型,string类型
headXml.setAttribute("bpufirst", "0");
headXml.setAttribute("bisstqc", "0");
headXml.setAttribute("bomfirst", "0");
headXml.setAttribute("biafirst", "0");
headXml.setAttribute("brdflag", 0);
headXml.setAttribute("ccode", storeOut.Code);
headXml.setAttribute("ddate", storeOut.Date);
2021-01-21 13:42:23 +08:00
headXml.setAttribute("cmaker", storeOut.Maker);
2021-03-15 13:34:02 +08:00
2021-01-18 16:44:18 +08:00
headXml.setAttribute("vt_id", new VT().GetDefaltVTID("0303"));
2021-01-13 15:02:56 +08:00
headXml.setAttribute("editprop", "A");
headXml.setAttribute("cdepcode", "");
headXml.setAttribute("cpersoncode", "");
headXml.setAttribute("crdcode", "");
headXml.setAttribute("csource", storeOut.Source);
headXml.setAttribute("cwhcode", storeOut.WhCode);
if (storeOut.Source == "发货单")
{
var dispatch = new Sale.DispatchListDAL().GetModel(storeOut.SourceCode);
headXml.setAttribute("cbuscode", storeOut.SourceCode);
2021-01-21 16:20:31 +08:00
headXml.setAttribute("cdlcode", dispatch.SalesOrderId);
2021-01-13 15:02:56 +08:00
headXml.setAttribute("iarriveid", storeOut.SourceCode);
headXml.setAttribute("iflowid", "");
headXml.setAttribute("cbustype", "普通销售");
headXml.setAttribute("cstcode", "");
2021-02-06 10:41:27 +08:00
headXml.setAttribute("ccuscode", dispatch.CustomerCode);
2021-01-13 15:02:56 +08:00
headXml.setAttribute("cmemo", "");
IXMLDOMElement bodyXml;
for (var n = 0; n < storeOut.Details.Count; n++)
{
bodyXml = domBody.createElement("z:row");
var detail = storeOut.Details[n];
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
bodyXml.setAttribute("irowno", n + 1);
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("editprop", "A");
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
}
}
domHead.selectSingleNode("//rs:data").appendChild(headXml);
try
{
return AddRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
2021-01-13 13:30:24 +08:00
2021-03-15 15:50:14 +08:00
public string SaveVoucher(SaleStoreOut storeOut)
2021-03-15 13:13:01 +08:00
{
2021-03-15 15:50:14 +08:00
var voucherParameter = this.LoadVoucher($"id='{storeOut.Id}'");
if (voucherParameter.DomHead.selectSingleNode("//rs:data").childNodes.length == 0)
{
return this.AddVoucher(storeOut);
}
else
{
if (this.UpdateVoucher(storeOut, voucherParameter))
{
return storeOut.Id.ToString();
}
else
{
throw new Exception("保存错误");
}
2021-03-15 13:13:01 +08:00
2021-03-15 15:50:14 +08:00
}
}
2021-03-15 13:13:01 +08:00
2021-05-29 10:18:22 +08:00
public bool UpdateVoucher(SaleStoreOut storeOut, STVoucherParameter voucherParameter = null)
2021-03-15 15:50:14 +08:00
{
if (voucherParameter == null)
{
voucherParameter = this.LoadVoucher($"id='{storeOut.Id}'");
}
2021-03-15 13:13:01 +08:00
DOMDocument domBody = voucherParameter.DomBody;
IXMLDOMElement bodyXml;
if (storeOut.Source == "发货单")
{
var dispatch = new Sale.DispatchListDAL().GetModel(storeOut.SourceCode);
2021-03-15 13:34:02 +08:00
2021-03-15 13:13:01 +08:00
for (var n = 0; n < storeOut.Details.Count; n++)
{
bodyXml = domBody.createElement("z:row");
var detail = storeOut.Details[n];
bodyXml.setAttribute("cinvcode", detail.InvCode);
bodyXml.setAttribute("iquantity", detail.Quantity);
2021-03-15 13:34:02 +08:00
2021-03-15 13:13:01 +08:00
bodyXml.setAttribute("cposition", detail.Position);
bodyXml.setAttribute("editprop", "A");
bodyXml.setAttribute("irowno", domBody.selectSingleNode("//rs:data").childNodes.length + 1);
domBody.selectSingleNode("//rs:data").appendChild(bodyXml);
}
}
2021-03-15 13:34:02 +08:00
2021-03-15 13:13:01 +08:00
try
{
return UpdateRdVoucher(voucherParameter);
}
catch (Exception err)
{
throw err;
}
}
2021-01-13 13:30:24 +08:00
}
}