ExportExcel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. string custcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString();
  27. if (result == DialogResult.OK)
  28. {
  29. StringBuilder sql = new StringBuilder();
  30. List<CheckBox> conditionbox = new List<CheckBox>();
  31. if (!CH_PBCODE.Checked && BoxCode.Checked)
  32. {
  33. MessageBox.Show("勾选盒号分页,打印内容请勾选盒号");
  34. return;
  35. }
  36. if (!CH_SPLITBATCH.Checked && BatchCode.Checked)
  37. {
  38. MessageBox.Show("勾选扩撒批分页,打印内容请勾选扩撒批号");
  39. return;
  40. }
  41. conditionbox.Add(CH_BLUEFILM);
  42. conditionbox.Add(CH_PBCODE);
  43. conditionbox.Add(CH_REMARK);
  44. conditionbox.Add(CH_SPLITBATCH);
  45. conditionbox.Add(CH_WATERID);
  46. conditionbox.Add(ch_code);
  47. conditionbox.Add(percent);
  48. conditionbox.Add(TS);
  49. conditionbox.Add(BVCEO);
  50. conditionbox.Add(FirstPage_WID);
  51. conditionbox.Add(FirstPage_YIELD);
  52. conditionbox.Add(FirstPage_REMARK);
  53. string SplitType = "";
  54. if (FixRow.Checked)
  55. {
  56. SplitType = FixRow.Name;
  57. }
  58. else if (BatchCode.Checked)
  59. {
  60. SplitType = BatchCode.Name;
  61. }
  62. else if (BoxCode.Checked)
  63. {
  64. SplitType = BoxCode.Name;
  65. }
  66. 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 and es_custcode='" + custcode + "' order by es_detno", "select");
  67. //没有置顶客户的取空的
  68. if (SQL1_.Rows.Count == 0)
  69. {
  70. 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 and es_custcode is null order by es_detno", "select");
  71. }
  72. string es_field1 = "";
  73. for (int i = 0; i < SQL1_.Rows.Count; i++)
  74. {
  75. es_field1 += SQL1_.Rows[i]["es_prefix"].ToString() + "||" + SQL1_.Rows[i]["es_filed"].ToString() + "||" + SQL1_.Rows[i]["es_suffix"].ToString() + ",";
  76. }
  77. //分页信息的DataTable
  78. sql.Clear();
  79. sql.Append("select " + es_field1.Substring(0, es_field1.Length - 1) + " from prodinout left join prodiodetail on pi_id=pd_piid left join ");
  80. 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 ");
  81. 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");
  82. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  83. for (int i = 0; i < dt.Columns.Count; i++)
  84. {
  85. if (dt.Columns[i].ColumnName == (SQL1_.Rows[i]["es_prefix"].ToString() + "||" + SQL1_.Rows[i]["es_filed"].ToString() + "||" + SQL1_.Rows[i]["es_suffix"].ToString()).ToUpper())
  86. {
  87. dt.Columns[i].ColumnName = SQL1_.Rows[i]["es_filed1"].ToString();
  88. dt.Columns[i].Caption = SQL1_.Rows[i]["es_caption"].ToString();
  89. }
  90. }
  91. //获取首页需要展示的字段
  92. 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 and es_custcode='" + custcode + "' order by es_detno", "select");
  93. if (SQL_.Rows.Count == 0)
  94. {
  95. 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 and es_custcode is null order by es_detno", "select");
  96. }
  97. string es_field = "";
  98. for (int i = 0; i < SQL_.Rows.Count; i++)
  99. {
  100. es_field += SQL_.Rows[i]["es_prefix"].ToString() + "||" + SQL_.Rows[i]["es_filed"].ToString() + "||" + SQL_.Rows[i]["es_suffix"].ToString() + ",";
  101. }
  102. //首页信息的DataTable
  103. sql.Clear();
  104. sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_BATCH_VIEW where pi_inoutno='" + inoutno + "'");
  105. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  106. for (int i = 0; i < dt1.Columns.Count; i++)
  107. {
  108. if (dt1.Columns[i].ColumnName == (SQL_.Rows[i]["es_prefix"].ToString() + "||" + SQL_.Rows[i]["es_filed"].ToString() + "||" + SQL_.Rows[i]["es_suffix"].ToString()).ToUpper())
  109. {
  110. dt1.Columns[i].ColumnName = SQL_.Rows[i]["es_filed1"].ToString();
  111. dt1.Columns[i].Caption = SQL_.Rows[i]["es_caption"].ToString();
  112. }
  113. }
  114. eh.ExportExcel(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox);
  115. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  116. if (close.ToString() == "Yes")
  117. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + inoutno + ".xls");
  118. Close();
  119. }
  120. }
  121. private void ExportExcel_Load(object sender, EventArgs e)
  122. {
  123. }
  124. }
  125. }