callm 3 месяцев назад
Родитель
Сommit
0d894789ee

+ 3 - 3
FileWatcher/AutoMakeQTYRZ.Designer.cs

@@ -95,7 +95,7 @@
             this.OperateResult.Location = new System.Drawing.Point(892, 22);
             this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.OperateResult.Name = "OperateResult";
-            this.OperateResult.Size = new System.Drawing.Size(517, 535);
+            this.OperateResult.Size = new System.Drawing.Size(806, 535);
             this.OperateResult.TabIndex = 7;
             this.OperateResult.Text = "";
             // 
@@ -329,7 +329,7 @@
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1443, 640);
+            this.ClientSize = new System.Drawing.Size(1711, 640);
             this.Controls.Add(this.FunctionNum1);
             this.Controls.Add(this.label7);
             this.Controls.Add(this.FunctionNum);
@@ -355,7 +355,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MaximizeBox = false;
             this.Name = "AutoMakeQTYRZ";
-            this.Text = "UAS设备数据解析 2024-11-29  10:05";
+            this.Text = "UAS设备数据解析 2025-07-22  10:05";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();

+ 88 - 54
FileWatcher/AutoMakeQTYRZ.cs

@@ -14,6 +14,7 @@ using System.IO.Ports;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement;
 using System.Windows.Media.Media3D;
 using System.Runtime.InteropServices;
+using NPOI.POIFS.Storage;
 
 namespace FileWatcher
 {
@@ -58,6 +59,12 @@ namespace FileWatcher
         {
             InitializeComponent();
             StartPosition = FormStartPosition.CenterScreen;
+            stableDataTimer.Interval = 2000; // 2秒
+            stableDataTimer.Tick += (s, args) =>
+            {
+                ProcessStableData();
+                stableDataTimer.Stop();
+            };
         }
         DataTable Dbfind;
 
@@ -178,49 +185,53 @@ namespace FileWatcher
 
         private bool isWaitingForStableData = false;
         private DateTime currentDetectionTime;
+        private bool canRecordNext = true;
         private string pendingData = "";
+        private System.Windows.Forms.Timer stableDataTimer = new System.Windows.Forms.Timer();
+        private object dataLock = new object();
         private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
         {
             try
             {
                 int len = serialPort1.BytesToRead;
-                Byte[] readBuffer = new Byte[len];
+                byte[] readBuffer = new byte[len];
                 serialPort1.Read(readBuffer, 0, len);
-                string rawData = BitConverter.ToString(readBuffer, 0, readBuffer.Length).Replace("-", "");
-
-                // 保存原始数据用于后续处理
-                pendingData = rawData.Length > 48 ? rawData.Substring(0, 48) : rawData;
+                string rawData = BitConverter.ToString(readBuffer).Replace("-", "");
 
-                if (pendingData.Length == 48)
+                this.Invoke((MethodInvoker)delegate
                 {
-                    float 电流数据 = getdata(pendingData.Substring(14, 8));
-
-                    // 如果检测到有电流且不在等待状态
-                    if (电流数据 != 0 && !isWaitingForStableData)
+                    lock (dataLock)
                     {
-                        OperateResult.AppendText($"检测到电流({电流数据}A),等待2秒稳定...\n");
-                        isWaitingForStableData = true;
-                        currentDetectionTime = DateTime.Now;
-
-                        // 启动定时器检查是否已等待足够时间
-                        System.Windows.Forms.Timer delayTimer = new System.Windows.Forms.Timer();
-                        delayTimer.Interval = 2000; // 2秒
-                        delayTimer.Tick += (s, args) =>
+                        pendingData = rawData.Length >= 48 ? rawData.Substring(0, 48) : rawData;
+                        //OperateResult.AppendText($"收到数据: {pendingData}\n");
+
+                        if (pendingData.Length == 48)
                         {
-                            delayTimer.Stop();
-                            ProcessStableData();
-                        };
-                        delayTimer.Start();
-                    }
-                    else if (电流数据 == 0)
-                    {
-                        isWaitingForStableData = false;
+                            float current = getdata(pendingData.Substring(14, 8));
+                            //OperateResult.AppendText($"当前电流: {current}A (允许记录:{canRecordNext})\n");
+                            // 电流归零时重置记录许可
+                            if (current == 0)
+                            {
+                                canRecordNext = true;
+                                //OperateResult.AppendText("电流归零,已允许下次记录\n");
+                            }
+                            // 电流非零且允许记录时触发
+                            else if (current != 0 && canRecordNext && !isWaitingForStableData)
+                            {
+                                //OperateResult.AppendText("[开始] 检测到有效电流,启动2秒延迟...\n");
+                                isWaitingForStableData = true;
+                                stableDataTimer.Start();
+                            }
+                        }
                     }
-                }
+                });
             }
             catch (Exception ex)
             {
-                OperateResult.AppendText($"处理数据时出错: {ex.Message}\n");
+                this.Invoke((MethodInvoker)delegate
+                {
+                    OperateResult.AppendText($"数据接收错误: {ex.Message}\n");
+                });
             }
         }
 
