Browse Source

文件打包

yhluo 4 days ago
parent
commit
d7bfd28099
3 changed files with 667 additions and 68 deletions
  1. 266 68
      UAS_Tools_HY/Main.Designer.cs
  2. 399 0
      UAS_Tools_HY/Main.cs
  3. 2 0
      UAS_Tools_HY/UAS_Tools_HY.csproj

+ 266 - 68
UAS_Tools_HY/Main.Designer.cs

@@ -76,6 +76,13 @@
             this.checkPage4 = new System.Windows.Forms.TabPage();
             this.queryDataBox1 = new System.Windows.Forms.Panel();
             this.QDDatas = new System.Windows.Forms.DataGridView();
+            this.dqSN = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqOUTBOX_NO = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqCOUNT = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqUPDATE_TIME = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqNAME = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqRULE_NAME = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dqRULE_VALUE = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.queryDataBox = new System.Windows.Forms.Panel();
             this.QDcheckbox1 = new System.Windows.Forms.CheckBox();
             this.QDlab3 = new System.Windows.Forms.Label();
@@ -112,17 +119,25 @@
             this.DRulesBtn = new System.Windows.Forms.Button();
             this.ShowMsg = new System.Windows.Forms.Label();
             this.Page2 = new System.Windows.Forms.TabPage();
+            this.MsgBox = new System.Windows.Forms.ListBox();
+            this.FileDetail_Box = new System.Windows.Forms.Panel();
+            this.timerLab1 = new System.Windows.Forms.Label();
+            this.FtpListen = new System.Windows.Forms.Button();
+            this.FtpConnect = new System.Windows.Forms.Button();
+            this.FtpPathVal = new System.Windows.Forms.TextBox();
+            this.FtpPathLab = new System.Windows.Forms.Label();
+            this.FtpPwVal = new System.Windows.Forms.TextBox();
+            this.FtpPwLab = new System.Windows.Forms.Label();
+            this.FtpAccountVal = new System.Windows.Forms.TextBox();
+            this.FtpAccountLab = new System.Windows.Forms.Label();
+            this.timerVal = new System.Windows.Forms.TextBox();
+            this.timerLab = new System.Windows.Forms.Label();
             this.bottom = new System.Windows.Forms.TableLayoutPanel();
             this.currUser = new System.Windows.Forms.Label();
             this.currTime = new System.Windows.Forms.Label();
             this.top = new System.Windows.Forms.Panel();
-            this.dqSN = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqOUTBOX_NO = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqCOUNT = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqUPDATE_TIME = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqNAME = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqRULE_NAME = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dqRULE_VALUE = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.FileCountVal = new System.Windows.Forms.TextBox();
+            this.FileCountLab = new System.Windows.Forms.Label();
             this.Pagination.SuspendLayout();
             this.Page1.SuspendLayout();
             this.checkPagination.SuspendLayout();
@@ -144,6 +159,8 @@
             this.detailLeftBox.SuspendLayout();
             this.detailCarton.SuspendLayout();
             this.detailSN.SuspendLayout();
+            this.Page2.SuspendLayout();
+            this.FileDetail_Box.SuspendLayout();
             this.bottom.SuspendLayout();
             this.top.SuspendLayout();
             this.SuspendLayout();
@@ -623,7 +640,7 @@
             this.rulesQuery.Name = "rulesQuery";
             this.rulesQuery.Size = new System.Drawing.Size(85, 30);
             this.rulesQuery.TabIndex = 14;
-            this.rulesQuery.Text = "获取";
+            this.rulesQuery.Text = "查询";
             this.rulesQuery.UseVisualStyleBackColor = true;
             this.rulesQuery.Click += new System.EventHandler(this.rulesQuery_Click);
             // 
@@ -682,6 +699,69 @@
             this.QDDatas.Size = new System.Drawing.Size(1230, 245);
             this.QDDatas.TabIndex = 1;
             // 
