瀏覽代碼

导出主料

callm 1 年之前
父節點
當前提交
0eacacc9c9
共有 1 個文件被更改,包括 30 次插入19 次删除
  1. 30 19
      UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.cs

+ 30 - 19
UAS_MES_LGDZ/FunctionCode/Query/Query_SpecialReport.cs

@@ -1,5 +1,6 @@
 using DevExpress.Printing.Core.PdfExport.Metafile;
 using DevExpress.XtraCharts.Native;
+using ExcelHelper;
 using LabelManager2;
 using NPOI.HSSF.UserModel;
 using NPOI.SS.Formula.Functions;
@@ -74,37 +75,47 @@ namespace UAS_MES_NEW.Query
                 }
             }
         }
-
+        ExcelHandler excel = new ExcelHandler();
         private void ExportData()
         {
-            Stream fs = new FileStream(ExportFileDialog.SelectedPath + @"\" + pr_code.Text + ".txt", FileMode.CreateNew, FileAccess.ReadWrite);
-            fs.Dispose();
-            List<string> list = new List<string>();
-            for (int i = 0; i < importdata.Rows.Count; i++)
+            try
             {
-                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");
-                if (bom.Rows.Count > 0)
+                string time = System.DateTime.Now.ToString("yyyyMMddhhmmss");
+                Stream fs = new FileStream(ExportFileDialog.SelectedPath + @"\" + time + pr_code.Text + ".txt", FileMode.CreateNew, FileAccess.ReadWrite);
+                fs.Dispose();
+                List<string> list = new List<string>();
+                for (int i = 0; i < importdata.Rows.Count; i++)
                 {
-                    if (bom.Rows[0][0].ToString() != "")
+                    string Refer = importdata.Rows[i]["Refer"].ToString();
+                    DataTable bom = (DataTable)dh.ExecuteSql("select bd_soncode,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 group by bd_soncode", "select");
+                    if (bom.Rows.Count > 0)
                     {
-                        if (!list.Contains(bom.Rows[0][0].ToString()))
+                        if (bom.Rows[0][1].ToString() != "")
                         {
-                            list.Add(bom.Rows[0][0].ToString());
+                            if (!list.Contains(bom.Rows[0][1].ToString()))
+                            {
+                                list.Add(bom.Rows[0][1].ToString());
+                            }
                         }
+                        importdata.Rows[i][1] = bom.Rows[0][0].ToString();
                     }
+                    Process.Text = (i + 1) + "/" + importdata.Rows.Count;
                 }
-                Process.Text = (i + 1) + "/" + importdata.Rows.Count;
+                excel.ExportExcel(importdata, ExportFileDialog.SelectedPath + @"\" + time + pr_code.Text + ".xls");
+                StreamWriter sw = File.AppendText(ExportFileDialog.SelectedPath + @"\" + time + pr_code.Text + ".txt");
+                for (int i = 0; i < list.Count; i++)
+                {
+                    Console.WriteLine(list[i]);
+                    sw.WriteLine(list[i]);
+                }
+                sw.Close();
             }
-            StreamWriter sw = File.AppendText(ExportFileDialog.SelectedPath + @"\" + pr_code.Text + ".txt");
-            for (int i = 0; i < list.Count; i++)
+            catch (Exception ex)
             {
-                Console.WriteLine(list[i]);
-                sw.WriteLine(list[i]);
+                MessageBox.Show(ex.Message);
             }
-            sw.Close();
         }