Query_DateRate.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_orispeccode # 型号,wc_code # 工作中心";
  50. ma_code.FormName = Name;
  51. ma_code.SetValueField = new string[] { "ma_code" };
  52. ma_code.Condition = "";
  53. ma_code.DbChange += pr_code_DbChange;
  54. ma_kind.TableName = " MAKIND_VIEW ";
  55. ma_kind.SelectField = "ma_kind # 工单类型";
  56. ma_kind.FormName = Name;
  57. ma_kind.SetValueField = new string[] { "ma_kind" };
  58. ma_kind.Condition = "";
  59. ma_kind.DbChange += pr_code_DbChange;
  60. //BeginDate.Value = new DateTime(now.year, Now.Month, now.day);
  61. }
  62. private void Export_Click(object sender, EventArgs e)
  63. {
  64. if (wc_code.Text == "")
  65. {
  66. MessageBox.Show("请输入车间");
  67. return;
  68. }
  69. if (EndDate.Value < BeginDate.Value)
  70. {
  71. MessageBox.Show("结束日期不能小于起始日期");
  72. }
  73. condition = "";
  74. 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') ";
  75. if (wc_code.Text != "")
  76. {
  77. condition += " and sp_wccode = '" + wc_code.Text + "'";
  78. }
  79. if (pr_code.Text != "")
  80. {
  81. // condition += " and sp_prodcode = '" + pr_code.Text + "'";
  82. condition += " and sp_prodcode in ('" + pr_code.Text.Replace("|", "','") + "')";
  83. }
  84. if (ma_code.Text != "")
  85. {
  86. // condition += " and sp_makecode = '" + ma_code.Text + "'";
  87. condition += " and sp_makecode in ('" + ma_code.Text.Replace("|", "','") + "')";
  88. }
  89. if (li_code.Text != "")
  90. {
  91. // condition += " and sp_linecode = '" + li_code.Text + "'";
  92. condition += " and sp_linecode in ('" + li_code.Text.Replace("|", "','") + "')";
  93. }
  94. if (ma_kind.Text != "")
  95. {
  96. condition += " and ma_kind in ('" + ma_kind.Text.Replace("|", "','") + "')";
  97. }
  98. string v_sql = "";
  99. //string v_sql1 = "";
  100. LogicHandler.GetQuerySQL(condition, "直通率", out v_sql);
  101. DataTable dt = (DataTable)dh.ExecuteSql(v_sql, "select");
  102. double agsum = 0;
  103. double bdsum = 0;
  104. double fisum = 0;
  105. double rate = 1;
  106. for (int i = 0; i < dt.Rows.Count; i++)
  107. {
  108. agsum = agsum + double.Parse(dt.Rows[i]["AGOKQTY"].ToString());
  109. bdsum = bdsum + double.Parse(dt.Rows[i]["NGQTY"].ToString());
  110. fisum = fisum + double.Parse(dt.Rows[i]["FIQTY"].ToString());
  111. if (dt.Rows[i]["ST_IFCALC"].ToString() == "-1")
  112. {
  113. rate = rate * (double.Parse(dt.Rows[i]["OKRATE"].ToString()) / 100);
  114. }
  115. }
  116. rate = rate * 100;
  117. DataRow dr = dt.NewRow();
  118. dr[3] = "ALL";
  119. dr[7] = agsum;
  120. dr[8] = bdsum;
  121. dr[9] = fisum;
  122. dr[10] = String.Format("{0:F}", rate);
  123. dt.Rows.InsertAt(dr, dt.Rows.Count);
  124. BaseUtil.FillDgvWithDataTable(Data, dt);
  125. }
  126. private void pr_code_DbChange(object sender, EventArgs e)
  127. {
  128. //Dbfind = pr_code.ReturnData;
  129. //BaseUtil.SetFormValue(this.Controls, Dbfind);
  130. }
  131. private void Data_CellContentClick(object sender, DataGridViewCellEventArgs e)
  132. {
  133. try
  134. {
  135. if (Data.Columns[e.ColumnIndex].Name == "SNQTY")
  136. {
  137. Form baditem = new BadItem(ma_code.Text,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);
  138. baditem.Show();
  139. }
  140. }
  141. catch (Exception ex)
  142. {
  143. MessageBox.Show(ex.Message);
  144. }
  145. }
  146. private void Query_DateRate_SizeChanged(object sender, EventArgs e)
  147. {
  148. asc.controlAutoSize(this);
  149. }
  150. private void normalButton1_Click(object sender, EventArgs e)
  151. {
  152. //Data表示导出数据
  153. //Templet表示导出模板
  154. folderBrowserDialog1.Description = "选择导出的路径";
  155. DialogResult result = folderBrowserDialog1.ShowDialog();
  156. if (result == DialogResult.OK)
  157. {
  158. string FolderPath = folderBrowserDialog1.SelectedPath;
  159. ExcelHandler eh = new ExcelHandler();
  160. //DataTable dt = (DataTable)Data.DataSource;
  161. //导出Excel的时候返回一个文件名,用户选择是否打开
  162. string filePath = eh.ExportExcel(Data, FolderPath);
  163. //用户选择导出之后是否立即打开
  164. MessageBoxButtons messButton = MessageBoxButtons.YesNo;
  165. string openFile = MessageBox.Show(this.ParentForm, "是否打开文件" + filePath, "提示", messButton).ToString();
  166. if (openFile == "Yes")
  167. {
  168. System.Diagnostics.Process.Start(filePath);
  169. }
  170. }
  171. }
  172. }
  173. }