+            // dqSN
+            // 
+            this.dqSN.DataPropertyName = "dqSN";
+            this.dqSN.HeaderText = "条码";
+            this.dqSN.MinimumWidth = 8;
+            this.dqSN.Name = "dqSN";
+            this.dqSN.ReadOnly = true;
+            this.dqSN.Width = 240;
+            // 
+            // dqOUTBOX_NO
+            // 
+            this.dqOUTBOX_NO.DataPropertyName = "dqOUTBOX_NO";
+            this.dqOUTBOX_NO.HeaderText = "箱码";
+            this.dqOUTBOX_NO.MinimumWidth = 8;
+            this.dqOUTBOX_NO.Name = "dqOUTBOX_NO";
+            this.dqOUTBOX_NO.ReadOnly = true;
+            this.dqOUTBOX_NO.Width = 260;
+            // 
+            // dqCOUNT
+            // 
+            this.dqCOUNT.DataPropertyName = "dqCOUNT";
+            this.dqCOUNT.HeaderText = "扫描次数";
+            this.dqCOUNT.MinimumWidth = 8;
+            this.dqCOUNT.Name = "dqCOUNT";
+            this.dqCOUNT.ReadOnly = true;
+            this.dqCOUNT.Width = 120;
+            // 
+            // dqUPDATE_TIME
+            // 
+            this.dqUPDATE_TIME.DataPropertyName = "dqUPDATE_TIME";
+            this.dqUPDATE_TIME.HeaderText = "扫描时间";
+            this.dqUPDATE_TIME.MinimumWidth = 8;
+            this.dqUPDATE_TIME.Name = "dqUPDATE_TIME";
+            this.dqUPDATE_TIME.ReadOnly = true;
+            this.dqUPDATE_TIME.Width = 180;
+            // 
+            // dqNAME
+            // 
+            this.dqNAME.DataPropertyName = "dqNAME";
+            this.dqNAME.HeaderText = "扫描人";
+            this.dqNAME.MinimumWidth = 8;
+            this.dqNAME.Name = "dqNAME";
+            this.dqNAME.ReadOnly = true;
+            this.dqNAME.Width = 120;
+            // 
+            // dqRULE_NAME
+            // 
+            this.dqRULE_NAME.DataPropertyName = "dqRULE_NAME";
+            this.dqRULE_NAME.HeaderText = "规则名称";
+            this.dqRULE_NAME.MinimumWidth = 8;
+            this.dqRULE_NAME.Name = "dqRULE_NAME";
+            this.dqRULE_NAME.ReadOnly = true;
+            this.dqRULE_NAME.Width = 150;
+            // 
+            // dqRULE_VALUE
+            // 
+            this.dqRULE_VALUE.DataPropertyName = "dqRULE_VALUE";
+            this.dqRULE_VALUE.HeaderText = "规则内容";
+            this.dqRULE_VALUE.MinimumWidth = 8;
+            this.dqRULE_VALUE.Name = "dqRULE_VALUE";
+            this.dqRULE_VALUE.ReadOnly = true;
+            this.dqRULE_VALUE.Width = 180;
+            // 
             // queryDataBox
             // 
             this.queryDataBox.Controls.Add(this.QDcheckbox1);
@@ -745,7 +825,7 @@
             this.QDquery.Name = "QDquery";
             this.QDquery.Size = new System.Drawing.Size(85, 30);
             this.QDquery.TabIndex = 6;
-            this.QDquery.Text = "获取";
+            this.QDquery.Text = "查询";
             this.QDquery.UseVisualStyleBackColor = true;
             this.QDquery.Click += new System.EventHandler(this.QDquery_Click);
             // 
@@ -1092,6 +1172,8 @@
             // Page2
             // 
             this.Page2.BackColor = System.Drawing.SystemColors.Control;
+            this.Page2.Controls.Add(this.MsgBox);
+            this.Page2.Controls.Add(this.FileDetail_Box);
             this.Page2.Cursor = System.Windows.Forms.Cursors.Default;
             this.Page2.Location = new System.Drawing.Point(4, 34);
             this.Page2.Name = "Page2";
@@ -1100,6 +1182,148 @@
             this.Page2.TabIndex = 1;
             this.Page2.Text = "DCR文件打包";
             // 
