Browse Source

特殊报表开发

callm 1 year ago
parent
commit
a0d8344da4

+ 57 - 0
UAS_MES_LGDZ/DataOperate/ExcelHandler.cs

@@ -9,6 +9,7 @@ using System.Text;
 using NPOI.SS.Util;
 using System.Drawing;
 using System.Collections.Generic;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.DataOperate
 {
@@ -35,6 +36,62 @@ namespace UAS_MES_NEW.DataOperate
             return filePath;
         }
 
+        public string ExportExcel_LIANGAN(DataTable dt, string FolderPath)
+        {
+            //创建一个内存流,用来接收转换成Excel的内容
+            MemoryStream ms;
+            ms = DataTableToExcel_LIANGAN(dt, FolderPath);
+            //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
+            string filePath = FolderPath;
+            FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
+            byte[] data = ms.ToArray();
+            fs.Write(data, 0, data.Length);
+            fs.Flush();
+            //释放当前Excel文件,否则打开文件的时候会显示文件被占用
+            ms.Dispose();
+            fs.Dispose();
+            return filePath;
+        }
+
+        public MemoryStream DataTableToExcel_LIANGAN(DataTable DataTable,  string FolderPath) {
+            //创建内存流
+            MemoryStream ms = new MemoryStream();
+            //创建一个Book,相当于一个Excel文件
+            HSSFWorkbook book = new HSSFWorkbook();
+            //Excel中的Sheet
+            //获取行数量和列数量
+            int rowNum = DataTable.Rows.Count;
+            int columnNum = DataTable.Columns.Count;
+            //设置列的宽度,根据首行的列的内容的长度来设置
+            for (int i = 0; i < DataTable.Rows.Count; i++)
+            {
+                if (DataTable.Rows[i]["STF_MACHINE"].ToString() != ""&&i!= DataTable.Rows.Count-1) {
+                    Console.WriteLine(DataTable.Rows[i]["STF_MACHINE"].ToString());
+                    ISheet sheet1 = book.CreateSheet(DataTable.Rows[i]["STF_MACHINE"].ToString()+"-"+ DataTable.Rows[i + 1]["STF_MACHINE"].ToString().Substring(0,1));
+                    IRow row1 = sheet1.CreateRow(0);
+                    IRow row2 = sheet1.CreateRow(1);
+                    IRow row3 = sheet1.CreateRow(2);
+                    IRow row4 = sheet1.CreateRow(3);
+                    IRow row5 = sheet1.CreateRow(4);
+                    IRow row6 = sheet1.CreateRow(5);
+                    IRow row7 = sheet1.CreateRow(6);
+                    IRow row8 = sheet1.CreateRow(7);
+                    row8.CreateCell(0); row8.Cells[0].SetCellValue("站位");
+                    row8.CreateCell(1); row8.Cells[1].SetCellValue("Feeder类型");
+                    row8.CreateCell(2); row8.Cells[2].SetCellValue("位置");
+                    row8.CreateCell(3); row8.Cells[3].SetCellValue("物料编码");
+                    row8.CreateCell(4); row8.Cells[4].SetCellValue("物料描述");
+                    row8.CreateCell(5); row8.Cells[5].SetCellValue("用量");
+                    row8.CreateCell(6); row8.Cells[6].SetCellValue("位号");
+                    row8.CreateCell(7); row8.Cells[7].SetCellValue("备注");
+                    i = i + 1;
+                }
+            }
+            //将book的内容写入内存流中返回
+            book.Write(ms);
+            return ms;
+        }
+
         /// <summary>
         /// 导出Excel,返回文件在客户端的路径
         /// </summary>

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

@@ -126,7 +126,7 @@
             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.Location = new System.Drawing.Point(434, 403);
             this.TraceFile.Margin = new System.Windows.Forms.Padding(6);
             this.TraceFile.MoveImage = ((System.Drawing.Image)(resources.GetObject("TraceFile.MoveImage")));
             this.TraceFile.Name = "TraceFile";

+ 14 - 9
UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.cs

@@ -184,19 +184,24 @@ namespace UAS_MES_NEW.Query
                 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();
+                List<string> STF_MACHINE = new List<string>();
+                string stf_code = dt.Rows[0][9].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() + " ";
-                    }
+                    STF_MODEL.Add(dt.Rows[i][0].ToString());
+                    STF_FEEDER.Add(dt.Rows[i][3].ToString());
+                    STF_FEEDERNO.Add(dt.Rows[i][11].ToString());
+                    STF_LOCATION.Add(dt.Rows[i][12].ToString());
+                    STF_MACHINE.Add(dt.Rows[i][1].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());
+                dh.ExecuteSql("delete from SMTTRACEFILE where stf_code='" + stf_code + "'", "delete");
+                dh.BatchInsert("insert into SMTTRACEFILE(STF_ID, STF_MODEL, STF_FEEDER, STF_FEEDERNO, STF_LOCATION,STF_MACHINE, STF_CODE, STF_INDATE, STF_INMAN)" +
+                    "values(SMTTRACEFILE_SEQ.nextval,:STF_MODEL,:STF_FEEDER,:STF_FEEDERNO,:STF_LOCATION,:STF_MACHINE,'" + stf_code + "',sysdate,'" + User.UserName + "')",
+                    new string[] { "STF_MODEL", "STF_FEEDER", "STF_FEEDERNO", "STF_LOCATION", "STF_MACHINE" }, STF_MODEL.ToArray(), STF_FEEDER.ToArray(), STF_FEEDERNO.ToArray(), STF_LOCATION.ToArray(), STF_MACHINE.ToArray());
+                dh.ExecuteSql("delete from SMTTRACEFILE where ( STF_MODEL is null and  STF_FEEDER is null and STF_FEEDERNO is null and STF_MACHINE is null ) or stf_model in ('料槽','数量','印刷板') or STF_MACHINE in('贴片生产线:','设置:') ", "delete");
                 dataGridView1.DataSource = dt;
+                DataTable dt1 = (DataTable)dh.ExecuteSql("select STF_ID, STF_MODEL,STF_MACHINE, STF_FEEDER, STF_FEEDERNO, STF_LOCATION, STF_CODE, STF_INDATE, STF_INMAN  from SMTTRACEFILE where stf_code='" + stf_code + "' order by stf_id", "select");
+                excel.ExportExcel_LIANGAN(dt1, "C:\\Users\\callm\\Desktop\\客户资料\\"+System.DateTime.Now.ToString("yyyyMMddhhmmss")+".xls");
             }
         }