@@ -228,48 +239,70 @@ namespace FileWatcher
         {
             try
             {
-                if (pendingData.Length == 48)
+                this.Invoke((MethodInvoker)delegate
                 {
-                    float 电压数据 = getdata(pendingData.Substring(6, 8));
-                    float 电流数据 = getdata(pendingData.Substring(14, 8));
-                    float 功率数据 = getdata(pendingData.Substring(22, 8));
-                    float 频率数据 = getdata(pendingData.Substring(30, 8));
-                    float 功率因素 = getdata(pendingData.Substring(38, 8));
-
-                    if (电流数据 != 0) // 再次确认电流仍然存在
+                    lock (dataLock)
                     {
-                        double num, num1;
-                        if (double.TryParse(FunctionNum.Text, out num) &&
-                            double.TryParse(FunctionNum1.Text, out num1))
+                        //OperateResult.AppendText("[触发] 处理稳定数据\n");
+
+                        if (string.IsNullOrEmpty(pendingData) || pendingData.Length < 48)
+                        {
+                            //OperateResult.AppendText("错误: 数据长度不足\n");
+                            isWaitingForStableData = false;
+                            return;
+                        }
+
+                        float current = getdata(pendingData.Substring(14, 8));
+
+                        // 延迟后再次检查电流
+                        if (current == 0)
+                        {
+                            //OperateResult.AppendText("警告: 延迟后电流已归零,取消记录\n");
+                            isWaitingForStableData = false;
+                            return;
+                        }
+
+                        // 解析其他数据
+                        float voltage = getdata(pendingData.Substring(6, 8));
+                        float power = getdata(pendingData.Substring(22, 8));
+                        float frequency = getdata(pendingData.Substring(30, 8));
+                        float powerFactor = getdata(pendingData.Substring(38, 8));
+
+                        // 检查功率范围
+                        if (double.TryParse(FunctionNum.Text, out double minPower) &&
+                            double.TryParse(FunctionNum1.Text, out double maxPower))
                         {
-                            if (功率数据 > num && 功率数据 < num1)
+                            if (power >= minPower && power <= maxPower)
                             {
-                                OperateResult.AppendText($"数据稳定,记录: 电压={电压数据}V, 电流={电流数据}A, 功率={功率数据}W\n");
-                                dh.ExecuteSql("insert into currenttest(CT_ID,ct_linecode, CT_MAKECODE, CT_VOLTAGE, CT_CURRENT, CT_POWER, CT_FREQUENCY, CT_POWER1) " +
-                                "VALUES(currenttest_SEQ.NEXTVAL,'" + li_code.Text + "','" + ma_code.Text + "','" + 电压数据 + "','" + 电流数据 + "','" + 功率数据 + "','" + 频率数据 + "','" + 功率因素 + "')", "insert");
-                                NowQTY.Text = dh.getRowCount("currenttest", "ct_makecode='" + ma_code.Text + "'").ToString();
+                                // 写入数据库
+                                dh.ExecuteSql("INSERT INTO currenttest(CT_ID, ct_linecode, CT_MAKECODE, CT_VOLTAGE, CT_CURRENT, CT_POWER, CT_FREQUENCY, CT_POWER1) " +
+                                                "VALUES(currenttest_SEQ.NEXTVAL,'" + li_code.Text + "', '" + ma_code.Text + "', " + voltage + ", " + current + ", " + power + ", " + frequency + "" +
+                                                ", " + powerFactor + ")", "insert");
+                                NowQTY.Text = dh.getRowCount("currenttest", $"ct_makecode='{ma_code.Text}'").ToString();
+                                OperateResult.AppendText(DateTime.Now.ToString("HH:mm:ss") + $"数据上成功,记录: 电流={current}A 功率={power}W\n");
+                                // 记录成功后禁止下次记录,直到电流归零
+                                canRecordNext = false;
                             }
                             else
                             {
-                                OperateResult.AppendText($"功率数据异常: {功率数据}W (应在{num}-{num1}W之间)\n");
+                                OperateResult.AppendText($"功率超出范围: {power}W (要求: {minPower}-{maxPower}W)\n");
                             }
                         }
                         else
                         {
-                            OperateResult.AppendText("请正确设置功率标准值\n");
+                            OperateResult.AppendText("错误: 无效的功率范围设置\n");
                         }
+                        isWaitingForStableData = false;
                     }
-                    else
-                    {
-                        OperateResult.AppendText("电流已消失,取消记录\n");
-                    }
-                }
-                isWaitingForStableData = false;
+                });
             }
             catch (Exception ex)
             {
-                OperateResult.AppendText($"处理稳定数据时出错: {ex.Message}\n");
-                isWaitingForStableData = false;
+                this.Invoke((MethodInvoker)delegate
+                {
+                    OperateResult.AppendText($"处理稳定数据时出错: {ex.Message}\n");
+                    isWaitingForStableData = false;
+                });
             }
         }
 
