ExportExcel.cs 6.6 KB

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