Selaa lähdekoodia

添加SPI日志解析功能

callm 2 viikkoa sitten
vanhempi
commit
5a75741ea1

+ 99 - 23
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.Designer.cs

@@ -23,6 +23,7 @@ namespace UAS_MES_NEW.Make
 
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
             this.Machine_label = new System.Windows.Forms.Label();
             this.Machine_combox = new System.Windows.Forms.ComboBox();
             this.Date_label = new System.Windows.Forms.Label();
@@ -32,15 +33,21 @@ namespace UAS_MES_NEW.Make
             this.Query_button = new System.Windows.Forms.Button();
             this.OperateResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
             this.LabelDataGridView = new System.Windows.Forms.DataGridView();
+            this.Path_label = new System.Windows.Forms.Label();
+            this.Path_text = new System.Windows.Forms.TextBox();
+            this.Path_button = new System.Windows.Forms.Button();
+            this.Auto_check = new System.Windows.Forms.CheckBox();
+            this.Scan_timer = new System.Windows.Forms.Timer(this.components);
             ((System.ComponentModel.ISupportInitialize)(this.LabelDataGridView)).BeginInit();
             this.SuspendLayout();
             // 
             // Machine_label
             // 
             this.Machine_label.AutoSize = true;
-            this.Machine_label.Location = new System.Drawing.Point(14, 16);
+            this.Machine_label.Location = new System.Drawing.Point(28, 32);
+            this.Machine_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.Machine_label.Name = "Machine_label";
-            this.Machine_label.Size = new System.Drawing.Size(41, 12);
+            this.Machine_label.Size = new System.Drawing.Size(58, 24);
             this.Machine_label.TabIndex = 0;
             this.Machine_label.Text = "机台";
             // 
@@ -48,33 +55,37 @@ namespace UAS_MES_NEW.Make
             // 
             this.Machine_combox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.Machine_combox.FormattingEnabled = true;
-            this.Machine_combox.Location = new System.Drawing.Point(62, 12);
+            this.Machine_combox.Location = new System.Drawing.Point(124, 24);
+            this.Machine_combox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Machine_combox.Name = "Machine_combox";
-            this.Machine_combox.Size = new System.Drawing.Size(120, 20);
+            this.Machine_combox.Size = new System.Drawing.Size(236, 32);
             this.Machine_combox.TabIndex = 1;
             // 
             // Date_label
             // 
             this.Date_label.AutoSize = true;
-            this.Date_label.Location = new System.Drawing.Point(200, 16);
+            this.Date_label.Location = new System.Drawing.Point(400, 32);
+            this.Date_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.Date_label.Name = "Date_label";
-            this.Date_label.Size = new System.Drawing.Size(41, 12);
+            this.Date_label.Size = new System.Drawing.Size(58, 24);
             this.Date_label.TabIndex = 2;
             this.Date_label.Text = "日期";
             // 
             // Date_picker
             // 
             this.Date_picker.Format = System.Windows.Forms.DateTimePickerFormat.Short;
-            this.Date_picker.Location = new System.Drawing.Point(248, 12);
+            this.Date_picker.Location = new System.Drawing.Point(496, 24);
+            this.Date_picker.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Date_picker.Name = "Date_picker";
-            this.Date_picker.Size = new System.Drawing.Size(120, 21);
+            this.Date_picker.Size = new System.Drawing.Size(236, 35);
             this.Date_picker.TabIndex = 3;
             // 
             // Import_button
             // 
-            this.Import_button.Location = new System.Drawing.Point(396, 9);
+            this.Import_button.Location = new System.Drawing.Point(792, 18);
+            this.Import_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Import_button.Name = "Import_button";
-            this.Import_button.Size = new System.Drawing.Size(96, 30);
+            this.Import_button.Size = new System.Drawing.Size(192, 60);
             this.Import_button.TabIndex = 4;
             this.Import_button.Text = "导入CSV";
             this.Import_button.UseVisualStyleBackColor = true;
@@ -82,9 +93,10 @@ namespace UAS_MES_NEW.Make
             // 
             // Save_button
             // 
-            this.Save_button.Location = new System.Drawing.Point(502, 9);
+            this.Save_button.Location = new System.Drawing.Point(1004, 18);
+            this.Save_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Save_button.Name = "Save_button";
-            this.Save_button.Size = new System.Drawing.Size(96, 30);
+            this.Save_button.Size = new System.Drawing.Size(192, 60);
             this.Save_button.TabIndex = 5;
             this.Save_button.Text = "保存入库";
             this.Save_button.UseVisualStyleBackColor = true;
@@ -92,9 +104,10 @@ namespace UAS_MES_NEW.Make
             // 
             // Query_button
             // 
-            this.Query_button.Location = new System.Drawing.Point(608, 9);
+            this.Query_button.Location = new System.Drawing.Point(1216, 18);
+            this.Query_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Query_button.Name = "Query_button";
-            this.Query_button.Size = new System.Drawing.Size(96, 30);
+            this.Query_button.Size = new System.Drawing.Size(192, 60);
             this.Query_button.TabIndex = 6;
             this.Query_button.Text = "查询";
             this.Query_button.UseVisualStyleBackColor = true;
@@ -102,33 +115,84 @@ namespace UAS_MES_NEW.Make
             // 
             // OperateResult
             // 
-            this.OperateResult.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))));
+            this.OperateResult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
             this.OperateResult.BackColor = System.Drawing.Color.White;
-            this.OperateResult.Location = new System.Drawing.Point(880, 50);
+            this.OperateResult.Location = new System.Drawing.Point(1760, 168);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.OperateResult.Name = "OperateResult";
-            this.OperateResult.Size = new System.Drawing.Size(340, 180);
+            this.OperateResult.Size = new System.Drawing.Size(676, 356);
             this.OperateResult.TabIndex = 7;
+            this.OperateResult.Text = "";
             // 
             // LabelDataGridView
             // 
             this.LabelDataGridView.AllowUserToAddRows = false;
             this.LabelDataGridView.AllowUserToDeleteRows = false;
-            this.LabelDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-            | System.Windows.Forms.AnchorStyles.Left)
+            this.LabelDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             this.LabelDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
-            this.LabelDataGridView.Location = new System.Drawing.Point(12, 50);
+            this.LabelDataGridView.Location = new System.Drawing.Point(24, 168);
+            this.LabelDataGridView.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.LabelDataGridView.Name = "LabelDataGridView";
             this.LabelDataGridView.ReadOnly = true;
+            this.LabelDataGridView.RowHeadersWidth = 82;
             this.LabelDataGridView.RowTemplate.Height = 23;
-            this.LabelDataGridView.Size = new System.Drawing.Size(850, 680);
+            this.LabelDataGridView.Size = new System.Drawing.Size(1700, 1292);
             this.LabelDataGridView.TabIndex = 8;
             // 
+            // Path_label
+            // 
+            this.Path_label.AutoSize = true;
+            this.Path_label.Location = new System.Drawing.Point(28, 100);
+            this.Path_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Path_label.Name = "Path_label";
+            this.Path_label.Size = new System.Drawing.Size(58, 24);
+            this.Path_label.TabIndex = 9;
+            this.Path_label.Text = "路径";
+            // 
+            // Path_text
+            // 
+            this.Path_text.Location = new System.Drawing.Point(124, 92);
+            this.Path_text.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Path_text.Name = "Path_text";
+            this.Path_text.Size = new System.Drawing.Size(1276, 35);
+            this.Path_text.TabIndex = 10;
+            this.Path_text.Leave += new System.EventHandler(this.Path_text_Leave);
+            // 
+            // Path_button
+            // 
+            this.Path_button.Location = new System.Drawing.Point(1416, 88);
+            this.Path_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Path_button.Name = "Path_button";
+            this.Path_button.Size = new System.Drawing.Size(112, 50);
+            this.Path_button.TabIndex = 11;
+            this.Path_button.Text = "浏览";
+            this.Path_button.UseVisualStyleBackColor = true;
+            this.Path_button.Click += new System.EventHandler(this.Path_button_Click);
+            // 
+            // Auto_check
+            // 
+            this.Auto_check.AutoSize = true;
+            this.Auto_check.Location = new System.Drawing.Point(1552, 96);
+            this.Auto_check.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Auto_check.Name = "Auto_check";
+            this.Auto_check.Size = new System.Drawing.Size(246, 28);
+            this.Auto_check.TabIndex = 12;
+            this.Auto_check.Text = "定时读取(1分钟)";
+            this.Auto_check.UseVisualStyleBackColor = true;
+            this.Auto_check.CheckedChanged += new System.EventHandler(this.Auto_check_CheckedChanged);
+            // 
+            // Scan_timer
+            // 
+            this.Scan_timer.Interval = 60000;
+            this.Scan_timer.Tick += new System.EventHandler(this.Scan_timer_Tick);
+            // 
             // Make_OvenTemp
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1240, 745);
+            this.ClientSize = new System.Drawing.Size(2480, 1490);
             this.Controls.Add(this.LabelDataGridView);
             this.Controls.Add(this.OperateResult);
             this.Controls.Add(this.Query_button);
