wanghan 6 月之前
父節點
當前提交
bce8f69d69

+ 1 - 116
TeamAAS-VM/Core/FileHelper.cs

@@ -866,121 +866,6 @@ namespace TeamAAS_VP.Core
         }
         #endregion
 
-        #region 写CTQ的csv
-        public static void WriteDataToCSV(DataFormCtq cd)
-        {
-            string s1, s2, s3, s4,
-                t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18,
-                r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18;
-            //
-            string path = "D:\\Data\\产品数据\\";
-            if (!Directory.Exists(path))
-            {
-                Directory.CreateDirectory(path);
-            }
-            //
-            t1 = "PPID";
-            t2 = "PROCESS_NAME";
-            t3 = "PROCESS_START_TIME";
-            t4 = "CTQ_NAME";
-            t5 = "CTQ_VALUE";
-            t6 = "CTQ_LSL";
-            t7 = "CTQ_USL";
-            t8 = "PROCESS_END_TIME";
-            t9 = "SUPPLIER_NAME";
-            t10 = "COMMODITY_TYPE";
-            t11 = "REVISION";
-            t12 = "WO#";
-            t13 = "MFG_LOT#";
-            t14 = "MFG_ASSY_LINE";
-            t15 = "PROCESS_OUTCOME";
-            t16 = "PROCESS_MACHINE_ID";
-            t17 = "CTQ_UNIT_OF_MEASURE";
-            t18 = "ERROR_MESSAGE";
-            //
-            r1 = cd.PPID;
-            r2 = cd.PROCESS_NAME;
-            r3 = cd.PROCESS_START_TIME;
-            r4 = cd.CTQ_NAME;
-            r5 = cd.CTQ_VALUE.ToString();
-            r6 = cd.CTQ_LSL.ToString();
-            r7 = cd.CTQ_USL.ToString();
-            r8 = cd.PROCESS_END_TIME;
-            r9 = cd.SUPPLIER_NAME;
-            r10 = cd.COMMODITY_TYPE;
-            r11 = cd.REVISION;
-            r12 = cd.WO;
-            r13 = cd.MFG_LOT;
-            r14 = cd.MFG_ASSY_LINE;
-            r15 = cd.PROCESS_OUTCOME;
-            r16 = cd.PROCESS_MACHINE_ID;
-            r17 = cd.CTQ_UNIT_OF_MEASURE;
-            r18 = cd.ERROR_MESSAGE;
-
-            //=========================
-            s1 = path;
-            s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录
-            s3 = t1 + "," + t2 + "," + t3 + "," + t4 + "," + t5 + "," + t6 + "," + t7 + "," + t8 + "," + t9 + "," + t10
-                + "," + t11 + "," + t12 + "," + t13 + "," + t14 + "," + t15 + "," + t16 + "," + t17 + "," + t18;
-            s4 = r1 + "," + r2 + "," + r3 + "," + r4 + "," + r5 + "," + r6 + "," + r7 + "," + r8 + "," + r9 + "," + r10
-                + "," + r11 + "," + r12 + "," + r13 + "," + r14 + "," + r15 + "," + r16 + "," + r17 + "," + r18;
-            //
-            Save(s1, s2, s3, s4);
-        }
-
-
-
-        //写csv
-        public static bool Save(string fullPath, string fileName, string RowName, string Data)
-        {
-            bool result = true;
-            try
-            {
-                if (!Directory.Exists(fullPath))
-                {
-                    Directory.CreateDirectory(fullPath);
-                }
-
-                if (fileName == null)
-                {
-                    fileName = DateTime.Now.ToString("yyyyMMdd");
-                }
-
-                string text = "";
-                string path = fullPath + "\\" + text;
-                string text2 = ".csv";
-                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
-                if (!File.Exists(fullPath + "\\" + fileNameWithoutExtension + fileName + text2))
-                {
-                    using (File.Create(fullPath + "\\" + fileNameWithoutExtension + fileName + text2))
-                    {
-                    }
-
-                    FileStream fileStream2 = new FileStream(fullPath + "\\" + fileNameWithoutExtension + fileName + text2, FileMode.Append);
-                    StreamWriter streamWriter = new StreamWriter(fileStream2, Encoding.UTF8);
-                    streamWriter.WriteLine(RowName);
-                    streamWriter.WriteLine(Data);
-                    streamWriter.Flush();
-                    streamWriter.Close();
-                    fileStream2.Close();
-                }
-                else
-                {
-                    FileStream fileStream2 = new FileStream(fullPath + "\\" + fileNameWithoutExtension + fileName + text2, FileMode.Append);
-                    StreamWriter streamWriter = new StreamWriter(fileStream2, Encoding.UTF8);
-                    streamWriter.WriteLine(Data);
-                    streamWriter.Flush();
-                    streamWriter.Close();
-                    fileStream2.Close();
-                }
-            }
-            catch
-            {
-                result = false;
-            }
-
-            return result;
-        }
-        #endregion
+       
     }
 }

