Query_DateRate.cs 5.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_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. LogicHandler.GetQuerySql(condition, out v_sql, out v_sql1);
  55. DataTable dt = (DataTable)dh.ExecuteSql(v_sql + v_sql1, "select");
  56. string FolderPath = folderBrowserDialog1.SelectedPath;
  57. string begindate = BeginDate.Value.ToString("yyyy-mm-dd");
  58. string enddate = EndDate.Value.ToString("yyyy-mm-dd");
  59. string path = eh.ExportExcel_BAIDU(dt, BeginDate.Value, (EndDate.Value - BeginDate.Value).Days + 1, FolderPath);
  60. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  61. if (close.ToString() == "Yes")
  62. System.Diagnostics.Process.Start(path);
  63. }
  64. }
  65. private void Query_SpecialReport_Load(object sender, EventArgs e)
  66. {
  67. //工单号放大镜配置
  68. pr_code.TableName = " product ";
  69. pr_code.SelectField = "pr_code # 产品编号,pr_detail # 产品名称,pr_spec # 型号";
  70. pr_code.FormName = Name;
  71. pr_code.SetValueField = new string[] { "pr_code" };
  72. pr_code.Condition = "pr_statuscode='AUDITED'";
  73. pr_code.DbChange += pr_code_DbChange;
  74. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  75. ma_code.SelectField = "ma_code # 工单编号,ma_prodcode # 产品编号,pr_spec # 型号";
  76. ma_code.FormName = Name;
  77. ma_code.SetValueField = new string[] { "ma_code" };
  78. ma_code.Condition = "ma_statuscode='STARTED'";
  79. ma_code.DbChange += pr_code_DbChange;
  80. }
  81. private void pr_code_DbChange(object sender, EventArgs e)
  82. {
  83. Dbfind = pr_code.ReturnData;
  84. BaseUtil.SetFormValue(this.Controls, Dbfind);
  85. }
  86. private void Miss_Test_Click(object sender, EventArgs e)
  87. {
  88. folderBrowserDialog1.Description = "选择导出的路径";
  89. DialogResult result = folderBrowserDialog1.ShowDialog();
  90. if (result == DialogResult.OK)
  91. {
  92. string v_sql = "";
  93. string v_sql1 = "";
  94. 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') ";
  95. if (pr_code.Text != "")
  96. {
  97. condition += " and sp_prodcode = '" + pr_code.Text + "'";
  98. }
  99. if (ma_code.Text != "")
  100. {
  101. condition += " and sp_makecode = '" + ma_code.Text + "'";
  102. }
  103. LogicHandler.GetMissItemQuerySql(condition, out v_sql, out v_sql1);
  104. DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select");
  105. LogicHandler.GetMissFiveQuerySql(condition, out v_sql, out v_sql1);
  106. DataTable dt1 = (DataTable)dh.ExecuteSql(v_sql, "select");
  107. LogicHandler.GetBadFiveQuerySql(condition, out v_sql, out v_sql1);
  108. DataTable dt2 = (DataTable)dh.ExecuteSql(v_sql, "select");
  109. string FolderPath = folderBrowserDialog1.SelectedPath;
  110. Console.WriteLine(dt.Rows.Count);
  111. Console.WriteLine(dt1.Rows.Count);
  112. Console.WriteLine(dt2.Rows.Count);
  113. string path = eh.ExportExcel(new DataTable[] { dt, dt1, dt2 }, FolderPath);
  114. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  115. if (close.ToString() == "Yes")
  116. System.Diagnostics.Process.Start(path);
  117. }
  118. }
  119. }
  120. }