+            // MsgBox
+            // 
+            this.MsgBox.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.MsgBox.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.MsgBox.FormattingEnabled = true;
+            this.MsgBox.ItemHeight = 24;
+            this.MsgBox.Location = new System.Drawing.Point(3, 191);
+            this.MsgBox.Name = "MsgBox";
+            this.MsgBox.Size = new System.Drawing.Size(1240, 393);
+            this.MsgBox.TabIndex = 0;
+            this.MsgBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.MsgBox_DrawItem);
+            // 
+            // FileDetail_Box
+            // 
+            this.FileDetail_Box.Controls.Add(this.FileCountVal);
+            this.FileDetail_Box.Controls.Add(this.FileCountLab);
+            this.FileDetail_Box.Controls.Add(this.timerLab1);
+            this.FileDetail_Box.Controls.Add(this.FtpListen);
+            this.FileDetail_Box.Controls.Add(this.FtpConnect);
+            this.FileDetail_Box.Controls.Add(this.FtpPathVal);
+            this.FileDetail_Box.Controls.Add(this.FtpPathLab);
+            this.FileDetail_Box.Controls.Add(this.FtpPwVal);
+            this.FileDetail_Box.Controls.Add(this.FtpPwLab);
+            this.FileDetail_Box.Controls.Add(this.FtpAccountVal);
+            this.FileDetail_Box.Controls.Add(this.FtpAccountLab);
+            this.FileDetail_Box.Controls.Add(this.timerVal);
+            this.FileDetail_Box.Controls.Add(this.timerLab);
+            this.FileDetail_Box.Dock = System.Windows.Forms.DockStyle.Top;
+            this.FileDetail_Box.Location = new System.Drawing.Point(3, 3);
+            this.FileDetail_Box.Name = "FileDetail_Box";
+            this.FileDetail_Box.Size = new System.Drawing.Size(1240, 188);
+            this.FileDetail_Box.TabIndex = 1;
+            // 
+            // timerLab1
+            // 
+            this.timerLab1.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.timerLab1.AutoSize = true;
+            this.timerLab1.Location = new System.Drawing.Point(454, 22);
+            this.timerLab1.Name = "timerLab1";
+            this.timerLab1.Size = new System.Drawing.Size(33, 28);
+            this.timerLab1.TabIndex = 11;
+            this.timerLab1.Text = "秒";
+            // 
+            // FtpListen
+            // 
+            this.FtpListen.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.FtpListen.Enabled = false;
+            this.FtpListen.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.FtpListen.Location = new System.Drawing.Point(620, 121);
+            this.FtpListen.Name = "FtpListen";
+            this.FtpListen.Size = new System.Drawing.Size(100, 38);
+            this.FtpListen.TabIndex = 10;
+            this.FtpListen.Text = "开启监听";
+            this.FtpListen.UseVisualStyleBackColor = true;
+            this.FtpListen.Click += new System.EventHandler(this.FtpListen_Click);
+            // 
+            // FtpConnect
+            // 
+            this.FtpConnect.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.FtpConnect.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.FtpConnect.Location = new System.Drawing.Point(490, 122);
+            this.FtpConnect.Name = "FtpConnect";
+            this.FtpConnect.Size = new System.Drawing.Size(100, 37);
+            this.FtpConnect.TabIndex = 9;
+            this.FtpConnect.Text = "开启连接";
+            this.FtpConnect.UseVisualStyleBackColor = true;
+            this.FtpConnect.Click += new System.EventHandler(this.FtpConnect_Click);
+            // 
+            // FtpPathVal
+            // 
+            this.FtpPathVal.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpPathVal.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.FtpPathVal.Location = new System.Drawing.Point(398, 72);
+            this.FtpPathVal.Name = "FtpPathVal";
+            this.FtpPathVal.Size = new System.Drawing.Size(322, 31);
+            this.FtpPathVal.TabIndex = 7;
+            // 
+            // FtpPathLab
+            // 
+            this.FtpPathLab.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpPathLab.AutoSize = true;
+            this.FtpPathLab.Location = new System.Drawing.Point(296, 74);
+            this.FtpPathLab.Name = "FtpPathLab";
+            this.FtpPathLab.Size = new System.Drawing.Size(137, 28);
+            this.FtpPathLab.TabIndex = 6;
+            this.FtpPathLab.Text = "FTP路径地址:";
+            // 
+            // FtpPwVal
+            // 
+            this.FtpPwVal.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpPwVal.Location = new System.Drawing.Point(94, 71);
+            this.FtpPwVal.Name = "FtpPwVal";
+            this.FtpPwVal.Size = new System.Drawing.Size(180, 35);
+            this.FtpPwVal.TabIndex = 5;
+            // 
+            // FtpPwLab
+            // 
+            this.FtpPwLab.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpPwLab.AutoSize = true;
+            this.FtpPwLab.Location = new System.Drawing.Point(12, 74);
+            this.FtpPwLab.Name = "FtpPwLab";
+            this.FtpPwLab.Size = new System.Drawing.Size(95, 28);
+            this.FtpPwLab.TabIndex = 4;
+            this.FtpPwLab.Text = "FTP密码:";
+            // 
+            // FtpAccountVal
+            // 
+            this.FtpAccountVal.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpAccountVal.Location = new System.Drawing.Point(94, 20);
+            this.FtpAccountVal.Name = "FtpAccountVal";
+            this.FtpAccountVal.Size = new System.Drawing.Size(180, 35);
+            this.FtpAccountVal.TabIndex = 3;
+            // 
+            // FtpAccountLab
+            // 
+            this.FtpAccountLab.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FtpAccountLab.AutoSize = true;
+            this.FtpAccountLab.Location = new System.Drawing.Point(12, 22);
+            this.FtpAccountLab.Name = "FtpAccountLab";
+            this.FtpAccountLab.Size = new System.Drawing.Size(95, 28);
+            this.FtpAccountLab.TabIndex = 2;
+            this.FtpAccountLab.Text = "FTP账户:";
+            // 
+            // timerVal
+            // 
+            this.timerVal.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.timerVal.Location = new System.Drawing.Point(398, 19);
+            this.timerVal.Name = "timerVal";
+            this.timerVal.Size = new System.Drawing.Size(54, 35);
+            this.timerVal.TabIndex = 1;
+            this.timerVal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
+            // 
+            // timerLab
+            // 
+            this.timerLab.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.timerLab.AutoSize = true;
+            this.timerLab.Location = new System.Drawing.Point(296, 22);
+            this.timerLab.Name = "timerLab";
+            this.timerLab.Size = new System.Drawing.Size(101, 28);
+            this.timerLab.TabIndex = 0;
+            this.timerLab.Text = "间隔时间:";
+            // 
             // bottom
             // 
             this.bottom.ColumnCount = 3;
