callm 6 месяцев назад
Родитель
Сommit
b5c2983cca

+ 10 - 10
FileWatcher/AutoAnalysisDeviceKS.cs

@@ -313,15 +313,15 @@ namespace FileWatcher
             const int BOARD_NAME_INDEX = 1;         // 基板名
             const int START_TIME_INDEX = 4;         // 生产开始时间
             const int END_TIME_INDEX = 6;           // 生产完成时间
-            const int ERROR_STOP_TIME_INDEX = 46;   // 出错停止时间(秒)
-            const int ERROR_REPAIR_TIME_INDEX = 47; // 出错修复时间(秒)
-            const int COMPLETED_PANELS_INDEX = 49;  // 完成贴装的拼板数
-            const int UPSTREAM_WAIT_INDEX = 50;     // 因上游待机的时间(秒)
-            const int DOWNSTREAM_WAIT_INDEX = 51;   // 因下游待机的时间(秒)
-            const int EFFICIENCY_INDEX = 52;        // 可动率(%)
-            const int PLACEMENT_POINTS_INDEX = 53;  // 贴装点数
-            const int COMPONENT_CONSUMP_INDEX = 54; // 元件消耗数
-            const int CONVEYOR_INDEX = 55;          // 输送台
+            const int ERROR_STOP_TIME_INDEX = 45;   // 出错停止时间(秒)
+            const int ERROR_REPAIR_TIME_INDEX = 46; // 出错修复时间(秒)
+            const int COMPLETED_PANELS_INDEX = 48;  // 完成贴装的拼板数
+            const int UPSTREAM_WAIT_INDEX = 49;     // 因上游待机的时间(秒)
+            const int DOWNSTREAM_WAIT_INDEX = 50;   // 因下游待机的时间(秒)
+            const int EFFICIENCY_INDEX = 51;        // 可动率(%)
+            const int PLACEMENT_POINTS_INDEX = 52;  // 贴装点数
+            const int COMPONENT_CONSUMP_INDEX = 53; // 元件消耗数
+            const int CONVEYOR_INDEX = 54;          // 输送台
 
             using (OracleConnection connection = new OracleConnection(connectionString))
             {
@@ -361,7 +361,7 @@ namespace FileWatcher
 
                         // 遍历CSV数据行
                         for (int i = 0; i < csvData.Count; i++)
-                        {
+                        {   
                             string[] values = csvData[i];
 
                             try

+ 30 - 41
FileWatcher/AutoMakeQTY.Designer.cs

@@ -50,11 +50,11 @@
             this.li_code = new FileWatcher.SearchTextBox();
             this.label5 = new System.Windows.Forms.Label();
             this.ma_code = new FileWatcher.SearchTextBox();
-            this.ChooseFolder = new System.Windows.Forms.Button();
-            this.FolderPath = new System.Windows.Forms.TextBox();
             this.label6 = new System.Windows.Forms.Label();
+            this.pr_pcbacount = new System.Windows.Forms.NumericUpDown();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.ATEFile)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).BeginInit();
             this.SuspendLayout();
             // 
             // XmlWatcher
@@ -113,7 +113,7 @@
             // 
             this.MakeCode_lable.AutoSize = true;
             this.MakeCode_lable.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.MakeCode_lable.Location = new System.Drawing.Point(34, 220);
+            this.MakeCode_lable.Location = new System.Drawing.Point(34, 197);
             this.MakeCode_lable.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.MakeCode_lable.Name = "MakeCode_lable";
             this.MakeCode_lable.Size = new System.Drawing.Size(104, 38);
@@ -137,9 +137,8 @@
             this.Type.FormattingEnabled = true;
             this.Type.Items.AddRange(new object[] {
             "投入",
-            "产出",
-            "印刷机"});
-            this.Type.Location = new System.Drawing.Point(204, 366);
+            "产出"});
+            this.Type.Location = new System.Drawing.Point(204, 344);
             this.Type.Name = "Type";
             this.Type.Size = new System.Drawing.Size(436, 32);
             this.Type.TabIndex = 18;
