callm 9 сар өмнө
parent
commit
ff032e0cbd

+ 163 - 0
FileWatcher/UploadMakePlan.Designer.cs

@@ -0,0 +1,163 @@
+namespace FileWatcher
+{
+    partial class UploadMakePlan
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.XmlWatcher = new System.IO.FileSystemWatcher();
+            this.XmlFolder = new System.Windows.Forms.FolderBrowserDialog();
+            this.OperateResult = new System.Windows.Forms.RichTextBox();
+            this.Timer = new System.Windows.Forms.Timer(this.components);
+            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
+            this.DateTime = new System.Windows.Forms.DateTimePicker();
+            this.FilePath = new System.Windows.Forms.TextBox();
+            this.label8 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.ImportExcel1 = new System.Windows.Forms.OpenFileDialog();
+            this.Upload = new System.Windows.Forms.Button();
+            this.ChooseFile = new System.Windows.Forms.Button();
+            ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // XmlWatcher
+            // 
+            this.XmlWatcher.EnableRaisingEvents = true;
+            this.XmlWatcher.Filter = "*.xml";
+            this.XmlWatcher.IncludeSubdirectories = true;
+            this.XmlWatcher.SynchronizingObject = this;
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Location = new System.Drawing.Point(979, 12);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(506, 564);
+            this.OperateResult.TabIndex = 7;
+            this.OperateResult.Text = "";
+            // 
+            // DateTime
+            // 
+            this.DateTime.Location = new System.Drawing.Point(211, 107);
+            this.DateTime.Name = "DateTime";
+            this.DateTime.Size = new System.Drawing.Size(200, 35);
+            this.DateTime.TabIndex = 8;
+            // 
+            // FilePath
+            // 
+            this.FilePath.Enabled = false;
+            this.FilePath.Location = new System.Drawing.Point(211, 200);
+            this.FilePath.Name = "FilePath";
+            this.FilePath.Size = new System.Drawing.Size(395, 35);
+            this.FilePath.TabIndex = 204;
+            // 
+            // label8
+            // 
+            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.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(146, 41);
+            this.label8.TabIndex = 203;
+            this.label8.Text = "文件路径";
+            // 
+            // label2
+            // 
+            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.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(146, 41);
+            this.label2.TabIndex = 205;
+            this.label2.Text = "计划日期";
+            // 
+            // ImportExcel1
+            // 
+            this.ImportExcel1.FileName = "ImportExcel";
+            // 
+            // Upload
+            // 
+            this.Upload.Location = new System.Drawing.Point(211, 313);
+            this.Upload.Name = "Upload";
+            this.Upload.Size = new System.Drawing.Size(185, 43);
+            this.Upload.TabIndex = 206;
+            this.Upload.Text = "上传";
+            this.Upload.UseVisualStyleBackColor = true;
+            this.Upload.Click += new System.EventHandler(this.Upload_Click);
+            // 
+            // ChooseFile
+            // 
+            this.ChooseFile.Location = new System.Drawing.Point(642, 197);
+            this.ChooseFile.Name = "ChooseFile";
+            this.ChooseFile.Size = new System.Drawing.Size(185, 43);
+            this.ChooseFile.TabIndex = 207;
+            this.ChooseFile.Text = "选择文件";
+            this.ChooseFile.UseVisualStyleBackColor = true;
+            this.ChooseFile.Click += new System.EventHandler(this.ChooseFile_Click);
+            // 
+            // 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.ChooseFile);
+            this.Controls.Add(this.Upload);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.FilePath);
+            this.Controls.Add(this.label8);
+            this.Controls.Add(this.DateTime);
+            this.Controls.Add(this.OperateResult);
+            this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.MaximizeBox = false;
+            this.Name = "UploadMakePlan";
+            this.Text = "生产计划上传";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.IO.FileSystemWatcher XmlWatcher;
+        private System.Windows.Forms.FolderBrowserDialog XmlFolder;
+        private System.Windows.Forms.RichTextBox OperateResult;
+        private System.Windows.Forms.Timer Timer;
+        private System.Windows.Forms.NotifyIcon notifyIcon1;
+        private System.Windows.Forms.DateTimePicker DateTime;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox FilePath;
+        private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.OpenFileDialog ImportExcel1;
+        private System.Windows.Forms.Button Upload;
+        private System.Windows.Forms.Button ChooseFile;
+    }
+}
+

+ 170 - 0
FileWatcher/UploadMakePlan.cs

@@ -0,0 +1,170 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.IO;
+using System.Threading;
+using System.Windows.Forms;
+using System.Xml;
+using System.Text;
+using System.Media;
+using System.Linq;
+using NPOI.SS.Formula.Functions;
+using System.Windows.Media.TextFormatting;
+using UMESDLLService;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using Oracle.ManagedDataAccess.Client;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
+
+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)));";
+
+
+        StringBuilder sql = new StringBuilder();
+
+        DataHelper dh;
+
+        string imaster;
+
+        public UploadMakePlan()
+        {
+            InitializeComponent();
+            StartPosition = FormStartPosition.CenterScreen;
+        }
+
+        string fieltype = "";
+        string ftpulr = "";
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            dh = new DataHelper(connectionString);
+        }
+
+        private void Upload_Click(object sender, EventArgs e)
+        {
+            DateTime today = DateTime.Value;
+            string todayDate = today.ToString("MMdd");
+            string code = dh.GetSerialNumberByCaller("MakePlan");
+            string id = "";
+            DataTable 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);
+
+
+                for (int i = 0; i < workbook.NumberOfSheets; i++)
+                {
+                    ISheet sheet = workbook.GetSheetAt(i);
+                    string sheetName = sheet.SheetName;
+
+                    if (sheetName.Contains(todayDate))
+                    {
+                        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;
+
+                        for (int colIndex = 0; colIndex < headerRow.LastCellNum; colIndex++)
+                        {
+                            ICell cell = headerRow.GetCell(colIndex);
+                            if (cell != null)
+                            {
+                                string headerValue = cell.ToString().Trim();
+                                if (headerValue == "工作中心")
+                                {
+                                    wccodeIndex = colIndex;
+                                }
+                                else if (headerValue == "订单序号")
+                                {
+                                    orderdetnoIndex = colIndex;
+                                }
+                                else if (headerValue == "订单编号")
+                                {
+                                    ordercodeIndex = colIndex;
+                                }
+                                else if (headerValue == "计划数量")
+                                {
+                                    planqtyIndex = colIndex;
+                                }
+                            }
+                        }
+
+                        if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -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).ToString();
+                                    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();
+                                    if (!string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
+                                    {
+                                        string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty) VALUES (" + id + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4)";
+                                        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.ExecuteNonQuery();
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
+                        OperateResult.AppendText("计划上传成功");
+                    }
+                }
+            }
+        }
+
+        private void ChooseFile_Click(object sender, EventArgs e)
+        {
+            DialogResult result;
+            result = ImportExcel1.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                FilePath.Text = ImportExcel1.FileName;
+            }
+        }
+    }
+}

+ 138 - 0
FileWatcher/UploadMakePlan.resx

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