+ 205 - 0
TeamAAS-VM/Core/FtpUploaderTest.cs

@@ -0,0 +1,205 @@
+using FluentFTP;
+using System;
+using System.IO;
+using System.IO.Compression;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TeamAAS_VP.Core
+{
+    public class FtpUploaderTest
+    {
+        public FtpUploaderTest()
+        {
+        }
+
+        public async void UploadFileTest()
+        {
+            //var rootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CuttingLine");
+            //string sourcePath = "Path.Combine(rootPath, SelectedFile)";
+            string sourcePath = @"C:\Users\Administrator\Desktop\test.txt";
+            string content = File.ReadAllText(sourcePath);
+
+            string ftpHost = "192.168.0.40";
+            string ftpUserName = "default";
+            string ftpPwd = "default";
+            content += "END";
+            var byteArray = Encoding.ASCII.GetBytes(content);
+
+            // FluentFTP async upload (replaces deprecated FtpWebRequest)
+            using (var ftp = new FtpClient(ftpHost, new NetworkCredential(ftpUserName, ftpPwd)))
+            {
+                ftp.Config.EncryptionMode = FtpEncryptionMode.None; // plain FTP
+                ftp.Config.DataConnectionType = FtpDataConnectionType.PASV; // passive mode
+
+                ftp.Connect();
+
+                var remotePath = "/usr/usrapp/saveCAM/data.txt";
+                using (var ms = new MemoryStream(byteArray))
+                {
+                    ftp.UploadStream(
+                            ms,
+                            remotePath,
+                            FtpRemoteExists.Overwrite,
+                            createRemoteDir: true
+                        );
+                    await Task.Delay(100).ConfigureAwait(false);
+
+                    Console.WriteLine("File uploaded successfully.");
+                }
+
+            }
+
+        }
+
+        // 测试上传ZIP文件,保持内容不变
+        public async Task UploadZipFileTest()
+        {
+            string sourcePath = @"C:\Users\Administrator\Desktop\test.zip"; // ZIP文件路径
+            string ftpHost = "192.168.0.40";
+            string ftpUserName = "default";
+            string ftpPwd = "default";
+
+            // 读取文件字节(不修改内容)
+            byte[] fileBytes = File.ReadAllBytes(sourcePath);
+
+            using (var ftp = new FtpClient(ftpHost, new NetworkCredential(ftpUserName, ftpPwd)))
+            {
+                ftp.Config.EncryptionMode = FtpEncryptionMode.None;
+                ftp.Config.DataConnectionType = FtpDataConnectionType.PASV;
+
+                ftp.Connect();
+
+                var remotePath = "/usr/usrapp/saveCAM/data.zip"; // 远程路径
+                using (var ms = new MemoryStream(fileBytes))
+                {
+                    ftp.UploadStream(
+                        ms,
+                        remotePath,
+                        FtpRemoteExists.Overwrite,
+                        createRemoteDir: true
+                    );
+
+                    Console.WriteLine("ZIP file uploaded successfully.");
+                }
+            }
+        }
+
+        // 测试上传整个文件夹,保持结构不变
+        public async Task UploadFolderTest()
+        {
+            string localFolderPath = @"C:\Users\Administrator\Desktop\MyFolder"; // 本地文件夹
+            string ftpHost = "192.168.0.40";
+            string ftpUserName = "default";
+            string ftpPwd = "default";
+            string remoteBasePath = "/usr/usrapp/saveCAM/MyFolder"; // 远程基础路径
+
+            using (var ftp = new FtpClient(ftpHost, new NetworkCredential(ftpUserName, ftpPwd)))
+            {
+                ftp.Config.EncryptionMode = FtpEncryptionMode.None;
+                ftp.Config.DataConnectionType = FtpDataConnectionType.PASV;
+
+                ftp.Connect();
+
+                await UploadDirectoryRecursively(ftp, localFolderPath, remoteBasePath);
+
+                Console.WriteLine("Folder uploaded successfully.");
+            }
+        }
+
+        private async Task UploadDirectoryRecursively(FtpClient ftp, string localPath, string remotePath)
+        {
+            // 创建远程目录
+            if (!ftp.DirectoryExists(remotePath))
+            {
+                ftp.CreateDirectory(remotePath);
+            }
+
+            // 上传文件
+            foreach (string file in Directory.GetFiles(localPath))
+            {
+                string fileName = Path.GetFileName(file);
+                string remoteFilePath = $"{remotePath}/{fileName}".Replace("\\", "/");
+
+                byte[] fileBytes = File.ReadAllBytes(file);
+                using (var ms = new MemoryStream(fileBytes))
+                {
+                    ftp.UploadStream(
+                        ms,
+                        remoteFilePath,
+                        FtpRemoteExists.Overwrite,
+                        createRemoteDir: false
+                    );
+                }
+
+                Console.WriteLine($"Uploaded file: {fileName}");
+            }
+
+            // 递归处理子文件夹
+            foreach (string subDir in Directory.GetDirectories(localPath))
+            {
+                string dirName = new DirectoryInfo(subDir).Name;
+                string remoteSubPath = $"{remotePath}/{dirName}".Replace("\\", "/");
+
+                await UploadDirectoryRecursively(ftp, subDir, remoteSubPath);
+            }
+
+            await Task.CompletedTask;
+        }
+
+        // 测试上传整个文件夹作为ZIP,保持内容不变
+        public async Task UploadFolderAsZipTest()
+        {
+            string sourceFolder = @"D:\image\Recored\2026-03\03-02\产品1\CN0D0NDYCKJ006250103X02";
+            string tempZipPath = Path.Combine(Path.GetTempPath(), $"CN0D0NDYCKJ006250103X02.zip");
+
+            try
+            {
+                // 创建ZIP文件
+                ZipFile.CreateFromDirectory(sourceFolder, tempZipPath);
+
+                // 上传ZIP
+                string ftpHost = "10.130.63.3";
+                string ftpUserName = "AE";
+                string ftpPwd = "LUX#PCiCT2026";
+
+                byte[] zipBytes = File.ReadAllBytes(tempZipPath);
+
+                using (var ftp = new FtpClient(ftpHost, new NetworkCredential(ftpUserName, ftpPwd)))
+                {
+                    ftp.Config.EncryptionMode = FtpEncryptionMode.None;
+                    ftp.Config.DataConnectionType = FtpDataConnectionType.PASV;
+                    ftp.Config.ConnectTimeout = 15000;
+
+                    ftp.Connect();
+
+                    var remotePath = $"/ae/KB_Screw_1/CN0D0NDYCKJ006250103X02.zip";
+                    using (var ms = new MemoryStream(zipBytes))
+                    {
+                        ftp.UploadStream(
+                            ms,
+                            remotePath,
+                            FtpRemoteExists.Overwrite,
+                            createRemoteDir: true
+                        );
+                    }
+
+                    Console.WriteLine("Folder compressed and uploaded as ZIP successfully.");
+                }
+            }
+            catch (Exception ex)
+            {
+                System.Windows.Forms.MessageBox.Show(ex.Message);
+            }
+            finally
+            {
+                // 清理临时文件
+                if (File.Exists(tempZipPath))
+                {
+                    File.Delete(tempZipPath);
+                }
+            }
+        }
+    }
+}