@@ -360,6 +393,7 @@ namespace FileWatcher
             ma_code.Enabled = true;
 
             StopWatch.Enabled = false;
+            serialPort1.Close();
             OperateResult.AppendText("停止执行监控\n");
         }
 

+ 186 - 4
FileWatcher/Form5.Designer.cs

@@ -31,15 +31,31 @@
             this.button1 = new System.Windows.Forms.Button();
             this.textBox2 = new System.Windows.Forms.TextBox();
             this.label5 = new System.Windows.Forms.Label();
+            this.label1 = new System.Windows.Forms.Label();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.textBox3 = new System.Windows.Forms.TextBox();
+            this.label3 = new System.Windows.Forms.Label();
+            this.textBox4 = new System.Windows.Forms.TextBox();
+            this.label4 = new System.Windows.Forms.Label();
+            this.textBox5 = new System.Windows.Forms.TextBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.textBox6 = new System.Windows.Forms.TextBox();
+            this.label7 = new System.Windows.Forms.Label();
+            this.label8 = new System.Windows.Forms.Label();
+            this.label9 = new System.Windows.Forms.Label();
+            this.label10 = new System.Windows.Forms.Label();
+            this.label11 = new System.Windows.Forms.Label();
+            this.label12 = new System.Windows.Forms.Label();
             this.SuspendLayout();
             // 
             // button1
             // 
-            this.button1.Location = new System.Drawing.Point(228, 115);
+            this.button1.Location = new System.Drawing.Point(251, 589);
             this.button1.Name = "button1";
             this.button1.Size = new System.Drawing.Size(137, 48);
             this.button1.TabIndex = 32;
-            this.button1.Text = "获取";
+            this.button1.Text = "保存";
             this.button1.UseVisualStyleBackColor = true;
             // 
             // textBox2
@@ -54,15 +70,165 @@
             this.label5.AutoSize = true;
             this.label5.Location = new System.Drawing.Point(89, 33);
             this.label5.Name = "label5";
-            this.label5.Size = new System.Drawing.Size(106, 24);
+            this.label5.Size = new System.Drawing.Size(58, 24);
             this.label5.TabIndex = 38;
