using MSXML2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UFIDA.U8.U8APIFramework;
using UFIDA.U8.U8APIFramework.Parameter;
using UFIDA.U8.U8MOMAPIFramework;
namespace NX.ERP.U8.Store
{
public class PuStoreInDAL
{
public static string ReadFile(string strFileName)
{
if (!File.Exists(strFileName))
{
return string.Empty;
}
using (StreamReader streamReader = new StreamReader(strFileName, Encoding.Default))
{
return streamReader.ReadToEnd();
}
}
public static bool WriteFile(string strContentToFile, string strFilePathName, Encoding encoding)
{
using (StreamWriter streamWriter = new StreamWriter(strFilePathName, append: false, encoding))
{
streamWriter.Write(strContentToFile);
return true;
}
}
public static bool WriteFile(string strContentToFile, string strFilePathName)
{
using (StreamWriter streamWriter = new StreamWriter(strFilePathName, append: false, Encoding.Default))
{
streamWriter.Write(strContentToFile);
return true;
}
}
///
/// 保存一个采购到货单
///
///
public void AddPuStoreIn(Model.Store.PuStoreIn puStoreIn)
{
VoucherParameter voucherParameter = new VoucherParameter();
voucherParameter.VoucherType = "01";
voucherParameter.DomHead = new DOMDocumentClass();
voucherParameter.DomBody = new DOMDocumentClass();
DOMDocument domHead = voucherParameter.DomHead;
DOMDocument domBody = voucherParameter.DomBody;
voucherParameter.DomHead.loadXML(ReadFile(AppDomain.CurrentDomain.BaseDirectory + "\\XMLDOM\\XMLDomHead01.xml"));
voucherParameter.DomBody.loadXML(ReadFile(AppDomain.CurrentDomain.BaseDirectory + "\\XMLDOM\\XMLDomBody01.xml"));
IXMLDOMElement iXMLDOMElement = domHead.createElement("z:row");
iXMLDOMElement.setAttribute("id", "11"); //DomHead[0]["id"] = ""; //主关键字段,int类型
iXMLDOMElement.setAttribute("bomfirst", "0"); //DomHead[0]["bomfirst"] = ""; //委外期初标志,string类型
iXMLDOMElement.setAttribute("ccode", "211"); //DomHead[0]["ccode"] = ""; //入库单号,string类型
iXMLDOMElement.setAttribute("ddate", puStoreIn.Date.ToShortDateString()); //DomHead[0]["ddate"] = ""; //入库日期,DateTime类型
iXMLDOMElement.setAttribute("iverifystate", 1); //DomHead[0]["iverifystate"] = ""; //iverifystate,int类型
iXMLDOMElement.setAttribute("iswfcontrolled", 1); //DomHead[0]["iswfcontrolled"] = ""; //iswfcontrolled,int类型
//iXMLDOMElement.setAttribute("cbustype", "0"); //DomHead[0]["cbustype"] = ""; //业务类型,int类型
//iXMLDOMElement.setAttribute("iexchrate", 1); //DomHead[0]["iexchrate"] = ""; //汇率,double类型
//iXMLDOMElement.setAttribute("cexch_name", "人民币"); //DomHead[0]["cexch_name"] = ""; //币种,string类型
//iXMLDOMElement.setAttribute("ufts", "asdasd"); //DomHead[0]["ufts"] = ""; //时间戳,string类型
iXMLDOMElement.setAttribute("bpufirst", "0"); //DomHead[0]["bpufirst"] = ""; //采购期初标志,string类型
iXMLDOMElement.setAttribute("cvouchtype", "01");//DomHead[0]["cvouchtype"] = ""; //单据类型,string类型
iXMLDOMElement.setAttribute("brdflag", 1); //DomHead[0]["brdflag"] = ""; //收发标志,int类型
iXMLDOMElement.setAttribute("csource", puStoreIn.Source); //DomHead[0]["csource"] = ""; //单据来源,int类型
iXMLDOMElement.setAttribute("cmaker", U8LoginContext.Instance.LoginUserName);//DomHead[0]["cmaker"] = ""; //制单人,string类型
iXMLDOMElement.setAttribute("vt_id", "27");
iXMLDOMElement.setAttribute("editprop", "A");
iXMLDOMElement.setAttribute("cdepcode", puStoreIn.Depcode);
iXMLDOMElement.setAttribute("cpersoncode", puStoreIn.PersonCode);
iXMLDOMElement.setAttribute("crdcode", puStoreIn.RdCode);
iXMLDOMElement.setAttribute("cwhcode", "1");
iXMLDOMElement.setAttribute("bisstqc", "0");
iXMLDOMElement.setAttribute("bomfirst", "0");
if (puStoreIn.Source == "采购到货单")
{
var Arrival = new Purchase.ArrivalDAL().GetModel(puStoreIn.SourceCode);
//iXMLDOMElement.setAttribute("cvencode", puStoreIn.SupplierCode); //DomHead[0]["cvencode"] = ""; //供货单位编码,string类型
//iXMLDOMElement.setAttribute("cvenabbname", puStoreIn.SupplierName);//DomHead[0]["cvenabbname"] = ""; //供货单位,string类型
iXMLDOMElement.setAttribute("cbustype", Arrival.SupplierCode);
iXMLDOMElement.setAttribute("iexchrate", Arrival.ExchRate);
iXMLDOMElement.setAttribute("cexch_name", Arrival.ExchName);
iXMLDOMElement.setAttribute("cvencode", Arrival.VenCode);
iXMLDOMElement.setAttribute("carvcode", Arrival.ArrivalCode);
iXMLDOMElement.setAttribute("ipurarriveid", Arrival.Id);
iXMLDOMElement.setAttribute("darvdate", Arrival.Date);
iXMLDOMElement.setAttribute("itaxrate", Arrival.TaxRate);
iXMLDOMElement.setAttribute("cptcode", Arrival.PTCode);
domHead.selectSingleNode("//rs:data").appendChild(iXMLDOMElement);
for (var n = 0; n < puStoreIn.PuStoreInDetails.Count; n++)
{
var detail = puStoreIn.PuStoreInDetails[n];
var arrivalDetail = Arrival.ArrivalDetails.First(m => { return m.Id == detail.SorceDetailId; });
(domHead.selectSingleNode("//z:row") as IXMLDOMElement).setAttribute("cordercode", arrivalDetail.OrderCode);
(domHead.selectSingleNode("//z:row") as IXMLDOMElement).setAttribute("ipurorderid", arrivalDetail.PoId);
iXMLDOMElement = domBody.createElement("z:row");
iXMLDOMElement.setAttribute("cinvcode", detail.Invcode);
iXMLDOMElement.setAttribute("iquantity", detail.Quantity);
iXMLDOMElement.setAttribute("irowno", n);
iXMLDOMElement.setAttribute("cbvencode", "10001");
iXMLDOMElement.setAttribute("cbatch", detail.Batch);
iXMLDOMElement.setAttribute("carvcode", Arrival.ArrivalCode);
iXMLDOMElement.setAttribute("cbarvcode", Arrival.ArrivalCode);
iXMLDOMElement.setAttribute("ipurarriveid", Arrival.Id);
iXMLDOMElement.setAttribute("iarrsid", detail.SorceDetailId);
iXMLDOMElement.setAttribute("darvdate", DateTime.Today.ToShortDateString());
iXMLDOMElement.setAttribute("editprop", "A");
iXMLDOMElement.setAttribute("cpoid", arrivalDetail.OrderCode);
iXMLDOMElement.setAttribute("iposid", arrivalDetail.posId);
var info = new NX.ERP.U8.Account.Accinformation();
//iorimoney = FormatMoney(iunitcost * iQuan);
//ioritaxprice = FormatMoney(iunitcost * iQuan * (itaxrate / 100.0));
//iorisum = FormatMoney(iunitcost * (1.0 + itaxrate / 100.0) * iQuan);
//itaxcost = FormatUPrice(iunitcost * (1.0 + itaxrate / 100.0));
var iorisum = info.FormatMoney(arrivalDetail.oricost * (1.00 + (Arrival.TaxRate / 100.0)) * detail.Quantity);
var ioritaxprice = info.FormatMoney(arrivalDetail.oricost * (Arrival.TaxRate / 100.0) * detail.Quantity);
var iorimoney = info.FormatMoney(arrivalDetail.oricost * detail.Quantity);
var oritaxcost = info.FormatMoney(arrivalDetail.oricost * (1.00 + (Arrival.TaxRate / 100.0)));
iXMLDOMElement.setAttribute("ioricost", arrivalDetail.oricost);
iXMLDOMElement.setAttribute("ioritaxcost", oritaxcost);
iXMLDOMElement.setAttribute("iorimoney", iorimoney);
iXMLDOMElement.setAttribute("ioritaxprice", ioritaxprice);
iXMLDOMElement.setAttribute("iorisum", iorisum);
domBody.selectSingleNode("//rs:data").appendChild(iXMLDOMElement);
}
}
var str = voucherParameter.DomBody.xml;
Console.WriteLine(str);
U8LoginContext.Instance.AddRdVoucher("U8API/PuStoreIn/Add", voucherParameter);
}
public void Loadd()
{
VoucherParameter rdVoucherParameter = null;
try
{
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "XMLDOM"))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "XMLDOM");
}
rdVoucherParameter = new VoucherParameter();
rdVoucherParameter.VoucherType = "01";
rdVoucherParameter.IsGetBlank = true;
U8LoginContext.Instance.LoadRdVoucher(rdVoucherParameter);
if (!rdVoucherParameter.ReturnValue)
{
}
else
{
WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead01.xml");
WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody01.xml");
}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead08) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody08))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "08";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载其他入库单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead08 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody08 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead08.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody08.xml");
// Log.WriteLog("加载其他入库单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead10) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody10))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "10";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载产成品入库单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead10 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody10 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead10.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody10.xml");
// Log.WriteLog("加载产成品入库单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead11) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody11))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "11";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载材料出库单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead11 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody11 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead11.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody11.xml");
// Log.WriteLog("加载材料出库单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead09) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody09))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "09";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载其他出库单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead09 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody09 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead09.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody09.xml");
// Log.WriteLog("加载其他出库单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead32) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody32))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "32";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载销售出库单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead32 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody32 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead32.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody32.xml");
// Log.WriteLog("加载销售出库单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead12) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody12))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "12";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载调拨单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead12 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody12 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead12.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody12.xml");
// Log.WriteLog("加载调拨单XML完成");
// }
//}
//if (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead18) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody18))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "18";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载盘点单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// }
// else
// {
// U8ApiCommonValue.XMLDomHead18 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody18 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead18.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody18.xml");
// Log.WriteLog("加载盘点单XML完成");
// }
//}
//if ((U8ApiFactoryBase.get_U8APIType() == U8APIType.API_VOUCHERCO_INTERFACE || U8ApiFactoryBase.get_U8APIType() == U8APIType.API_BUSINESS_INTERFACE) && (string.IsNullOrEmpty(U8ApiCommonValue.XMLDomHead19) || string.IsNullOrEmpty(U8ApiCommonValue.XMLDomBody19)))
//{
// rdVoucherParameter = new RdVoucherParameter();
// rdVoucherParameter.VoucherType = "19";
// rdVoucherParameter.IsGetBlank = true;
// u8STApiInterface.LoadRdVoucher(rdVoucherParameter);
// if (!rdVoucherParameter.ReturnValue)
// {
// Log.WriteLog("加载货位调整单XML失败,原因:" + rdVoucherParameter.ErrMsg);
// return;
// }
// U8ApiCommonValue.XMLDomHead19 = rdVoucherParameter.DomHead.xml;
// U8ApiCommonValue.XMLDomBody19 = rdVoucherParameter.DomBody.xml;
// FileUtil.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomHead19.xml");
// FileUtil.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + "XMLDOM\\XMLDomBody19.xml");
// Log.WriteLog("加载货位调整单XML完成");
//}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
}
}