using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Orm.Metadata.DataEntity; using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet; using Spire.Doc; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; using Kingdee.K3.SCM.App.Stock.Report; namespace UnitTestProject2 { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { //var a = new DynamicObject(new DynamicObjectType("COUNT_GAIN")); //var a = new Dictionary>(); //a.Add("a", new Dictionary()); //a.Add("b", new Dictionary()); //var keys = new[] { "a", "a", "b" }; //foreach (var key in keys) //{ // var item = a[key]; // item.Add("ttt", "1232"); //} var rowList = new List(); var rowList2 = new List>(); 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"); } 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; } return; } [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; /// /// SFTP连接状态 /// public bool Connected => _sftp.IsConnected; #endregion #region 构造 /// /// 构造 /// /// IP /// 端口 /// 用户名 /// 密码 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 /// /// 连接SFTP /// /// true成功 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 /// /// 断开SFTP /// 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上传文件 /// /// SFTP上传文件 /// /// 本地文件全路径 例:G:\\Project\\logo.png /// 远程路径 例:/logo.png 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获取文件 /// /// SFTP获取文件 /// /// 远程路径 /// 本地路径 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文件 /// /// 删除SFTP文件 /// /// 远程路径 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(); } } } }