@@ -148,7 +147,7 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(34, 360);
+            this.label1.Location = new System.Drawing.Point(34, 338);
             this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(75, 38);
@@ -160,7 +159,7 @@
             this.AutoStart.AutoSize = true;
             this.AutoStart.Checked = true;
             this.AutoStart.CheckState = System.Windows.Forms.CheckState.Checked;
-            this.AutoStart.Location = new System.Drawing.Point(678, 227);
+            this.AutoStart.Location = new System.Drawing.Point(678, 204);
             this.AutoStart.Name = "AutoStart";
             this.AutoStart.Size = new System.Drawing.Size(186, 28);
             this.AutoStart.TabIndex = 20;
@@ -199,7 +198,7 @@
             // 
             // NowQTY
             // 
-            this.NowQTY.Location = new System.Drawing.Point(204, 487);
+            this.NowQTY.Location = new System.Drawing.Point(204, 497);
             this.NowQTY.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.NowQTY.Name = "NowQTY";
             this.NowQTY.Size = new System.Drawing.Size(146, 35);
@@ -209,7 +208,7 @@
             // 
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label4.Location = new System.Drawing.Point(34, 484);
+            this.label4.Location = new System.Drawing.Point(34, 494);
             this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(133, 38);
@@ -231,7 +230,7 @@
             this.li_code.Condition = null;
             this.li_code.DBTitle = null;
             this.li_code.FormName = null;
-            this.li_code.Location = new System.Drawing.Point(204, 291);
+            this.li_code.Location = new System.Drawing.Point(204, 268);
             this.li_code.Name = "li_code";
             this.li_code.Power = null;
             this.li_code.ReturnData = null;
@@ -246,7 +245,7 @@
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label5.Location = new System.Drawing.Point(34, 291);
+            this.label5.Location = new System.Drawing.Point(34, 268);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(82, 41);
             this.label5.TabIndex = 27;
@@ -259,7 +258,7 @@
             this.ma_code.Condition = null;
             this.ma_code.DBTitle = null;
             this.ma_code.FormName = null;
-            this.ma_code.Location = new System.Drawing.Point(204, 214);
+            this.ma_code.Location = new System.Drawing.Point(204, 191);
             this.ma_code.Name = "ma_code";
             this.ma_code.Power = null;
             this.ma_code.ReturnData = null;
@@ -270,45 +269,35 @@
             this.ma_code.TableName = null;
             this.ma_code.TextBoxEnable = false;
             // 
-            // ChooseFolder
-            // 
-            this.ChooseFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ChooseFolder.Location = new System.Drawing.Point(672, 420);
-            this.ChooseFolder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.ChooseFolder.Name = "ChooseFolder";
-            this.ChooseFolder.Size = new System.Drawing.Size(156, 48);
-            this.ChooseFolder.TabIndex = 32;
-            this.ChooseFolder.Text = "选择文件夹";
-            this.ChooseFolder.UseVisualStyleBackColor = true;
-            this.ChooseFolder.Click += new System.EventHandler(this.ChooseFolder_Click);
-            // 
-            // FolderPath
-            // 
-            this.FolderPath.Enabled = false;
-            this.FolderPath.Location = new System.Drawing.Point(204, 426);
-            this.FolderPath.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.FolderPath.Name = "FolderPath";
-            this.FolderPath.Size = new System.Drawing.Size(436, 35);
-            this.FolderPath.TabIndex = 31;
-            // 
             // label6
             // 
             this.label6.AutoSize = true;
             this.label6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(34, 426);
+            this.label6.Location = new System.Drawing.Point(34, 414);
             this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label6.Name = "label6";
-            this.label6.Size = new System.Drawing.Size(162, 38);
+            this.label6.Size = new System.Drawing.Size(104, 38);
             this.label6.TabIndex = 30;
