ソースを参照

修改数据读取功能

callm 2 ヶ月 前
コミット
3953ca2ff4

+ 1 - 1
FileWatcher/AutoMakeQTYRZ.Designer.cs

@@ -354,7 +354,7 @@
             this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.MaximizeBox = false;
             this.Name = "AutoMakeQTYRZ";
-            this.Text = "UAS设备数据解析 2025-07-22  10:05";
+            this.Text = "UAS设备数据解析 2025-09-09  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();

+ 6 - 22
FileWatcher/AutoMakeQTYRZ.cs

@@ -75,12 +75,7 @@ namespace FileWatcher
             stw.StartPosition = FormStartPosition.CenterScreen;
             stw.ShowDialog();
             FormBorderStyle = FormBorderStyle.FixedSingle;
-            serialPort1.DataReceived += SerialPort1_DataReceived;
-
-            //添加监控事件
-            XmlWatcher.Changed += new FileSystemEventHandler(XmlWatcher_Created);
-            //ATEFile.Changed += new FileSystemEventHandler(XmlWatcher_Created);
-
+          
             List<string> CacheInf = new List<string>();
             //获取缓存信息
             try
@@ -216,6 +211,7 @@ namespace FileWatcher
                         else
                         {
                             OperateResult.AppendText($"功率超出范围: {power}W (要求: {minPower}-{maxPower}W)\n");
+                            canRecordNext = false;
                         }
                     }
                     else
@@ -273,6 +269,7 @@ namespace FileWatcher
             StartWatch.Enabled = false;
             ma_code.Enabled = false;
             StopWatch.Enabled = true;
+            serialPort1.DataReceived += SerialPort1_DataReceived;
             try
             {
                 serialPort1.PortName = ComPort.Text;
@@ -290,29 +287,16 @@ namespace FileWatcher
             OperateResult.AppendText("开始执行监控\n");
         }
 
-        private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
-        {
-            OperateResult.AppendText("文件修改:" + e.FullPath + "\n");
-            TxtHandleProcess(e.FullPath);
-        }
-
-        string nextLine;
-        private void TxtHandleProcess(string FileName)
-        {
-            List<string> badcode = new List<string>();
-            List<string> badlocation = new List<string>();
-            List<string> badprod = new List<string>();
-
-        }
 
         private void StopWatch_Click(object sender, EventArgs e)
         {
-            XmlWatcher.EnableRaisingEvents = false;
             StartWatch.Enabled = true;
             ma_code.Enabled = true;
-
             StopWatch.Enabled = false;
+            serialPort1.DataReceived -= SerialPort1_DataReceived;
             serialPort1.Close();
+          
+            Timer.Stop();
             OperateResult.AppendText("停止执行监控\n");
         }
 

+ 4 - 4
FileWatcher/DataHelper.cs

@@ -9,9 +9,9 @@ namespace FileWatcher
     public class DataHelper
     {
         ////CY
-        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11701)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=11701)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         ////用户选择的数据库的连接字符串
-        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11701)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=11701)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
 
         //RZ
@@ -32,9 +32,9 @@ namespace FileWatcher
         //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
         ////KS
-        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11710)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         ////用户选择的数据库的连接字符串
-        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11710)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
         ////ZZ
         //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.22.100.2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";

+ 1 - 1
FileWatcher/Login.cs

@@ -18,7 +18,7 @@ namespace FileWatcher
         private void CheckLogin_Click(object sender, EventArgs e)
         {
             string ErrMessage = "";
-            DataHelper.DBConnectionString = "Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11660)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+            DataHelper.DBConnectionString = "Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=11660)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
             //重新执行一遍构造函数使得重置之后的链接字符串生效
             //dh = new DataHelper();
             AutoAnalysisXmlByStep.dh = dh;

+ 2 - 2
FileWatcher/Program.cs

