callm 2 недель назад
Родитель
Сommit
1bd8dbe19e

+ 161 - 0
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.Designer.cs

@@ -0,0 +1,161 @@
+namespace UAS_MES_NEW.Make
+{
+    partial class Make_OvenTemp
+    {
+        /// <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.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.Import_button = new System.Windows.Forms.Button();
+            this.Save_button = new System.Windows.Forms.Button();
+            this.Query_button = new System.Windows.Forms.Button();
+            this.OperateResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
+            this.LabelDataGridView = new System.Windows.Forms.DataGridView();
+            ((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.Name = "Machine_label";
+            this.Machine_label.Size = new System.Drawing.Size(41, 12);
+            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(62, 12);
+            this.Machine_combox.Name = "Machine_combox";
+            this.Machine_combox.Size = new System.Drawing.Size(120, 20);
+            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.Name = "Date_label";
+            this.Date_label.Size = new System.Drawing.Size(41, 12);
+            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.Name = "Date_picker";
+            this.Date_picker.Size = new System.Drawing.Size(120, 21);
+            this.Date_picker.TabIndex = 3;
+            // 
+            // Import_button
+            // 
+            this.Import_button.Location = new System.Drawing.Point(396, 9);
+            this.Import_button.Name = "Import_button";
+            this.Import_button.Size = new System.Drawing.Size(96, 30);
+            this.Import_button.TabIndex = 4;
+            this.Import_button.Text = "导入CSV";
+            this.Import_button.UseVisualStyleBackColor = true;
+            this.Import_button.Click += new System.EventHandler(this.Import_button_Click);
+            // 
+            // Save_button
+            // 
+            this.Save_button.Location = new System.Drawing.Point(502, 9);
+            this.Save_button.Name = "Save_button";
+            this.Save_button.Size = new System.Drawing.Size(96, 30);
+            this.Save_button.TabIndex = 5;
+            this.Save_button.Text = "保存入库";
+            this.Save_button.UseVisualStyleBackColor = true;
+            this.Save_button.Click += new System.EventHandler(this.Save_button_Click);
+            // 
+            // Query_button
+            // 
+            this.Query_button.Location = new System.Drawing.Point(608, 9);
+            this.Query_button.Name = "Query_button";
+            this.Query_button.Size = new System.Drawing.Size(96, 30);
+            this.Query_button.TabIndex = 6;
+            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(880, 50);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(340, 180);
+            this.OperateResult.TabIndex = 7;
+            // 
+            // 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(12, 50);
+            this.LabelDataGridView.Name = "LabelDataGridView";
+            this.LabelDataGridView.ReadOnly = true;
+            this.LabelDataGridView.RowTemplate.Height = 23;
+            this.LabelDataGridView.Size = new System.Drawing.Size(850, 680);
+            this.LabelDataGridView.TabIndex = 8;
+            // 
+            // Make_OvenTemp
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1240, 745);
+            this.Controls.Add(this.LabelDataGridView);
+            this.Controls.Add(this.OperateResult);
+            this.Controls.Add(this.Query_button);
+            this.Controls.Add(this.Save_button);
+            this.Controls.Add(this.Import_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.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
+
+        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 Import_button;
+        private System.Windows.Forms.Button Save_button;
+        private System.Windows.Forms.Button Query_button;
+        private UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom OperateResult;
+        private System.Windows.Forms.DataGridView LabelDataGridView;
+    }
+}

+ 632 - 0
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.cs

@@ -0,0 +1,632 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows.Forms;
+using UAS_MES_NEW.DataOperate;
+using UAS_MES_NEW.Entity;
+using UAS_MES_NEW.PublicMethod;
+
+namespace UAS_MES_NEW.Make
+{
+    /// <summary>
+    /// 炉温数据监控(Make_OvenTemp)
+    /// 1) 导入两种炉温 CSV:
+    ///    - 竖向格式(时间, 温区, 温度):每个时间点多行,导入时按时间转成横向;
+    ///    - 横向格式(EquipState:Time + 各温区 PV 列):直接按列取值。
+    /// 2) 转置后的数据统一为「每行一个时间点、10 个温区 × 2 个测点」,写入 OVENTEMP 表。
+    /// </summary>
+    public partial class Make_OvenTemp : Form
+    {
+        private const int ZONE_COUNT = 10;
+        private const int SENSOR_PER_ZONE = 2;
+        private const int BATCH_SIZE = 100;
+
+        private DataHelper dh;
+
+        // 预览数据:列 OT_TIME / OT_Z1_1 .. OT_Z10_2
+        private DataTable preview;
+
+        public Make_OvenTemp()
+        {
+            InitializeComponent();
+            try { UAS_MES_NEW.I18n.LanguageManager.Localize(this); } catch { }
+        }
+
+        private void Make_OvenTemp_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;
+
+                BuildPreviewTable();
+                BindGrid(preview);
+                QueryData();
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 初始化失败:" + ex.Message + "\n", Color.Red);
+            }
+        }
+
+        private void Make_OvenTemp_SizeChanged(object sender, EventArgs e)
+        {
+        }
+
+        /// <summary>构造空的预览表结构(横向)。</summary>
+        private void BuildPreviewTable()
+        {
+            preview = new DataTable();
+            preview.Columns.Add("OT_TIME", typeof(DateTime));
+            for (int z = 1; z <= ZONE_COUNT; z++)
+            {
+                for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                {
+                    preview.Columns.Add("OT_Z" + z + "_" + s, typeof(double));
+                }
+            }
+        }
+
+        /// <summary>把 DataTable 绑定到表格,并设置中文列头。</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 && LabelDataGridView.Columns.Count > 0)
+            {
+                if (LabelDataGridView.Columns.Contains("OT_TIME"))
+                    LabelDataGridView.Columns["OT_TIME"].HeaderText = "时间";
+                for (int z = 1; z <= ZONE_COUNT; z++)
+                {
+                    for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                    {
+                        string col = "OT_Z" + z + "_" + s;
+                        // 现场测点命名为「上 / 下」,表头沿用同样叫法,便于和原始报表对照
+                        if (LabelDataGridView.Columns.Contains(col))
+                            LabelDataGridView.Columns[col].HeaderText = "温区" + z + (s == 1 ? "上" : "下");
+                    }
+                }
+            }
+        }
+
+        // ---------------- 导入 ----------------
+
+        private void Import_button_Click(object sender, EventArgs e)
+        {
+            using (OpenFileDialog ofd = new OpenFileDialog())
+            {
+                ofd.Filter = "CSV 文件(*.csv)|*.csv|所有文件(*.*)|*.*";
+                ofd.Title = "选择炉温数据文件";
+                if (ofd.ShowDialog(this) != DialogResult.OK) return;
+
+                try
+                {
+                    string text = ReadAllTextAuto(ofd.FileName);
+                    var lines = SplitCsvLines(text);
+                    if (lines.Count < 2)
+                    {
+                        OperateResult.AppendText(">> 文件内容为空\n", Color.Red);
+                        return;
+                    }
+
+                    string[] header = ParseCsvLine(lines[0]);
+                    DataTable result;
+
+                    // 列数 <= 5 视为竖向格式(时间, 温区, 温度)
+                    if (header.Length <= 5)
+                        result = ParseVertical(lines, Date_picker.Value.Date);
+                    else
+                        result = ParseHorizontal(lines);
+
+                    if (result == null || result.Rows.Count == 0)
+                    {
+                        OperateResult.AppendText(">> 未解析到有效炉温数据,请检查文件格式\n", Color.Red);
+                        return;
+                    }
+
+                    preview = result;
+                    BindGrid(preview);
+                    OperateResult.AppendText(">> 导入成功:" + Path.GetFileName(ofd.FileName)
+                        + ",共 " + result.Rows.Count + " 个时间点\n", Color.Green);
+                }
+                catch (Exception ex)
+                {
+                    OperateResult.AppendText(">> 导入失败:" + ex.Message + "\n", Color.Red);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 竖向格式转横向:同一时间的多条温区记录合并成一行。
+        /// 每个温区出现 2 条,按出现顺序记为测点 1 / 2。
+        /// </summary>
+        private DataTable ParseVertical(List<string> lines, DateTime baseDate)
+        {
+            DataTable dt = BuildEmptyTable();
+            // 时间 -> 行;同一时间同一温区的计数
+            var rowMap = new Dictionary<string, DataRow>();
+            var sensorCount = new Dictionary<string, int>();
+
+            for (int i = 1; i < lines.Count; i++)
+            {
+                string[] cols = ParseCsvLine(lines[i]);
+                if (cols.Length < 3) continue;
+
+                DateTime time;
+                if (!TryParseTime(cols[0].Trim(), baseDate, out time)) continue;
+
+                int zone = ExtractZoneNo(cols[1]);
+                if (zone < 1 || zone > ZONE_COUNT) continue;
+
+                double val;
+                if (!double.TryParse(cols[2].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out val)
+                    && !double.TryParse(cols[2].Trim(), out val))
+                    continue;
+
+                string key = time.ToString("yyyy-MM-dd HH:mm:ss");
+                DataRow row;
+                if (!rowMap.TryGetValue(key, out row))
+                {
+                    row = dt.NewRow();
+                    row["OT_TIME"] = time;
+                    dt.Rows.Add(row);
+                    rowMap[key] = row;
+                }
+
+                string sensorKey = key + "|" + zone;
+                int sensor;
+                string zoneName = cols[1];
+                if (zoneName.Contains("上")) sensor = 1;            // 现场命名:上 = 测点1
+                else if (zoneName.Contains("下")) sensor = 2;       // 下 = 测点2
+                else
+                {
+                    // 区名里没有上下标识时,按同一时间内的出现顺序编号
+                    int cnt;
+                    sensorCount.TryGetValue(sensorKey, out cnt);
+                    cnt++;
+                    sensorCount[sensorKey] = cnt;
+                    sensor = cnt;
+                }
+
+                if (sensor < 1 || sensor > SENSOR_PER_ZONE) continue;  // 超出测点数的忽略
+
+                row["OT_Z" + zone + "_" + sensor] = val;
+            }
+
+            return dt;
+        }
+
+        /// <summary>
+        /// 横向格式(EquipState):按「温区N上PV / 温区N下PV」列直接取值。
+        /// 上 = 测点1,下 = 测点2;列头无上下标识时按出现顺序编号。
+        /// </summary>
+        private DataTable ParseHorizontal(List<string> lines)
+        {
+            DataTable dt = BuildEmptyTable();
+            string[] header = ParseCsvLine(lines[0]);
+
+            // 找时间列
+            int timeCol = -1;
+            for (int i = 0; i < header.Length; i++)
+            {
+                string h = header[i].Trim();
+                if (h.Equals("Time", StringComparison.OrdinalIgnoreCase) || h.Contains("时间"))
+                {
+                    timeCol = i;
+                    break;
+                }
+            }
+            if (timeCol < 0) timeCol = 0;
+
+            // 找温区 PV 列:温区N上PV / 温区N下PV,测点号在识别列头时就固定下来,
+            // 避免某一路为空时后续列被错位写成测点1。
+            var zoneCols = new List<int[]>();                     // [列索引, 温区号, 测点号]
+            var sensorIdx = new Dictionary<int, int>();           // 无上下标识时用于顺序编号
+
+            for (int i = 0; i < header.Length; i++)
+            {
+                if (i == timeCol) continue;
+                string h = header[i].Trim();
+                int zone = ExtractZoneNo(h);
+                if (zone < 1 || zone > ZONE_COUNT) continue;
+                // 只取过程值列(PV),排除设定值列(SP/SV)
+                if (h.IndexOf("PV", StringComparison.OrdinalIgnoreCase) < 0) continue;
+
+                int sensor;
+                if (h.Contains("上")) sensor = 1;
+                else if (h.Contains("下")) sensor = 2;
+                else
+                {
+                    int cnt;
+                    sensorIdx.TryGetValue(zone, out cnt);
+                    cnt++;
+                    sensorIdx[zone] = cnt;
+                    sensor = cnt;
+                }
+
+                if (sensor >= 1 && sensor <= SENSOR_PER_ZONE)
+                    zoneCols.Add(new int[] { i, zone, sensor });
+            }
+
+            // 兜底:列头里没有 PV 字样时,按「温区N区」列的出现顺序直接取
+            if (zoneCols.Count == 0)
+            {
+                sensorIdx.Clear();
+                for (int i = 0; i < header.Length; i++)
+                {
+                    if (i == timeCol) continue;
+                    string h = header[i].Trim();
+                    int zone = ExtractZoneNo(h);
+                    if (zone < 1 || zone > ZONE_COUNT) continue;
+
+                    int sensor;
+                    if (h.Contains("上")) sensor = 1;
+                    else if (h.Contains("下")) sensor = 2;
+                    else
+                    {
+                        int cnt;
+                        sensorIdx.TryGetValue(zone, out cnt);
+                        cnt++;
+                        sensorIdx[zone] = cnt;
+                        sensor = cnt;
+                    }
+
+                    if (sensor >= 1 && sensor <= SENSOR_PER_ZONE)
+                        zoneCols.Add(new int[] { i, zone, sensor });
+                }
+            }
+
+            if (zoneCols.Count == 0)
+            {
+                OperateResult.AppendText(">> 未能识别温区列(需要形如「温区1上PV」「温区1下PV」的列头)\n", Color.Red);
+                return dt;
+            }
+
+            for (int r = 1; r < lines.Count; r++)
+            {
+                string[] cols = ParseCsvLine(lines[r]);
+                if (cols.Length <= timeCol) continue;
+
+                DateTime time;
+                if (!TryParseTime(cols[timeCol].Trim(), DateTime.Today, out time)) continue;
+
+                DataRow row = dt.NewRow();
+                row["OT_TIME"] = time;
+
+                // 按列头识别时已固定温区号与测点号,这里直接按列取值
+                foreach (var item in zoneCols)
+                {
+                    int colIdx = item[0];
+                    int zone = item[1];
+                    int sensor = item[2];
+                    if (colIdx >= cols.Length) continue;
+
+                    double val;
+                    if (!double.TryParse(cols[colIdx].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out val)
+                        && !double.TryParse(cols[colIdx].Trim(), out val))
+                        continue;
+
+                    row["OT_Z" + zone + "_" + sensor] = val;
+                }
+
+                dt.Rows.Add(row);
+            }
+
+            return dt;
+        }
+
+        private DataTable BuildEmptyTable()
+        {
+            DataTable dt = new DataTable();
+            dt.Columns.Add("OT_TIME", typeof(DateTime));
+            for (int z = 1; z <= ZONE_COUNT; z++)
+                for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                    dt.Columns.Add("OT_Z" + z + "_" + s, typeof(double));
+            return dt;
+        }
+
+        // ---------------- 保存 ----------------
+
+        private void Save_button_Click(object sender, EventArgs e)
+        {
+            if (preview == null || preview.Rows.Count == 0)
+            {
+                OperateResult.AppendText(">> 没有可保存的数据,请先导入 CSV\n", Color.Red);
+                return;
+            }
+
+            string machine = Machine_combox.Text.Trim();
+            if (machine == "")
+            {
+                OperateResult.AppendText(">> 请先选择机台\n", Color.Red);
+                return;
+            }
+
+            try
+            {
+                // 1) 先取出该机台在这批数据时间范围内的已有时间点,用于跳过重复导入
+                DateTime minTime = DateTime.MaxValue;
+                DateTime maxTime = DateTime.MinValue;
+                foreach (DataRow r in preview.Rows)
+                {
+                    DateTime t = Convert.ToDateTime(r["OT_TIME"]);
+                    if (t < minTime) minTime = t;
+                    if (t > maxTime) maxTime = t;
+                }
+
+                HashSet<string> exists = LoadExistingTimePoints(machine, minTime, maxTime);
+
+                // 2) 先筛掉重复时间点,再一次性向序列取号
+                int skipped = 0;
+                List<DataRow> toSave = new List<DataRow>();
+                foreach (DataRow row in preview.Rows)
+                {
+                    DateTime t = Convert.ToDateTime(row["OT_TIME"]);
+                    if (exists.Contains(t.ToString("yyyy-MM-dd HH:mm:ss")))
+                    {
+                        skipped++;
+                        continue;
+                    }
+                    toSave.Add(row);
+                }
+
+                if (toSave.Count == 0)
+                {
+                    OperateResult.AppendText(">> 该时间段的数据已全部存在(" + skipped + " 条),无需重复导入\n", Color.Blue);
+                    QueryData();
+                    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;
+                }
+
+                string msg = ">> 保存成功:" + machine + " 新增 " + saved + " 条";
+                if (skipped > 0) msg += ",跳过已存在的 " + skipped + " 条";
+                OperateResult.AppendText(msg + "\n", Color.Green);
+
+                if (saved > 0)
+                {
+                    LogicHandler.DoCommandLog(Tag == null ? "Make!OvenTemp" : Tag.ToString(), User.UserCode, "",
+                        User.UserLineCode, User.UserSourceCode, "炉温数据导入", "保存" + saved + "条", machine, "");
+                }
+                QueryData();
+            }
+            catch (Exception ex)
+            {
+                OperateResult.AppendText(">> 保存失败:" + ex.Message + "\n", Color.Red);
+            }
+        }
+
+        // ---------------- 查询 ----------------
+
+        /// <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;
+        }
+
+        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(OT_TIME,'yyyy-mm-dd hh24:mi:ss') OT_TIME,";
+                for (int z = 1; z <= ZONE_COUNT; z++)
+                    for (int s = 1; s <= SENSOR_PER_ZONE; s++)
+                        sql += "OT_Z" + z + "_" + s + ",";
+                sql += "OT_MACHINE from OVENTEMP where OT_MACHINE='" + machine.Replace("'", "''") + "'";
+                sql += " and OT_TIME >= to_date('" + day.ToString("yyyy-MM-dd") + "','yyyy-mm-dd')";
+                sql += " and OT_TIME < to_date('" + day.AddDays(1).ToString("yyyy-MM-dd") + "','yyyy-mm-dd')";
+                sql += " order by OT_TIME desc) where rownum <= 2000";
+
+                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>按 UTF8 → GBK 顺序尝试读取,兼容两种编码的导出文件。</summary>
+        private static string ReadAllTextAuto(string path)
+        {
+            byte[] bytes = File.ReadAllBytes(path);
+            try
+            {
+                var strictUtf8 = new UTF8Encoding(false, true);
+                return strictUtf8.GetString(bytes);
+            }
+            catch
+            {
+                return Encoding.GetEncoding(936).GetString(bytes);
+            }
+        }
+
+        private static List<string> SplitCsvLines(string text)
+        {
+            var list = new List<string>();
+            foreach (string line in text.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'))
+            {
+                if (line.Trim() != "") list.Add(line);
+            }
+            return list;
+        }
+
+        /// <summary>解析一行 CSV,支持双引号包裹的字段。</summary>
+        private static string[] ParseCsvLine(string line)
+        {
+            var fields = new List<string>();
+            var cur = new StringBuilder();
+            bool inQuote = false;
+
+            for (int i = 0; i < line.Length; i++)
+            {
+                char c = line[i];
+                if (inQuote)
+                {
+                    if (c == '"')
+                    {
+                        if (i + 1 < line.Length && line[i + 1] == '"') { cur.Append('"'); i++; }
+                        else inQuote = false;
+                    }
+                    else cur.Append(c);
+                }
+                else
+                {
+                    if (c == '"') inQuote = true;
+                    else if (c == ',') { fields.Add(cur.ToString()); cur.Clear(); }
+                    else cur.Append(c);
+                }
+            }
+            fields.Add(cur.ToString());
+            return fields.ToArray();
+        }
+
+        /// <summary>
+        /// 从「温区10上」「温区1下PV」「温区3区」等文本中提取温区号。
+        /// 现场导出的命名有三种写法:温区N区 / 温区N上 / 温区N下。
+        /// </summary>
+        private static int ExtractZoneNo(string text)
+        {
+            if (string.IsNullOrEmpty(text)) return 0;
+            Match m = Regex.Match(text, @"温区\s*(\d+)\s*[区上中下]");
+            if (!m.Success) m = Regex.Match(text, @"(\d+)\s*[区上中下]");
+            if (!m.Success) m = Regex.Match(text, @"温区\s*(\d+)");
+            if (!m.Success) return 0;
+            int zone;
+            return int.TryParse(m.Groups[1].Value, out zone) ? zone : 0;
+        }
+
+        /// <summary>兼容多种时间格式的解析。</summary>
+        private static bool TryParseTime(string text, DateTime baseDate, out DateTime time)
+        {
+            time = DateTime.MinValue;
+            if (string.IsNullOrEmpty(text)) return false;
+
+            string[] formats = {
+                "HH:mm:ss", "H:mm:ss", "HH:mm",
+                "yy/MM/dd HH:mm:ss", "yyyy/M/d HH:mm:ss", "yyyy/M/d H:mm:ss",
+                "yyyy-MM-dd HH:mm:ss", "yyyy/M/d HH:mm", "yyyy-MM-dd HH:mm"
+            };
+
+            if (DateTime.TryParseExact(text, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
+            {
+                // 只有时分秒的情况下补日期
+                if (time.Year == 1)
+                    time = baseDate.Date.Add(time.TimeOfDay);
+                return true;
+            }
+            if (DateTime.TryParse(text, out time)) return true;
+
+            return false;
+        }
+    }
+}

+ 15 - 0
UAS_MES_STW/FunctionCode/Make/Make_OvenTemp.resx

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <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>
+</root>