Query_DateRate.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. AutoSizeFormClass asc = new AutoSizeFormClass();
  17. string querysql = "";
  18. string condition;
  19. DataHelper dh = SystemInf.dh;
  20. DataTable Dbfind;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. public Query_DateRate()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Query_SpecialReport_Load(object sender, EventArgs e)
  27. {
  28. asc.controllInitializeSize(this);
  29. //工单号放大镜配置
  30. pr_code.TableName = " product ";
  31. pr_code.SelectField = "pr_code # 产品编号,pr_detail # 产品名称,pr_orispeccode # 型号";
  32. pr_code.FormName = Name;
  33. pr_code.SetValueField = new string[] { "pr_code" };
  34. pr_code.Condition = "pr_statuscode='AUDITED'";
  35. pr_code.DbChange += pr_code_DbChange;
  36. wc_code.TableName = " workcenter ";
  37. wc_code.SelectField = "wc_code # 车间编号,wc_name # 车间名称";
  38. wc_code.FormName = Name;
  39. wc_code.SetValueField = new string[] { "wc_code" };
  40. wc_code.Condition = "wc_statuscode='AUDITED'";
  41. wc_code.DbChange += pr_code_DbChange;
  42. li_code.TableName = " line ";
  43. li_code.SelectField = "li_code # 车间编号,li_name # 车间名称";
  44. li_code.FormName = Name;
  45. li_code.SetValueField = new string[] { "li_code" };
  46. li_code.Condition = "li_statuscode='AUDITED'";
  47. li_code.DbChange += pr_code_DbChange;
  48. ma_code.TableName = " make left join product on ma_prodcode=pr_code left join workcenter on ma_wccode = wc_code";
  49. ma_code.SelectField = "ma_code # 工单编号,ma_prodcode # 产品编号,pr_spec # 型号,wc_code # 工作中心";
  50. ma_code.FormName = Name;
  51. ma_code.SetValueField = new string[] { "ma_code", "wc_code" };
  52. ma_code.Condition = "ma_statuscode='STARTED'";
  53. ma_code.DbChange += pr_code_DbChange;
  54. //如果ms_makecode的值修改过再去查询
  55. sql.Clear();
  56. sql.Append("select distinct ma_kind from make");
  57. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  58. ma_kind.DisplayMember = "ma_kind";
  59. ma_kind.ValueMember = "ma_kind";
  60. ma_kind.DataSource = dt;
  61. ma_kind.Text = "";
  62. //BeginDate.Value = new DateTime(now.year, Now.Month, now.day);
  63. }
  64. private void Export_Click(object sender, EventArgs e)
  65. {
  66. if (wc_code.Text == "")
  67. {
  68. MessageBox.Show("请输入车间");
  69. return;
  70. }
  71. if (EndDate.Value < BeginDate.Value)
  72. {
  73. MessageBox.Show("结束日期不能小于起始日期");
  74. }
  75. condition = "";
  76. 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') ";
  77. if (wc_code.Text != "")
  78. {
  79. condition += " and sp_wccode = '" + wc_code.Text + "'";
  80. }
  81. if (pr_code.Text != "")
  82. {
  83. condition += " and sp_prodcode = '" + pr_code.Text + "'";
  84. }
  85. if (ma_code.Text != "")
  86. {
  87. condition += " and sp_makecode = '" + ma_code.Text + "'";
  88. }
  89. if (li_code.Text != "")
  90. {
  91. condition += " and sp_linecode = '" + li_code.Text + "'";
  92. }
  93. if (ma_kind.Text != "")
  94. {
  95. condition += " and ma_kind = '" + ma_kind.Text + "'";
  96. }
  97. string v_sql = "";
  98. //string v_sql1 = "";
  99. LogicHandler.GetQuerySQL(condition, "直通率", out v_sql);
  100. DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select");
  101. double agsum = 0;
  102. double bdsum = 0;
  103. double fisum = 0;
  104. double rate = 1;
  105. for (int i = 0; i < dt.Rows.Count; i++)
  106. {
  107. agsum = agsum + double.Parse(dt.Rows[i]["AGOKQTY"].ToString());
  108. bdsum = bdsum + double.Parse(dt.Rows[i]["NGQTY"].ToString());
  109. fisum = fisum + double.Parse(dt.Rows[i]["FIQTY"].ToString());
  110. if (dt.Rows[i]["ST_IFCALC"].ToString() == "-1")
  111. {
  112. rate = rate * (double.Parse(dt.Rows[i]["OKRATE"].ToString()) / 100);
  113. }
  114. }
  115. rate = rate * 100;
  116. DataRow dr = dt.NewRow();
  117. dr[3] = "ALL";
  118. dr[7] = agsum;
  119. dr[8] = bdsum;
  120. dr[9] = fisum;
  121. dr[10] = String.Format("{0:F}", rate);
  122. dt.Rows.InsertAt(dr, dt.Rows.Count);
  123. BaseUtil.FillDgvWithDataTable(Data, dt);
  124. }
  125. private void pr_code_DbChange(object sender, EventArgs e)
  126. {
  127. Dbfind = pr_code.ReturnData;
  128. BaseUtil.SetFormValue(this.Controls, Dbfind);
  129. }
  130. private void Data_CellContentClick(object sender, DataGridViewCellEventArgs e)
  131. {
  132. try
  133. {
  134. if (Data.Columns[e.ColumnIndex].Name == "SNQTY")
  135. {
  136. Form baditem = new BadItem(li_code.Text, pr_code.Text, wc_code.Text, BeginDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), Data.Rows[e.RowIndex].Cells["sp_stepcode"].Value.ToString(),ma_kind.Text);
  137. baditem.Show();
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. MessageBox.Show(ex.Message);
  143. }
  144. }
  145. private void Query_DateRate_SizeChanged(object sender, EventArgs e)
  146. {
  147. asc.controlAutoSize(this);
  148. }
  149. private void normalButton1_Click(object sender, EventArgs e)
  150. {
  151. //Data表示导出数据
  152. //Templet表示导出模板
  153. folderBrowserDialog1.Description = "选择导出的路径";
  154. DialogResult result = folderBrowserDialog1.ShowDialog();
  155. if (result == DialogResult.OK)
  156. {
  157. string FolderPath = folderBrowserDialog1.SelectedPath;
  158. ExcelHandler eh = new ExcelHandler();
  159. DataTable dt = (DataTable)Data.DataSource;
  160. //导出Excel的时候返回一个文件名,用户选择是否打开
  161. string filePath = eh.ExportExcel(dt, FolderPath);
  162. //用户选择导出之后是否立即打开
  163. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  164. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString();
  165. if (openFile == "Yes")
  166. {
  167. System.Diagnostics.Process.Start(filePath);
  168. }
  169. }
  170. }
  171. }
  172. }