-            this.label5.Text = "机台编号";
+            this.label5.Text = "车间";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(89, 127);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(106, 24);
+            this.label1.TabIndex = 40;
+            this.label1.Text = "出勤人数";
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(210, 124);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(243, 35);
+            this.textBox1.TabIndex = 39;
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(89, 208);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(106, 24);
+            this.label2.TabIndex = 42;
+            this.label2.Text = "缺勤人数";
+            // 
+            // textBox3
+            // 
+            this.textBox3.Location = new System.Drawing.Point(210, 205);
+            this.textBox3.Name = "textBox3";
+            this.textBox3.Size = new System.Drawing.Size(243, 35);
+            this.textBox3.TabIndex = 41;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(41, 292);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(154, 24);
+            this.label3.TabIndex = 44;
+            this.label3.Text = "实际出勤人数";
+            // 
+            // textBox4
+            // 
+            this.textBox4.Location = new System.Drawing.Point(210, 281);
+            this.textBox4.Name = "textBox4";
+            this.textBox4.Size = new System.Drawing.Size(243, 35);
+            this.textBox4.TabIndex = 43;
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Location = new System.Drawing.Point(89, 363);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(106, 24);
+            this.label4.TabIndex = 46;
+            this.label4.Text = "借入人数";
+            // 
+            // textBox5
+            // 
+            this.textBox5.Location = new System.Drawing.Point(210, 360);
+            this.textBox5.Name = "textBox5";
+            this.textBox5.Size = new System.Drawing.Size(243, 35);
+            this.textBox5.TabIndex = 45;
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Location = new System.Drawing.Point(89, 436);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(106, 24);
+            this.label6.TabIndex = 48;
+            this.label6.Text = "借出人数";
+            // 
+            // textBox6
+            // 
+            this.textBox6.Location = new System.Drawing.Point(210, 433);
+            this.textBox6.Name = "textBox6";
+            this.textBox6.Size = new System.Drawing.Size(243, 35);
+            this.textBox6.TabIndex = 47;
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Location = new System.Drawing.Point(469, 444);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(154, 24);
+            this.label7.TabIndex = 53;
+            this.label7.Text = "li_borrowout";
+            // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.Location = new System.Drawing.Point(483, 371);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(130, 24);
+            this.label8.TabIndex = 52;
+            this.label8.Text = "li_realnum";
+            // 
+            // label9
+            // 
+            this.label9.AutoSize = true;
+            this.label9.Location = new System.Drawing.Point(483, 292);
+            this.label9.Name = "label9";
+            this.label9.Size = new System.Drawing.Size(130, 24);
+            this.label9.TabIndex = 51;
+            this.label9.Text = "li_realnum";
+            // 
+            // label10
+            // 
+            this.label10.AutoSize = true;
+            this.label10.Location = new System.Drawing.Point(483, 216);
+            this.label10.Name = "label10";
+            this.label10.Size = new System.Drawing.Size(130, 24);
+            this.label10.TabIndex = 50;
+            this.label10.Text = "li_lacknum";
+            // 
+            // label11
+            // 
+            this.label11.AutoSize = true;
+            this.label11.Location = new System.Drawing.Point(507, 127);
+            this.label11.Name = "label11";
+            this.label11.Size = new System.Drawing.Size(82, 24);
+            this.label11.TabIndex = 49;
+            this.label11.Text = "li_num";
+            // 
+            // label12
+            // 
+            this.label12.AutoSize = true;
+            this.label12.Location = new System.Drawing.Point(507, 33);
+            this.label12.Name = "label12";
+            this.label12.Size = new System.Drawing.Size(94, 24);
+            this.label12.TabIndex = 54;
+            this.label12.Text = "li_code";
             // 
             // Form5
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(647, 820);
+            this.Controls.Add(this.label12);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.label8);
+            this.Controls.Add(this.label9);
+            this.Controls.Add(this.label10);
+            this.Controls.Add(this.label11);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.textBox6);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.textBox5);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.textBox4);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.textBox3);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.textBox1);
             this.Controls.Add(this.label5);
             this.Controls.Add(this.textBox2);
             this.Controls.Add(this.button1);
@@ -78,5 +244,21 @@
         private System.Windows.Forms.Button button1;
         private System.Windows.Forms.TextBox textBox2;
         private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox textBox3;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.TextBox textBox4;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.TextBox textBox5;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox textBox6;
+        private System.Windows.Forms.Label label7;
+        private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.Label label9;
+        private System.Windows.Forms.Label label10;
+        private System.Windows.Forms.Label label11;
+        private System.Windows.Forms.Label label12;
     }
 }

+ 2 - 2
FileWatcher/Program.cs

