This commit is contained in:
PastSaid
2024-08-29 09:42:49 +08:00
parent fa480006a8
commit 5472714e30
66 changed files with 7417 additions and 243 deletions

View File

@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using HandleUtils;
using System.Data.SqlClient;
using Kingdee.BOS.Util;
@@ -17,6 +16,9 @@ using Kingdee.BOS.Core.Util;
using LexmarkSFTPSDK.Response;
using System.Globalization;
using System.Xml;
using System.Text;
using HUIWEI.Lexmark.sftp.SDK.Doamin;
using Microsoft.Office.Interop.Excel;
namespace UnitTestProject2
{
@@ -39,27 +41,30 @@ namespace UnitTestProject2
// var item = a[key];
// item.Add("ttt", "1232");
//}
var rowList = new List<string>();
var rowList2 = new List<List<string>>();
var aaa = rowList2.ToArray();
Random rd = new Random();
var r1 = rd.Next(200, 1000);
//var rowList = new List<string>();
//var rowList2 = new List<List<string>>();
//var aaa = rowList2.ToArray();
//Random rd = new Random();
//var r1 = rd.Next(200, 1000);
for (int i = 0; i < r1; i++)
{
rowList.Add($"100123,{i},100123,2024-04-07 00:00:00,100123,100123,T_STK_STKTRANSFERINENTRY1");
}
//for (int i = 0; i < r1; i++)
//{
// rowList.Add($"100123,{i},100123,2024-04-07 00:00:00,100123,100123,T_STK_STKTRANSFERINENTRY1");
//}
var len = rowList.Max(x => x.Length);
var num = 8000 / 100;
int ii = 0;
var flag = rowList.Any();
while (flag)
{
ii++;
var t = rowList.Skip(num * ii).Take(num).ToList();
flag = num * ii > 8000;
}
//var len = rowList.Max(x => x.Length);
//var num = 8000 / 100;
//int ii = 0;
//var flag = rowList.Any();
//while (flag)
//{
// ii++;
// var t = rowList.Skip(num * ii).Take(num).ToList();
// flag = num * ii > 8000;
//}
var num = 2.00000001;
var res = Math.Ceiling(num);
var t = DateTime.Now.ToShortDateString();
return;
}
@@ -84,13 +89,132 @@ namespace UnitTestProject2
}
[TestMethod]
public void TestMethod3XML()
{
var receivePath = @"C:\Users\Fareoh\Desktop\对比\新建文件夹\22\";
var diInfos = new DirectoryInfo(receivePath);
var fileInfos = diInfos.GetFiles();
var encoding = 65001;
Application excelApp = new Application();
Workbook workbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
var allRowNum = 1;
var titleNum = 1;
worksheet.Cells[allRowNum, titleNum++].Value = "PurchaseOrderNumber";
worksheet.Cells[allRowNum, titleNum++].Value = "PurchaseOrderDate";
worksheet.Cells[allRowNum, titleNum++].Value = "RequestedDeliveryDate";
worksheet.Cells[allRowNum, titleNum++].Value = "Currency";
worksheet.Cells[allRowNum, titleNum++].Value = "TotalAmount";
worksheet.Cells[allRowNum, titleNum++].Value = "Incoterms";
worksheet.Cells[allRowNum, titleNum++].Value = "SalesOrganisation";
worksheet.Cells[allRowNum, titleNum++].Value = "Vendor.PartyId";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.PartyId";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.Name";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.AddressLine1";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.City";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.PostalCode";
worksheet.Cells[allRowNum, titleNum++].Value = "ShipTo.Country";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.PartyId";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.Name";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.AddressLine1";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.City";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.PostalCode";
worksheet.Cells[allRowNum, titleNum++].Value = "BillTo.Country";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemLineNumber";
worksheet.Cells[allRowNum, titleNum++].Value = "MaterialNumber";
worksheet.Cells[allRowNum, titleNum++].Value = "EANorUPCNumber";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemQuantity";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemUnitPrice";
worksheet.Cells[allRowNum, titleNum++].Value = "NetPrice";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemUOM";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemDescription";
worksheet.Cells[allRowNum, titleNum++].Value = "ItemCustomField1";
allRowNum = 2;
foreach (var fileInfo in fileInfos)
{
var fileName = fileInfo.Name;
using (StreamReader sr = new StreamReader(receivePath + fileName, Encoding.GetEncoding(encoding)))
{
var xml = XmlUtils.LoadSecureXmlDocByReader(sr);
var purchase = XmlSerializerHelper.Deserialize<PurchaseOrderDoamin>(xml.InnerXml);
var header = purchase.Header;
var pItem = purchase.LineItem;
var colNum = 1;
var rowNum = 1;
foreach (var item in pItem)
{
if (rowNum == 1)
{
worksheet.Cells[allRowNum, colNum++].Value = header.PurchaseOrderNumber;
worksheet.Cells[allRowNum, colNum++].Value = header.PurchaseOrderDate;
worksheet.Cells[allRowNum, colNum++].Value = header.RequestedDeliveryDate;
worksheet.Cells[allRowNum, colNum++].Value = header.Currency;
worksheet.Cells[allRowNum, colNum++].Value = header.TotalAmount;
worksheet.Cells[allRowNum, colNum++].Value = header.Incoterms;
worksheet.Cells[allRowNum, colNum++].Value = header.SalesOrganisation;
worksheet.Cells[allRowNum, colNum++].Value = header.Vendor.PartyId;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.PartyId;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.Name;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.AddressLine1;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.City;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.PostalCode;
worksheet.Cells[allRowNum, colNum++].Value = header.ShipTo.Country;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.PartyId;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.Name;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.AddressLine1;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.City;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.PostalCode;
worksheet.Cells[allRowNum, colNum++].Value = header.BillTo.Country;
}
else
{
colNum = 21;
}
worksheet.Cells[allRowNum, colNum++].Value = item.ItemLineNumber;
worksheet.Cells[allRowNum, colNum++].Value = item.MaterialNumber;
worksheet.Cells[allRowNum, colNum++].Value = item.EANorUPCNumber;
worksheet.Cells[allRowNum, colNum++].Value = item.ItemQuantity;
worksheet.Cells[allRowNum, colNum++].Value = item.ItemUnitPrice;
worksheet.Cells[allRowNum, colNum++].Value = item.NetPrice;
worksheet.Cells[allRowNum, colNum++].Value = item.ItemUOM;
worksheet.Cells[allRowNum, colNum++].Value = item.ItemDescription;
worksheet.Cells[allRowNum, colNum++].Value = item.ItemCustomField1;
rowNum++;
allRowNum++;
}
}
}
var guid = Guid.NewGuid().ToString("N");
workbook.SaveAs($@"C:\Users\Fareoh\Desktop\对比\新建文件夹\{guid}.xlsx");
workbook.Close();
excelApp.Quit();
}
[TestMethod]
public void TestMethodSetXml()
{
var path = @"C:\Users\Fareoh\Desktop\对比\新建文件夹\LEXMK_Encode.LEXMK_SFTP_PRD.HUIWE_SFTP_PRD.ORDERSUTF8.PO202408080352.20240808035231.45840";
using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding(65001)))
{
var xml2 = XmlUtils.LoadSecureXmlDocByReader(sr);
var purchase = XmlSerializerHelper.Deserialize<PurchaseOrderDoamin>(xml2.InnerXml);
}
var dateTIme = DateTime.Now.GetTimestamp();
var date = dateTIme.ToString("yyyyMMdd");
var xml = XmlUtils.LoadSecureXmlDocByFile(@"D:\Work\GateDge\VS\GateDge2023\00.未分类\UnitTestProject2\POSH_CB_PRODUCTCOSTREDUCTION.xml");
var xml = XmlUtils.LoadSecureXmlDocByFile(@"C:\Users\Fareoh\Desktop\对比\新建文件夹\LEXMK_Encode.LEXMK_SFTP_PRD.HUIWE_SFTP_PRD.ORDCHGUTF8.POC20240805134.20240805134419.9060.U");
var x2 = JsonUtil.Serialize("");
var x = XmlSerializerHelper.Deserialize<FormMetadata>(xml.InnerXml);
var fieldList = x.BusinessInfo.BusinessInfo.Elements.SysReportForm.SQLDataSource.SQLDataSource.FieldList;
@@ -193,27 +317,27 @@ namespace UnitTestProject2
[TestMethod]
public void ConvertHTMLtoWord()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Word|*.docx";
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK)
{
string filepath = dialog.FileName;
//创建 Document 对象
Document document = new Document();
//OpenFileDialog dialog = new OpenFileDialog();
//dialog.Filter = "Word|*.docx";
//DialogResult result = dialog.ShowDialog();
//if (result == DialogResult.OK)
//{
// string filepath = dialog.FileName;
// //创建 Document 对象
// Document document = new Document();
document.LoadFromFile(filepath);
string fileExs = System.IO.Path.GetExtension(filepath);
string fileName = System.IO.Path.GetFileNameWithoutExtension(filepath);
string newFilePath = "";
//newFilePath = filepath.Replace(fileExs, ".html");
//document.SaveToFile(newFilePath, FileFormat.Html);
//document.Close();
newFilePath = filepath.Replace(fileExs, ".xml");
//document.LoadFromFile(newFilePath, FileFormat.Html);
document.SaveToFile(newFilePath, FileFormat.Xml);
document.Close();
}
// document.LoadFromFile(filepath);
// string fileExs = System.IO.Path.GetExtension(filepath);
// string fileName = System.IO.Path.GetFileNameWithoutExtension(filepath);
// string newFilePath = "";
// //newFilePath = filepath.Replace(fileExs, ".html");
// //document.SaveToFile(newFilePath, FileFormat.Html);
// //document.Close();
// newFilePath = filepath.Replace(fileExs, ".xml");
// //document.LoadFromFile(newFilePath, FileFormat.Html);
// document.SaveToFile(newFilePath, FileFormat.Xml);
// document.Close();
//}
}
}