Special_SmtLocation.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.Special
  13. {
  14. public partial class Special_SmtLocation : Form
  15. {
  16. DataHelper dh;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. DataTable dt = new DataTable();
  19. DataTable dbfind;
  20. ExcelHandler eh;
  21. DataTable dbbom;
  22. public Special_SmtLocation()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Special_BoxSplit_Load(object sender, EventArgs e)
  27. {
  28. eh = new ExcelHandler();
  29. dh = SystemInf.dh;
  30. pr_code.FormName = Name;
  31. pr_code.SetValueField = new string[] { "pr_code" };
  32. pr_code.TableName = "product";
  33. pr_code.SelectField = "pr_code # 物料编号,pr_detail # 物料名称,pr_kind # 物料种类,pr_spec # 物料规格";
  34. pr_code.DbChange += Pr_code_DbChange;
  35. }
  36. private void Pr_code_DbChange(object sender, EventArgs e)
  37. {
  38. dbfind = pr_code.ReturnData;
  39. BaseUtil.SetFormValue(this.Controls, dbfind);
  40. }
  41. private void normalButton2_Click(object sender, EventArgs e)
  42. {
  43. DialogResult result = openFileDialog1.ShowDialog();
  44. if (result == DialogResult.OK)
  45. {
  46. textBox1.Text = openFileDialog1.FileName;
  47. }
  48. }
  49. private void normalButton3_Click(object sender, EventArgs e)
  50. {
  51. if (pr_code.Text == "" || textBox1.Text == "")
  52. {
  53. MessageBox.Show("产品编号与座标图地址不可为空");
  54. return;
  55. }
  56. dt = eh.ImportExcel(textBox1.Text, "test");
  57. DataTable dta = new DataTable();
  58. DataTable dtb = new DataTable();
  59. dta.Columns.Add("序号", typeof(string));
  60. dta.Columns.Add("线别", typeof(string));
  61. dta.Columns.Add("产品编号", typeof(string));
  62. dta.Columns.Add("设备编号", typeof(string));
  63. dta.Columns.Add("站位", typeof(string));
  64. dta.Columns.Add("板面", typeof(string));
  65. dta.Columns.Add("首选料号", typeof(string));
  66. dta.Columns.Add("替代料号", typeof(string));
  67. dta.Columns.Add("单位用量", typeof(int));
  68. dtb.Columns.Add("序号", typeof(string));
  69. dtb.Columns.Add("线别", typeof(string));
  70. dtb.Columns.Add("产品编号", typeof(string));
  71. dtb.Columns.Add("设备编号", typeof(string));
  72. dtb.Columns.Add("站位", typeof(string));
  73. dtb.Columns.Add("板面", typeof(string));
  74. dtb.Columns.Add("首选料号", typeof(string));
  75. dtb.Columns.Add("替代料号", typeof(string));
  76. dtb.Columns.Add("单位用量", typeof(int));
  77. //for (int i = 0; i < dt.Rows.Count; i++)
  78. //{
  79. // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
  80. //}
  81. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  82. dbbom = (DataTable)dh.ExecuteSql("select BD_SONCODE, case when SUBSTR(BD_LOCATION,length(BD_LOCATION)) = ',' then SUBSTR(BD_LOCATION,1,LENGTH(BD_LOCATION)-1) else BD_LOCATION end BD_LOCATION from bomdetail@WP where bd_mothercode = '"+pr_code.Text+"' and bd_location is not null and nvl(bd_usestatus,' ') <>'DISABLE'", "select");
  83. for (int i = 0; i < dbbom.Rows.Count; i++)
  84. {
  85. String[] locationsum = dbbom.Rows[i]["BD_LOCATION"].ToString().Split(',');
  86. int A = 0;
  87. int B = 0;
  88. for (int j = 0; j < locationsum.Length; j++)
  89. {
  90. String location = locationsum[j];
  91. DataRow[] dra = dt.Select("RefDes = '"+location+ "' and Layer = 'Top'");
  92. DataRow[] drb = dt.Select("RefDes = '" + location + "' and Layer = 'Bottom'");
  93. if (dra.Length > 0)
  94. {
  95. A++;
  96. }
  97. if (drb.Length > 0)
  98. {
  99. B++;
  100. }
  101. }
  102. if (A > 0)
  103. {
  104. DataRow dr = dta.NewRow();
  105. dr[2] = pr_code.Text;
  106. dr[5] = "A";
  107. dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  108. dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  109. dr[8] = A;
  110. dta.Rows.Add(dr);
  111. }
  112. if (B > 0)
  113. {
  114. DataRow dr = dtb.NewRow();
  115. dr[2] = pr_code.Text;
  116. dr[5] = "B";
  117. dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  118. dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  119. dr[8] = B;
  120. dtb.Rows.Add(dr);
  121. }
  122. }
  123. String filepath;
  124. DialogResult result = folderBrowserDialog1.ShowDialog();
  125. if (result == DialogResult.OK)
  126. {
  127. filepath = folderBrowserDialog1.SelectedPath;
  128. eh.ExportExcel(dta, filepath,"A");
  129. eh.ExportExcel(dtb, filepath,"B");
  130. MessageBox.Show("OK");
  131. }
  132. }
  133. }
  134. }