2024-03-18 11:42:45 +08:00
|
|
|
|
using Kingdee.BOS.Orm.DataEntity;
|
|
|
|
|
|
using Kingdee.BOS.Orm.Metadata.DataEntity;
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2024-04-22 09:39:19 +08:00
|
|
|
|
using Renci.SshNet;
|
|
|
|
|
|
using Spire.Doc;
|
2024-03-18 11:42:45 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-04-22 09:39:19 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using Kingdee.K3.SCM.App.Stock.Report;
|
2024-03-18 11:42:45 +08:00
|
|
|
|
namespace UnitTestProject2
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public class UnitTest1
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestMethod1()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//var a = new DynamicObject(new DynamicObjectType("COUNT_GAIN"));
|
|
|
|
|
|
|
2024-04-22 09:39:19 +08:00
|
|
|
|
//var a = new Dictionary<string, Dictionary<string, string>>();
|
|
|
|
|
|
//a.Add("a", new Dictionary<string, string>());
|
|
|
|
|
|
//a.Add("b", new Dictionary<string, string>());
|
|
|
|
|
|
|
|
|
|
|
|
//var keys = new[] { "a", "a", "b" };
|
|
|
|
|
|
//foreach (var key in keys)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var item = a[key];
|
|
|
|
|
|
// item.Add("ttt", "1232");
|
|
|
|
|
|
//}
|
|
|
|
|
|
var rowList = new List<string>();
|
|
|
|
|
|
var rowList2 = new List<List<string>>();
|
|
|
|
|
|
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");
|
|
|
|
|
|
}
|
2024-03-18 11:42:45 +08:00
|
|
|
|
|
2024-04-22 09:39:19 +08:00
|
|
|
|
var len = rowList.Max(x => x.Length);
|
|
|
|
|
|
var num = 8000 / 100;
|
|
|
|
|
|
int ii = 0;
|
|
|
|
|
|
var flag = rowList.Any();
|
|
|
|
|
|
while (flag)
|
2024-03-18 11:42:45 +08:00
|
|
|
|
{
|
2024-04-22 09:39:19 +08:00
|
|
|
|
ii++;
|
|
|
|
|
|
var t = rowList.Skip(num * ii).Take(num).ToList();
|
|
|
|
|
|
flag = num * ii > 8000;
|
2024-03-18 11:42:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-04-22 09:39:19 +08:00
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestMethod2()
|
|
|
|
|
|
{
|
|
|
|
|
|
string ip = "sftp.betagrid.gxs.com";
|
|
|
|
|
|
string port = "22";
|
|
|
|
|
|
string user = "HUIWE_SFTP_TST";
|
|
|
|
|
|
string pwd = "@m+n|9+v^.R}1[^";
|
|
|
|
|
|
string localPath = "D:\\Work\\GateDge\\SFTP\\aatat.docx";
|
|
|
|
|
|
string remotePath = "/aatat.docx";
|
|
|
|
|
|
SFTPHelper SFTPHelper = new SFTPHelper(ip, user, pwd, port);
|
|
|
|
|
|
var flag = SFTPHelper.Put(localPath, remotePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class SFTPHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 字段或属性
|
|
|
|
|
|
private SftpClient _sftp;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SFTP连接状态
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Connected => _sftp.IsConnected;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 构造
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构造
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ip">IP</param>
|
|
|
|
|
|
/// <param name="port">端口</param>
|
|
|
|
|
|
/// <param name="user">用户名</param>
|
|
|
|
|
|
/// <param name="pwd">密码</param>
|
|
|
|
|
|
public SFTPHelper(string ip, string user, string pwd, string port = "22")
|
|
|
|
|
|
{
|
|
|
|
|
|
_sftp = new SftpClient(ip, int.Parse(port), user, pwd);
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~SFTPHelper()
|
|
|
|
|
|
{
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 连接SFTP
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接SFTP
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>true成功</returns>
|
|
|
|
|
|
public bool Connect()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Connected)
|
|
|
|
|
|
{
|
|
|
|
|
|
_sftp.Connect();
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("连接SFTP失败,原因:{0}", ex.Message));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 断开SFTP
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 断开SFTP
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Disconnect()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_sftp != null && Connected)
|
|
|
|
|
|
{
|
|
|
|
|
|
_sftp.Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("断开SFTP失败,原因:{0}", ex.Message));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region SFTP上传文件
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SFTP上传文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="localPath">本地文件全路径 例:G:\\Project\\logo.png</param>
|
|
|
|
|
|
/// <param name="remotePath">远程路径 例:/logo.png</param>
|
|
|
|
|
|
public bool Put(string localPath, string remotePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var file = File.OpenRead(localPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
_sftp.UploadFile(file, remotePath);
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region SFTP获取文件
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SFTP获取文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="remotePath">远程路径</param>
|
|
|
|
|
|
/// <param name="localPath">本地路径</param>
|
|
|
|
|
|
public void Get(string remotePath, string localPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
var byt = _sftp.ReadAllBytes(remotePath);
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
File.WriteAllBytes(localPath, byt);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("SFTP文件获取失败,原因:{0}", ex.Message));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 删除SFTP文件
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除SFTP文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="remoteFile">远程路径</param>
|
|
|
|
|
|
public void Delete(string remoteFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Connect();
|
|
|
|
|
|
_sftp.Delete(remoteFile);
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("SFTP文件删除失败,原因:{0}", ex.Message));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[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();
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-18 11:42:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|