Browse Source

修改Excel导出

callm 4 years ago
parent
commit
182c64229d

+ 8 - 8
UAS_MES_ODLF/DataOperate/ExcelHandler.cs

@@ -44,7 +44,7 @@ namespace UAS_MES_NEW.DataOperate
             MemoryStream ms;
             ms = DataTableToExcel_BAIDU(dt, begindate, DateNum);
             //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
-            string filePath = @FolderPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
+            string filePath = @FolderPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + "各工序直通率.xls";
             FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
             byte[] data = ms.ToArray();
             fs.Write(data, 0, data.Length);
@@ -509,8 +509,8 @@ namespace UAS_MES_NEW.DataOperate
 
             for (int i = 0; i < DateNum; i++)
             {
-                double TotalFPY = 0;
-                double TotalRPY = 0;
+                double TotalFPY = -1;
+                double TotalRPY = -1;
                 double TotalNG = 0;
                 double TotalIN = 0;
                 for (int j = 0; j < StepCode.Length; j++)
@@ -575,7 +575,7 @@ namespace UAS_MES_NEW.DataOperate
                                         {
                                             cell.SetCellValue(FPY);
                                             //累计所有FPY
-                                            if (TotalFPY == 0)
+                                            if (TotalFPY == -1)
                                             {
                                                 TotalFPY = FPY;
                                             }
@@ -595,7 +595,7 @@ namespace UAS_MES_NEW.DataOperate
                                         {
                                             cell.SetCellValue(RPY);
                                             //累计所有RPY
-                                            if (TotalRPY == 0)
+                                            if (TotalRPY == -1)
                                             {
                                                 TotalRPY = RPY;
                                             }
@@ -659,7 +659,7 @@ namespace UAS_MES_NEW.DataOperate
                                         {
                                             cell.SetCellValue(FPY);
                                             //累计所有FPY
-                                            if (TotalFPY == 0)
+                                            if (TotalFPY == -1)
                                             {
                                                 TotalFPY = FPY;
                                             }
@@ -692,12 +692,12 @@ namespace UAS_MES_NEW.DataOperate
                 row = sheet.GetRow(4);
                 cell = row.CreateCell(i + 2);
                 cell.CellStyle = LIGHT_GREEN;
-                cell.SetCellValue(TotalFPY);
+                cell.SetCellValue(TotalFPY==-1?0: TotalFPY);
 
                 row = sheet.GetRow(5);
                 cell = row.CreateCell(i + 2);
                 cell.CellStyle = LIGHT_CORNFLOWER_BLUE;
-                cell.SetCellValue(TotalRPY);
+                cell.SetCellValue(TotalRPY==-1?0: TotalRPY);
             }
             for (int i = 0; i < sheet.PhysicalNumberOfRows; i++)
             {

+ 4 - 1
UAS_MES_ODLF/FunctionCode/Query/Query_DateRate.cs

@@ -48,7 +48,10 @@ namespace UAS_MES_NEW.Query
                 ExcelHandler eh = new ExcelHandler();
                 string begindate = BeginDate.Value.ToString("yyyy-mm-dd");
                 string enddate = EndDate.Value.ToString("yyyy-mm-dd");
-                eh.ExportExcel_BAIDU(dt, BeginDate.Value, (EndDate.Value - BeginDate.Value).Days+1, FolderPath);
+                string path = eh.ExportExcel_BAIDU(dt, BeginDate.Value, (EndDate.Value - BeginDate.Value).Days + 1, FolderPath);
+                string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                if (close.ToString() == "Yes")
+                    System.Diagnostics.Process.Start(path);
             }
         }