-            this.label6.Text = "监控文件夹";
+            this.label6.Text = "拼版数";
+            // 
+            // pr_pcbacount
+            // 
+            this.pr_pcbacount.Location = new System.Drawing.Point(204, 417);
+            this.pr_pcbacount.Name = "pr_pcbacount";
+            this.pr_pcbacount.Size = new System.Drawing.Size(120, 35);
+            this.pr_pcbacount.TabIndex = 32;
+            this.pr_pcbacount.Value = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
             // 
             // AutoMakeQTY
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1443, 640);
-            this.Controls.Add(this.ChooseFolder);
-            this.Controls.Add(this.FolderPath);
+            this.Controls.Add(this.pr_pcbacount);
             this.Controls.Add(this.label6);
             this.Controls.Add(this.ma_code);
             this.Controls.Add(this.li_code);
@@ -335,6 +324,7 @@
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.ATEFile)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -363,9 +353,8 @@
         private SearchTextBox li_code;
         private System.Windows.Forms.Label label5;
         private SearchTextBox ma_code;
-        private System.Windows.Forms.Button ChooseFolder;
-        private System.Windows.Forms.TextBox FolderPath;
         private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.NumericUpDown pr_pcbacount;
     }
 }
 

+ 7 - 40
FileWatcher/AutoMakeQTY.cs

@@ -163,15 +163,15 @@ namespace FileWatcher
                 {
                     string ma_inqty = dh.getFieldDataByCondition("make", "nvl(ma_inqty,0)", "ma_code='" + ma_code.Text + "'").ToString();
                     dh.ExecuteSql("update make set ma_inqty=nvl(ma_inqty,0)+'" + (qty - lastqty) + "' where ma_code='" + ma_code.Text + "' ", "update");
-                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode)" +
-                        "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "')", "insert");
+                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode,mhc_pcbcount)" +
+                        "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "','" + pr_pcbacount.Value + "')", "insert");
                 }
                 else
                 {
                     string ma_endqty = dh.getFieldDataByCondition("make", "nvl(ma_endqty,0)", "ma_code='" + ma_code.Text + "'").ToString();
                     dh.ExecuteSql("update make set ma_endqty=nvl(ma_endqty,0)+'" + (qty - lastqty) + "' where ma_code='" + ma_code.Text + "' ", "update");
-                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode)" +
-                             "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "')", "insert");
+                    dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode,mhc_pcbcount)" +
+                             "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "','" + pr_pcbacount.Value + "')", "insert");
                 }
                 lastqty = qty;
             }
@@ -294,42 +294,10 @@ namespace FileWatcher
 
         private void Timer_Tick(object sender, EventArgs e)
         {
-            if (Type.Text == "印刷机")
-            {
-                DateTime targetDate = new DateTime(2025, 3, 17);
-                var AllXmls = Directory.GetFiles(FolderPath.Text, "*.*", SearchOption.AllDirectories).Where(s => s.ToUpper().EndsWith(".CSV") || s.ToUpper().EndsWith(".INI"));
-                foreach (var Xml in AllXmls)
-                {
-                    //解析当天日志
-                    if (Xml.Contains(DateTime.Now.ToString("yyyy-MM-dd")))
-                    {
-                        var filteredLines = File.ReadLines(Xml).Skip(1) // 跳过标题行
-                        .Where(line =>
-                        {
-                            string[] parts = line.Split(',');
-                            if (parts.Length < 2) return false;
-                            if (DateTime.TryParse(parts[1], out DateTime timestamp))
-                            {
-                                return timestamp > DateTime.Now.AddDays(-10);
-                            }
-                            return false;
-                        });
-                        int pcbcount = int.Parse(dh.getFieldDataByCondition("make left join product on ma_prodcode=pr_code", "nvl(pr_pcbacount,1)", "ma_code='" + ma_code.Text + "'").ToString());
-                        foreach (var line in filteredLines)
-                        {
-                            dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode)" +
-                            "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + pcbcount + "','" + li_code.Text + "')", "insert");
-                        }
-                    }
-                }
-            }
-            else
+            if (serialPort1.IsOpen)
             {
-                if (serialPort1.IsOpen)
-                {
-                    byte[] data = HexStringToBytes("01 03 00 01 00 06 94 08");
-                    serialPort1.Write(data, 0, data.Length);
-                }
+                byte[] data = HexStringToBytes("01 03 00 01 00 06 94 08");
+                serialPort1.Write(data, 0, data.Length);
             }
         }
 