+ 25 - 19
TeamAAS-VM/Core/Management.cs

@@ -268,8 +268,6 @@ namespace TeamAAS_VP.Core
             set { SetProperty(ref _dfc, value); }
         }
 
-        public FtpUploader ftpService { get; set; } = new FtpUploader();
-
         private ObservableCollection<ProductModel> _ProductList;
         public ObservableCollection<ProductModel> ProductList
         {
@@ -2250,6 +2248,7 @@ namespace TeamAAS_VP.Core
                                                     {
                                                         ProductMainSN[i] = item[4].Replace("sn=", "");
                                                         SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
+                                                        _productService.CurrentProductCode = ProductMainSN[i];
                                                     }
                                                     if (item[5].Contains("wo="))
                                                     {
@@ -2337,6 +2336,7 @@ namespace TeamAAS_VP.Core
                                                 {
                                                     ProductMainSN[i] = item[4].Replace("sn=", "");
                                                     SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
+                                                    _productService.CurrentProductCode = ProductMainSN[i];
                                                 }
                                                 if (item[5].Contains("wo="))
                                                 {
@@ -2557,24 +2557,17 @@ namespace TeamAAS_VP.Core
                                                 {
                                                     SendTaskMessage($"{i}:{stationConfig.DeviceName}产品记录保存成功", MessageLevel.Debug);
 
-                                                    //ftpService.UploadToFtp(stationConfig.SaveCsvPath);
-                                                    //if (i == 0)
+                                                   
+                                                    //(bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], "");
+                                                    //if (isSuc)
+                                                    //{
+                                                    //    LogHelper.WriteLogMes($"上传数据成功");
+                                                    //    SendTaskMessage($"上传数据成功", MessageLevel.Debug);
+                                                    //}
+                                                    //else
                                                     //{
-                                                    //    string name = $"{ProductMainSN[i]}_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
-                                                    //    string zippath = await ftpService.CompressionImage(name);
-                                                    //    ftpService.UploadToFtp(zippath);
-
-                                                    //    (bool isSuc, string resp) = await _mesService.SendFtpFileAsync(ProductMainSN[i], name);
-                                                    //    if (isSuc)
-                                                    //    {
-                                                    //        LogHelper.WriteLogMes($"上传ftp成功");
-                                                    //        SendTaskMessage($"上传ftp成功", MessageLevel.Debug);
-                                                    //    }
-                                                    //    else
-                                                    //    {
-                                                    //        LogHelper.WriteLogMes($"上传ftp失败");
-                                                    //        SendTaskMessage($"上传ftp失败", MessageLevel.Error);
-                                                    //    }
+                                                    //    LogHelper.WriteLogMes($"上传数据失败");
+                                                    //    SendTaskMessage($"上传数据失败", MessageLevel.Error);
                                                     //}
                                                 }
                                                 else
@@ -3242,6 +3235,19 @@ namespace TeamAAS_VP.Core
         }
         #endregion
 
+        #region 写log
+        TxtFile mesLog = new TxtFile($"D:\\Data\\Mes记录", "");
+        public void MesMessage(string msg)
+        {
+            mesLog.WriteLine("==  " + msg + "\r\n");
+        }
+        TxtFile infoLog = new TxtFile($"D:\\Data\\运行日志", "");
+        public void InfoMessage(string msg)
+        {
+            infoLog.WriteLine("==  " + msg + "\r\n");
+        }
+        #endregion
+
         #endregion
     }
 }

