BadItem.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 BadItem : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. string _linecode;
  19. string _prodcode;
  20. string _wccode;
  21. string _begindate;
  22. string _enddate;
  23. string _stepcode;
  24. string _makind;
  25. string _macode;
  26. public BadItem(string macode,string linecode, string prodcode, string wccode, string begindate, string enddate, string stepcode,string makind)
  27. {
  28. InitializeComponent();
  29. _macode = macode;
  30. _prodcode = prodcode;
  31. _linecode = linecode;
  32. _wccode = wccode;
  33. _begindate = begindate;
  34. _enddate = enddate;
  35. _stepcode = stepcode;
  36. _makind = makind;
  37. }
  38. private void BadItem_SizeChanged(object sender, EventArgs e)
  39. {
  40. asc.controlAutoSize(this);
  41. }
  42. private void BadItem_Load(object sender, EventArgs e)
  43. {
  44. string condition = " mb_indate between to_date('" + _begindate + "', 'yyyy-mm-dd hh24:mi:ss') and to_date('" + _enddate + "', 'yyyy-mm-dd hh24:mi:ss') ";
  45. if (_prodcode != "")
  46. {
  47. // condition += " and ma_prodcode = '" + _prodcode + "'";
  48. condition += " and ma_prodcode in ('" + _prodcode.Replace("|", "','") + "')";
  49. }
  50. if (_linecode != "")
  51. {
  52. //condition += " and mb_linecode = '" + _linecode + "'";
  53. condition += " and mb_linecode in ('" + _linecode.Replace("|", "','") + "')";
  54. }
  55. if (_macode != "")
  56. {
  57. condition += " and ma_code in ('" + _macode.Replace("|", "','") + "')";
  58. }
  59. if (_wccode != "")
  60. {
  61. condition += " and ma_wccode = '" + _wccode + "'";
  62. }
  63. if (_makind != "")
  64. {
  65. //condition += " and ma_kind = '" + _makind + " '";
  66. condition += " and ma_kind in ('" + _makind.Replace("|", "','") + "')";
  67. }
  68. if (_stepcode != "")
  69. {
  70. condition += " and mb_stepcode = '" + _stepcode + "'";
  71. }
  72. string v_sql = "";
  73. if (_stepcode != "")
  74. {
  75. if (_stepcode == "CT1" || _stepcode == "CT2")
  76. {
  77. LogicHandler.GetQuerySQL(condition, "不良代码CT", out v_sql);
  78. }
  79. else
  80. {
  81. LogicHandler.GetQuerySQL(condition, "不良代码", out v_sql);
  82. }
  83. }else
  84. {
  85. LogicHandler.GetQuerySQL(condition, "不良代码ALL", out v_sql);
  86. }
  87. DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select");
  88. BaseUtil.FillDgvWithDataTable(Data, dt);
  89. }
  90. private void Data_CellContentClick(object sender, DataGridViewCellEventArgs e)
  91. {
  92. try
  93. {
  94. if (Data.Columns[e.ColumnIndex].Name == "times"&& _stepcode != "CT1" && _stepcode != "CT2")
  95. {
  96. Form badsn = new BadSn(_macode,_linecode, _prodcode, _wccode, _begindate, _enddate, _stepcode, _makind, Data.Rows[e.RowIndex].Cells["mb_badname"].Value.ToString());
  97. badsn.Show();
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. MessageBox.Show(ex.Message);
  103. }
  104. }
  105. private void normalButton12_Click(object sender, EventArgs e)
  106. {
  107. //Data表示导出数据
  108. //Templet表示导出模板
  109. folderBrowserDialog12.Description = "选择导出的路径";
  110. DialogResult result = folderBrowserDialog12.ShowDialog();
  111. if (result == DialogResult.OK)
  112. {
  113. string FolderPath = folderBrowserDialog12.SelectedPath;
  114. ExcelHandler eh = new ExcelHandler();
  115. //DataTable dt = (DataTable)Data.DataSource;
  116. //导出Excel的时候返回一个文件名,用户选择是否打开
  117. string filePath = eh.ExportExcel(Data, FolderPath);
  118. //用户选择导出之后是否立即打开
  119. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  120. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString();
  121. if (openFile == "Yes")
  122. {
  123. System.Diagnostics.Process.Start(filePath);
  124. }
  125. }
  126. }
  127. }
  128. }