浏览代码

设备数据读取项目提交

callm 1 年之前
父节点
当前提交
9ea5acbeb6

+ 11 - 10
FileWatcher/AutoAnalysisXmlByStep.Designer.cs

@@ -50,7 +50,7 @@
             this.li_code = new System.Windows.Forms.TextBox();
             this.label3 = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
-            this.ma_code = new System.Windows.Forms.TextBox();
+            this.MachineType = new System.Windows.Forms.TextBox();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
@@ -209,6 +209,7 @@
             this.button1.TabIndex = 21;
             this.button1.Text = "选择文件夹";
             this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.ChooseBackUpFolder_Click);
             // 
             // Device
             // 
@@ -266,13 +267,13 @@
             this.label2.TabIndex = 17;
             this.label2.Text = "机型";
             // 
-            // ma_code
+            // MachineType
             // 
-            this.ma_code.Location = new System.Drawing.Point(218, 262);
-            this.ma_code.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.ma_code.Name = "ma_code";
-            this.ma_code.Size = new System.Drawing.Size(436, 35);
-            this.ma_code.TabIndex = 18;
+            this.MachineType.Location = new System.Drawing.Point(218, 262);
+            this.MachineType.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.MachineType.Name = "MachineType";
+            this.MachineType.Size = new System.Drawing.Size(436, 35);
+            this.MachineType.TabIndex = 18;
             // 
             // AutoAnalysisXmlByStep
             // 
@@ -286,7 +287,7 @@
             this.Controls.Add(this.button1);
             this.Controls.Add(this.BackUpFolderPath);
             this.Controls.Add(this.bei);
-            this.Controls.Add(this.ma_code);
+            this.Controls.Add(this.MachineType);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.AutoStart);
             this.Controls.Add(this.Master);
@@ -301,7 +302,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MaximizeBox = false;
             this.Name = "AutoAnalysisXmlByStep";
-            this.Text = "UAS自动过站解析器 2022-07-20  15:05";
+            this.Text = "UAS自动过站解析器 2024-04-18 09:19";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();
@@ -332,7 +333,7 @@
         private System.Windows.Forms.Label label5;
         private System.Windows.Forms.TextBox li_code;
         private System.Windows.Forms.Label label3;
-        private System.Windows.Forms.TextBox ma_code;
+        private System.Windows.Forms.TextBox MachineType;
         private System.Windows.Forms.Label label2;
     }
 }

+ 157 - 20
FileWatcher/AutoAnalysisXmlByStep.cs

@@ -9,6 +9,9 @@ using System.Xml;
 using System.Text;
 using System.Media;
 using System.Linq;
+using NPOI.SS.Formula.Functions;
+using System.Windows.Media.TextFormatting;
+using UMESDLLService;
 
 namespace FileWatcher
 {
@@ -82,7 +85,6 @@ namespace FileWatcher
         string ftpulr = "";
         private void Form1_Load(object sender, EventArgs e)
         {
-
             tipform.Show();
             CheckForIllegalCrossThreadCalls = false;
             FormBorderStyle = FormBorderStyle.FixedSingle;
@@ -93,8 +95,20 @@ namespace FileWatcher
             stw.StartPosition = FormStartPosition.CenterScreen;
             stw.ShowDialog();
             List<string> CacheInf = new List<string>();
-            ftpulr = dh.getFieldDataByCondition("configs", "data", "code='UploadFTP' and caller='MESSetting'").ToString();
-            fieltype = dh.getFieldDataByCondition("configs", "data", "code='UploadFile' and caller='MESSetting'").ToString();
+            StreamReader sR = new StreamReader(Application.StartupPath + @"\MES_SETTING.txt", Encoding.Default);
+            while ((nextLine = sR.ReadLine()) != null)
+            {
+                string name = nextLine.ToString().Split('=')[0];
+                string value = nextLine.ToString().Split('=')[1];
+                if (name == "FTPURL")
+                {
+                    ftpulr = value;
+                }
+                if (name == "FileType")
+                {
+                    fieltype = value;
+                }
+            }
             string[] FTPInf = ftpulr.Split('#');
             ftp = new ftpOperater(FTPInf[0], FTPInf[1], FTPInf[2]);
             //获取缓存信息
@@ -103,7 +117,9 @@ namespace FileWatcher
                 FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
                 BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
                 Master.Text = BaseUtil.GetCacheData("Master").ToString();
-                //AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
+                li_code.Text = BaseUtil.GetCacheData("Line").ToString();
+                MachineType.Text = BaseUtil.GetCacheData("MachineType").ToString();
+                Device.Text = BaseUtil.GetCacheData("Device").ToString();
             }
             catch (Exception ex) { MessageBox.Show(ex.Message); }
         }