@@ -1151,68 +1375,24 @@
             this.top.Size = new System.Drawing.Size(1254, 625);
             this.top.TabIndex = 3;
             // 
-            // dqSN
-            // 
-            this.dqSN.DataPropertyName = "dqSN";
-            this.dqSN.HeaderText = "条码";
-            this.dqSN.MinimumWidth = 8;
-            this.dqSN.Name = "dqSN";
-            this.dqSN.ReadOnly = true;
-            this.dqSN.Width = 240;
-            // 
-            // dqOUTBOX_NO
-            // 
-            this.dqOUTBOX_NO.DataPropertyName = "dqOUTBOX_NO";
-            this.dqOUTBOX_NO.HeaderText = "箱码";
-            this.dqOUTBOX_NO.MinimumWidth = 8;
-            this.dqOUTBOX_NO.Name = "dqOUTBOX_NO";
-            this.dqOUTBOX_NO.ReadOnly = true;
-            this.dqOUTBOX_NO.Width = 260;
-            // 
-            // dqCOUNT
-            // 
-            this.dqCOUNT.DataPropertyName = "dqCOUNT";
-            this.dqCOUNT.HeaderText = "扫描次数";
-            this.dqCOUNT.MinimumWidth = 8;
-            this.dqCOUNT.Name = "dqCOUNT";
-            this.dqCOUNT.ReadOnly = true;
-            this.dqCOUNT.Width = 120;
-            // 
-            // dqUPDATE_TIME
-            // 
-            this.dqUPDATE_TIME.DataPropertyName = "dqUPDATE_TIME";
-            this.dqUPDATE_TIME.HeaderText = "扫描时间";
-            this.dqUPDATE_TIME.MinimumWidth = 8;
-            this.dqUPDATE_TIME.Name = "dqUPDATE_TIME";
-            this.dqUPDATE_TIME.ReadOnly = true;
-            this.dqUPDATE_TIME.Width = 180;
-            // 
-            // dqNAME
-            // 
-            this.dqNAME.DataPropertyName = "dqNAME";
-            this.dqNAME.HeaderText = "扫描人";
-            this.dqNAME.MinimumWidth = 8;
-            this.dqNAME.Name = "dqNAME";
-            this.dqNAME.ReadOnly = true;
-            this.dqNAME.Width = 120;
-            // 
-            // dqRULE_NAME
+            // FileCountVal
             // 
