浏览代码

原始报表解析

callm 1 年之前
父节点
当前提交
0fe259390e

+ 79 - 10
UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.Designer.cs

@@ -35,10 +35,15 @@
             this.ImportExcel1 = new System.Windows.Forms.OpenFileDialog();
             this.label1 = new System.Windows.Forms.Label();
             this.Process = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label6 = new System.Windows.Forms.Label();
+            this.TraceFilePath = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.EnterTextBox();
+            this.TraceFile = new UAS_MES_NEW.CustomControl.ButtonUtil.NormalButton();
             this.pr_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SearchTextBox();
             this.XY = new UAS_MES_NEW.CustomControl.ButtonUtil.NormalButton();
             this.XYFilePath = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.EnterTextBox();
-            this.label2 = new System.Windows.Forms.Label();
+            this.dataGridView1 = new System.Windows.Forms.DataGridView();
+            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
             this.SuspendLayout();
             // 
             // label5
@@ -77,6 +82,62 @@
             this.Process.Size = new System.Drawing.Size(0, 41);
             this.Process.TabIndex = 241;
             // 
+            // 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(891, 149);
+            this.label2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(82, 41);
+            this.label2.TabIndex = 242;
+            this.label2.Text = "进度";
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label6.Location = new System.Drawing.Point(180, 336);
+            this.label6.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(242, 41);
+            this.label6.TabIndex = 244;
+            this.label6.Text = "贴片机导出文件";
+            // 
+            // TraceFilePath
+            // 
+            this.TraceFilePath.AllPower = null;
+            this.TraceFilePath.BackColor = System.Drawing.Color.White;
+            this.TraceFilePath.ID = null;
+            this.TraceFilePath.Location = new System.Drawing.Point(434, 342);
+            this.TraceFilePath.Margin = new System.Windows.Forms.Padding(6);
+            this.TraceFilePath.Name = "TraceFilePath";
+            this.TraceFilePath.Power = null;
+            this.TraceFilePath.Size = new System.Drawing.Size(445, 35);
+            this.TraceFilePath.Str = null;
+            this.TraceFilePath.Str1 = null;
+            this.TraceFilePath.Str2 = null;
+            this.TraceFilePath.TabIndex = 245;
+            // 
+            // TraceFile
+            // 
+            this.TraceFile.AllPower = null;
+            this.TraceFile.BackColor = System.Drawing.Color.Transparent;
+            this.TraceFile.DownImage = ((System.Drawing.Image)(resources.GetObject("TraceFile.DownImage")));
+            this.TraceFile.Image = null;
+            this.TraceFile.IsShowBorder = true;
+            this.TraceFile.Location = new System.Drawing.Point(434, 420);
+            this.TraceFile.Margin = new System.Windows.Forms.Padding(6);
+            this.TraceFile.MoveImage = ((System.Drawing.Image)(resources.GetObject("TraceFile.MoveImage")));
+            this.TraceFile.Name = "TraceFile";
+            this.TraceFile.NormalImage = ((System.Drawing.Image)(resources.GetObject("TraceFile.NormalImage")));
+            this.TraceFile.Power = null;
+            this.TraceFile.Size = new System.Drawing.Size(198, 56);
+            this.TraceFile.TabIndex = 243;
+            this.TraceFile.Text = "导入贴片机资料";
+            this.TraceFile.UseVisualStyleBackColor = false;
+            this.TraceFile.Click += new System.EventHandler(this.TraceFile_Click);
+            // 
             // pr_code
             // 
             this.pr_code.AllPower = "ifall";
@@ -133,22 +194,25 @@
             this.XYFilePath.TabIndex = 12;
             this.XYFilePath.TextChanged += new System.EventHandler(this.inoutno_TextChanged);
             // 
-            // label2
+            // dataGridView1
             // 
-            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(891, 149);
-            this.label2.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
-            this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(82, 41);
-            this.label2.TabIndex = 242;
-            this.label2.Text = "进度";
+            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.dataGridView1.Location = new System.Drawing.Point(41, 482);
+            this.dataGridView1.Name = "dataGridView1";
+            this.dataGridView1.RowHeadersWidth = 82;
+            this.dataGridView1.RowTemplate.Height = 37;
+            this.dataGridView1.Size = new System.Drawing.Size(1416, 535);
+            this.dataGridView1.TabIndex = 246;
             // 
             // Query_SpecialReport
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1494, 1075);
+            this.Controls.Add(this.dataGridView1);
+            this.Controls.Add(this.TraceFilePath);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.TraceFile);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.Process);
             this.Controls.Add(this.label1);
