ExportExcel.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. string SqlField = "";
  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. if (CH_BLUEFILM.Checked)
  41. {
  42. SqlField += "CH_BLUEFILM " + CH_BLUEFILM.Text + ",";
  43. }
  44. if (CH_PBCODE.Checked)
  45. {
  46. SqlField += "CH_PBCODE " + CH_PBCODE.Text + ",";
  47. }
  48. if (CH_REMARK.Checked)
  49. {
  50. SqlField += "CH_REMARK " + CH_REMARK.Text + ",";
  51. }
  52. if (CH_SPLITBATCH.Checked)
  53. {
  54. SqlField += "CH_SPLITBATCH " + CH_SPLITBATCH.Text + ",";
  55. }
  56. if (CH_WATERID.Checked)
  57. {
  58. SqlField += "CH_WATERID " + CH_WATERID.Text + ",";
  59. }
  60. if (ch_code.Checked)
  61. {
  62. SqlField += "ch_code " + ch_code.Text + ",";
  63. }
  64. if (percent.Checked)
  65. {
  66. SqlField += "chw_percent1,chw_percent2,chw_itemname1,chw_itemname2,";
  67. }
  68. if (TS.Checked)
  69. {
  70. SqlField += "TS1,TS2,TS3,";
  71. }
  72. if (BVCEO.Checked)
  73. {
  74. SqlField += "BVCEO1,BVCEO2,BVCEO3,";
  75. }
  76. SqlField += "pd_ordercode,pr_spec,";
  77. string SplitType = "";
  78. if (FixRow.Checked)
  79. {
  80. SplitType = FixRow.Name;
  81. }
  82. else if (BatchCode.Checked)
  83. {
  84. SplitType = BatchCode.Name;
  85. }
  86. else if (BoxCode.Checked)
  87. {
  88. SplitType = BoxCode.Name;
  89. }
  90. //分页信息的DataTable
  91. sql.Clear();
  92. sql.Append("select '客户:'||pi_title,'出货单号:'||pi_inoutno,'型号'||pr_spec||' 销售类型:市场部','销售日期:'||pi_date,rownum 序号,io_qty,");
  93. sql.Append("" + SqlField.Substring(0, SqlField.Length - 1) + " from prodinout left join prodiodetail on pi_id=pd_piid left join chip_in_out ");
  94. sql.Append("on pd_id=io_pdid left join chip on ch_code=io_chipcode left join CHIP_WAFERTEST_VIEW on ch_code=chw_chipcode ");
  95. 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");
  96. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  97. //首页信息的DataTable
  98. sql.Clear();
  99. sql.Append("select '客户:'||pi_title 客户,'出货单号:'||pi_inoutno 出货单号,'型号'||pr_spec||' 销售类型:市场部' 型号,");
  100. sql.Append("'销售日期:'||pi_date 销售日期,pd_ordercode,pr_spec,ch_splitbatch,ch_waterid,num,io_qty from FIRSTPAGE_BATCH_VIEW where pi_inoutno='" + inoutno + "'");
  101. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  102. eh.ExportExcel(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), FirstPage_WID.Checked);
  103. }
  104. }
  105. private void ExportExcel_Load(object sender, EventArgs e)
  106. {
  107. }
  108. }
  109. }