@@ -46,8 +46,8 @@ namespace FileWatcher
                 Application.SetCompatibleTextRenderingDefault(false);
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                 {
-                    Application.Run(new UploadMakePlan());
-                    //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());

+ 42 - 35
FileWatcher/UploadMakePlan.cs

@@ -1,21 +1,17 @@
 using System;
-using System.Data;
 using System.IO;
 using System.Windows.Forms;
 using System.Text;
 using NPOI.SS.UserModel;
 using NPOI.XSSF.UserModel;
 using Oracle.ManagedDataAccess.Client;
-using System.Reflection.Emit;
-using Microsoft.Office.Interop.Excel;
-using NPOI.SS.Formula.Functions;
 
 namespace FileWatcher
 {
     public partial class UploadMakePlan : Form
     {
 
-        string connectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        string connectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11710)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
 
         StringBuilder sql = new StringBuilder();
@@ -41,7 +37,10 @@ namespace FileWatcher
         {
             DateTime today = DateTime.Value;
             string todayDate = today.ToString("MMdd");
-            string code = dh.GetSerialNumberByCaller("MakePlan");
+            string code = "";
+            string[] param = new string[] { "MakePlan", "1", code };
+            dh.CallProcedure("SP_GETMAXNUMBER", ref param);
+            code = param[2];
             string id = "";
             System.Data.DataTable dt = (System.Data.DataTable)dh.ExecuteSql("select mp_id from MakePlan where to_char(mp_begintime,'yyyymmdd')='" + today.ToString("yyyyMMdd") + "'", "select");
             if (dt.Rows.Count == 0)
@@ -65,13 +64,19 @@ namespace FileWatcher
                 {
                     ISheet sheet = workbook.GetSheetAt(i);
                     string sheetName = sheet.SheetName;
-                    if (sheetName.Contains(todayDate))
+
                     {
 
                         //Console.WriteLine($"Processing sheet: {sheetName}");
 
                         // 获取标题行(第4行)
-                        IRow headerRow = sheet.GetRow(3); // 第4行索引为3
+                        string wccode = sheet.GetRow(2).GetCell(2).StringCellValue; // 第4行索引为3
+                        if (wccode == "")
+                        {
+                            OperateResult.AppendText("工作中心不存在");
+                            return;
+                        }
+                        IRow headerRow = sheet.GetRow(4); // 第4行索引为3
                         if (headerRow == null)
                         {
                             Console.WriteLine("Header row not found.");
@@ -79,7 +84,7 @@ namespace FileWatcher
                         }
 
                         // 获取标题列的索引
-                        int wccodeIndex = -1;
+                        int dateIndex = -1;
                         int orderdetnoIndex = -1;
                         int ordercodeIndex = -1;
                         int planqtyIndex = -1;
@@ -92,11 +97,7 @@ namespace FileWatcher
                             if (cell != null)
                             {
                                 string headerValue = cell.ToString().Trim().Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
-                                if (headerValue == "工作中心")
-                                {
-                                    wccodeIndex = colIndex;
-                                }
-                                else if (headerValue == "订单序号")
+                                if (headerValue == "订单序号")
                                 {
                                     orderdetnoIndex = colIndex;
                                 }
@@ -108,10 +109,14 @@ namespace FileWatcher
                                 {
                                     planqtyIndex = colIndex;
                                 }
-                                else if (headerValue == "工序编号")
+                                else if (headerValue == "工序")
                                 {
                                     stepcodeIndex = colIndex;
                                 }
+                                else if (headerValue == "日期")
+                                {
+                                    dateIndex = colIndex;
+                                }
                                 else if (headerValue.Contains("备注") && !headerValue.Contains("生产异常备注"))
                                 {
                                     remarkIndex = colIndex;
@@ -119,7 +124,7 @@ namespace FileWatcher
                             }
                         }
 
-                        if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1 || stepcodeIndex == -1)
+                        if (orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1 || stepcodeIndex == -1)
                         {
                             OperateResult.AppendText("列头缺少,请检查表结构");
                             return;
@@ -128,22 +133,22 @@ namespace FileWatcher
                         using (OracleConnection conn = new OracleConnection(connectionString))
                         {
                             conn.Open();
-                            for (int rowIndex = 4; rowIndex <= sheet.LastRowNum; rowIndex++) // 从第5行开始解析数据
+                            for (int rowIndex = 5; rowIndex <= sheet.LastRowNum; rowIndex++) // 从第5行开始解析数据
                             {
                                 IRow row = sheet.GetRow(rowIndex);
                                 if (row != null)
                                 {
-                                    string wccode = row.GetCell(wccodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue.ToString();
-                                    if (wccode == "")
+                                    string date = row.GetCell(dateIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
+                                    if (date == "")
                                     {
-                                        continue;
+                                        break;
                                     }
                                     string orderdetno = row.GetCell(orderdetnoIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
                                     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))
+                                    if (todayDate == date && !string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
                                     {
                                         string day = today.ToString("yyyy-MM-dd");
                                         if (dh.CheckExist("MakePlanDetail left join makeplan on mpd_mpid=mp_id ", "trunc(mp_begintime)=to_date('" + day + "','yyyy-mm-dd') and mpd_orderdetno='" + orderdetno + "' and mpd_ordercode='" + ordercode + "' and mpd_wccode='" + wccode + "'"))
@@ -152,19 +157,21 @@ namespace FileWatcher
                                             return;
                                         }
                                         //销售订单+订单序号存在ERP中,才允许上传
-                                        if (!dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said", "SD_DETNO='" + orderdetno + "' and sa_code='" + ordercode + "'"))
-                                        {
-                                            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 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;
-                                        }
+                                        //if (!dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said", "SD_DETNO='" + orderdetno + "' and sa_code='" + ordercode + "'"))
+                                        //{
+                                        //    OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'不存在");
+                                        //    return;
+                                        //}
+                                        //dt = (System.Data.DataTable)dh.ExecuteSql("select * from 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,nvl(sum(mpd_outqty),0)mpd_outqty, " +
+                                        //    "mpd_ordercode, mpd_orderdetno from MakePlanDetail where mpd_wccode='" + wccode + "' and nvl(mpd_stepcode,' ')='" + stepcode + "' group by mpd_ordercode, mpd_orderdetno,mpd_stepcode)group " +
+                                        //    "by mpd_ordercode, mpd_orderdetno,mpd_stepcode) on sa_code = mpd_ordercode and sd_detno =mpd_orderdetno " +
+                                        //    "where sd_qty<nvl(mpd_outqty,0)+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'", "select");
+                                        //if (dt.Rows.Count > 0)
+                                        //{
+                                        //    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))
                                         {
@@ -184,7 +191,7 @@ namespace FileWatcher
                         dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
                         OperateResult.AppendText($"Processing sheet: {sheetName}计划上传成功\n");
                         string Error = "";
-                        string[] param = new string[] { id, "0", Error };
+                        param = new string[] { id, "0", Error };
                         dh.CallProcedure("USER_PLANSPLIT_COMMIT", ref param);
                         dh.CallProcedure("USER_PLANINSERT_WORK", ref param);
                     }