@@ -162,6 +226,7 @@
             this.Tag = "Query!SpecialReport";
             this.Text = "Query_SpecialReport";
             this.Load += new System.EventHandler(this.Query_SpecialReport_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -178,5 +243,9 @@
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label Process;
         private System.Windows.Forms.Label label2;
+        private CustomControl.ButtonUtil.NormalButton TraceFile;
+        private CustomControl.TextBoxWithIcon.EnterTextBox TraceFilePath;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.DataGridView dataGridView1;
     }
 }

+ 196 - 1
UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.cs

@@ -85,7 +85,7 @@ namespace UAS_MES_NEW.Query
                 string Refer = importdata.Rows[i]["Refer"].ToString();
                 DataTable bom = (DataTable)dh.ExecuteSql("select replace(wm_concat(bd_location||';'||nvl(bd_soncode,PRE_SONCODE)||' '||PRE_REPCODE),',',' ') from BOMDetail " +
                     "LEFT JOIN bom on bd_bomid=bo_id left join Product ON bd_soncode=pr_code left join ProdReplace on pre_bdid =bd_id where " +
-                    "bo_mothercode='" + pr_code.Text + "' and instr(bd_location,'" + Refer + "')>0", "select");
+                    "bo_mothercode='" + pr_code.Text + "' and instr(','||bd_location||',',',"+Refer+",')>0", "select");
                 if (bom.Rows.Count > 0)
                 {
                     if (bom.Rows[0][0].ToString() != "")
@@ -107,6 +107,88 @@ namespace UAS_MES_NEW.Query
             sw.Close();
         }
 
+
+
+        public static bool OpenCSVFile(ref DataTable mycsvdt, string filepath)
+        {
+            string strpath = filepath; //csv文件的路径
+            try
+            {
+                int intColCount = 0;
+                bool blnFlag = true;
+
+                DataColumn mydc;
+                DataRow mydr;
+
+                string strline;
+                string[] aryline;
+                StreamReader mysr = new StreamReader(strpath, System.Text.Encoding.UTF8);
+
+                while ((strline = mysr.ReadLine()) != null)
+                {
+                    aryline = strline.Split(new char[] { ',' });
+
+                    //给datatable加上列名
+                    if (blnFlag)
+                    {
+                        blnFlag = false;
+                        intColCount = aryline.Length;
+                        int col = 0;
+                        for (int i = 0; i < aryline.Length; i++)
+                        {
+                            col = i + 1;
+                            mydc = new DataColumn(col.ToString());
+                            mycsvdt.Columns.Add(mydc);
+                        }
+                    }
+
+                    //填充数据并加入到datatable中
+                    mydr = mycsvdt.NewRow();
+                    for (int i = 0; i < aryline.Length; i++)
+                    {
+                        mydr[i] = aryline[i];
+                    }
+                    mycsvdt.Rows.Add(mydr);
+                }
+                mysr.Close();
+                return true;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message + ex.StackTrace);
+                return false;
+            }
+        }
+
+        private void TraceFile_Click(object sender, EventArgs e)
+        {
+            ImportExcel1.Filter = "(*.xls)|*.xls";
+            DialogResult result;
+            result = ImportExcel1.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                TraceFilePath.Text = ImportExcel1.FileName;
+                DataTable dt = ExcelToDataTable1(ImportExcel1.FileName, false);
+                List<string> STF_MODEL = new List<string>();
+                List<string> STF_FEEDER = new List<string>();
+                List<string> STF_FEEDERNO = new List<string>();
+                List<string> STF_LOCATION = new List<string>();
+                string stf_code = dt.Rows[0][10].ToString();
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    string data = "";
+                    for (int j = 0; j < dt.Columns.Count; j++)
+                    {
+                        data += dt.Rows[i][j].ToString() + " ";
+                    }
+                }
+                dh.BatchInsert("insert into SMTTRACEFILE(STF_ID, STF_MODEL, STF_FEEDER, STF_FEEDERNO, STF_LOCATION, STF_CODE, STF_INDATE, STF_INMAN)" +
+                    "values(SMTTRACEFILE_SEQ.nextval,:STF_MODEL,:STF_FEEDER,:STF_FEEDERNO,:STF_LOCATION,'"+ stf_code + "',sysdate,'" + User.UserName + "')",
+                    new string[] { "STF_MODEL", "STF_FEEDER", "STF_FEEDERNO", "STF_LOCATION" }, STF_MODEL.ToArray(), STF_FEEDER.ToArray(), STF_FEEDERNO.ToArray(), STF_LOCATION.ToArray());
+                dataGridView1.DataSource = dt;
+            }
+        }
+
         public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
         {
             DataTable dataTable = null;
@@ -218,5 +300,118 @@ namespace UAS_MES_NEW.Query
                 return null;
             }
         }
