ExportExcel.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_LabelMachine.Entity;
  10. namespace UAS_LabelMachine
  11. {
  12. public partial class ExportExcel : Form
  13. {
  14. ExcelHandler eh = new ExcelHandler();
  15. DataHelper dh = SystemInf.dh;
  16. string inoutno;
  17. public ExportExcel(string pi_inoutno)
  18. {
  19. InitializeComponent();
  20. inoutno = pi_inoutno;
  21. }
  22. private void Export_Click(object sender, EventArgs e)
  23. {
  24. ExportFileDialog.Description = "选择导出的路径";
  25. DialogResult result = ExportFileDialog.ShowDialog();
  26. if (result == DialogResult.OK)
  27. {
  28. StringBuilder sql = new StringBuilder();
  29. List<CheckBox> conditionbox = new List<CheckBox>();
  30. if (!CH_PBCODE.Checked && BoxCode.Checked)
  31. {
  32. MessageBox.Show("勾选盒号分页,打印内容请勾选盒号");
  33. return;
  34. }
  35. if (!CH_SPLITBATCH.Checked && BatchCode.Checked)
  36. {
  37. MessageBox.Show("勾选扩撒批分页,打印内容请勾选扩撒批号");
  38. return;
  39. }
  40. conditionbox.Add(CH_BLUEFILM);
  41. conditionbox.Add(CH_PBCODE);
  42. conditionbox.Add(CH_REMARK);
  43. conditionbox.Add(CH_SPLITBATCH);
  44. conditionbox.Add(CH_WATERID);
  45. conditionbox.Add(ch_code);
  46. conditionbox.Add(percent);
  47. conditionbox.Add(TS);
  48. conditionbox.Add(BVCEO);
  49. conditionbox.Add(FirstPage_WID);
  50. conditionbox.Add(FirstPage_YIELD);
  51. conditionbox.Add(FirstPage_REMARK);
  52. string SplitType = "";
  53. if (FixRow.Checked)
  54. {
  55. SplitType = FixRow.Name;
  56. }
  57. else if (BatchCode.Checked)
  58. {
  59. SplitType = BatchCode.Name;
  60. }
  61. else if (BoxCode.Checked)
  62. {
  63. SplitType = BoxCode.Name;
  64. }
  65. DataTable SQL1_ = (DataTable)dh.ExecuteSql("select es_filed,es_caption,es_prefix,es_suffix,es_filed1 from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 order by es_detno", "select");
  66. string es_field1 = "";
  67. for (int i = 0; i < SQL1_.Rows.Count; i++)
  68. {
  69. es_field1 += SQL1_.Rows[i]["es_prefix"].ToString() + "||" + SQL1_.Rows[i]["es_filed"].ToString() + "||" + SQL1_.Rows[i]["es_suffix"].ToString() + ",";
  70. }
  71. //分页信息的DataTable
  72. sql.Clear();
  73. sql.Append("select " + es_field1.Substring(0, es_field1.Length - 1)+ " from prodinout left join prodiodetail on pi_id=pd_piid left join ");
  74. sql.Append("chip_in_out on pd_id=io_pdid left join chip on ch_code=io_chipcode left join CHIP_WAFERTEST_VIEW on ch_code=chw_chipcode ");
  75. sql.Append("left join CHIP_EDCDATA_VIEW on che_chipcode=ch_code left join product on pr_code=pd_prodcode where pi_inoutno='" + inoutno + "' order by io_detno");
  76. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  77. for (int i = 0; i < dt.Columns.Count; i++)
  78. {
  79. if (dt.Columns[i].ColumnName == (SQL1_.Rows[i]["es_prefix"].ToString() + "||" + SQL1_.Rows[i]["es_filed"].ToString() + "||" + SQL1_.Rows[i]["es_suffix"].ToString()).ToUpper())
  80. {
  81. dt.Columns[i].ColumnName = SQL1_.Rows[i]["es_filed1"].ToString();
  82. dt.Columns[i].Caption = SQL1_.Rows[i]["es_caption"].ToString();
  83. }
  84. }
  85. //获取首页需要展示的字段
  86. DataTable SQL_ = (DataTable)dh.ExecuteSql("select es_filed,es_caption,es_prefix,es_suffix,es_filed1 from CS_EXPORTSETTING where es_type='First' and es_enable=-1 order by es_detno", "select");
  87. string es_field = "";
  88. for (int i = 0; i < SQL_.Rows.Count; i++)
  89. {
  90. es_field += SQL_.Rows[i]["es_prefix"].ToString() + "||" + SQL_.Rows[i]["es_filed"].ToString() + "||" + SQL_.Rows[i]["es_suffix"].ToString() + ",";
  91. }
  92. //首页信息的DataTable
  93. sql.Clear();
  94. sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_BATCH_VIEW where pi_inoutno='" + inoutno + "'");
  95. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  96. for (int i = 0; i < dt1.Columns.Count; i++)
  97. {
  98. if (dt1.Columns[i].ColumnName == (SQL_.Rows[i]["es_prefix"].ToString() + "||" + SQL_.Rows[i]["es_filed"].ToString() + "||" + SQL_.Rows[i]["es_suffix"].ToString()).ToUpper())
  99. {
  100. dt1.Columns[i].ColumnName = SQL_.Rows[i]["es_filed1"].ToString();
  101. dt1.Columns[i].Caption = SQL_.Rows[i]["es_caption"].ToString();
  102. }
  103. }
  104. eh.ExportExcel(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox);
  105. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  106. if (close.ToString() == "Yes")
  107. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + inoutno + ".xls");
  108. Close();
  109. }
  110. }
  111. private void ExportExcel_Load(object sender, EventArgs e)
  112. {
  113. }
  114. }
  115. }