+ 414 - 0
TeamAAS-VM/Core/TxtFile.cs

@@ -0,0 +1,414 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TeamAAS_VP.Core
+{
+    public class TxtFile
+    {
+        private string _filepath = string.Empty;
+
+        private string _filename = string.Empty;
+
+        private int _filesize = 0;
+
+        private int _interval = 0;
+
+        private string _seperator = ",";
+
+        private int logcount = 0;
+
+        private bool _bWrite = true;
+
+        private object _objlock = new object();
+
+        public bool bWrite
+        {
+            get
+            {
+                return _bWrite;
+            }
+            set
+            {
+                _bWrite = value;
+            }
+        }
+
+        public string FilePath
+        {
+            get
+            {
+                return _filepath;
+            }
+            set
+            {
+                _filepath = value;
+            }
+        }
+
+        public string FileName
+        {
+            get
+            {
+                return _filename;
+            }
+            set
+            {
+                _filename = value;
+            }
+        }
+
+        public int FileSize
+        {
+            get
+            {
+                return _filesize;
+            }
+            set
+            {
+                _filesize = value;
+            }
+        }
+
+        public int Interval
+        {
+            get
+            {
+                return _interval;
+            }
+            set
+            {
+                if (value > 0 && value <= 12)
+                {
+                    _interval = value;
+                }
+                else if (value < 0)
+                {
+                    _interval = 0;
+                }
+                else
+                {
+                    _interval = 12;
+                }
+            }
+        }
+
+        public string Seperator
+        {
+            get
+            {
+                return _seperator;
+            }
+            set
+            {
+                _seperator = value;
+            }
+        }
+
+        public TxtFile()
+        {
+        }
+
+        public TxtFile(string strFilePath, string strFileName)
+        {
+            _filepath = strFilePath;
+            _filename = strFileName;
+        }
+
+        public TxtFile(string strFilePath, string strFileName, int filesize, int interval, string seperator)
+        {
+            _filepath = strFilePath;
+            _filename = strFileName;
+            _filesize = filesize;
+            _interval = interval;
+            _seperator = seperator;
+        }
+
+        public void WriteLine(string strSave)
+        {
+            if (!bWrite)
+            {
+                return;
+            }
+
+            try
+            {
+                lock (_objlock)
+                {
+                    if (!Directory.Exists(_filepath))
+                    {
+                        Directory.CreateDirectory(_filepath);
+                    }
+
+                    string text = DateTime.Now.ToString("yyyy-MM-dd-");
+                    if (_interval > 0 && _interval <= 12)
+                    {
+                        logcount = DateTime.Now.Hour / _interval;
+                    }
+
+                    string text2 = _filepath + "\\" + _filename;
+                    string text3 = Path.GetExtension(text2);
+                    if (text3.Length == 0)
+                    {
+                        text2 += ".log";
+                        text3 = ".log";
+                    }
+
+                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2);
+                    if (!File.Exists(_filepath + "\\" + fileNameWithoutExtension + text + logcount + text3))
+                    {
+                        using (File.Create(_filepath + "\\" + fileNameWithoutExtension + text + logcount + text3))
+                        {
+                        }
+                    }
+
+                    using (StreamWriter streamWriter = File.AppendText(_filepath + "\\" + fileNameWithoutExtension + text + logcount + text3))
+                    {
+                        StringBuilder stringBuilder = new StringBuilder();
+                        stringBuilder.Append(text.Substring(0, text.Length - 1));
+                        stringBuilder.Append(_seperator);
+                        string value = DateTime.Now.TimeOfDay.ToString();
+                        stringBuilder.Append(value);
+                        stringBuilder.Append(_seperator);
+                        stringBuilder.Append(strSave);
+                        if (strSave.Length > 2)
+                        {
+                            if ('\r' != strSave[strSave.Length - 2] || '\n' != strSave[strSave.Length - 1])
+                            {
+                                streamWriter.WriteLine(stringBuilder.ToString());
+                            }
+                            else
+                            {
+                                streamWriter.Write(stringBuilder.ToString());
+                            }
+                        }
+                        else
+                        {
+                            streamWriter.WriteLine(stringBuilder.ToString());
+                        }
+
+                        streamWriter.Flush();
+                        streamWriter.Close();
+                    }
+
+                    if (_filesize > 0)
+                    {
+                        FileInfo fileInfo = new FileInfo(_filepath + fileNameWithoutExtension + "\\" + text + logcount + text3);
+                        if (fileInfo.Length > 1048576 * _filesize)
+                        {
+                            logcount++;
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
+        public void WriteLine(string strSave, bool bwrite)
+        {
+            if (bwrite)
+            {
+                WriteLine(strSave);
+            }
+        }
+
+        public void WriteTxt(string strSave)
+        {
+            try
+            {
+                lock (_objlock)
+                {
+                    if (!Directory.Exists(_filepath))
+                    {
+                        Directory.CreateDirectory(_filepath);
+                    }
+
+                    string text = _filepath + "\\" + _filename;
+                    string text2 = Path.GetExtension(text);
+                    if (text2.Length == 0)
+                    {
+                        text += ".txt";
+                        text2 = ".txt";
+                    }
+
+                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
+                    if (!File.Exists(_filepath + "\\" + fileNameWithoutExtension + text2))
+                    {
+                        using (File.Create(_filepath + "\\" + fileNameWithoutExtension + text2))
+                        {
+                        }
+                    }
+
+                    StreamWriter streamWriter = File.AppendText(_filepath + "\\" + fileNameWithoutExtension + text2);
+                    StringBuilder stringBuilder = new StringBuilder();
+                    stringBuilder.Append(strSave);
+                    if (strSave.Length > 2)
+                    {
+                        if ('\r' != strSave[strSave.Length - 2] || '\n' != strSave[strSave.Length - 1])
+                        {
+                            streamWriter.WriteLine(stringBuilder.ToString());
+                        }
+                        else
+                        {
+                            streamWriter.Write(stringBuilder.ToString());
+                        }
+                    }
+                    else
+                    {
+                        streamWriter.WriteLine(stringBuilder.ToString());
+                    }
+
+                    streamWriter.Flush();
+                    streamWriter.Close();
+                }
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
+        public void WriteTxtAndName(string strSave, string filename)
+        {
+            try
+            {
+                lock (_objlock)
+                {
+                    if (!Directory.Exists(_filepath))
+                    {
+                        Directory.CreateDirectory(_filepath);
+                    }
+
+                    string text = Path.GetExtension(filename);
+                    if (text.Length == 0)
+                    {
+                        filename += ".txt";
+                        text = ".txt";
+                    }
+
+                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
+                    if (!File.Exists(_filepath + "\\" + fileNameWithoutExtension + text))
+                    {
+                        using (File.Create(_filepath + "\\" + fileNameWithoutExtension + text))
+                        {
+                        }
+                    }
+
+                    StreamWriter streamWriter = File.AppendText(_filepath + "\\" + fileNameWithoutExtension + text);
+                    StringBuilder stringBuilder = new StringBuilder();
+                    stringBuilder.Append(strSave);
+                    if (strSave.Length > 2)
+                    {
+                        if ('\r' != strSave[strSave.Length - 2] || '\n' != strSave[strSave.Length - 1])
+                        {
+                            streamWriter.WriteLine(stringBuilder.ToString());
+                        }
+                        else
+                        {
+                            streamWriter.Write(stringBuilder.ToString());
+                        }
+                    }
+                    else
+                    {
+                        streamWriter.WriteLine(stringBuilder.ToString());
+                    }
+
+                    streamWriter.Flush();
+                    streamWriter.Close();
+                }
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
+        public void Write(string strSave, string strSeperator)
+        {
+            StreamWriter streamWriter = null;
+            string path = _filepath + "\\" + _filename;
+            try
+            {
+                if (!Directory.Exists(_filepath))
+                {
+                    Directory.CreateDirectory(_filepath);
+                }
+
+                if (!File.Exists(path))
+                {
+                    using (File.Create(path))
+                    {
+                    }
+                }
+
+                streamWriter = new StreamWriter(path, append: true);
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.Append(strSave);
+                stringBuilder.Append(strSeperator);
+                streamWriter.Write(stringBuilder);
+                streamWriter.Close();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            finally
+            {
+                streamWriter?.Close();
+            }
+        }
+
+        public string ReadLine()
+        {
+            StreamReader streamReader = null;
+            try
+            {
+                string text = null;
+                streamReader = new StreamReader(FilePath + "\\" + FileName, detectEncodingFromByteOrderMarks: false);
+                text = streamReader.ReadLine();
+                streamReader.Close();
+                return text;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            finally
+            {
+                streamReader?.Close();
+            }
+        }
+
+        public List<string> ReadAll()
+        {
+            StreamReader streamReader = null;
+            try
+            {
+                List<string> list = new List<string>();
+                string text = null;
+                streamReader = new StreamReader(FilePath + "\\" + FileName, Encoding.GetEncoding("gb2312"), detectEncodingFromByteOrderMarks: false);
+                for (text = streamReader.ReadLine(); text != null; text = streamReader.ReadLine())
+                {
+                    list.Add(text);
+                }
+
+                streamReader.Close();
+                return list;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+            finally
+            {
+                streamReader?.Close();
+            }
+        }
+    }
+}

+ 11 - 0
TeamAAS-VM/Models/DeviceInfo.cs

@@ -57,6 +57,17 @@ namespace TeamAAS_VP.Models
         /// </summary>
         public string MesUrl { get => _mesUrl; set => SetProperty(ref _mesUrl, value); }
 
+        private string _LogUrl;
+        /// <summary>
+        /// log的url
+        /// </summary>
+        public string LogUrl { get => _LogUrl; set => SetProperty(ref _LogUrl, value); }
+
+        private string _ApiKey;
+        /// <summary>
+        /// ApiKey
+        /// </summary>
+        public string ApiKey { get => _ApiKey; set => SetProperty(ref _ApiKey, value); }
 
         private string _f;
         /// <summary>

+ 7 - 8
TeamAAS-VM/Services/MesService.cs

@@ -707,7 +707,7 @@ namespace TeamAAS_VP.Services
         }
 
         /// <summary>
-        /// 上传ftp
+        /// 上传log服务器
         /// </summary>
         /// <param name="sn"></param>
         /// <param name="name"></param>
@@ -724,8 +724,12 @@ namespace TeamAAS_VP.Services
             {
                 return (true, "MES功能未启用!");
             }
-           
-            string url = $"http://127.0.0.1/api.ashx?db=mysql&ApiKey=123!#yuiop&jsondata={{\"SN\":\"{sn}\",\"LINE\":\"{device.Line}\",\"STATION\":\"{device.Station}\",\"TESTRESULT\":\"PASS\",\"FIXTUREID\":\"{device.FixtureId}\",\"TESTDATETIME\":\"{DateTime.Now.ToString()}\",\"LOGFILENAME\":\"{name}.zip\"}}";
+            if (string.IsNullOrWhiteSpace(device.LogUrl))
+            {
+                return (false, "Missing MES station LogUrl");
+            }
+
+            string url = $"{device.LogUrl}?db=mysql&ApiKey={device.ApiKey}&jsondata={{\"SN\":\"{sn}\",\"LINE\":\"{device.Line}\",\"STATION\":\"{device.Station}\",\"TESTRESULT\":\"PASS\",\"FIXTUREID\":\"{device.FixtureId}\",\"TESTDATETIME\":\"{DateTime.Now.ToString()}\",\"LOGFILENAME\":\"{name}.zip\"}}";
            
             LogHelper.WriteLogMes($"【上传FTP的URL】{url}");
             SendTaskMessage($"【上传FTP的URL】{url}", MessageLevel.Info);
@@ -743,11 +747,6 @@ namespace TeamAAS_VP.Services
                         // "SFC_OK" 代表和 MES 连接成功
                         if (text.Contains("SFC_OK"))
                         {
-                            // 如果有附加信息(多行),代表此 SN 数据有问题,视为失败并返回该文本
-                            if (text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Length > 1)
-                            {
-                                return (false, text);
-                            }
                             return (true, text);
                         }
                         result = (false, text);

+ 5 - 0
TeamAAS-VM/TeamAAS-VP.csproj

@@ -191,6 +191,9 @@
     <Reference Include="ExtendedNumerics.BigDecimal, Version=3001.0.1.201, Culture=neutral, PublicKeyToken=65f1315a45ad8949, processorArchitecture=MSIL">
       <HintPath>..\packages\ExtendedNumerics.BigDecimal.3001.0.1.201\lib\net48\ExtendedNumerics.BigDecimal.dll</HintPath>
     </Reference>
+    <Reference Include="FluentFTP, Version=53.0.2.0, Culture=neutral, PublicKeyToken=f4af092b1d8df44f, processorArchitecture=MSIL">
+      <HintPath>..\packages\FluentFTP.53.0.2\lib\net472\FluentFTP.dll</HintPath>
+    </Reference>
     <Reference Include="GxIAPINET, Version=1.0.2503.8311, Culture=neutral, processorArchitecture=AMD64">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>TeamAAS-VP\exe\GxIAPINET.dll</HintPath>
@@ -533,7 +536,9 @@
     </Compile>
     <Compile Include="Core\FileNameTemplate.cs" />
     <Compile Include="Core\FtpUploader.cs" />
+    <Compile Include="Core\FtpUploaderTest.cs" />
     <Compile Include="Core\StabilityAnalyzer.cs" />
+    <Compile Include="Core\TxtFile.cs" />
     <Compile Include="Core\VisionProFileHelper.cs" />
     <Compile Include="Events\MainTabSwitchNotification.cs" />
     <Compile Include="Events\WorkShiftChangedNotification.cs" />

+ 11 - 9
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -1926,6 +1926,11 @@ namespace TeamAAS_VP.ViewModels
                 ProMesInfo.ProductCode = "";
                 ProMesInfo.ProductColor = "";
             }
+            else
+            {
+                ProMesInfo.ProductCode = v.ProductCode;
+                ProMesInfo.ProductColor = v.ProductColor;
+            }
         }
 
         private async void ExecuteDeleteProWithMesCommand()
@@ -1965,20 +1970,17 @@ namespace TeamAAS_VP.ViewModels
         private DelegateCommand _testCommand;
         public DelegateCommand testCommand =>
             _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
-        public FtpUploader ftpService { get; set; } = new FtpUploader();
+        public FtpUploaderTest ftpService { get; set; } = new FtpUploaderTest();
 
         private async void Execute_testCommand()
         {
-            //var stationConfig = _configService.GetDeviceInfo(0);
-
-            //ftpService.UploadToFtp(stationConfig.SaveCsvPath);
-            var currentproduct = _productService.GetCurrentProduct();
-            
-            string sn = $"CN0D0NDYCKJ006260336X02";
-            string zippath = await ftpService.CompressionImage(sn, currentproduct.Name);
-            ftpService.UploadToFtp(zippath);
+            //var currentproduct = _productService.GetCurrentProduct();
 
+            //string sn = $"CN0D0NDYCKJ006260336X02";
+            //string zippath = await ftpService.CompressionImage(sn, currentproduct.Name);
+            //ftpService.UploadToFtp(zippath);
 
+            //ftpService.UploadFolderAsZipTest();
         }
     }
 }

+ 0 - 4
TeamAAS-VM/Views/Home/ShowVisionRender.xaml.cs

@@ -549,10 +549,6 @@ namespace TeamAAS_VP.Views.Home
                         {
                             reimage.Save(Recordedpath);
                         }
-                        ////================
-                        //FtpUploader ftpService = new FtpUploader();
-                        //string zippath = ftpService.CompressionImage("123456789");
-                        //ftpService.UploadToFtp(zippath);
                     }
                 }
                 catch (Exception ex)

+ 45 - 26
TeamAAS-VM/Views/SettingView.xaml

@@ -353,6 +353,10 @@
                                     <RowDefinition Height="Auto" />
                                     <RowDefinition Height="Auto" />
                                     <RowDefinition Height="Auto" />
+                                    <RowDefinition Height="Auto" />
+                                    <RowDefinition Height="Auto" />
+                                    <RowDefinition Height="Auto" />
+                                    <RowDefinition Height="Auto" />
                                 </Grid.RowDefinitions>
                                 <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="auto" />
@@ -451,11 +455,26 @@
                                          Margin="6,2" />
 
                                 <!--<TextBlock Grid.Row="9"
-                                           Grid.Column="0"
-                                           Text="启用 MES:"
-                                           HorizontalAlignment="Right"
-                                           VerticalAlignment="Center" />-->
-                                <CheckBox Grid.Row="9"
+           Grid.Column="0"
+           Text="LogUrl:"
+           HorizontalAlignment="Right"
+           VerticalAlignment="Center" />
+                                <TextBox Grid.Row="9"
+         Grid.Column="1"
+         Text="{Binding SelectDeviceInfo.LogUrl, Mode=TwoWay}"
+         Margin="6,2" />
+
+                                <TextBlock Grid.Row="10"
+           Grid.Column="0"
+           Text="apikey:"
+           HorizontalAlignment="Right"
+           VerticalAlignment="Center" />
+                                <TextBox Grid.Row="10"
+         Grid.Column="1"
+         Text="{Binding SelectDeviceInfo.ApiKey, Mode=TwoWay}"
+         Margin="6,2" />-->
+
+                                <CheckBox Grid.Row="11"
                                           Grid.Column="1"
                                           Content="启用 MES"
                                           IsChecked="{Binding SelectDeviceInfo.EnableMES, Mode=TwoWay}"
@@ -465,18 +484,18 @@
                                           Content="是否启用两次产品编号"
                                           IsChecked="{Binding SelectDeviceInfo.EnableDoubleMes, Mode=TwoWay}"
                                           Margin="6,2" />-->
-                                <CheckBox Grid.Row="11"
+                                <CheckBox Grid.Row="13"
                                           Grid.Column="1"
                                           Content="是否保存CSV文件"
                                           IsChecked="{Binding SelectDeviceInfo.SaveCsv, Mode=TwoWay}"
                                           Margin="6,2" />
-                                <TextBlock Grid.Row="12"
+                                <TextBlock Grid.Row="14"
                                            Grid.Column="0"
                                            Text="保存的CSV文件路径:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
                                 <DockPanel HorizontalAlignment="Stretch"
-                                           Grid.Row="12"
+                                           Grid.Row="14"
                                            Grid.Column="1"
                                            Margin="6,2">
                                     <Button DockPanel.Dock="Right"
@@ -491,92 +510,92 @@
 
                                 </DockPanel>
                                 <!--CTQ 数据信息-->
-                                <TextBlock Grid.Row="13"
+                                <TextBlock Grid.Row="15"
                                            Grid.Column="0"
                                            Text="PROCESS_NAME:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="13"
+                                <TextBox Grid.Row="15"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.PROCESS_NAME, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="14"
+                                <TextBlock Grid.Row="16"
                                            Grid.Column="0"
                                            Text="CTQ_LSL(压力下限):"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="14"
+                                <TextBox Grid.Row="16"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.CTQ_LSL_Pressure, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="15"
+                                <TextBlock Grid.Row="17"
                                            Grid.Column="0"
                                            Text="CTQ_USL(压力上限):"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="15"
+                                <TextBox Grid.Row="17"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.CTQ_USL_Pressure, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="16"
+                                <TextBlock Grid.Row="18"
                                            Grid.Column="0"
                                            Text="SUPPLIER_NAME:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="16"
+                                <TextBox Grid.Row="18"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.SUPPLIER_NAME, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="17"
+                                <TextBlock Grid.Row="19"
                                            Grid.Column="0"
                                            Text="COMMODITY_TYPE:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="17"
+                                <TextBox Grid.Row="19"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.COMMODITY_TYPE, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="18"
+                                <TextBlock Grid.Row="20"
                                            Grid.Column="0"
                                            Text="REVISION:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="18"
+                                <TextBox Grid.Row="20"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.REVISION, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="19"
+                                <TextBlock Grid.Row="21"
                                            Grid.Column="0"
                                            Text="MFG_LOT#:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="19"
+                                <TextBox Grid.Row="21"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.MFG_LOT, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="20"
+                                <TextBlock Grid.Row="22"
                                            Grid.Column="0"
                                            Text="MFG_ASSY_LINE:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="20"
+                                <TextBox Grid.Row="22"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.MFG_ASSY_LINE, Mode=TwoWay}"
                                          Margin="6,2" />
 
-                                <TextBlock Grid.Row="21"
+                                <TextBlock Grid.Row="23"
                                            Grid.Column="0"
                                            Text="PROCESS_MACHINE_ID:"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center" />
-                                <TextBox Grid.Row="21"
+                                <TextBox Grid.Row="23"
                                          Grid.Column="1"
                                          Text="{Binding SelectDeviceInfo.DataInfo.PROCESS_MACHINE_ID, Mode=TwoWay}"
                                          Margin="6,2" />

+ 1 - 0
TeamAAS-VM/packages.config

@@ -7,6 +7,7 @@
   <package id="EntityFramework" version="6.5.1" targetFramework="net48" />
   <package id="Enums.NET" version="5.0.0" targetFramework="net48" />
   <package id="ExtendedNumerics.BigDecimal" version="3001.0.1.201" targetFramework="net48" />
+  <package id="FluentFTP" version="53.0.2" targetFramework="net48" />
   <package id="iTextSharp" version="5.5.13.4" targetFramework="net48" />
   <package id="log4net" version="3.2.0" targetFramework="net48" />
   <package id="MahApps.Metro" version="2.4.10" targetFramework="net48" />