@@ -395,7 +363,6 @@ namespace FileWatcher
             DialogResult result = folder.ShowDialog();
             if (result == DialogResult.OK)
             {
-                FolderPath.Text = folder.SelectedPath;
             }
         }
     }

+ 7 - 7
FileWatcher/DataHelper.cs

@@ -14,19 +14,19 @@ namespace FileWatcher
         //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)));";
 
         //HY
-        //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=11697)))(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=11697)))(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=192.168.0.253)(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=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)));";
         ////用户选择的数据库的连接字符串
         //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)));";
 
-        //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)));";
-        //用户选择的数据库的连接字符串
-        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=172.22.100.2)(PORT=1521)))(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)));";
+        ////用户选择的数据库的连接字符串
+        //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=172.22.100.2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
         public static OracleConnection connection = null;
         OracleCommand command = null;

+ 2 - 1
FileWatcher/Program.cs

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

+ 54 - 6
FileWatcher/UploadMakePlan.Designer.cs

@@ -41,6 +41,10 @@
             this.ImportExcel1 = new System.Windows.Forms.OpenFileDialog();
             this.Upload = new System.Windows.Forms.Button();
             this.ChooseFile = new System.Windows.Forms.Button();
+            this.label1 = new System.Windows.Forms.Label();
+            this.DateTime1 = new System.Windows.Forms.DateTimePicker();
+            this.label3 = new System.Windows.Forms.Label();
+            this.DateTime2 = new System.Windows.Forms.DateTimePicker();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
@@ -62,7 +66,7 @@
             // 
             // DateTime
             // 
-            this.DateTime.Location = new System.Drawing.Point(211, 107);
+            this.DateTime.Location = new System.Drawing.Point(222, 64);
             this.DateTime.Name = "DateTime";
             this.DateTime.Size = new System.Drawing.Size(200, 35);
             this.DateTime.TabIndex = 8;
@@ -70,7 +74,7 @@
             // FilePath
             // 
             this.FilePath.Enabled = false;
-            this.FilePath.Location = new System.Drawing.Point(211, 200);
+            this.FilePath.Location = new System.Drawing.Point(222, 261);
             this.FilePath.Name = "FilePath";
             this.FilePath.Size = new System.Drawing.Size(395, 35);
             this.FilePath.TabIndex = 204;
@@ -79,7 +83,7 @@
             // 
             this.label8.AutoSize = true;
             this.label8.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label8.Location = new System.Drawing.Point(48, 194);
+            this.label8.Location = new System.Drawing.Point(48, 255);
             this.label8.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.label8.Name = "label8";
             this.label8.Size = new System.Drawing.Size(146, 41);
@@ -90,7 +94,7 @@
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(48, 102);
+            this.label2.Location = new System.Drawing.Point(48, 58);
             this.label2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(146, 41);
@@ -103,7 +107,7 @@
             // 
             // Upload
             // 
-            this.Upload.Location = new System.Drawing.Point(211, 313);
+            this.Upload.Location = new System.Drawing.Point(211, 374);
             this.Upload.Name = "Upload";
             this.Upload.Size = new System.Drawing.Size(185, 43);
             this.Upload.TabIndex = 206;
@@ -113,7 +117,7 @@
             // 
             // ChooseFile
             // 