-            this.dqRULE_NAME.DataPropertyName = "dqRULE_NAME";
-            this.dqRULE_NAME.HeaderText = "规则名称";
-            this.dqRULE_NAME.MinimumWidth = 8;
-            this.dqRULE_NAME.Name = "dqRULE_NAME";
-            this.dqRULE_NAME.ReadOnly = true;
-            this.dqRULE_NAME.Width = 150;
+            this.FileCountVal.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FileCountVal.Location = new System.Drawing.Point(629, 19);
+            this.FileCountVal.Name = "FileCountVal";
+            this.FileCountVal.Size = new System.Drawing.Size(65, 35);
+            this.FileCountVal.TabIndex = 13;
+            this.FileCountVal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
             // 
-            // dqRULE_VALUE
+            // FileCountLab
             // 
-            this.dqRULE_VALUE.DataPropertyName = "dqRULE_VALUE";
-            this.dqRULE_VALUE.HeaderText = "规则内容";
-            this.dqRULE_VALUE.MinimumWidth = 8;
-            this.dqRULE_VALUE.Name = "dqRULE_VALUE";
-            this.dqRULE_VALUE.ReadOnly = true;
-            this.dqRULE_VALUE.Width = 180;
+            this.FileCountLab.Anchor = System.Windows.Forms.AnchorStyles.Left;
+            this.FileCountLab.AutoSize = true;
+            this.FileCountLab.Location = new System.Drawing.Point(515, 22);
+            this.FileCountLab.Name = "FileCountLab";
+            this.FileCountLab.Size = new System.Drawing.Size(122, 28);
+            this.FileCountLab.TabIndex = 12;
+            this.FileCountLab.Text = "打包文件数:";
             // 
             // Main
             // 
@@ -1260,6 +1440,9 @@
             this.detailCarton.PerformLayout();
             this.detailSN.ResumeLayout(false);
             this.detailSN.PerformLayout();
+            this.Page2.ResumeLayout(false);
+            this.FileDetail_Box.ResumeLayout(false);
+            this.FileDetail_Box.PerformLayout();
             this.bottom.ResumeLayout(false);
             this.bottom.PerformLayout();
             this.top.ResumeLayout(false);
@@ -1363,5 +1546,20 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn dqNAME;
         private System.Windows.Forms.DataGridViewTextBoxColumn dqRULE_NAME;
         private System.Windows.Forms.DataGridViewTextBoxColumn dqRULE_VALUE;
+        private System.Windows.Forms.ListBox MsgBox;
+        private System.Windows.Forms.Panel FileDetail_Box;
+        private System.Windows.Forms.TextBox timerVal;
+        private System.Windows.Forms.TextBox FtpPwVal;
+        private System.Windows.Forms.Label FtpPwLab;
+        private System.Windows.Forms.TextBox FtpAccountVal;
+        private System.Windows.Forms.Label FtpAccountLab;
+        private System.Windows.Forms.TextBox FtpPathVal;
+        private System.Windows.Forms.Label FtpPathLab;
+        private System.Windows.Forms.Button FtpConnect;
+        private System.Windows.Forms.Button FtpListen;
+        private System.Windows.Forms.Label timerLab1;
+        private System.Windows.Forms.Label timerLab;
+        private System.Windows.Forms.TextBox FileCountVal;
+        private System.Windows.Forms.Label FileCountLab;
     }
 }

+ 399 - 0
UAS_Tools_HY/Main.cs

@@ -6,8 +6,10 @@ using System.Data;
 using System.Drawing;
 using System.Globalization;
 using System.IO;
+using System.IO.Compression;
 using System.Linq;
 using System.Media;
+using System.Net;
 using System.Runtime.InteropServices;
 using System.Security.Principal;
 using System.Text;
@@ -35,6 +37,10 @@ namespace UAS_MES_Tools
 
         int ishaveInd;
 
