ExportExcel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.Threading;
  9. using System.Windows.Forms;
  10. using UAS_LabelMachine.Entity;
  11. using UAS_LabelMachine.PublicForm;
  12. using UAS_LabelMachine.PublicMethod;
  13. namespace UAS_LabelMachine
  14. {
  15. public partial class ExportExcel : Form
  16. {
  17. ExcelHandler eh = new ExcelHandler();
  18. DataHelper dh = SystemInf.dh;
  19. string inoutno;
  20. SetLoadingWindow stw;
  21. public ExportExcel(string pi_inoutno)
  22. {
  23. InitializeComponent();
  24. inoutno = pi_inoutno;
  25. }
  26. private void Export_Click(object sender, EventArgs e)
  27. {
  28. ExportFileDialog.Description = "选择导出的路径";
  29. DialogResult result = ExportFileDialog.ShowDialog();
  30. if (result == DialogResult.OK)
  31. {
  32. Thread thread = new Thread(ExportMethod);
  33. stw = new SetLoadingWindow(thread, "正在导出数据");
  34. BaseUtil.SetFormCenter(stw);
  35. stw.ShowDialog();
  36. }
  37. }
  38. private void ExportMethod()
  39. {
  40. string custcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString();
  41. {
  42. StringBuilder sql = new StringBuilder();
  43. List<CheckBox> conditionbox = new List<CheckBox>();
  44. if (!CH_PBCODE.Checked && BoxCode.Checked)
  45. {
  46. MessageBox.Show("勾选盒号分页,打印内容请勾选盒号");
  47. return;
  48. }
  49. //if (!CH_SPLITBATCH.Checked && BatchCode.Checked)
  50. //{
  51. // MessageBox.Show("勾选扩撒批分页,打印内容请勾选扩撒批号");
  52. // return;
  53. //}
  54. if ((!CH_SPLITBATCH.Checked || !CH_PBCODE.Checked) && BoxSplit.Checked)
  55. {
  56. MessageBox.Show("勾选盒号拆批,打印内容请勾选扩撒批号和盒号");
  57. return;
  58. }
  59. conditionbox.Add(CH_BLUEFILM);
  60. conditionbox.Add(CH_PBCODE);
  61. conditionbox.Add(CH_REMARK);
  62. conditionbox.Add(CH_SPLITBATCH);
  63. conditionbox.Add(CH_WATERID);
  64. conditionbox.Add(ch_code);
  65. conditionbox.Add(CH_YIELD);
  66. conditionbox.Add(M_Param1);
  67. conditionbox.Add(H_Param1);
  68. conditionbox.Add(H_Param2);
  69. conditionbox.Add(FirstPage_WID);
  70. conditionbox.Add(FirstPage_YIELD);
  71. conditionbox.Add(FirstPage_REMARK);
  72. string SplitType = "";
  73. if (FixRow.Checked)
  74. {
  75. SplitType = FixRow.Name;
  76. }
  77. else if (BatchCode.Checked)
  78. {
  79. SplitType = BatchCode.Name;
  80. }
  81. else if (BoxCode.Checked)
  82. {
  83. SplitType = BoxCode.Name;
  84. }
  85. else if (BoxSplit.Checked)
  86. {
  87. SplitType = BoxSplit.Name;
  88. }
  89. string caption = "";
  90. if (Chinese.Checked)
  91. {
  92. caption = "es_caption";
  93. dh.ExecuteSql("update prodinout set pi_exporttype='Chinese' where pi_inoutno='" + inoutno + "'", "update");
  94. }
  95. else
  96. {
  97. caption = "es_engcaption es_caption";
  98. dh.ExecuteSql("update prodinout set pi_exporttype='English' where pi_inoutno='" + inoutno + "'", "update");
  99. }
  100. if (Mount.Checked)
  101. {
  102. dh.ExecuteSql("update prodinout set pi_exporttype1='QTY' where pi_inoutno='" + inoutno + "'", "update");
  103. }
  104. else
  105. {
  106. dh.ExecuteSql("update prodinout set pi_exporttype1='Rate' where pi_inoutno='" + inoutno + "'", "update");
  107. }
  108. DataTable SQL1_ = (DataTable)dh.ExecuteSql("select es_filed,es_datatype," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select");
  109. //没有置顶客户的取空的
  110. if (SQL1_.Rows.Count == 0)
  111. {
  112. SQL1_ = (DataTable)dh.ExecuteSql("select es_filed,es_datatype," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode is null order by es_detno", "select");
  113. }
  114. string es_field1 = "";
  115. for (int i = 0; i < SQL1_.Rows.Count; i++)
  116. {
  117. //不是参数的直接拼接
  118. if (SQL1_.Rows[i]["es_datatype"].ToString() != "Param")
  119. es_field1 += SQL1_.Rows[i]["es_filed"].ToString() + ",";
  120. //是参数的则先判断是否含有内容
  121. else if (
  122. (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param1.Text) && M_Param1.Visible == true && M_Param1.Checked) ||
  123. (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param2.Text) && M_Param2.Visible == true && M_Param2.Checked) ||
  124. (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param3.Text) && M_Param3.Visible == true && M_Param3.Checked) ||
  125. (SQL1_.Rows[i]["es_filed"].ToString().Contains(M_Param4.Text) && M_Param4.Visible == true && M_Param4.Checked) ||
  126. (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param1.Text) && H_Param1.Visible == true && H_Param1.Checked) ||
  127. (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param2.Text) && H_Param2.Visible == true && H_Param2.Checked) ||
  128. (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param3.Text) && H_Param3.Visible == true && H_Param3.Checked) ||
  129. (SQL1_.Rows[i]["es_filed"].ToString().Contains(H_Param4.Text) && H_Param4.Visible == true && H_Param4.Checked))
  130. {
  131. es_field1 += SQL1_.Rows[i]["es_filed"].ToString() + ",";
  132. }
  133. }
  134. //生成导出数据
  135. LogicHandler.GenHFEData(inoutno);
  136. //分页信息的DataTable
  137. string datasql = "";
  138. LogicHandler.GetDataSQL(inoutno, es_field1.Substring(0, es_field1.Length - 1), Mount.Checked ? "QTY" : "Rate", out datasql);
  139. DataTable dt = (DataTable)dh.ExecuteSql(datasql, "select");
  140. for (int i = 0; i < dt.Columns.Count; i++)
  141. {
  142. for (int j = 0; j < SQL1_.Rows.Count; j++)
  143. {
  144. if (dt.Columns[i].ColumnName == SQL1_.Rows[j]["es_filed1"].ToString().ToUpper())
  145. {
  146. dt.Columns[i].ColumnName = SQL1_.Rows[j]["es_filed1"].ToString();
  147. dt.Columns[i].Caption = SQL1_.Rows[j]["es_caption"].ToString();
  148. }
  149. }
  150. }
  151. //获取首页需要展示的字段
  152. DataTable SQL_ = (DataTable)dh.ExecuteSql("select es_filed," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select");
  153. if (SQL_.Rows.Count == 0)
  154. {
  155. SQL_ = (DataTable)dh.ExecuteSql("select es_filed," + caption + ",es_filed1 from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode is null order by es_detno", "select");
  156. }
  157. string es_field = "";
  158. for (int i = 0; i < SQL_.Rows.Count; i++)
  159. {
  160. es_field += SQL_.Rows[i]["es_filed"].ToString() + ",";
  161. }
  162. sql.Clear();
  163. //首页信息的DataTable
  164. if (BoxCode.Checked)
  165. {
  166. sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_Box_VIEW where pi_inoutno='" + inoutno + "'");
  167. }
  168. else
  169. {
  170. sql.Append("select " + es_field.Substring(0, es_field.Length - 1) + " from FIRSTPAGE_BATCH_VIEW where pi_inoutno='" + inoutno + "'");
  171. }
  172. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  173. for (int i = 0; i < dt1.Columns.Count; i++)
  174. {
  175. if (dt1.Columns[i].ColumnName == SQL_.Rows[i]["es_filed1"].ToString().ToUpper())
  176. {
  177. dt1.Columns[i].ColumnName = SQL_.Rows[i]["es_filed1"].ToString();
  178. dt1.Columns[i].Caption = SQL_.Rows[i]["es_caption"].ToString();
  179. }
  180. }
  181. string FilePath = "";
  182. string pi_cardcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString();
  183. //晶源客户
  184. if (pi_cardcode == dh.GetConfig("JINGYUAN", "ExportProdExcel").ToString())
  185. {
  186. FilePath = eh.JINYUAN(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox);
  187. }
  188. else if (pi_cardcode == dh.GetConfig("LIPUXIN", "ExportProdExcel").ToString())
  189. {
  190. FilePath = eh.LIPIUXIN(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox);
  191. }
  192. else
  193. {
  194. FilePath = eh.ExportExcel_Normal(dt1, dt, ExportFileDialog.SelectedPath, inoutno, SplitType, int.Parse(RowNum.Text), conditionbox);
  195. }
  196. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  197. if (close.ToString() == "Yes")
  198. System.Diagnostics.Process.Start(FilePath);
  199. Close();
  200. }
  201. }
  202. private void ExportExcel_Load(object sender, EventArgs e)
  203. {
  204. Activate();
  205. LogicHandler.CustInit("0");
  206. StringBuilder sql = new StringBuilder();
  207. sql.Clear();
  208. sql.Append("select distinct replace(cep_name,'(ON)','ON')cep_name,CEP_COLLECTIONTYPE from ProdIODetail left join Product on pd_prodcode = pr_code ");
  209. sql.Append("left join CHIP_EDCPARAMS_SPEC on pr_orispeccode=ced_model left join CHIP_EDCPARAMS_SPECDETAIL on ced_id=cesd_cedid ");
  210. sql.Append("left join CHIP_EDCPARAMS on CESD_CEPID = CEP_ID where pd_inoutno='" + inoutno + "' and ced_status='-1' and CEP_COLLECTIONTYPE='机测'");
  211. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  212. for (int i = 0; i < dt.Rows.Count; i++)
  213. {
  214. if (i <= 4)
  215. {
  216. Controls["M_Param" + (i + 1)].Visible = true;
  217. ((CheckBox)Controls["M_Param" + (i + 1)]).Checked = true;
  218. Controls["M_Param" + (i + 1)].Text = dt.Rows[i]["cep_name"].ToString();
  219. }
  220. }
  221. sql.Clear();
  222. sql.Append("select distinct replace(cep_name,'(ON)','ON')cep_name,CEP_COLLECTIONTYPE from ProdIODetail left join Product on pd_prodcode = pr_code ");
  223. sql.Append("left join CHIP_EDCPARAMS_SPEC on pr_orispeccode=ced_model left join CHIP_EDCPARAMS_SPECDETAIL on ced_id=cesd_cedid ");
  224. sql.Append("left join CHIP_EDCPARAMS on CESD_CEPID = CEP_ID where pd_inoutno='" + inoutno + "' and ced_status='-1' and CEP_COLLECTIONTYPE='手测'");
  225. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  226. for (int i = 0; i < dt.Rows.Count; i++)
  227. {
  228. if (i <= 4)
  229. {
  230. Controls["H_Param" + (i + 1)].Visible = true;
  231. ((CheckBox)Controls["H_Param" + (i + 1)]).Checked = true;
  232. Controls["H_Param" + (i + 1)].Text = dt.Rows[i]["cep_name"].ToString();
  233. }
  234. }
  235. }
  236. private void ExportSetting_Click(object sender, EventArgs e)
  237. {
  238. ExportColumns ex = new ExportColumns(inoutno);
  239. ex.WindowState = FormWindowState.Maximized;
  240. ex.ShowDialog();
  241. }
  242. private void groupBox1_Paint(object sender, PaintEventArgs e)
  243. {
  244. e.Graphics.Clear(this.BackColor);
  245. }
  246. private void BatchCode_CheckedChanged(object sender, EventArgs e)
  247. {
  248. RadioButton box = (RadioButton)sender;
  249. if (box.Checked)
  250. {
  251. switch (box.Name)
  252. {
  253. case "BatchCode":
  254. CH_SPLITBATCH.Checked = true;
  255. break;
  256. case "BoxCode":
  257. CH_PBCODE.Checked = true;
  258. break;
  259. case "FixRow":
  260. break;
  261. case "BoxSplit":
  262. CH_SPLITBATCH.Checked = true;
  263. CH_PBCODE.Checked = true;
  264. break;
  265. default:
  266. break;
  267. }
  268. }
  269. }
  270. }
  271. }