-            this.ChooseFile.Location = new System.Drawing.Point(642, 197);
+            this.ChooseFile.Location = new System.Drawing.Point(642, 258);
             this.ChooseFile.Name = "ChooseFile";
             this.ChooseFile.Size = new System.Drawing.Size(185, 43);
             this.ChooseFile.TabIndex = 207;
@@ -121,11 +125,51 @@
             this.ChooseFile.UseVisualStyleBackColor = true;
             this.ChooseFile.Click += new System.EventHandler(this.ChooseFile_Click);
             // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(48, 128);
+            this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(165, 41);
+            this.label1.TabIndex = 209;
+            this.label1.Text = "计划日期1";
+            // 
+            // DateTime1
+            // 
+            this.DateTime1.Location = new System.Drawing.Point(222, 133);
+            this.DateTime1.Name = "DateTime1";
+            this.DateTime1.Size = new System.Drawing.Size(200, 35);
+            this.DateTime1.TabIndex = 208;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label3.Location = new System.Drawing.Point(48, 190);
+            this.label3.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(165, 41);
+            this.label3.TabIndex = 211;
+            this.label3.Text = "计划日期2";
+            // 
+            // DateTime2
+            // 
+            this.DateTime2.Location = new System.Drawing.Point(222, 195);
+            this.DateTime2.Name = "DateTime2";
+            this.DateTime2.Size = new System.Drawing.Size(200, 35);
+            this.DateTime2.TabIndex = 210;
+            // 
             // UploadMakePlan
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1498, 640);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.DateTime2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.DateTime1);
             this.Controls.Add(this.ChooseFile);
             this.Controls.Add(this.Upload);
             this.Controls.Add(this.label2);
@@ -158,6 +202,10 @@
         private System.Windows.Forms.OpenFileDialog ImportExcel1;
         private System.Windows.Forms.Button Upload;
         private System.Windows.Forms.Button ChooseFile;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.DateTimePicker DateTime1;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.DateTimePicker DateTime2;
     }
 }
 

+ 268 - 1
FileWatcher/UploadMakePlan.cs

@@ -138,7 +138,7 @@ namespace FileWatcher
                                     if (!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 + "'"))
+                                        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 + "'"))
                                         {
                                             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)";
                                             using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
@@ -165,6 +165,273 @@ namespace FileWatcher
                     }
                 }
             }