+
+        public static DataTable ExcelToDataTable1(string filePath, bool isColumnName)
+        {
+            DataTable dataTable = null;
+            FileStream fs = null;
+            DataColumn column = null;
+            DataRow dataRow = null;
+            IWorkbook workbook = null;
+            ISheet sheet = null;
+            IRow row = null;
+            ICell cell = null;
+            int startRow = 0;
+            try
+            {
+                using (fs = File.OpenRead(filePath))
+                {
+                    // 2007版本
+                    workbook = new HSSFWorkbook(fs);
+                    if (workbook != null)
+                    {
+                        sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
+                        dataTable = new DataTable();
+                        if (sheet != null)
+                        {
+                            int rowCount = sheet.LastRowNum;//总行数
+                            if (rowCount > 0)
+                            {
+                                IRow firstRow = sheet.GetRow(1);//第一行
+                                int cellCount = firstRow.LastCellNum;//列数
+
+                                //构建datatable的列
+                                if (isColumnName)
+                                {
+                                    startRow = 1;//如果第一行是列名,则从第二行开始读取
+                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
+                                    {
+                                        cell = firstRow.GetCell(i);
+                                        if (cell != null)
+                                        {
+                                            if (cell.StringCellValue != null)
+                                            {
+                                                column = new DataColumn(cell.StringCellValue);
+                                                dataTable.Columns.Add(column);
+                                            }
+                                        }
+                                    }
+                                }
+                                else
+                                {
+                                    startRow = 1;
+                                    for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
+                                    {
+                                        column = new DataColumn("column" + (i + 1));
+                                        dataTable.Columns.Add(column);
+                                    }
+                                }
+                                //填充行
+                                for (int i = startRow; i <= rowCount; ++i)
+                                {
+                                    row = sheet.GetRow(i);
+                                    Console.WriteLine(i);
+                                    if (row == null) continue;
+                                    dataRow = dataTable.NewRow();
+                                    for (int j = 0; j < 40; ++j)
+                                    {
+                                        cell = row.GetCell(j);
+                                        if (cell == null)
+                                        {
+                                            dataRow[j] = "";
+                                        }
+                                        else
+                                        {
+                                            //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
+                                            switch (cell.CellType)
+                                            {
+                                                case CellType.BLANK:
+                                                    dataRow[j] = "";
+                                                    break;
+                                                case CellType.NUMERIC:
+                                                    short format = cell.CellStyle.DataFormat;
+                                                    //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
+                                                    if (format == 14 || format == 31 || format == 57 || format == 58)
+                                                        dataRow[j] = cell.DateCellValue;
+                                                    else
+                                                        dataRow[j] = cell.NumericCellValue;
+                                                    break;
+                                                case CellType.STRING:
+                                                    dataRow[j] = cell.StringCellValue;
+                                                    break;
+                                                case CellType.FORMULA:
+                                                    dataRow[j] = cell.StringCellValue;
+                                                    break;
+                                            }
+                                        }
+                                    }
+                                    dataTable.Rows.Add(dataRow);
+                                }
+                            }
+                        }
+                    }
+                }
+                return dataTable;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+                if (fs != null)
+                {
+                    fs.Close();
+                }
+                return null;
+            }
+        }
     }
 }

+ 38 - 0
UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.resx

@@ -127,6 +127,44 @@
     <value>1018, 17</value>
   </metadata>
   <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="TraceFile.DownImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAAEUAAAAWCAYAAACWl1FwAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