@@ -128,11 +144,11 @@ namespace FileWatcher
                     return;
                 }
             }
-            //if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
-            //{
-            //    OperateResult.AppendText("工单号不存在\n");
-            //    return;
-            //}
+            if (!dh.CheckExist("line", "li_code='" + li_code.Text + "'"))
+            {
+                OperateResult.AppendText("线别不存在\n");
+                return;
+            }
             XmlWatcher.Path = FolderPath.Text;
             XmlWatcher.Filter = "*.*";
             XmlWatcher.EnableRaisingEvents = true;
@@ -140,6 +156,9 @@ namespace FileWatcher
             BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
             BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
             BaseUtil.SetCacheData("Master", Master.Text);
+            BaseUtil.SetCacheData("Line", li_code.Text);
+            BaseUtil.SetCacheData("MachineType", MachineType.Text);
+            BaseUtil.SetCacheData("Device", Device.Text);
             //BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
             Timer.Interval = 1000 * 10;
             Timer.Start();
@@ -163,13 +182,13 @@ namespace FileWatcher
             string[] str = fieltype.Split('#');
             for (int i = 0; i < str.Length; i++)
             {
-                if (e.FullPath.EndsWith(str[i]))
+                if (e.FullPath.ToUpper().EndsWith(str[i].ToUpper()))
                 {
                     TxtHandleProcess(e.FullPath);
                 }
             }
         }