@@ -138,12 +202,19 @@ namespace UAS_MES_NEW.Make
             this.Controls.Add(this.Date_label);
             this.Controls.Add(this.Machine_combox);
             this.Controls.Add(this.Machine_label);
+            this.Controls.Add(this.Path_label);
+            this.Controls.Add(this.Path_text);
+            this.Controls.Add(this.Path_button);
+            this.Controls.Add(this.Auto_check);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
             this.Name = "Make_OvenTemp";
             this.Text = "炉温数据监控";
             this.Load += new System.EventHandler(this.Make_OvenTemp_Load);
             ((System.ComponentModel.ISupportInitialize)(this.LabelDataGridView)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
+
         }
 
         #endregion
@@ -157,5 +228,10 @@ namespace UAS_MES_NEW.Make
         private System.Windows.Forms.Button Query_button;
         private UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom OperateResult;
         private System.Windows.Forms.DataGridView LabelDataGridView;
+        private System.Windows.Forms.Label Path_label;
+        private System.Windows.Forms.TextBox Path_text;
+        private System.Windows.Forms.Button Path_button;
+        private System.Windows.Forms.CheckBox Auto_check;
+        private System.Windows.Forms.Timer Scan_timer;
     }
 }

+ 339 - 91
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.cs

@@ -15,10 +15,14 @@ namespace UAS_MES_NEW.Make
 {
     /// <summary>
     /// 炉温数据监控(Make_OvenTemp)
-    /// 1) 导入两种炉温 CSV:
-    ///    - 竖向格式(时间, 温区, 温度):每个时间点多行,导入时按时间转成横向;
-    ///    - 横向格式(EquipState:Time + 各温区 PV 列):直接按列取值。
-    /// 2) 转置后的数据统一为「每行一个时间点、10 个温区 × 2 个测点」,写入 OVENTEMP 表。
+    /// 数据来源两种 CSV:
+    ///   - 竖向格式(时间HH:mm:ss, 温区, 温度):列数少;日期取文件的「修改日期」,时间取文件内容;
+    ///   - 横向格式(EquipState:Time + 温区N上PV / 温区N下PV 列):时间自带完整日期。
+    /// 自动采集:定时扫描指定路径下「修改日期为当天」的文件,
+    ///          按该机台已存在的时间点精确去重后增量入库(不使用 max(OT_TIME) 比对,
+    ///          避免两类文件日期基准不同时误杀日期较小的一批)。
+    /// 机台归属:根目录下的文件按界面所选机台;若根目录下存在与机台同名的子目录
+    ///          (机台1 / 机台2),则该子目录内的文件自动归属对应机台。
     /// </summary>
     public partial class Make_OvenTemp : Form
     {
@@ -28,9 +32,16 @@ namespace UAS_MES_NEW.Make
 
         private DataHelper dh;
 
-        // 预览数据:列 OT_TIME / OT_Z1_1 .. OT_Z10_2
+        // 手动导入的预览数据:列 OT_TIME / OT_Z1_1 .. OT_Z10_2
         private DataTable preview;
 
+        // 自动扫描防重入标记
+        private bool scanning = false;
+
+        // 已成功处理过的文件及其修改时间:文件未变化时跳过,避免每轮重复解析
+        private readonly Dictionary<string, DateTime> processedFiles =
+            new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase);
+
         public Make_OvenTemp()
         {
             InitializeComponent();
@@ -50,6 +61,8 @@ namespace UAS_MES_NEW.Make
 
                 Date_picker.Value = DateTime.Today;
 
+                LoadSavedPath();
+
                 BuildPreviewTable();
                 BindGrid(preview);
                 QueryData();
@@ -64,6 +77,201 @@ namespace UAS_MES_NEW.Make
         {
         }
 
+        // ---------------- 界面事件 ----------------
+
+        private void Path_text_Leave(object sender, EventArgs e)
+        {
+            SavePath();
+        }
+
+        private void Path_button_Click(object sender, EventArgs e)
+        {
+            using (FolderBrowserDialog fbd = new FolderBrowserDialog())
+            {
+                fbd.Description = "选择炉温数据文件所在目录";
+                fbd.SelectedPath = Path_text.Text.Trim();
+                if (fbd.ShowDialog(this) == DialogResult.OK)
+                {
+                    Path_text.Text = fbd.SelectedPath;
+                    SavePath();
+                }
+            }
+        }
+
+        private void Auto_check_CheckedChanged(object sender, EventArgs e)
+        {
+            Scan_timer.Enabled = Auto_check.Checked;
+            if (Auto_check.Checked)
+            {
+                SavePath();
+                OperateResult.AppendText(">> 自动采集已开启(每 " + (Scan_timer.Interval / 1000) + " 秒扫描一次)\n", Color.Blue);
+                DoScan();   // 开启后立即执行一轮,不用等下一个周期
+            }
+            else
+            {
+                OperateResult.AppendText(">> 自动采集已停止\n", Color.Blue);
+            }
+        }
+
+        // ---------------- 自动扫描 ----------------
+
+        private void Scan_timer_Tick(object sender, EventArgs e)
+        {
+            if (!Auto_check.Checked) return;
+            DoScan();
+        }
+
+        /// <summary>扫描一轮:当天修改的 CSV -> 解析 -> 按机台最大时间过滤 -> 增量入库。</summary>
+        private void DoScan()
+        {
+            if (scanning) return;               // 上一轮还没结束
+            if (dh == null) return;
+
+            string root = Path_text.Text.Trim();
+            if (root == "" || !Directory.Exists(root))
+            {
+                OperateResult.AppendText(">> 扫描路径无效:" + root + ",请先设置数据目录\n", Color.Red);
+                return;
+            }
+
+            scanning = true;
+            try
+            {
+                // 目录与机台的对应关系:
+                //   根目录        -> 界面所选机台
+                //   子目录=机台名 -> 对应机台(如 root\机台1)
+                var jobs = new List<KeyValuePair<string, string>>();
+                string sel = Machine_combox.Text.Trim();
+                if (sel != "") jobs.Add(new KeyValuePair<string, string>(root, sel));
+                foreach (object item in Machine_combox.Items)
+                {
+                    string m = item == null ? "" : item.ToString();
+                    if (m == "") continue;
+                    string sub = Path.Combine(root, m);
+                    if (Directory.Exists(sub))
+                        jobs.Add(new KeyValuePair<string, string>(sub, m));
+                }
+
+                foreach (var job in jobs)
+                    ScanFolder(job.Key, job.Value);
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 自动扫描异常:" + ex.Message + "\n", Color.Red);
+            }
+            finally
+            {
+                scanning = false;
+            }
+        }
+
+        /// <summary>扫描一个目录,处理其中修改日期为当天的 CSV 文件。</summary>
+        private void ScanFolder(string folder, string machine)
+        {
+            string[] files;
+            try { files = Directory.GetFiles(folder, "*.csv"); }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 读取目录失败:" + folder + ":" + ex.Message + "\n", Color.Red);
+                return;
+            }
+
+            foreach (string file in files)
+            {
+                DateTime mtime;
+                try { mtime = File.GetLastWriteTime(file); }
+                catch { continue; }
+
+                // 只处理修改日期为当天的文件
+                if (mtime.Date != DateTime.Today) continue;
+
+                // 文件自上次成功处理后没有变化,跳过
+                DateTime last;
+                if (processedFiles.TryGetValue(file, out last) && last == mtime) continue;
+
+                try
+                {
+                    int saved = ProcessFile(file, machine, mtime);
+                    processedFiles[file] = mtime;   // 无论有无新增,本版本文件已处理完毕
+
+                    if (saved > 0)
+                        OperateResult.AppendText(">> 自动入库:" + Path.GetFileName(file)
+                            + "(" + machine + ")新增 " + saved + " 条\n", Color.Green);
+                    else
+                        OperateResult.AppendText(">> 跳过:" + Path.GetFileName(file)
+                            + "(" + machine + ")无新增时间点\n", Color.Gray);
+                }
+                catch (Exception ex)
+                {
+                    // 处理失败不记录,下一轮(文件被继续写入后)会再次尝试
+                    OperateResult.AppendText(">> 处理失败:" + Path.GetFileName(file) + ":" + ex.Message + "\n", Color.Red);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 处理单个文件:解析 -> 与该机台系统中的最大时间比对 -> 增量入库。
+        /// 返回新增条数。
+        /// </summary>
+        private int ProcessFile(string file, string machine, DateTime mtime)
+        {
+            if (machine == "") return 0;
+
+            string text = ReadAllTextAuto(file);
+            List<string> lines = SplitCsvLines(text);
+            if (lines.Count < 2) return 0;
+
+            string[] header = ParseCsvLine(lines[0]);
+
+            // 列数少的(竖向:时间,温区,温度):日期取文件修改日期,时间取文件内容
+            // 列数多的(横向 EquipState):时间自带完整日期
+            DataTable dt = header.Length <= 5
+                ? ParseVertical(lines, mtime.Date)
+                : ParseHorizontal(lines);
+            if (dt == null || dt.Rows.Count == 0) return 0;
+
+            // 过滤已插入的时间:取该机台在本批数据时间范围内的已有时间集合,
+            // 只剔除真实已存在的时间点。
+            // 注意不能用 max(OT_TIME) 比对:横向文件时间取自文件内容、竖向文件取修改日期,
+            // 两类文件日期可能不一致,max 比对会把日期较小的那份文件整批误杀。
+            DateTime minTime = DateTime.MaxValue;
+            DateTime maxTime = DateTime.MinValue;
+            foreach (DataRow row in dt.Rows)
+            {
+                DateTime t = Convert.ToDateTime(row["OT_TIME"]);
+                if (t < minTime) minTime = t;
+                if (t > maxTime) maxTime = t;
+            }
+            HashSet<string> exists = LoadExistingTimePoints(machine, minTime, maxTime);
+
+            var seen = new HashSet<string>();
+            List<DataRow> toSave = new List<DataRow>();
+            foreach (DataRow row in dt.Rows)
+            {
+                DateTime t = Convert.ToDateTime(row["OT_TIME"]);
+                string timeKey = t.ToString("yyyy-MM-dd HH:mm:ss");
+                if (exists.Contains(timeKey)) continue;   // 数据库中已存在
+                if (!seen.Add(timeKey)) continue;         // 本文件内重复的时间点
+                toSave.Add(row);
+            }
+
+            if (toSave.Count == 0) return 0;
+
+            int saved = BatchInsert(toSave, machine);
+            if (saved > 0)
+            {
+                LogicHandler.DoCommandLog(Tag == null ? "Make!OvenTemp" : Tag.ToString(), User.UserCode, "",
+                    User.UserLineCode, User.UserSourceCode, "炉温自动采集",
+                    Path.GetFileName(file) + " 新增" + saved + "条", machine, "");
+                // 若当前界面正在看这台机台,刷新查询结果
+                if (Machine_combox.Text.Trim() == machine)
+                    QueryData();
+            }
+            return saved;
+        }
+
+        // ---------------- 预览表格 ----------------
+
         /// <summary>构造空的预览表结构(横向)。</summary>
         private void BuildPreviewTable()
         {
@@ -106,7 +314,7 @@ namespace UAS_MES_NEW.Make
             }
         }
 
-        // ---------------- 导入 ----------------
+        // ---------------- 手动导入 ----------------
 
         private void Import_button_Click(object sender, EventArgs e)
         {
@@ -118,6 +326,7 @@ namespace UAS_MES_NEW.Make
 
                 try
                 {
+                    DateTime mtime = File.GetLastWriteTime(ofd.FileName);
                     string text = ReadAllTextAuto(ofd.FileName);
                     var lines = SplitCsvLines(text);
                     if (lines.Count < 2)
@@ -129,9 +338,9 @@ namespace UAS_MES_NEW.Make
                     string[] header = ParseCsvLine(lines[0]);
                     DataTable result;
 
-                    // 列数 <= 5 视为竖向格式(时间, 温区, 温度)
+                    // 列数 <= 5 视为竖向格式:日期取文件修改日期,时间取文件内容
                     if (header.Length <= 5)
-                        result = ParseVertical(lines, Date_picker.Value.Date);
+                        result = ParseVertical(lines, mtime.Date);
                     else
                         result = ParseHorizontal(lines);
 
@@ -144,7 +353,9 @@ namespace UAS_MES_NEW.Make
                     preview = result;
                     BindGrid(preview);
                     OperateResult.AppendText(">> 导入成功:" + Path.GetFileName(ofd.FileName)
-                        + ",共 " + result.Rows.Count + " 个时间点\n", Color.Green);
+                        + ",共 " + result.Rows.Count + " 个时间点(日期基准 "
+                        + (header.Length <= 5 ? "文件修改日期 " + mtime.Date.ToString("yyyy-MM-dd") : "文件内时间")
+                        + ")\n", Color.Green);
                 }
                 catch (Exception ex)
                 {
@@ -155,7 +366,8 @@ namespace UAS_MES_NEW.Make
 
         /// <summary>
         /// 竖向格式转横向:同一时间的多条温区记录合并成一行。
-        /// 每个温区出现 2 条,按出现顺序记为测点 1 / 2。
+        /// 温区名为「温区N上 / 温区N下」,上=测点1,下=测点2;
+        /// 无上下标识时按同一时间内的出现顺序编号。
         /// </summary>
         private DataTable ParseVertical(List<string> lines, DateTime baseDate)
         {
@@ -373,7 +585,7 @@ namespace UAS_MES_NEW.Make
 
                 HashSet<string> exists = LoadExistingTimePoints(machine, minTime, maxTime);
 
-                // 2) 先筛掉重复时间点,再一次性向序列取号
+                // 2) 筛掉已存在的时间点
                 int skipped = 0;
                 List<DataRow> toSave = new List<DataRow>();
                 foreach (DataRow row in preview.Rows)
@@ -394,70 +606,7 @@ namespace UAS_MES_NEW.Make
                     return;
                 }
 
-                // 3) Oracle 不允许序列出现在带 union all 的查询里(ORA-02287),
-                //    所以先用 GetSEQ 批量取号,再按字面量拼 union all 插入。
-                string[] ids = dh.GetSEQ("OVENTEMP_SEQ", toSave.Count);
-                if (ids.Length < toSave.Count)
-                {
-                    OperateResult.AppendText(">> 取序列号失败(需要 " + toSave.Count + " 个,实际 "
-                        + ids.Length + " 个),已取消本次保存\n", Color.Red);
-                    return;
-                }
-
-                int saved = 0;
-                StringBuilder sb = new StringBuilder();
-                int inBatch = 0;
-
-                for (int i = 0; i < toSave.Count; i++)
-                {
-                    DataRow row = toSave[i];
-                    DateTime t = Convert.ToDateTime(row["OT_TIME"]);
-                    string timeKey = t.ToString("yyyy-MM-dd HH:mm:ss");
-
-                    if (inBatch == 0)
-                    {
-                        sb.Append("insert into OVENTEMP(OT_ID,OT_MACHINE,OT_TIME,");
-                        for (int z = 1; z <= ZONE_COUNT; z++)
-                            for (int s = 1; s <= SENSOR_PER_ZONE; s++)
-                                sb.Append("OT_Z" + z + "_" + s + ",");
-                        sb.Append("OT_INDATE,OT_INMAN) ");
-                    }
-                    else
-                    {
-                        sb.Append(" union all ");
-                    }
-
-                    sb.Append("select " + ids[i] + ",'" + machine.Replace("'", "''") + "',");
-                    sb.Append("to_date('" + timeKey + "','yyyy-mm-dd hh24:mi:ss'),");
-                    for (int z = 1; z <= ZONE_COUNT; z++)
-                    {
-                        for (int s = 1; s <= SENSOR_PER_ZONE; s++)
-                        {
-                            object v = row["OT_Z" + z + "_" + s];
-                            // 空测点写成 to_number(null),确保 union all 各分支该列类型一致
-                            sb.Append(v == DBNull.Value || v == null
-                                ? "to_number(null)"
-                                : Convert.ToDouble(v).ToString("0.##", CultureInfo.InvariantCulture));
-                            sb.Append(",");
-                        }
-                    }
-                    sb.Append("sysdate,'" + User.UserCode + "' from dual");
-
-                    inBatch++;
-                    if (inBatch >= BATCH_SIZE)
-                    {
-                        dh.ExecuteSql(sb.ToString(), "insert");
-                        saved += inBatch;
-                        sb.Clear();
-                        inBatch = 0;
-                    }
-                }
-
-                if (inBatch > 0)
-                {
-                    dh.ExecuteSql(sb.ToString(), "insert");
-                    saved += inBatch;
-                }
+                int saved = BatchInsert(toSave, machine);
 
                 string msg = ">> 保存成功:" + machine + " 新增 " + saved + " 条";
                 if (skipped > 0) msg += ",跳过已存在的 " + skipped + " 条";
@@ -476,31 +625,79 @@ namespace UAS_MES_NEW.Make
             }
         }
 
-        // ---------------- 查询 ----------------
-
         /// <summary>
-        /// 取该机台在指定时间范围内已存在的时间点集合,避免同一份曲线重复导入。
+        /// 批量入库:先向序列一次性取号,再按字面量拼 union all 插入。
+        /// Oracle 不允许序列出现在带 union all 的查询里(ORA-02287),所以不能在
+        /// insert ... select 里直接引用序列。返回成功插入的条数。
         /// </summary>
-        private HashSet<string> LoadExistingTimePoints(string machine, DateTime from, DateTime to)
+        private int BatchInsert(List<DataRow> rows, string machine)
         {
-            var set = new HashSet<string>();
-            try
+            if (rows == null || rows.Count == 0) return 0;
+
+            string[] ids = dh.GetSEQ("OVENTEMP_SEQ", rows.Count);
+            if (ids.Length < rows.Count)
+                throw new Exception("取序列号失败(需要 " + rows.Count + " 个,实际 " + ids.Length + " 个)");
+
+            int saved = 0;
+            StringBuilder sb = new StringBuilder();
+            int inBatch = 0;
+
+            for (int i = 0; i < rows.Count; i++)
             {
-                string sql = "select to_char(OT_TIME,'yyyy-mm-dd hh24:mi:ss') OT_TIME from OVENTEMP"
-                    + " where OT_MACHINE='" + machine.Replace("'", "''") + "'"
-                    + " and OT_TIME >= to_date('" + from.ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')"
-                    + " and OT_TIME <= to_date('" + to.ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')";
-                DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
-                foreach (DataRow r in dt.Rows)
-                    set.Add(r["OT_TIME"].ToString());
+                DataRow row = rows[i];
+                DateTime t = Convert.ToDateTime(row["OT_TIME"]);
+                string timeKey = t.ToString("yyyy-MM-dd HH:mm:ss");
+
+                if (inBatch == 0)
+                {
+                    sb.Append("insert into OVENTEMP(OT_ID,OT_MACHINE,OT_TIME,");
+                    for (int z = 1; z <= ZONE_COUNT; z++)
+                        for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                            sb.Append("OT_Z" + z + "_" + s + ",");
+                    sb.Append("OT_INDATE,OT_INMAN) ");
+                }
+                else
+                {
+                    sb.Append(" union all ");
+                }
+
+                sb.Append("select " + ids[i] + ",'" + machine.Replace("'", "''") + "',");
+                sb.Append("to_date('" + timeKey + "','yyyy-mm-dd hh24:mi:ss'),");
+                for (int z = 1; z <= ZONE_COUNT; z++)
+                {
+                    for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                    {
+                        object v = row["OT_Z" + z + "_" + s];
+                        // 空测点写成 to_number(null),确保 union all 各分支该列类型一致
+                        sb.Append(v == DBNull.Value || v == null
+                            ? "to_number(null)"
+                            : Convert.ToDouble(v).ToString("0.##", CultureInfo.InvariantCulture));
+                        sb.Append(",");
+                    }
+                }
+                sb.Append("sysdate,'" + User.UserCode + "' from dual");
+
+                inBatch++;
+                if (inBatch >= BATCH_SIZE)
+                {
+                    dh.ExecuteSql(sb.ToString(), "insert");
+                    saved += inBatch;
+                    sb.Clear();
+                    inBatch = 0;
+                }
             }
-            catch (Exception ex)
+
+            if (inBatch > 0)
             {
-                OperateResult.AppendText(">> 读取已有记录失败(将按全部新增处理):" + ex.Message + "\n", Color.Red);
+                dh.ExecuteSql(sb.ToString(), "insert");
+                saved += inBatch;
             }
-            return set;
+
+            return saved;
         }
 
+        // ---------------- 查询 ----------------
+
         private void Query_button_Click(object sender, EventArgs e)
         {
             QueryData();
@@ -533,6 +730,57 @@ namespace UAS_MES_NEW.Make
             }
         }
 
+        /// <summary>
+        /// 取该机台在指定时间范围内已存在的时间点集合,避免同一份曲线重复导入。
+        /// </summary>
+        private HashSet<string> LoadExistingTimePoints(string machine, DateTime from, DateTime to)
+        {
+            var set = new HashSet<string>();
+            try
+            {
+                string sql = "select to_char(OT_TIME,'yyyy-mm-dd hh24:mi:ss') OT_TIME from OVENTEMP"
+                    + " where OT_MACHINE='" + machine.Replace("'", "''") + "'"
+                    + " and OT_TIME >= to_date('" + from.ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')"
+                    + " and OT_TIME <= to_date('" + to.ToString("yyyy-MM-dd HH:mm:ss") + "','yyyy-mm-dd hh24:mi:ss')";
+                DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+                foreach (DataRow r in dt.Rows)
+                    set.Add(r["OT_TIME"].ToString());
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 读取已有记录失败(将按全部新增处理):" + ex.Message + "\n", Color.Red);
+            }
+            return set;
+        }
+
+        // ---------------- 路径记忆 ----------------
+
+        /// <summary>扫描路径保存在用户数据目录,重启后自动带出。</summary>
+        private string GetPathConfigFile()
+        {
+            return Path.Combine(Application.UserAppDataPath, "OvenTempPath.txt");
+        }
+
+        private void SavePath()
+        {
+            try
+            {
+                File.WriteAllText(GetPathConfigFile(), Path_text.Text.Trim(), Encoding.UTF8);
+            }
+            catch { }
+        }
+
+        private void LoadSavedPath()
+        {
+            try
+            {
+                string f = GetPathConfigFile();
+                if (File.Exists(f))
+                    Path_text.Text = File.ReadAllText(f).Trim();
+            }
+            catch { }
+        }
+
         // ---------------- 工具方法 ----------------
 
         /// <summary>按 UTF8 → GBK 顺序尝试读取,兼容两种编码的导出文件。</summary>

+ 109 - 1
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.resx

@@ -1,5 +1,110 @@
 <?xml version="1.0" encoding="utf-8"?>
 <root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
   <resheader name="resmimetype">
     <value>text/microsoft-resx</value>
   </resheader>
@@ -12,4 +117,7 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-</root>
+  <metadata name="Scan_timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>

+ 209 - 0
UAS_MES_STW/FunctionCode/Make/Make_SPIData.Designer.cs

@@ -0,0 +1,209 @@
+namespace UAS_MES_NEW.Make
+{
+    partial class Make_SPIData
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.Machine_label = new System.Windows.Forms.Label();
+            this.Machine_combox = new System.Windows.Forms.ComboBox();
+            this.Date_label = new System.Windows.Forms.Label();
+            this.Date_picker = new System.Windows.Forms.DateTimePicker();
+            this.Query_button = new System.Windows.Forms.Button();
+            this.OperateResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
+            this.LabelDataGridView = new System.Windows.Forms.DataGridView();
+            this.Path_label = new System.Windows.Forms.Label();
+            this.Path_text = new System.Windows.Forms.TextBox();
+            this.Path_button = new System.Windows.Forms.Button();
+            this.Auto_check = new System.Windows.Forms.CheckBox();
+            this.Scan_timer = new System.Windows.Forms.Timer(this.components);
+            ((System.ComponentModel.ISupportInitialize)(this.LabelDataGridView)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // Machine_label
+            // 
+            this.Machine_label.AutoSize = true;
+            this.Machine_label.Location = new System.Drawing.Point(28, 32);
+            this.Machine_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Machine_label.Name = "Machine_label";
+            this.Machine_label.Size = new System.Drawing.Size(58, 24);
+            this.Machine_label.TabIndex = 0;
+            this.Machine_label.Text = "机台";
+            // 
+            // Machine_combox
+            // 
+            this.Machine_combox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.Machine_combox.FormattingEnabled = true;
+            this.Machine_combox.Location = new System.Drawing.Point(124, 24);
+            this.Machine_combox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Machine_combox.Name = "Machine_combox";
+            this.Machine_combox.Size = new System.Drawing.Size(236, 32);
+            this.Machine_combox.TabIndex = 1;
+            // 
+            // Date_label
+            // 
+            this.Date_label.AutoSize = true;
+            this.Date_label.Location = new System.Drawing.Point(400, 32);
+            this.Date_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Date_label.Name = "Date_label";
+            this.Date_label.Size = new System.Drawing.Size(58, 24);
+            this.Date_label.TabIndex = 2;
+            this.Date_label.Text = "日期";
+            // 
+            // Date_picker
+            // 
+            this.Date_picker.Format = System.Windows.Forms.DateTimePickerFormat.Short;
+            this.Date_picker.Location = new System.Drawing.Point(496, 24);
+            this.Date_picker.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Date_picker.Name = "Date_picker";
+            this.Date_picker.Size = new System.Drawing.Size(236, 35);
+            this.Date_picker.TabIndex = 3;
+            // 
+            // Query_button
+            // 
+            this.Query_button.Location = new System.Drawing.Point(792, 18);
+            this.Query_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Query_button.Name = "Query_button";
+            this.Query_button.Size = new System.Drawing.Size(192, 60);
+            this.Query_button.TabIndex = 4;
+            this.Query_button.Text = "查询";
+            this.Query_button.UseVisualStyleBackColor = true;
+            this.Query_button.Click += new System.EventHandler(this.Query_button_Click);
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.OperateResult.BackColor = System.Drawing.Color.White;
+            this.OperateResult.Location = new System.Drawing.Point(1760, 168);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(676, 356);
+            this.OperateResult.TabIndex = 7;
+            this.OperateResult.Text = "";
+            // 
+            // LabelDataGridView
+            // 
+            this.LabelDataGridView.AllowUserToAddRows = false;
+            this.LabelDataGridView.AllowUserToDeleteRows = false;
+            this.LabelDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.LabelDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.LabelDataGridView.Location = new System.Drawing.Point(24, 168);
+            this.LabelDataGridView.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.LabelDataGridView.Name = "LabelDataGridView";
+            this.LabelDataGridView.ReadOnly = true;
+            this.LabelDataGridView.RowHeadersWidth = 82;
+            this.LabelDataGridView.RowTemplate.Height = 23;
+            this.LabelDataGridView.Size = new System.Drawing.Size(1700, 1292);
+            this.LabelDataGridView.TabIndex = 8;
+            // 
+            // Path_label
+            // 
+            this.Path_label.AutoSize = true;
+            this.Path_label.Location = new System.Drawing.Point(28, 100);
+            this.Path_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Path_label.Name = "Path_label";
+            this.Path_label.Size = new System.Drawing.Size(58, 24);
+            this.Path_label.TabIndex = 9;
+            this.Path_label.Text = "路径";
+            // 
+            // Path_text
+            // 
+            this.Path_text.Location = new System.Drawing.Point(124, 92);
+            this.Path_text.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Path_text.Name = "Path_text";
+            this.Path_text.Size = new System.Drawing.Size(1276, 35);
+            this.Path_text.TabIndex = 10;
+            this.Path_text.Leave += new System.EventHandler(this.Path_text_Leave);
+            // 
+            // Path_button
+            // 
+            this.Path_button.Location = new System.Drawing.Point(1416, 88);
+            this.Path_button.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Path_button.Name = "Path_button";
+            this.Path_button.Size = new System.Drawing.Size(112, 50);
+            this.Path_button.TabIndex = 11;
+            this.Path_button.Text = "浏览";
+            this.Path_button.UseVisualStyleBackColor = true;
+            this.Path_button.Click += new System.EventHandler(this.Path_button_Click);
+            // 
+            // Auto_check
+            // 
+            this.Auto_check.AutoSize = true;
+            this.Auto_check.Location = new System.Drawing.Point(1552, 96);
+            this.Auto_check.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Auto_check.Name = "Auto_check";
+            this.Auto_check.Size = new System.Drawing.Size(246, 28);
+            this.Auto_check.TabIndex = 12;
+            this.Auto_check.Text = "定时读取(1分钟)";
+            this.Auto_check.UseVisualStyleBackColor = true;
+            this.Auto_check.CheckedChanged += new System.EventHandler(this.Auto_check_CheckedChanged);
+            // 
+            // Scan_timer
+            // 
+            this.Scan_timer.Interval = 60000;
+            this.Scan_timer.Tick += new System.EventHandler(this.Scan_timer_Tick);
+            // 
+            // Make_SPIData
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(2480, 1490);
+            this.Controls.Add(this.LabelDataGridView);
+            this.Controls.Add(this.OperateResult);
+            this.Controls.Add(this.Query_button);
+            this.Controls.Add(this.Date_picker);
+            this.Controls.Add(this.Date_label);
+            this.Controls.Add(this.Machine_combox);
+            this.Controls.Add(this.Machine_label);
+            this.Controls.Add(this.Path_label);
+            this.Controls.Add(this.Path_text);
+            this.Controls.Add(this.Path_button);
+            this.Controls.Add(this.Auto_check);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.Name = "Make_SPIData";
+            this.Text = "SPI数据监控";
+            this.Load += new System.EventHandler(this.Make_SPIData_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.LabelDataGridView)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label Machine_label;
+        private System.Windows.Forms.ComboBox Machine_combox;
+        private System.Windows.Forms.Label Date_label;
+        private System.Windows.Forms.DateTimePicker Date_picker;
+        private System.Windows.Forms.Button Query_button;
+        private UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom OperateResult;
+        private System.Windows.Forms.DataGridView LabelDataGridView;
+        private System.Windows.Forms.Label Path_label;
+        private System.Windows.Forms.TextBox Path_text;
+        private System.Windows.Forms.Button Path_button;
+        private System.Windows.Forms.CheckBox Auto_check;
+        private System.Windows.Forms.Timer Scan_timer;
+    }
+}

+ 631 - 0
UAS_MES_STW/FunctionCode/Make/Make_SPIData.cs

@@ -0,0 +1,631 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Windows.Forms;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using UAS_MES_NEW.DataOperate;
+using UAS_MES_NEW.Entity;
+using UAS_MES_NEW.PublicMethod;
+
+namespace UAS_MES_NEW.Make
+{
+    /// <summary>
+    /// SPI 数据监控(Make_SPIData)
+    /// 数据来源:SPI 检测设备输出的 JSON 日志(每个文件 = 一次整板检测)。
+    /// 自动采集:定时扫描指定路径下的 .json 文件,按「机台 + 文件名」去重后增量入库。
+    /// 表结构(主从):
+    ///   SPIDATA        主表  —— 每个文件一条
+    ///   SPIDATAMEASURE 从表1 —— 测量明细,每个 PAD × 每项指标一行(纵表)
+    ///   SPIDATAALARM   从表2 —— 报警明细,每条报警一行
+    /// 机台归属:根目录下的文件按界面所选机台;若根目录下存在与机台同名的子目录
+    ///          (机台1 / 机台2),则该子目录内的文件自动归属对应机台。
+    /// </summary>
+    public partial class Make_SPIData : Form
+    {
+        private const int BATCH_SIZE = 100;
+
+        private DataHelper dh;
+
+        // 自动扫描防重入标记
+        private bool scanning = false;
+
+        // 已检查过的文件及其修改时间:文件未变化时跳过
+        private readonly Dictionary<string, DateTime> processedFiles =
+            new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase);
+
+        public Make_SPIData()
+        {
+            InitializeComponent();
+            try { UAS_MES_NEW.I18n.LanguageManager.Localize(this); } catch { }
+        }
+
+        private void Make_SPIData_Load(object sender, EventArgs e)
+        {
+            try
+            {
+                dh = SystemInf.dh;
+
+                Machine_combox.Items.Clear();
+                Machine_combox.Items.Add("机台1");
+                Machine_combox.Items.Add("机台2");
+                Machine_combox.SelectedIndex = 0;
+
+                Date_picker.Value = DateTime.Today;
+
+                LoadSavedPath();
+
+                QueryData();
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 初始化失败:" + ex.Message + "\n", Color.Red);
+            }
+        }
+
+        // ---------------- 界面事件 ----------------
+
+        private void Path_text_Leave(object sender, EventArgs e)
+        {
+            SavePath();
+        }
+
+        private void Path_button_Click(object sender, EventArgs e)
+        {
+            using (FolderBrowserDialog fbd = new FolderBrowserDialog())
+            {
+                fbd.Description = "选择 SPI JSON 日志所在目录";
+                fbd.SelectedPath = Path_text.Text.Trim();
+                if (fbd.ShowDialog(this) == DialogResult.OK)
+                {
+                    Path_text.Text = fbd.SelectedPath;
+                    SavePath();
+                }
+            }
+        }
+
+        private void Auto_check_CheckedChanged(object sender, EventArgs e)
+        {
+            Scan_timer.Enabled = Auto_check.Checked;
+            if (Auto_check.Checked)
+            {
+                SavePath();
+                OperateResult.AppendText(">> 自动采集已开启(每 " + (Scan_timer.Interval / 1000) + " 秒扫描一次)\n", Color.Blue);
+                DoScan();   // 开启后立即执行一轮
+            }
+            else
+            {
+                OperateResult.AppendText(">> 自动采集已停止\n", Color.Blue);
+            }
+        }
+
+        // ---------------- 自动扫描 ----------------
+
+        private void Scan_timer_Tick(object sender, EventArgs e)
+        {
+            if (!Auto_check.Checked) return;
+            DoScan();
+        }
+
+        /// <summary>扫描一轮:目录下的 .json -> 按「机台+文件名」去重 -> 解析入库。</summary>
+        private void DoScan()
+        {
+            if (scanning) return;               // 上一轮还没结束
+            if (dh == null) return;
+
+            string root = Path_text.Text.Trim();
+            if (root == "" || !Directory.Exists(root))
+            {
+                OperateResult.AppendText(">> 扫描路径无效:" + root + ",请先设置数据目录\n", Color.Red);
+                return;
+            }
+
+            scanning = true;
+            try
+            {
+                // 目录与机台的对应关系:
+                //   根目录        -> 界面所选机台
+                //   子目录=机台名 -> 对应机台(如 root\机台1)
+                var jobs = new List<KeyValuePair<string, string>>();
+                string sel = Machine_combox.Text.Trim();
+                if (sel != "") jobs.Add(new KeyValuePair<string, string>(root, sel));
+                foreach (object item in Machine_combox.Items)
+                {
+                    string m = item == null ? "" : item.ToString();
+                    if (m == "") continue;
+                    string sub = Path.Combine(root, m);
+                    if (Directory.Exists(sub))
+                        jobs.Add(new KeyValuePair<string, string>(sub, m));
+                }
+
+                foreach (var job in jobs)
+                    ScanFolder(job.Key, job.Value);
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 自动扫描异常:" + ex.Message + "\n", Color.Red);
+            }
+            finally
+            {
+                scanning = false;
+            }
+        }
+
+        /// <summary>扫描一个目录,导入其中新增的 .json 文件。</summary>
+        private void ScanFolder(string folder, string machine)
+        {
+            string[] files;
+            try { files = Directory.GetFiles(folder, "*.json"); }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 读取目录失败:" + folder + ":" + ex.Message + "\n", Color.Red);
+                return;
+            }
+
+            // 该机台已入库的文件名集合(一次查询,避免逐个文件查库)
+            HashSet<string> imported = LoadImportedFiles(machine);
+
+            foreach (string file in files)
+            {
+                DateTime mtime;
+                try { mtime = File.GetLastWriteTime(file); }
+                catch { continue; }
+
+                // 文件自上次检查后没有变化,跳过
+                DateTime last;
+                if (processedFiles.TryGetValue(file, out last) && last == mtime) continue;
+
+                try
+                {
+                    string fileName = Path.GetFileName(file);
+                    processedFiles[file] = mtime;
+
+                    // 「新增文件」判断:机台 + 文件名 已存在则跳过
+                    if (imported.Contains(fileName))
+                    {
+                        OperateResult.AppendText(">> 跳过:" + fileName + "(" + machine + ")已入库\n", Color.Gray);
+                        continue;
+                    }
+
+                    int[] counts = InsertFile(file, machine);
+                    imported.Add(fileName);
+                    OperateResult.AppendText(">> 入库成功:" + fileName + "(" + machine + ")测量 "
+                        + counts[0] + " 条,报警 " + counts[1] + " 条\n", Color.Green);
+
+                    if (Machine_combox.Text.Trim() == machine)
+                        QueryData();
+                }
+                catch (Exception ex)
+                {
+                    // 处理失败不记录,下一轮(文件被继续写入后)会再次尝试
+                    OperateResult.AppendText(">> 处理失败:" + Path.GetFileName(file) + ":" + ex.Message + "\n", Color.Red);
+                }
+            }
+        }
+
+        /// <summary>取某机台已入库的 JSON 文件名集合。</summary>
+        private HashSet<string> LoadImportedFiles(string machine)
+        {
+            var set = new HashSet<string>();
+            try
+            {
+                DataTable dt = (DataTable)dh.ExecuteSql(
+                    "select SPI_FILE from SPIDATA where SPI_MACHINE='" + machine.Replace("'", "''") + "'", "select");
+                foreach (DataRow r in dt.Rows)
+                    set.Add(r["SPI_FILE"].ToString());
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 读取已入库文件失败:" + ex.Message + "\n", Color.Red);
+            }
+            return set;
+        }
+
+        // ---------------- JSON 解析与入库 ----------------
+
+        /// <summary>
+        /// 解析单个 SPI JSON 并写主表 + 两张从表。
+        /// 返回 [测量明细行数, 报警行数]。
+        /// </summary>
+        private int[] InsertFile(string file, string machine)
+        {
+            string text = File.ReadAllText(file);
+            JObject root = JObject.Parse(text);
+            string fileName = Path.GetFileName(file);
+
+            // ---------- 1. 主表 ----------
+            string[] masterIds = dh.GetSEQ("SPIDATA_SEQ", 1);
+            string masterId = masterIds[0];
+
+            string inspectedTime = S(root, "inspected_time");
+            string beginTime = S(root, "inspection_begin_time");
+            JToken programInfo = root["program_info"];
+            JToken savedBitmap = root["saved_bitmap"];
+
+            StringBuilder sb = new StringBuilder();
+            sb.Append("insert into SPIDATA(SPI_ID,SPI_MACHINE,SPI_FILE,SPI_INSPECTEDTIME,SPI_BEGINTIME,");
+            sb.Append("SPI_STATUS,SPI_VERSION,SPI_NGCOUNT,SPI_ALARMCOUNT,");
+            sb.Append("SPI_APERTURECOUNT,SPI_APERGROUPCOUNT,SPI_DISABLEDCOUNT,SPI_ENABLEDCOUNT,SPI_POINTCOUNT,SPI_MARKCOUNT,");
+            sb.Append("SPI_PCBNAME,SPI_PCBLIST,SPI_PROGRAMPATH,SPI_THICKNESS,");
+            sb.Append("SPI_BITMAPFILE,SPI_BITMAPW,SPI_BITMAPH,SPI_BITMAPRES,SPI_BARCODE,SPI_MACHINEINFO,");
+            sb.Append("SPI_INDATE,SPI_INMAN) select ");
+            sb.Append(masterId + ",'").Append(machine.Replace("'", "''")).Append("','");
+            sb.Append(fileName.Replace("'", "''")).Append("',");
+            sb.Append(DateLiteral(inspectedTime)).Append(",");
+            sb.Append(DateLiteral(beginTime)).Append(",");
+            sb.Append(StrLiteral(S(root, "status"))).Append(",");
+            sb.Append(StrLiteral(S(root, "version"))).Append(",");
+            sb.Append(NumLiteral(N(root, "ng_count"))).Append(",");
+            sb.Append(NumLiteral(N(root, "alarm_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "aperture_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "aperture_group_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "disabled_aperture_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "enabled_aperture_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "inspection_point_count"))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "mark_count"))).Append(",");
+            sb.Append(StrLiteral(S(programInfo, "pcb_name"))).Append(",");
+            sb.Append(StrLiteral(JoinArray(programInfo, "pcbs"))).Append(",");
+            sb.Append(StrLiteral(Truncate(S(root, "file_path"), 300))).Append(",");
+            sb.Append(NumLiteral(N(programInfo, "stencil_thickness"))).Append(",");
+            sb.Append(StrLiteral(S(savedBitmap, "file_path"))).Append(",");
+            sb.Append(NumLiteral(N(savedBitmap, "w"))).Append(",");
+            sb.Append(NumLiteral(N(savedBitmap, "h"))).Append(",");
+            sb.Append(NumLiteral(N(savedBitmap, "resolution"))).Append(",");
+            sb.Append(StrLiteral(Truncate(JoinBarcodes(root), 1000))).Append(",");
+            sb.Append(StrLiteral(Truncate(RawJson(root, "machine_info"), 1000))).Append(",");
+            sb.Append("sysdate,'").Append(User.UserCode.Replace("'", "''")).Append("' from dual");
+            dh.ExecuteSql(sb.ToString(), "insert");
+
+            // ---------- 2. 测量明细(每个 PAD × 每项指标一行) ----------
+            int measureRows = 0;
+            JArray measurements = root["measurements"] as JArray;
+            if (measurements != null && measurements.Count > 0)
+            {
+                // 先展开成行集合
+                var rows = new List<string[]>();
+                foreach (JToken mt in measurements)
+                {
+                    JObject m = mt as JObject;
+                    if (m == null) continue;
+                    JToken aperture = m["aperture_info"];
+                    JToken bounds = aperture == null ? null : aperture["bounds"];
+
+                    string pad = S(aperture, "pad");
+                    string pcb = S(aperture, "pcb");
+                    string loc = S(aperture, "location_name");
+                    string uid = S(aperture, "aperture_uid");
+                    string area = N(aperture, "area");
+                    string bh = N(bounds, "h"), bw = N(bounds, "w"), bx = N(bounds, "x"), by = N(bounds, "y");
+                    string thick = N(aperture, "stencil_thickness");
+
+                    foreach (JProperty prop in m.Properties())
+                    {
+                        if (prop.Name == "aperture_info") continue;
+                        JObject metric = prop.Value as JObject;
+                        if (metric == null) continue;
+                        if (metric["is_inspected"] == null && metric["value"] == null) continue;
+
+                        bool inspected = (string)metric["is_inspected"] == "True"
+                                      || (bool?)metric["is_inspected"] == true;
+                        string value = N(metric, "value");
+                        JToken range = metric["range"];
+                        string min = N(range, "min");
+                        string max = N(range, "max");
+
+                        // 单项判定:开启检测且有范围时,值越界即 ng
+                        string result = null;
+                        if (inspected && (min != null || max != null))
+                        {
+                            decimal dv, dmin, dmax;
+                            bool ng = false;
+                            if (value != null && decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out dv))
+                            {
+                                if (min != null && decimal.TryParse(min, NumberStyles.Any, CultureInfo.InvariantCulture, out dmin) && dv < dmin) ng = true;
+                                if (max != null && decimal.TryParse(max, NumberStyles.Any, CultureInfo.InvariantCulture, out dmax) && dv > dmax) ng = true;
+                            }
+                            result = ng ? "ng" : "ok";
+                        }
+
+                        rows.Add(new string[] { pad, pcb, loc, uid, area, bh, bw, bx, by, thick,
+                            prop.Name, inspected ? "1" : "0", value, min, max, result });
+                    }
+                }
+
+                if (rows.Count > 0)
+                {
+                    string[] ids = dh.GetSEQ("SPIDATAMEASURE_SEQ", rows.Count);
+                    sb.Clear();
+                    int inBatch = 0;
+                    for (int i = 0; i < rows.Count; i++)
+                    {
+                        string[] r = rows[i];
+                        if (inBatch == 0)
+                        {
+                            sb.Append("insert into SPIDATAMEASURE(SM_ID,SPI_ID,SM_PAD,SM_PCB,SM_LOCATIONNAME,SM_APERTUREUID,");
+                            sb.Append("SM_AREA,SM_BOUNDS_H,SM_BOUNDS_W,SM_BOUNDS_X,SM_BOUNDS_Y,SM_THICKNESS,");
+                            sb.Append("SM_METRIC,SM_INSPECTED,SM_VALUE,SM_MIN,SM_MAX,SM_RESULT) ");
+                        }
+                        else
+                        {
+                            sb.Append(" union all ");
+                        }
+                        sb.Append("select ").Append(ids[i]).Append(",").Append(masterId).Append(",");
+                        sb.Append(StrLiteral(r[0])).Append(",").Append(NumLiteral(r[1])).Append(",");
+                        sb.Append(StrLiteral(r[2])).Append(",").Append(StrLiteral(r[3])).Append(",");
+                        sb.Append(NumLiteral(r[4])).Append(",").Append(NumLiteral(r[5])).Append(",");
+                        sb.Append(NumLiteral(r[6])).Append(",").Append(NumLiteral(r[7])).Append(",");
+                        sb.Append(NumLiteral(r[8])).Append(",").Append(NumLiteral(r[9])).Append(",");
+                        sb.Append(StrLiteral(r[10])).Append(",").Append(r[11]).Append(",");
+                        sb.Append(NumLiteral(r[12])).Append(",").Append(NumLiteral(r[13])).Append(",");
+                        sb.Append(NumLiteral(r[14])).Append(",").Append(StrLiteral(r[15])).Append(" from dual");
+
+                        inBatch++;
+                        if (inBatch >= BATCH_SIZE)
+                        {
+                            dh.ExecuteSql(sb.ToString(), "insert");
+                            sb.Clear();
+                            inBatch = 0;
+                        }
+                    }
+                    if (inBatch > 0)
+                        dh.ExecuteSql(sb.ToString(), "insert");
+                    measureRows = rows.Count;
+                }
+            }
+
+            // ---------- 3. 报警明细 ----------
+            int alarmRows = 0;
+            JArray alarms = root["alarms"] as JArray;
+            if (alarms != null && alarms.Count > 0)
+            {
+                string[] ids = dh.GetSEQ("SPIDATAALARM_SEQ", alarms.Count);
+                sb.Clear();
+                int inBatch = 0;
+                int alarmIdx = 0;
+                foreach (JToken at in alarms)
+                {
+                    JObject a = at as JObject;
+                    if (a == null) continue;
+                    JToken bounds = a["bounds"];
+                    // 报警可能关联多个开口,取第一条的拼板号 / UID
+                    string pcb = null, uid = null;
+                    JArray apertures = a["apertures"] as JArray;
+                    if (apertures != null && apertures.Count > 0)
+                    {
+                        JObject ap = apertures[0] as JObject;
+                        if (ap != null)
+                        {
+                            pcb = S(ap, "pcb");
+                            uid = S(ap, "uid");
+                        }
+                    }
+
+                    if (inBatch == 0)
+                    {
+                        sb.Append("insert into SPIDATAALARM(SA_ID,SPI_ID,SA_INFO,SA_IMAGE,SA_RECLASS,SA_PCB,SA_UID,");
+                        sb.Append("SA_BOUNDS_H,SA_BOUNDS_W,SA_BOUNDS_X,SA_BOUNDS_Y) ");
+                    }
+                    else
+                    {
+                        sb.Append(" union all ");
+                    }
+                    sb.Append("select ").Append(ids[alarmIdx]).Append(",").Append(masterId).Append(",");
+                    sb.Append(StrLiteral(S(a, "alarm_info"))).Append(",");
+                    sb.Append(StrLiteral(S(a, "image_link"))).Append(",");
+                    sb.Append(StrLiteral(S(a, "reclassified"))).Append(",");
+                    sb.Append(NumLiteral(pcb)).Append(",").Append(StrLiteral(uid)).Append(",");
+                    sb.Append(NumLiteral(N(bounds, "h"))).Append(",").Append(NumLiteral(N(bounds, "w"))).Append(",");
+                    sb.Append(NumLiteral(N(bounds, "x"))).Append(",").Append(NumLiteral(N(bounds, "y"))).Append(" from dual");
+
+                    inBatch++;
+                    alarmIdx++;
+                    alarmRows++;
+                    if (inBatch >= BATCH_SIZE)
+                    {
+                        dh.ExecuteSql(sb.ToString(), "insert");
+                        sb.Clear();
+                        inBatch = 0;
+                    }
+                }
+                if (inBatch > 0)
+                    dh.ExecuteSql(sb.ToString(), "insert");
+            }
+
+            LogicHandler.DoCommandLog(Tag == null ? "Make!SPIData" : Tag.ToString(), User.UserCode, "",
+                User.UserLineCode, User.UserSourceCode, "SPI数据采集",
+                fileName + " 测量" + measureRows + "条", machine, "");
+
+            return new int[] { measureRows, alarmRows };
+        }
+
+        // ---------------- JSON 取值辅助 ----------------
+
+        /// <summary>取对象指定键的字符串值,键不存在或为 null 返回 null。</summary>
+        private static string S(JToken parent, string name)
+        {
+            if (parent == null) return null;
+            JToken v = parent[name];
+            if (v == null || v.Type == JTokenType.Null) return null;
+            return v.ToString();
+        }
+
+        /// <summary>取对象指定键的数值字符串(保持不变的文化格式),不存在返回 null。</summary>
+        private static string N(JToken parent, string name)
+        {
+            if (parent == null) return null;
+            JToken v = parent[name];
+            if (v == null || v.Type == JTokenType.Null) return null;
+            if (v.Type == JTokenType.Integer || v.Type == JTokenType.Float)
+                return ((JValue)v).ToString(CultureInfo.InvariantCulture);
+            decimal d;
+            if (decimal.TryParse(v.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out d))
+                return d.ToString(CultureInfo.InvariantCulture);
+            return v.ToString();
+        }
+
+        /// <summary>字符串值 -> Oracle 字面量(带引号,NULL 处理为 to_number(null) 不适用,用 null)。</summary>
+        private static string StrLiteral(string s)
+        {
+            if (s == null) return "null";
+            return "'" + s.Replace("'", "''") + "'";
+        }
+
+        /// <summary>数值字符串 -> Oracle 字面量,空值写 to_number(null)。</summary>
+        private static string NumLiteral(string s)
+        {
+            if (string.IsNullOrEmpty(s)) return "to_number(null)";
+            decimal d;
+            if (!decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out d)) return "to_number(null)";
+            return d.ToString("0.######", CultureInfo.InvariantCulture);
+        }
+
+        /// <summary>ISO 时间字符串 -> to_date(...) 字面量,空值写 null。</summary>
+        private static string DateLiteral(string s)
+        {
+            if (string.IsNullOrEmpty(s)) return "null";
+            DateTime t;
+            if (!DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out t)) return "null";
+            return "to_date('" + t.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
+                + "','yyyy-mm-dd hh24:mi:ss')";
+        }
+
+        /// <summary>把数组字段的元素用逗号拼成字符串(如 pcbs 拼板列表)。</summary>
+        private static string JoinArray(JToken parent, string name)
+        {
+            if (parent == null) return null;
+            JArray arr = parent[name] as JArray;
+            if (arr == null || arr.Count == 0) return null;
+            var parts = new List<string>();
+            foreach (JToken t in arr)
+                parts.Add(t.ToString());
+            return string.Join(",", parts.ToArray());
+        }
+
+        /// <summary>把 barcodes 数组的 code 用逗号拼成字符串。</summary>
+        private static string JoinBarcodes(JObject root)
+        {
+            JArray arr = root["barcodes"] as JArray;
+            if (arr == null || arr.Count == 0) return null;
+            var parts = new List<string>();
+            foreach (JToken t in arr)
+            {
+                string code = S(t, "code");
+                if (!string.IsNullOrEmpty(code)) parts.Add(code);
+            }
+            return parts.Count == 0 ? null : string.Join(",", parts.ToArray());
+        }
+
+        /// <summary>把指定键的原始 JSON 序列化成字符串(存 machine_info 备用)。</summary>
+        private static string RawJson(JObject root, string name)
+        {
+            JToken v = root[name];
+            if (v == null) return null;
+            string s = v.ToString(Formatting.None);
+            return s == "{}" ? null : s;
+        }
+
+        /// <summary>截断超长字符串以匹配字段长度。</summary>
+        private static string Truncate(string s, int max)
+        {
+            if (s == null || s.Length <= max) return s;
+            return s.Substring(0, max);
+        }
+
+        // ---------------- 查询 ----------------
+
+        private void Query_button_Click(object sender, EventArgs e)
+        {
+            QueryData();
+        }
+
+        private void QueryData()
+        {
+            try
+            {
+                string machine = Machine_combox.Text.Trim();
+                if (machine == "") return;
+
+                DateTime day = Date_picker.Value.Date;
+                string sql = "select * from (select to_char(SPI_INSPECTEDTIME,'yyyy-mm-dd hh24:mi:ss') SPI_INSPECTEDTIME,";
+                sql += "SPI_STATUS,SPI_NGCOUNT,SPI_ALARMCOUNT,SPI_POINTCOUNT,SPI_THICKNESS,SPI_PCBNAME,SPI_BARCODE,SPI_FILE";
+                sql += " from SPIDATA where SPI_MACHINE='" + machine.Replace("'", "''") + "'";
+                sql += " and SPI_INSPECTEDTIME >= to_date('" + day.ToString("yyyy-MM-dd") + "','yyyy-mm-dd')";
+                sql += " and SPI_INSPECTEDTIME < to_date('" + day.AddDays(1).ToString("yyyy-MM-dd") + "','yyyy-mm-dd')";
+                sql += " order by SPI_INSPECTEDTIME desc) where rownum <= 500";
+
+                DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+                BindGrid(dt);
+                OperateResult.AppendText(">> 查询到 " + dt.Rows.Count + " 条检测记录(" + machine + " " + day.ToString("yyyy-MM-dd") + ")\n", Color.Blue);
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 查询失败:" + ex.Message + "\n", Color.Red);
+            }
+        }
+
+        /// <summary>绑定主表查询结果并设置中文列头。</summary>
+        private void BindGrid(DataTable dt)
+        {
+            LabelDataGridView.DataSource = null;
+            LabelDataGridView.AutoGenerateColumns = true;
+            LabelDataGridView.DataSource = dt;
+            LabelDataGridView.ReadOnly = true;
+            LabelDataGridView.AllowUserToAddRows = false;
+            LabelDataGridView.RowHeadersVisible = false;
+            LabelDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
+
+            if (dt != null)
+            {
+                var heads = new Dictionary<string, string>
+                {
+                    { "SPI_INSPECTEDTIME", "检测时间" },
+                    { "SPI_STATUS", "状态" },
+                    { "SPI_NGCOUNT", "NG数" },
+                    { "SPI_ALARMCOUNT", "报警数" },
+                    { "SPI_POINTCOUNT", "测点数" },
+                    { "SPI_THICKNESS", "钢网厚度" },
+                    { "SPI_PCBNAME", "程序名称" },
+                    { "SPI_BARCODE", "条码" },
+                    { "SPI_FILE", "文件名" }
+                };
+                foreach (var kv in heads)
+                {
+                    if (LabelDataGridView.Columns.Contains(kv.Key))
+                        LabelDataGridView.Columns[kv.Key].HeaderText = kv.Value;
+                }
+            }
+        }
+
+        // ---------------- 路径记忆 ----------------
+
+        /// <summary>扫描路径保存在用户数据目录,重启后自动带出。</summary>
+        private string GetPathConfigFile()
+        {
+            return Path.Combine(Application.UserAppDataPath, "SPIDataPath.txt");
+        }
+
+        private void SavePath()
+        {
+            try
+            {
+                File.WriteAllText(GetPathConfigFile(), Path_text.Text.Trim(), Encoding.UTF8);
+            }
+            catch { }
+        }
+
+        private void LoadSavedPath()
+        {
+            try
+            {
+                string f = GetPathConfigFile();
+                if (File.Exists(f))
+                    Path_text.Text = File.ReadAllText(f).Trim();
+            }
+            catch { }
+        }
+    }
+}

+ 123 - 0
UAS_MES_STW/FunctionCode/Make/Make_SPIData.resx

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="Scan_timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>