+        Timer File_timer;
+
+        string saveFiles;
+
         public Main(string account, string password)
         {
             _Account = account;
@@ -74,6 +80,26 @@ namespace UAS_MES_Tools
 
             rulesQuery_Click(null, null);
             QDquery_Click(null, null);
+
+            saveFiles = Path.Combine(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).FullName, $"FtpFiles");
+            if (!Directory.Exists(saveFiles))
+            {
+                Directory.CreateDirectory(saveFiles);
+            }
+
+            saveFiles = Path.Combine(saveFiles, DateTime.Now.ToString("yyyyMMdd"));
+            if (!Directory.Exists(saveFiles))
+            {
+                Directory.CreateDirectory(saveFiles);
+            }
+
+            File_timer = new Timer();
+            File_timer.Interval = 30 * 1000;
+            File_timer.Tick += Timer_Tick;
+
+            timerVal.Text = "30";
+            FileCountVal.Text = "10";
+            FtpPathVal.Text = "ftp://10.18.6.200:21//2-各部门资料夹//23-信息部//dcr";
         }
 
         private void SN_KeyDown(object sender, KeyEventArgs e)
@@ -679,5 +705,378 @@ namespace UAS_MES_Tools
             currTime.Text = currentDate;
         }
 
+        private async void FtpConnect_Click(object sender, EventArgs e)
+        {
+            if(FtpConnect.Text == "开启连接")
+            {
+                if (string.IsNullOrEmpty(FtpAccountVal.Text))
+                {
+                    LogMessage("NG,请填写ftp账户");
+                    return;
+                }
+                if (string.IsNullOrEmpty(FtpPwVal.Text))
+                {
+                    LogMessage("NG,请填写ftp密码");
+                    return;
+                }
+                if (string.IsNullOrEmpty(timerVal.Text))
+                {
+                    LogMessage("NG,请填写间隔抓取文件时间");
+                    return;
+                }
+                if (string.IsNullOrEmpty(FtpPathVal.Text))
+                {
+                    LogMessage("NG,请填写ftp抓取路径地址");
+                    return;
+                }
+                if (string.IsNullOrEmpty(FileCountVal.Text))
+                {
+                    LogMessage("NG,请填写打包文件数");
+                    return;
+                }
+
+                FtpConnect.Enabled = false;
+                FtpConnect.Text = "连接中...";
+
+                LogMessage("开始测试连接...");
+                bool testConnect = await TestFtpConnection(FtpPathVal.Text.Trim(), FtpAccountVal.Text.Trim(), FtpPwVal.Text.Trim());
+
+                if (testConnect)
+                {
+                    FtpAccountVal.Enabled = false;
+                    FtpPwVal.Enabled = false;
+                    timerVal.Enabled = false;
+                    FtpPathVal.Enabled = false;
+                    FtpConnect.Text = "关闭连接";
+                    FtpListen.Enabled = true;
+                }
+                else
+                {
+                    FtpConnect.Enabled = true;
+                    FtpConnect.Text = "开启连接";
+                }
+            }
+            else if(FtpConnect.Text == "关闭连接")
+            {
+                FtpAccountVal.Enabled = true;
+                FtpPwVal.Enabled = true;
+                timerVal.Enabled = true;
+                FtpPathVal.Enabled = true;
+                FtpConnect.Text = "开启连接";
+                FtpListen.Enabled = false;
+            }
+        }
+
+        public async Task<bool> TestFtpConnection(string ftpServer, string username, string password)
+        {
+            try
+            {
+                var request = (FtpWebRequest)WebRequest.Create(ftpServer);
+                request.Method = WebRequestMethods.Ftp.ListDirectory;
+                request.Credentials = new NetworkCredential(username, password);
+                request.UsePassive = true;
+                request.UseBinary = true;
+                request.KeepAlive = false;
+                request.Timeout = 10000;
+
+                using (var response = await request.GetResponseAsync() as FtpWebResponse)
+                {
+                    await Task.Run(() =>
+                    {
+                        LogMessage($"OK,FTP连接成功: {response.StatusDescription}");
+                    });
+                    return true;
+                }
+            }
+            catch (WebException ex)
+            {
+                await Task.Run(() =>
+                {
+                    if (ex.Response is FtpWebResponse response)
+                    {
+                        LogMessage($"NG,FTP连接失败,错误码: {(int)response.StatusCode} - {response.StatusDescription}");
+                    }
+                    else
+                    {
+                        LogMessage("NG,连接异常: " + ex.Message);
+                    }
+                });
+                return false;
+            }
+            catch (Exception ex)
+            {
+                await Task.Run(() =>
+                {
+                    LogMessage($"NG,连接失败: " + ex.Message);
+                });
+                return false;
+            }
+        }
+
+        private void FtpListen_Click(object sender, EventArgs e)
+        {
+            File_timer.Interval = Convert.ToInt32(timerVal.Text.Trim()) * 1000;
+
+            if (FtpListen.Text == "开启监听")
+            {
+                FtpListen.Text = "关闭监听";
+                FtpConnect.Enabled = false;
+                File_timer.Start();
+                Timer_Tick(null, null);
+            }
+            else if (FtpListen.Text == "关闭监听")
+            {
+                FtpListen.Text = "开启监听";
+                FtpConnect.Enabled = true;
+                File_timer.Stop();
+            }
+        }
+
+        private void MsgBox_DrawItem(object sender, DrawItemEventArgs e)
+        {
+            e.DrawBackground();
+            Brush mybsh = Brushes.Black;
+            string msgStr = MsgBox.Items[e.Index].ToString();
+            Console.WriteLine();
+            if (MsgBox.Items[e.Index].ToString().Contains("OK"))
+            {
+                mybsh = Brushes.Green;
+            }
+            else if (MsgBox.Items[e.Index].ToString().Contains("NG"))
+            {
+                mybsh = Brushes.Red;
+            }
+            e.DrawFocusRectangle();
+            e.Graphics.DrawString(MsgBox.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
+        }
+
+        private void LogMessage(string message)
+        {
+            if (MsgBox.InvokeRequired)
+            {
+                MsgBox.Invoke(new Action<string>(LogMessage), message);
+                return;
+            }
+            MsgBox.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
+            MsgBox.TopIndex = MsgBox.Items.Count - 1;
+            MsgBox.DrawMode = DrawMode.OwnerDrawFixed;
+        }
+
+        private void Timer_Tick(object sender, EventArgs e)
+        {
+            try
+            {
+                if (!Directory.Exists(saveFiles))
+                {
+                    Directory.CreateDirectory(saveFiles);
+                    LogMessage($"创建本地文件夹: {saveFiles}");
+                }
+
+                string ftpServer = FtpPathVal.Text.Trim();
+                string remoteFolderPath = "";
+                string username = FtpAccountVal.Text.Trim();
+                string password = FtpPwVal.Text.Trim();
+
+                List<string> fileList = GetFtpFileList(ftpServer, remoteFolderPath, username, password);
+
+                if (fileList.Count == 0)
+                {
+                    LogMessage($"远程文件夹 '{remoteFolderPath}' 中没有文件");
+                    return;
+                }
+
+                int successCount = 0;
+                int failCount = 0;
+
+                LogMessage($"开始下载 {fileList.Count} 个文件...");
+
+                foreach (string remoteFile in fileList)
+                {
+                    string remoteFilePath = $"{remoteFolderPath.TrimEnd('/')}/{remoteFile}";
+                    string localFilePath = Path.Combine(saveFiles, remoteFile);
+
+                    if (DownloadSingleFile(ftpServer, remoteFilePath, localFilePath, username, password))
+                    {
+                        successCount++;
+                    }
+                    else
+                    {
+                        failCount++;
+                    }
+                }
+
+                LogMessage($"下载完成: 成功 {successCount} 个, 失败 {failCount} 个");
+
+                string[] files = Directory.GetFiles(saveFiles);
+                string zipFilePath = Path.Combine(Path.GetDirectoryName(saveFiles),Path.GetFileName(saveFiles) + ".zip");
+
+                if (Convert.ToInt32(FileCountVal.Text.Trim()) == files.Length)
+                {
+                    CompressFolder(saveFiles, zipFilePath);
+                }
+
+                return;
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"NG,自动获取文件失败,Error: {ex.Message}");
+            }
+        }
+
+
+        private List<string> GetFtpFileList(string ftpServer, string folderPath, string username, string password)
+        {
+            List<string> fileList = new List<string>();
+
+            try
+            {
+                string uri = $"{ftpServer.TrimEnd('/')}/{folderPath.TrimStart('/')}";
+
+                var request = (FtpWebRequest)WebRequest.Create(uri);
+                request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
+                request.Credentials = new NetworkCredential(username, password);
+                request.UsePassive = true;
+                request.UseBinary = true;
+                request.KeepAlive = false;
+
+                using (var response = (FtpWebResponse)request.GetResponse())
+                using (var responseStream = response.GetResponseStream())
+                using (var reader = new StreamReader(responseStream))
+                {
+                    string line;
+                    while ((line = reader.ReadLine()) != null)
+                    {
+                        // 解析FTP返回的行,提取文件名
+                        // FTP返回格式通常类似于: "-rw-r--r-- 1 ftp ftp 12345 Jan 1 10:00 filename.txt"
+                        if (!string.IsNullOrWhiteSpace(line))
+                        {
+                            string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+                            if (parts.Length >= 9)
+                            {
+                                string fileName = parts[8];
+
+                                // 目录则跳过(通常以'd'开头)
+                                if (!parts[0].StartsWith("d") && fileName != "." && fileName != "..")
+                                {
+                                    fileList.Add(fileName);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"获取文件列表失败: {ex.Message}");
+            }
+
+            return fileList;
+        }
+
+        private bool DownloadSingleFile(string ftpServer, string remoteFilePath, string localFilePath, string username, string password)
+        {
+            try
+            {
+                string uri = $"{ftpServer.TrimEnd('/')}/{remoteFilePath.TrimStart('/')}";
+
+                var request = (FtpWebRequest)WebRequest.Create(uri);
+                request.Method = WebRequestMethods.Ftp.DownloadFile;
+                request.Credentials = new NetworkCredential(username, password);
+                request.UsePassive = true;
+                request.UseBinary = true;
+                request.KeepAlive = false;
+
+                using (var response = (FtpWebResponse)request.GetResponse())
+                using (var responseStream = response.GetResponseStream())
+                using (var fileStream = File.Create(localFilePath))
+                {
+                    byte[] buffer = new byte[4096];
+                    int bytesRead;
+                    while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
+                    {
+                        fileStream.Write(buffer, 0, bytesRead);
+                    }
+
+                    LogMessage($"OK,文件下载成功: {remoteFilePath} -> {localFilePath}");
+                    return true;
+                }
+            }
+            catch (WebException ex)
+            {
+                if (ex.Response is FtpWebResponse response)
+                {
+                    LogMessage($"NG,下载失败 {remoteFilePath}: {(int)response.StatusCode} - {response.StatusDescription}");
+                }
+                else
+                {
+                    LogMessage($"NG,下载失败 {remoteFilePath}: {ex.Message}");
+                }
+                return false;
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"NG,下载失败 {remoteFilePath}: {ex.Message}");
+                return false;
+            }
+        }
+
+        private void CompressFile(string sourceFile, string zipPath)
+        {
+            try
+            {
+                using (FileStream zipToOpen = new FileStream(zipPath, FileMode.Create))
+                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
+                {
+                    string fileName = Path.GetFileName(sourceFile);
+                    ZipArchiveEntry readmeEntry = archive.CreateEntry(fileName);
+
+                    using (Stream stream = readmeEntry.Open())
+                    using (FileStream fileStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
+                    {
+                        fileStream.CopyTo(stream);
+                    }
+                }
+                LogMessage($"OK,文件已压缩到:{zipPath}");
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"NG,压缩失败:{ex.Message}");
+            }
+        }
+
+        private void CompressFolder(string sourceFolder, string zipPath)
+        {
+            try
+            {
+                if (File.Exists(zipPath)) 
+                {
+                    try
+                    {
+                        File.Delete(zipPath);
+                    }
+                    catch (IOException ex)
+                    {
+                        LogMessage($"NG,无法删除已存在的文件,可能被其他程序占用:{ex.Message}");
+                        return;
+                    }
+                    catch (UnauthorizedAccessException ex)
+                    {
+                        LogMessage($"NG,没有权限删除文件:{ex.Message}");
+                        return;
+                    }
+                }
+
+                ZipFile.CreateFromDirectory(sourceFolder, zipPath);
+                LogMessage($"OK,文件已压缩到:{zipPath}");
+            }
+            catch (UnauthorizedAccessException ex)
+            {
+                LogMessage($"NG,访问被拒绝:{ex.Message}");
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"NG,压缩失败:{ex.Message}");
+            }
+        }
     }
 }

+ 2 - 0
UAS_Tools_HY/UAS_Tools_HY.csproj

@@ -66,6 +66,8 @@
     <Reference Include="System" />
     <Reference Include="System.configuration" />
     <Reference Include="System.Core" />
+    <Reference Include="System.IO.Compression" />
+    <Reference Include="System.IO.Compression.FileSystem" />
     <Reference Include="System.Numerics" />
     <Reference Include="System.Security" />
     <Reference Include="System.Xml.Linq" />