Query_DateRate.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Query
  13. {
  14. public partial class Query_DateRate : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. DataTable Dbfind;
  18. ExcelHandler eh = new ExcelHandler();
  19. public Query_DateRate()
  20. {
  21. InitializeComponent();
  22. }
  23. private void Export_Click(object sender, EventArgs e)
  24. {
  25. if (pr_code.Text == "")
  26. {
  27. MessageBox.Show("请输入产品代码");
  28. return;
  29. }
  30. if (EndDate.Value < BeginDate.Value)
  31. {
  32. MessageBox.Show("结束日期不能小于起始日期");
  33. }
  34. ExcelExport("");
  35. }
  36. //选择导出Excel时是选择导出数据的还是模板
  37. private void ExcelExport(string DataOrTemplet)
  38. {
  39. folderBrowserDialog1.Description = "选择导出的路径";
  40. DialogResult result = folderBrowserDialog1.ShowDialog();
  41. if (result == DialogResult.OK)
  42. {
  43. string v_sql = "";
  44. string v_sql1 = "";
  45. string condition = "sp_date between to_date('" + BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') and to_date('" + EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') ";
  46. if (pr_code.Text != "")
  47. {
  48. condition += " and sp_prodcode = '" + pr_code.Text + "'";
  49. }
  50. if (ma_code.Text != "")
  51. {
  52. condition += " and sp_makecode = '" + ma_code.Text + "'";
  53. }
  54. if (li_code.Text != "")
  55. {
  56. condition += " and sp_linecode = '" + li_code.Text + "'";
  57. }
  58. LogicHandler.GetQuerySql(condition, out v_sql, out v_sql1);
  59. DataTable dt = (DataTable)dh.ExecuteSql(v_sql + v_sql1, "select");
  60. string FolderPath = folderBrowserDialog1.SelectedPath;
  61. string begindate = BeginDate.Value.ToString("yyyy-mm-dd");
  62. string enddate = EndDate.Value.ToString("yyyy-mm-dd");
  63. string path = eh.ExportExcel_BAIDU(dt, BeginDate.Value, (EndDate.Value - BeginDate.Value).Days + 1, FolderPath);
  64. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  65. if (close.ToString() == "Yes")
  66. System.Diagnostics.Process.Start(path);
  67. }
  68. }
  69. private void Query_SpecialReport_Load(object sender, EventArgs e)
  70. {
  71. //工单号放大镜配置
  72. pr_code.TableName = " product ";
  73. pr_code.SelectField = "pr_code # 产品编号,pr_detail # 产品名称,pr_spec # 型号";
  74. pr_code.FormName = Name;
  75. pr_code.SetValueField = new string[] { "pr_code" };
  76. pr_code.Condition = "pr_statuscode='AUDITED'";
  77. pr_code.DbChange += pr_code_DbChange;
  78. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  79. ma_code.SelectField = "ma_code # 工单编号,ma_prodcode # 产品编号,pr_spec # 型号";
  80. ma_code.FormName = Name;
  81. ma_code.SetValueField = new string[] { "ma_code" };
  82. ma_code.Condition = "ma_statuscode='STARTED'";
  83. ma_code.DbChange += pr_code_DbChange;
  84. li_code.TableName = " line ";
  85. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  86. li_code.FormName = Name;
  87. li_code.SetValueField = new string[] { "li_code" };
  88. li_code.Condition = "li_code is not null";
  89. li_code.DbChange += pr_code_DbChange;
  90. }
  91. private void pr_code_DbChange(object sender, EventArgs e)
  92. {
  93. Dbfind = pr_code.ReturnData;
  94. BaseUtil.SetFormValue(this.Controls, Dbfind);
  95. }
  96. private void Miss_Test_Click(object sender, EventArgs e)
  97. {
  98. folderBrowserDialog1.Description = "选择导出的路径";
  99. DialogResult result = folderBrowserDialog1.ShowDialog();
  100. if (result == DialogResult.OK)
  101. {
  102. string v_sql = "";
  103. string v_sql1 = "";
  104. string condition = "sp_date between to_date('" + BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') and to_date('" + EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 'yyyy-mm-dd hh24:mi:ss') ";
  105. if (pr_code.Text != "")
  106. {
  107. condition += " and sp_prodcode = '" + pr_code.Text + "'";
  108. }
  109. if (ma_code.Text != "")
  110. {
  111. condition += " and sp_makecode = '" + ma_code.Text + "'";
  112. }
  113. if (li_code.Text != "")
  114. {
  115. condition += " and sp_linecode = '" + li_code.Text + "'";
  116. }
  117. LogicHandler.GetMissItemQuerySql(condition, out v_sql, out v_sql1);
  118. DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select");
  119. LogicHandler.GetMissFiveQuerySql(condition, out v_sql, out v_sql1);
  120. DataTable dt1 = (DataTable)dh.ExecuteSql(v_sql, "select");
  121. LogicHandler.GetBadFiveQuerySql(condition, out v_sql, out v_sql1);
  122. DataTable dt2 = (DataTable)dh.ExecuteSql(v_sql, "select");
  123. string FolderPath = folderBrowserDialog1.SelectedPath;
  124. Console.WriteLine(dt.Rows.Count);
  125. Console.WriteLine(dt1.Rows.Count);
  126. Console.WriteLine(dt2.Rows.Count);
  127. string path = eh.ExportExcel(new DataTable[] { dt, dt1, dt2 }, FolderPath);
  128. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  129. if (close.ToString() == "Yes")
  130. System.Diagnostics.Process.Start(path);
  131. }
  132. }
  133. }
  134. }