+            //上传日期1
+            if (DateTime1.Value != DateTime.Value)
+            {
+                today = DateTime1.Value;
+                todayDate = today.ToString("MMdd");
+                code = dh.GetSerialNumberByCaller("MakePlan");
+                id = "";
+                dt = (DataTable)dh.ExecuteSql("select mp_id from MakePlan where to_char(mp_begintime,'yyyymmdd')='" + today.ToString("yyyyMMdd") + "'", "select");
+                if (dt.Rows.Count == 0)
+                {
+                    id = dh.GetSEQ("MakePlan_seq");
+                    dh.ExecuteSql("insert into MakePlan(MP_ID, MP_CODE, MP_KIND, MP_INDATE, MP_STATUS, MP_STATUSCODE, MP_BEGINTIME)" +
+                        "values(" + id + ",'" + code + "','日计划',sysdate,'在录入','ENTERING',to_date('" + today.ToString("yyyyMMdd") + "','yyyymmdd'))", "insert");
+                }
+                else
+                {
+                    id = dt.Rows[0]["mp_id"].ToString();
+                    dh.ExecuteSql("delete from MakePlandetail where mpd_mpid=" + id, "delete");
+                }
+
+                using (FileStream file = new FileStream(FilePath.Text, FileMode.Open, FileAccess.Read))
+                {
+                    XSSFWorkbook workbook = new XSSFWorkbook(file);
+                    int detno = 1;
+
+                    for (int i = 0; i < workbook.NumberOfSheets; i++)
+                    {
+                        ISheet sheet = workbook.GetSheetAt(i);
+                        string sheetName = sheet.SheetName;
+                        if (sheetName.Contains(todayDate))
+                        {
+                            OperateResult.AppendText(sheetName);
+                            OperateResult.AppendText($"Processing sheet: {sheetName}\n");
+                            //Console.WriteLine($"Processing sheet: {sheetName}");
+
+                            // 获取标题行(第4行)
+                            IRow headerRow = sheet.GetRow(3); // 第4行索引为3
+                            if (headerRow == null)
+                            {
+                                Console.WriteLine("Header row not found.");
+                                continue;
+                            }
+
+                            // 获取标题列的索引
+                            int wccodeIndex = -1;
+                            int orderdetnoIndex = -1;
+                            int ordercodeIndex = -1;
+                            int planqtyIndex = -1;
+                            int remarkIndex = -1;
+
+                            for (int colIndex = 0; colIndex < headerRow.LastCellNum; colIndex++)
+                            {
+                                ICell cell = headerRow.GetCell(colIndex);
+                                if (cell != null)
+                                {
+                                    string headerValue = cell.ToString().Trim().Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
+                                    if (headerValue == "工作中心")
+                                    {
+                                        wccodeIndex = colIndex;
+                                    }
+                                    else if (headerValue == "订单序号")
+                                    {
+                                        orderdetnoIndex = colIndex;
+                                    }
+                                    else if (headerValue == "订单编号")
+                                    {
+                                        ordercodeIndex = colIndex;
+                                    }
+                                    else if (headerValue == "计划数量")
+                                    {
+                                        planqtyIndex = colIndex;
+                                    }
+                                    else if (headerValue.Contains("备注") && !headerValue.Contains("生产异常备注"))
+                                    {
+                                        remarkIndex = colIndex;
+                                    }
+                                }
+                            }
+
+                            if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1)
+                            {
+                                Console.WriteLine("Required columns not found in the header.");
+                                continue;
+                            }
+
+                            using (OracleConnection conn = new OracleConnection(connectionString))
+                            {
+                                conn.Open();
+                                for (int rowIndex = 4; 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 == "")
+                                        {
+                                            continue;
+                                        }
+                                        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();
+                                        if (!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 + "'"))
+                                            {
+                                                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)";
+                                                using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
+                                                {
+                                                    cmd.Parameters.Add(new OracleParameter(":1", wccode));
+                                                    cmd.Parameters.Add(new OracleParameter(":2", orderdetno));
+                                                    cmd.Parameters.Add(new OracleParameter(":3", ordercode));
+                                                    cmd.Parameters.Add(new OracleParameter(":4", planqty));
+                                                    cmd.Parameters.Add(new OracleParameter(":5", remark));
+                                                    cmd.ExecuteNonQuery();
+                                                }
+                                            }
+                                            else
+                                            {
+                                                OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "' 工作中心'" + wccode + "' 重复");
+                                            }
+                                        }
+                                    }
+                                    detno = detno + 1;
+                                }
+                            }
+                            dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
+                            OperateResult.AppendText("计划上传成功");
+                        }
+                    }
+                }
+            }
+
+            //上传日期2
+            if (DateTime2.Value != DateTime1.Value && DateTime2.Value != DateTime.Value)
+            {
+                today = DateTime2.Value;
+                todayDate = today.ToString("MMdd");
+                code = dh.GetSerialNumberByCaller("MakePlan");
+                id = "";
+                dt = (DataTable)dh.ExecuteSql("select mp_id from MakePlan where to_char(mp_begintime,'yyyymmdd')='" + today.ToString("yyyyMMdd") + "'", "select");
+                if (dt.Rows.Count == 0)
+                {
+                    id = dh.GetSEQ("MakePlan_seq");
+                    dh.ExecuteSql("insert into MakePlan(MP_ID, MP_CODE, MP_KIND, MP_INDATE, MP_STATUS, MP_STATUSCODE, MP_BEGINTIME)" +
+                        "values(" + id + ",'" + code + "','日计划',sysdate,'在录入','ENTERING',to_date('" + today.ToString("yyyyMMdd") + "','yyyymmdd'))", "insert");
+                }
+                else
+                {
+                    id = dt.Rows[0]["mp_id"].ToString();
+                    dh.ExecuteSql("delete from MakePlandetail where mpd_mpid=" + id, "delete");
+                }
+
+                using (FileStream file = new FileStream(FilePath.Text, FileMode.Open, FileAccess.Read))
+                {
+                    XSSFWorkbook workbook = new XSSFWorkbook(file);
+                    int detno = 1;
+
+                    for (int i = 0; i < workbook.NumberOfSheets; i++)
+                    {
+                        ISheet sheet = workbook.GetSheetAt(i);
+                        string sheetName = sheet.SheetName;
+                        if (sheetName.Contains(todayDate))
+                        {
+                            OperateResult.AppendText(sheetName);
+                            OperateResult.AppendText($"Processing sheet: {sheetName}\n");
+                            //Console.WriteLine($"Processing sheet: {sheetName}");
+
+                            // 获取标题行(第4行)
+                            IRow headerRow = sheet.GetRow(3); // 第4行索引为3
+                            if (headerRow == null)
+                            {
+                                Console.WriteLine("Header row not found.");
+                                continue;
+                            }
+
+                            // 获取标题列的索引
+                            int wccodeIndex = -1;
+                            int orderdetnoIndex = -1;
+                            int ordercodeIndex = -1;
+                            int planqtyIndex = -1;
+                            int remarkIndex = -1;
+
+                            for (int colIndex = 0; colIndex < headerRow.LastCellNum; colIndex++)
+                            {
+                                ICell cell = headerRow.GetCell(colIndex);
+                                if (cell != null)
+                                {
+                                    string headerValue = cell.ToString().Trim().Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
+                                    if (headerValue == "工作中心")
+                                    {
+                                        wccodeIndex = colIndex;
+                                    }
+                                    else if (headerValue == "订单序号")
+                                    {
+                                        orderdetnoIndex = colIndex;
+                                    }
+                                    else if (headerValue == "订单编号")
+                                    {
+                                        ordercodeIndex = colIndex;
+                                    }
+                                    else if (headerValue == "计划数量")
+                                    {
+                                        planqtyIndex = colIndex;
+                                    }
+                                    else if (headerValue.Contains("备注") && !headerValue.Contains("生产异常备注"))
+                                    {
+                                        remarkIndex = colIndex;
+                                    }
+                                }
+                            }
+
+                            if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1)
+                            {
+                                Console.WriteLine("Required columns not found in the header.");
+                                continue;
+                            }
+
+                            using (OracleConnection conn = new OracleConnection(connectionString))
+                            {
+                                conn.Open();
+                                for (int rowIndex = 4; 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 == "")
+                                        {
+                                            continue;
+                                        }
+                                        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();
+                                        if (!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 + "'"))
+                                            {
+                                                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)";
+                                                using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
+                                                {
+                                                    cmd.Parameters.Add(new OracleParameter(":1", wccode));
+                                                    cmd.Parameters.Add(new OracleParameter(":2", orderdetno));
+                                                    cmd.Parameters.Add(new OracleParameter(":3", ordercode));
+                                                    cmd.Parameters.Add(new OracleParameter(":4", planqty));
+                                                    cmd.Parameters.Add(new OracleParameter(":5", remark));
+                                                    cmd.ExecuteNonQuery();
+                                                }
+                                            }
+                                            else
+                                            {
+                                                OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "' 工作中心'" + wccode + "' 重复");
+                                            }
+                                        }
+                                    }
+                                    detno = detno + 1;
+                                }
+                            }
+                            dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
+                            OperateResult.AppendText("计划上传成功");
+                        }
+                    }
+                }
+            }
         }
 
         private void ChooseFile_Click(object sender, EventArgs e)