@@ -46,8 +46,8 @@ namespace FileWatcher
                 Application.SetCompatibleTextRenderingDefault(false);
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                 {
-                    //Application.Run(new AutoAnalysisDeviceKS());
-                    Application.Run(new AutoMakeQTYRZ());
+                    Application.Run(new UploadMakePlan());
+                    //Application.Run(new AutoMakeQTYRZ());
                     //Application.Run(new AutoAnalysisXmlByStep());
                     //Application.Run(new SOP_PNE("", ""));
                     //Application.Run(new AutoMakeQTY());

+ 23 - 16
FileWatcher/UploadMakePlan.cs

@@ -8,6 +8,7 @@ using NPOI.XSSF.UserModel;
 using Oracle.ManagedDataAccess.Client;
 using System.Reflection.Emit;
 using Microsoft.Office.Interop.Excel;
+using NPOI.SS.Formula.Functions;
 
 namespace FileWatcher
 {
@@ -66,8 +67,7 @@ namespace FileWatcher
                     string sheetName = sheet.SheetName;
                     if (sheetName.Contains(todayDate))
                     {
-                        OperateResult.AppendText(sheetName);
-                        OperateResult.AppendText($"Processing sheet: {sheetName}\n");
+
                         //Console.WriteLine($"Processing sheet: {sheetName}");
 
                         // 获取标题行(第4行)
@@ -84,6 +84,7 @@ namespace FileWatcher
                         int ordercodeIndex = -1;
                         int planqtyIndex = -1;
                         int remarkIndex = -1;
+                        int stepcodeIndex = -1;
 
                         for (int colIndex = 0; colIndex < headerRow.LastCellNum; colIndex++)
                         {
@@ -107,6 +108,10 @@ namespace FileWatcher
                                 {
                                     planqtyIndex = colIndex;
                                 }
+                                else if (headerValue == "工序编号")
+                                {
+                                    stepcodeIndex = colIndex;
+                                }
                                 else if (headerValue.Contains("备注") && !headerValue.Contains("生产异常备注"))
                                 {
                                     remarkIndex = colIndex;
@@ -114,10 +119,10 @@ namespace FileWatcher
                             }
                         }
 
-                        if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1)
+                        if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1 || stepcodeIndex == -1)
                         {
-                            Console.WriteLine("Required columns not found in the header.");
-                            continue;
+                            OperateResult.AppendText("列头缺少,请检查表结构");
+                            return;
                         }
 
                         using (OracleConnection conn = new OracleConnection(connectionString))
@@ -137,6 +142,7 @@ namespace FileWatcher
                                     string ordercode = row.GetCell(ordercodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
                                     string planqty = row.GetCell(planqtyIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.ToString();
                                     string remark = row.GetCell(remarkIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
+                                    string stepcode = row.GetCell(stepcodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
                                     if (!string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
                                     {
                                         string day = today.ToString("yyyy-MM-dd");
@@ -151,15 +157,15 @@ namespace FileWatcher
                                             OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'不存在");
                                             return;
                                         }
-                                        //if (dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said left join (select min(mpd_outqty)mpd_outqty, mpd_ordercode," +
-                                        //    " mpd_orderdetno  from(select sum(mpd_outqty)mpd_outqty, mpd_ordercode, mpd_orderdetno from MakePlanDetail  group by " +
-                                        //    "mpd_ordercode, mpd_orderdetno, MPD_WCCODE)group by mpd_ordercode, mpd_orderdetno) on sa_code = mpd_ordercode and sd_detno" +
-                                        //    " = mpd_orderdetno", "sd_qty<mpd_outqty+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'"))
-                                        //{
-                                        //    OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'累计排产数量超出");
-                                        //    //return;
-                                        //}
-                                        string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_detno,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty,mpd_remark) VALUES (" + id + "," + detno + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4,:5)";
+                                        if (dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said left join (select min(mpd_outqty)mpd_outqty, mpd_ordercode," +
+                                            " mpd_orderdetno  from(select mpd_stepcode,sum(mpd_outqty)mpd_outqty, mpd_ordercode, mpd_orderdetno from MakePlanDetail  group by " +
+                                            "mpd_ordercode, mpd_orderdetno,mpd_stepcode, MPD_WCCODE)group by mpd_ordercode, mpd_orderdetno,mpd_stepcode) on sa_code = mpd_ordercode and sd_detno" +
+                                            " = mpd_orderdetno", "sd_qty<mpd_outqty+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'"))
+                                        {
+                                            OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'工序" + stepcode + "累计排产数量超出");
+                                            return;
+                                        }
+                                        string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_detno,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty,mpd_remark,mpd_stepcode) VALUES (" + id + "," + detno + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4,:5,:6)";
                                         using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
                                         {
                                             cmd.Parameters.Add(new OracleParameter(":1", wccode));
@@ -167,6 +173,7 @@ namespace FileWatcher
                                             cmd.Parameters.Add(new OracleParameter(":3", ordercode));
                                             cmd.Parameters.Add(new OracleParameter(":4", planqty));
                                             cmd.Parameters.Add(new OracleParameter(":5", remark));
+                                            cmd.Parameters.Add(new OracleParameter(":6", stepcode));
                                             cmd.ExecuteNonQuery();
                                         }
                                     }
@@ -175,7 +182,7 @@ namespace FileWatcher
                             }
                         }
                         dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
-                        OperateResult.AppendText("计划上传成功");
+                        OperateResult.AppendText($"Processing sheet: {sheetName}计划上传成功\n");
                         string Error = "";
                         string[] param = new string[] { id, "0", Error };
                         dh.CallProcedure("USER_PLANSPLIT_COMMIT", ref param);
@@ -183,7 +190,7 @@ namespace FileWatcher
                     }
                 }
             }
-          
+
         }
 
         private void ChooseFile_Click(object sender, EventArgs e)