+        dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFcSURBVFhH5di7UsJAFMbxtDT6QMI76IAFT0npIE0K
+        GcRORxHklpAIBHLfbILV8XxeNsMznJ35F5vu+82kWYuILD4N7oq75roCw27sb/x5WBdc27btntY64o/i
+        DnZjPxy4S6A0R6PHO1WUNHc9ep4uxIXd2D8eP/XZowWUThBG+n3p0stsKbbJ0qFDFFfscQuUbpzm9Pqx
+        Eh8c4PGLkuX0Nl+LDw4GJckUTRaO+OBQo+SKpitXfHAwKClfZuuN+OBgUDJV0NzxxAeHM5TFxhffGUpe
+        aFp5n+KDg0FRfHH8nfjgUKPoktztXnxwMCgFX7xdID441ChlRf7+ID44GBTNl21wFB8capSqot0xFB8c
+        /lE6Wa70IU5oH0Ziw/5cFebpoPUwHPbL04nCJKUgisWF3dgPB3gABc9v7fvBoBcnaVKdvkha2I39cPjx
+        oPrhusndcPinpIXd2N8gIusbTaFspKtR2SQAAAAASUVORK5CYII=
+</value>
+  </data>
+  <data name="TraceFile.MoveImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAAEUAAAAWCAYAAACWl1FwAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
+        dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFzSURBVFhH5djNSgJRGMZxL2P2gTfQFbZvHSEZFBEW
+        CEIQBEIgVFiS9qXWoDmp4/fHzDmjM2a+vU/QqUVX0DvwXxxn9fwYXJwYEcXWNzIWt83dcq7AsBv7LXgA
+        ZI0r71/aaqjCJf8o7sFu7IcDFwdK4vimrv1oSZXRnArdQFzYjf3pQkOzRxIoVWc6X5X6M7ruBGIr9mbU
+        9MIVe9hAcXvBO125WnxwgMcXSpcPF20tPjgYlI5eUK6lxAcHg9Lmw3nTFx8cDEpLLSjr+OKDg0FpqojO
+        Gp744GBQ3vyITutT8cHBoDheRCe1ifjgYFBe+ZCxJ+KDg0GpT0NKv4zFBweDUpuEdFQdiQ8OBsXmw2Fl
+        JD44/KCM53TwNBQfHAzKMx/2Hgfig8M3SrXYUasUfz67DwOxYf9dV5urg+RWzta4aEnxn83OfV9c2I39
+        cIAHUOJceTNbUfmW94GX0sJu7IcDPH5fXCe4EvfXxe5/D7ux3yKi2CfkPhTy27lqkwAAAABJRU5ErkJg
+        gg==
+</value>
+  </data>
+  <data name="TraceFile.NormalImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        iVBORw0KGgoAAAANSUhEUgAAAEUAAAAWCAYAAACWl1FwAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m
+        dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGVSURBVFhH5di7agJRFIXhDSKoYBQEC8FCECwEQRBE
+        4uUVEtTiPKVlom2wttM6IfF+15njXHRnL19jD/zFmanWV8zAEDNTp9OJS6/Sm2QUht3YH4cHtdvtF6k7
+        mUwG1tqd3FR3YTf2w0FKUVOu6XT68Xgw3+8PtWH/bDYbCkeLGo1Gz/d9JwzvrL0gCKx49KlerxtIBUGo
+        PjjAg2q1mqDc2fN99cEBHlStVk0oB+t56oMDPKhSqZggDNm1N/XBAR5ULpeNvGD46rrqgwM8qFQqGV8O
+        56ujPjjAg4rFosFL5ni5qA8O8KBCoWBuns/701l9cIAH5fN5QfF4dzipDw7woFwuZ+zN483+oD44wIOy
+        2azB52i13asPDvCgTCZjHGt5sdmqDw7woHQ6bRzX8ny1UR8c4EHJZNJc5fC7XKsPDvCgRCLR2x9Pzt9q
+        zT+Lpdqw/3A6W/HoUywWa32Nx8OL4zwffM8X6sJu7IcDPCgajaak7udoNNjsdgc81BZ2Yz8c4PH8cR2J
+        ROJSU3qXjMKwG/vjzEz/skOI3Zqgv7AAAAAASUVORK5CYII=
+</value>
+  </data>
   <data name="XY.DownImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         iVBORw0KGgoAAAANSUhEUgAAAEUAAAAWCAYAAACWl1FwAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m