-
+        string nextLine;
         private void TxtHandleProcess(string FileName)
         {
             List<string> badcode = new List<string>();
@@ -185,15 +204,133 @@ namespace FileWatcher
                     try
                     {
                         string sn1 = SN.Split('.')[0];
-                        string makecode = dh.getFieldDataByCondition("makeserial","ms_makecode","ms_sncode='"+sn1+"'").ToString();
-                        ma_code.Text = makecode;
-                        string ftppath = "/" + ma_code.Text + "/";
-                        ftp.UpLoadFile(folderpath, SN, ftppath, "");
-                        int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class,STD_RESCODE,std_stepcode)select STEPTESTDETAIL_seq.nextval,'" + SN + "','',sysdate,'" + ftpulr.Split('#')[0] + imaster + "/" + ftppath + SN + "','" + isource + "','' from dual", "insert").ToString());
-                        if (num > 0)
+                        //string makecode = dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode='" + sn1 + "'").ToString();
+                        //MachineType.Text = makecode;
+                        string ftppath = "/" + MachineType.Text + "/";
+                        //string ErrMessage = ftp.UpLoadFile(folderpath, SN, ftppath, "");
+
+                        DirectoryInfo info = new DirectoryInfo(folderpath);
+                        String path = info.Parent.Parent.FullName;
+                        MachineType.Text = info.Name;//获取当前路径最后一级文件夹名称
+                        if (Device.Text == "炉后AOI")
                         {
-                            OperateResult.AppendText("序列号:" + SN + "上传成功\n");
-                            //File.Delete(FileName);
+                            StreamReader sR = new StreamReader(FileName, Encoding.Default);
+                            string ASN = "";
+                            string Model = "";
+                            string Shift = "";
+                            string Rep_Date_Time = "";
+                            string OPID = "";
+                            string StationName = "";
+                            string Surface = "";
+                            string CycleTime = "";
+                            string Result = "";
+                            int Rowindex = 0;
+                            List<string> Location = new List<string>();
+                            List<string> PinNum = new List<string>();
+                            List<string> ErrCode = new List<string>();
+                            List<string> RepairStatus = new List<string>();
+                            while ((nextLine = sR.ReadLine()) != null)
+                            {
+                                string data = nextLine.ToString().Split('=')[1];
+                                string itemname = nextLine.ToString().Split('=')[0];
+                                switch (Rowindex)
+                                {
+                                    case 0:
+                                        ASN = data;
+                                        break;
+                                    case 1:
+                                        Model = data;
+                                        break;
+                                    case 2:
+                                        Shift = data;
+                                        break;
+                                    case 3:
+                                        Rep_Date_Time = data;
+                                        break;
+                                    case 4:
+                                        OPID = data;
+                                        break;
+                                    case 5:
+                                        StationName = data;
+                                        break;
+                                    case 6:
+                                        Surface = data;
+                                        break;
+                                    case 7:
+                                        CycleTime = data;
+                                        break;
+                                    default:
+                                        break;
+                                }
+                                if (itemname == "Result")
+                                {
+                                    Result = data;
+                                    continue;
+                                }
+                                if (Rowindex >= 8)
+                                {
+                                    //Location
+                                    if ((Rowindex - 8) % 4 == 0)
+                                    {
+                                        Location.Add(data);
+                                    }
+                                    //PinNum
+                                    if ((Rowindex - 8) % 4 == 1)
+                                    {
+                                        PinNum.Add(data);
+                                    }
+                                    //ErrCode
+                                    if ((Rowindex - 8) % 4 == 2)
+                                    {
+                                        ErrCode.Add(data);
+                                    }
+                                    //RepairStatus
+                                    if ((Rowindex - 8) % 4 == 3)
+                                    {
+                                        RepairStatus.Add(data);
+                                    }
+                                }
+
+                                Rowindex = Rowindex + 1;
+                            }
+                            sR.Close();
+                            Thread.Sleep(500);
+                            int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class,STD_RESCODE,std_stepcode,std_linecode,std_machinetype)select STEPTESTDETAIL_seq.nextval,'" + SN + "','',sysdate,'" + ftpulr.Split('#')[0] + imaster + "/" + ftppath + SN + "','" + isource + "','" + Device.Text + "','" + li_code.Text + "','" + MachineType.Text + "' from dual", "insert").ToString());
+                            if (Result.ToUpper() == "FAIL")
+                            {
+                                sql.Clear();
+                                sql.Append("insert into makebad(mb_id,MB_MSCODE, MB_SNCODE, MB_INDATE, MB_STEPCODE, MB_SOURCECODE, MB_BADCODE, MB_YMD, MB_LINECODE,MB_BADNAME)");
+                                sql.Append("values(makebad_seq.nextval,'" + ASN + "','" + ASN + "',sysdate,'AOI-B','',:MB_BADCODE,to_char(sysdate,'yyyymmdd'),'" + li_code.Text + "',:MB_BADNAME)");
+                                dh.BatchInsert(sql.ToString(), new string[] { "mb_badcode", "mb_badname" }, ErrCode.ToArray(), Location.ToArray());
+                            }
+                            if (num > 0)
+                            {
+                                OperateResult.AppendText("序列号:" + SN + "上传成功\n");
+                                string Backupfilename = BackUpFolderPath.Text + @"\" + MachineType.Text + @"\" + SN;
+                                if (!Directory.Exists(BackUpFolderPath.Text + @"\" + MachineType.Text))
+                                {
+                                    Directory.CreateDirectory(BackUpFolderPath.Text + @"\" + MachineType.Text);
+                                }
+                                if (File.Exists(Backupfilename))
+                                {
+                                    File.Delete(Backupfilename);
+                                }
+                                File.Move(FileName, Backupfilename);
+                            }
+                        }
+                        else
+                        {
+                            int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class,STD_RESCODE,std_stepcode,std_linecode,std_machinetype)select STEPTESTDETAIL_seq.nextval,'" + SN + "','',sysdate,'" + ftpulr.Split('#')[0] + imaster + "/" + ftppath + SN + "','" + isource + "','" + Device.Text + "','" + li_code.Text + "','" + MachineType.Text + "' from dual", "insert").ToString());
+                            if (num > 0)
+                            {
+                                OperateResult.AppendText("序列号:" + SN + "上传成功\n");
+                                string Backupfilename = BackUpFolderPath.Text + @"\" + MachineType.Text + @"\" + SN;
+                                if (!Directory.Exists(BackUpFolderPath.Text + @"\" + MachineType.Text))
+                                {
+                                    Directory.CreateDirectory(BackUpFolderPath.Text + @"\" + MachineType.Text);
+                                }
+                                File.Move(FileName, Backupfilename);
+                            }
                         }
                     }
                     catch (Exception ex)
@@ -242,7 +379,7 @@ namespace FileWatcher
             DialogResult result = folder.ShowDialog();
             if (result == DialogResult.OK)
             {
-
+                BackUpFolderPath.Text = folder.SelectedPath;
             }
         }
 

+ 24 - 1
FileWatcher/BaseUtil.cs

@@ -1,10 +1,12 @@
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.IO;
 using System.Net;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Web.Script.Serialization;
+using System.Windows.Forms;
 using System.Xml;
 
 namespace FileWatcher
@@ -31,7 +33,28 @@ namespace FileWatcher
                 doc.Save(iSN + ".xml");
             }
         }
-
+        public static void FillDgvWithDataTable(DataGridView dgv, DataTable dt, params DataGridViewImageColumn[] operate)
+        {
+            dgv.AutoGenerateColumns = false;
+            dgv.DataSource = dt;
+            if (operate.Length > 0)
+            {
+                if (dgv.Columns[operate[0].Name] != null)
+                {
+                    dgv.Columns.Remove(dgv.Columns[operate[0].Name]);
+                }
+                dgv.Columns.Add(operate[0]);
+            }
+            ////纯英文的列不予展示
+            //Regex regEnglish = new Regex("^[A-z]+$");
+            //foreach (DataGridViewColumn dgvc in dgv.Columns)
+            //{
+            //    if (regEnglish.IsMatch(dgvc.HeaderText))
+            //    {
+            //        dgvc.Visible = false;
+            //    }
+            //}
+        }
         public static string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic, out string fp_path, out string fp_id)
         {
             fp_id = "";

+ 2 - 2
FileWatcher/DataHelper.cs

@@ -9,9 +9,9 @@ namespace FileWatcher
    public class DataHelper
     {
         //系统默认的的连接字符串
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.98.0.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.11.28.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.98.0.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.11.28.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         public static OracleConnection connection = null;
         OracleCommand command = null;
         int ReconnectTime = 0;

+ 1 - 1
FileWatcher/FileWatcher.csproj

@@ -92,7 +92,7 @@
     <Reference Include="System.Xml" />
     <Reference Include="UMESDLLService, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\UAS_MesInterface(LGDZ)\bin\Debug\UMESDLLService.dll</HintPath>
+      <HintPath>tool\UMESDLLService.dll</HintPath>
     </Reference>
   </ItemGroup>
   <ItemGroup>

+ 1 - 1
FileWatcher/Form4.cs

@@ -49,7 +49,7 @@ namespace FileWatcher
             string json = "";
             string json1 = "";
             MESHelper mes = new MESHelper();
-            mes.GetMEIOrNetCodeRange("204295642X000002", "", "", out json1, out json);
+            mes.GetMobileAllInfo("355845240054121", out json1, out json);
             //mes.GetMobileAllInfo("F45112235030001",  out json1, out json);
             //Console.WriteLine(mes.CheckRoutePassed("S558B231013033559", "IMEI-01", out json));
             //Console.WriteLine(mes.GetMEIOrNetCodeRange(null, "352977841215497", null, out json1, out json));

+ 1 - 1
FileWatcher/Program.cs

@@ -45,7 +45,7 @@ namespace FileWatcher
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                    Application.Run(new Form4());
+                    Application.Run(new AutoAnalysisXmlByStep());
                 else
                 {
                     //创建启动对象

+ 33 - 42
FileWatcher/ftpOperater.cs

@@ -33,9 +33,9 @@ namespace FileWatcher
             //status = BaseUtil.connectState(FTPInf);
         }
 
-        public ftpOperater(string IP,string user,string password)
+        public ftpOperater(string IP, string user, string password)
         {
-        
+
             this.ftpServerIP = IP;
             this.ftpUser = user;
             this.ftpPwd = password;
@@ -47,56 +47,45 @@ namespace FileWatcher
 
 
         #region
-        public void UpLoadFile(string filepath, string filename, string UploadFolder,string BackUp)
+        public string UpLoadFile(string filepath, string filename, string UploadFolder, string BackUp)
         {
             try
             {
-                //上传之前判断文件是否存在
-                //string[] filelist = GetFileList();
-                //if (filelist != null)
-                //    for (int i = 0; i < filelist.Length; i++)
-                //    {
-                //        if (filelist[i] == filename)
-                //        {
-                //            string upload = MessageBox.Show("已存在同名文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
-                //            if (upload.ToString() != "Yes")
-                //            {
-                //                return;
-                //            }
-                //        }
-                //    }
                 FtpWebRequest reqFTP;
-                FtpCheckDirectoryExist(UploadFolder);
-                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + UploadFolder + filename));
-                reqFTP.UseBinary = true;
-                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
-                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
-                FileInfo file = new FileInfo(filepath + "/" + filename);
-                const int BufferSize = 2048;
-                byte[] content = new byte[BufferSize - 1 + 1];
-                int dataRead;
-                using (FileStream fs = file.OpenRead())
+                if (FtpCheckDirectoryExist(UploadFolder) == "")
                 {
-                    //把上传的文件写入流
-                    using (Stream rs = reqFTP.GetRequestStream())
+                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + UploadFolder + filename));
+                    reqFTP.UseBinary = true;
+                    reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
+                    FileInfo file = new FileInfo(filepath + "/" + filename);
+                    const int BufferSize = 2048;
+                    byte[] content = new byte[BufferSize - 1 + 1];
+                    int dataRead;
+                    using (FileStream fs = file.OpenRead())
                     {
-                        do
+                        //把上传的文件写入流
+                        using (Stream rs = reqFTP.GetRequestStream())
                         {
-                            //每次读文件流的2KB
-                            dataRead = fs.Read(content, 0, BufferSize);
-                            rs.Write(content, 0, dataRead);
-                        } while (!(dataRead < BufferSize));
-                        rs.Close();
+                            do
+                            {
+                                //每次读文件流的2KB
+                                dataRead = fs.Read(content, 0, BufferSize);
+                                rs.Write(content, 0, dataRead);
+                            } while (!(dataRead < BufferSize));
+                            rs.Close();
+                        }
+                        fs.Close();
                     }
-                    fs.Close();
                 }
-                Thread.Sleep(2000);
+
+                Thread.Sleep(1000);
             }
             catch (Exception ex)
             {
-                Console.WriteLine(ex.Message);
+                return ex.Message;
             }
-        
+            return "";
             //File.Delete(filepath + "/" + filename);
         }
 
@@ -114,7 +103,8 @@ namespace FileWatcher
 
         public delegate string AsyncMethodCaller(int callDuration, out int threadId);
 
-        private void UploadFileContent() {
+        private void UploadFileContent()
+        {
 
 
         }
@@ -274,7 +264,7 @@ namespace FileWatcher
             return fileSize;
         }
 
-        public void FtpCheckDirectoryExist(string destFilePath)
+        public string FtpCheckDirectoryExist(string destFilePath)
         {
             string fullDir = FtpParseDirectory(destFilePath);
             string[] dirs = fullDir.Split('/');
@@ -292,10 +282,11 @@ namespace FileWatcher
                     }
                     catch (Exception ex)
                     {
-                        Console.WriteLine(ex.Message);
+
                     }
                 }
             }
+            return "";
         }
 
         public string FtpParseDirectory(string destFilePath)

二进制
FileWatcher/tool/UMESDLLService.dll