Special_SmtLocation.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.Text.RegularExpressions;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Special
  14. {
  15. public partial class Special_SmtLocation : Form
  16. {
  17. DataHelper dh;
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt = new DataTable();
  20. DataTable dbfind;
  21. ExcelHandler eh;
  22. DataTable dbbom;
  23. public Special_SmtLocation()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Special_BoxSplit_Load(object sender, EventArgs e)
  28. {
  29. eh = new ExcelHandler();
  30. dh = SystemInf.dh;
  31. pr_code.FormName = Name;
  32. pr_code.SetValueField = new string[] { "pr_code" };
  33. pr_code.TableName = "product";
  34. pr_code.SelectField = "pr_code # 物料编号,pr_detail # 物料名称,pr_kind # 物料种类,pr_spec # 物料规格";
  35. pr_code.Condition = "PR_MANUTYPE = 'MAKE'";
  36. pr_code.DbChange += Pr_code_DbChange;
  37. }
  38. private void Pr_code_DbChange(object sender, EventArgs e)
  39. {
  40. dbfind = pr_code.ReturnData;
  41. BaseUtil.SetFormValue(this.Controls, dbfind);
  42. }
  43. private void normalButton2_Click(object sender, EventArgs e)
  44. {
  45. DialogResult result = openFileDialog1.ShowDialog();
  46. if (result == DialogResult.OK)
  47. {
  48. textBox1.Text = openFileDialog1.FileName;
  49. }
  50. }
  51. private void normalButton3_Click(object sender, EventArgs e)
  52. {
  53. if (pr_code.Text == "" || textBox1.Text == "")
  54. {
  55. MessageBox.Show("产品编号与座标图地址不可为空");
  56. return;
  57. }
  58. dt = eh.ImportExcel(textBox1.Text, "test");
  59. DataTable dta = new DataTable();
  60. DataTable dtb = new DataTable();
  61. DataTable dtc = new DataTable();
  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(string));
  68. dta.Columns.Add("首选料号", typeof(string));
  69. dta.Columns.Add("替代料号", typeof(string));
  70. dta.Columns.Add("单位用量", typeof(int));
  71. dta.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(string));
  77. dtb.Columns.Add("板面", typeof(string));
  78. dtb.Columns.Add("首选料号", typeof(string));
  79. dtb.Columns.Add("替代料号", typeof(string));
  80. dtb.Columns.Add("单位用量", typeof(int));
  81. dtb.Columns.Add("规格", typeof(string));
  82. dtc.Columns.Add("序号", typeof(string));
  83. dtc.Columns.Add("线别", typeof(string));
  84. dtc.Columns.Add("产品编号", typeof(string));
  85. dtc.Columns.Add("设备编号", typeof(string));
  86. dtc.Columns.Add("站位", typeof(string));
  87. dtc.Columns.Add("板面", typeof(string));
  88. dtc.Columns.Add("首选料号", typeof(string));
  89. dtc.Columns.Add("替代料号", typeof(string));
  90. dtc.Columns.Add("单位用量", typeof(int));
  91. dtc.Columns.Add("规格", typeof(string));
  92. //for (int i = 0; i < dt.Rows.Count; i++)
  93. //{
  94. // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
  95. //}
  96. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  97. dbbom = (DataTable)dh.ExecuteSql("select BD_SONCODE, replace(case when SUBSTR(bd_remark2,length(bd_remark2)) = ',' then SUBSTR(bd_remark2,1,LENGTH(bd_remark2)-1) else bd_remark2 end,' ','') BD_LOCATION,replace(pr_spec,',','-') pr_spec from bomdetail@ERP LEFT JOIN Product ON bd_soncode=pr_code where (bd_mothercode = '" + pr_code.Text + "' or bd_mothercode in(select BD_SONCODE from BOMDetail LEFT JOIN Product ON bd_soncode=pr_code where bd_mothercode = '"+ pr_code.Text + "' and pr_detail = 'SMT贴片部件' ) ) and bd_remark2 is not null and nvl(bd_usestatus,' ') <>'DISABLE' ", "select");
  98. for (int i = 0; i < dbbom.Rows.Count; i++)
  99. {
  100. String[] locationsum = dbbom.Rows[i]["BD_LOCATION"].ToString().Replace(" ","").Replace(",",",").Split(',');
  101. int A = 0;
  102. int B = 0;
  103. int C = 0;
  104. for (int j = 0; j < locationsum.Length; j++)
  105. {
  106. String location = locationsum[j];
  107. if (location.Contains('-'))
  108. {
  109. String[] arrheng = ConvertToCollection(location).ToArray();
  110. for (int s = 0; s < arrheng.Length; s++)
  111. {
  112. String location2 = arrheng[s];
  113. DataRow[] dra = dt.Select("RefDes = '" + location2 + "' and Layer = 'A'");
  114. DataRow[] drb = dt.Select("RefDes = '" + location2 + "' and Layer = 'B'");
  115. DataRow[] drc = dt.Select("RefDes = '" + location2 + "' and Layer = 'C'");
  116. if (dra.Length > 0)
  117. {
  118. A++;
  119. }
  120. if (drb.Length > 0)
  121. {
  122. B++;
  123. }
  124. if (drc.Length > 0)
  125. {
  126. C++;
  127. }
  128. }
  129. }
  130. else
  131. {
  132. DataRow[] dra = dt.Select("RefDes = '" + location + "' and Layer = 'A'");
  133. DataRow[] drb = dt.Select("RefDes = '" + location + "' and Layer = 'B'");
  134. DataRow[] drc = dt.Select("RefDes = '" + location + "' and Layer = 'C'");
  135. if (dra.Length > 0)
  136. {
  137. A++;
  138. }
  139. if (drb.Length > 0)
  140. {
  141. B++;
  142. }
  143. if (drc.Length > 0)
  144. {
  145. C++;
  146. }
  147. }
  148. }
  149. if (A > 0)
  150. {
  151. DataRow dr = dta.NewRow();
  152. dr[2] = pr_code.Text;
  153. dr[5] = "A";
  154. dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  155. dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  156. dr[8] = A;
  157. dr[9] = dbbom.Rows[i]["pr_spec"].ToString();
  158. dta.Rows.Add(dr);
  159. }
  160. if (B > 0)
  161. {
  162. DataRow dr = dtb.NewRow();
  163. dr[2] = pr_code.Text;
  164. dr[5] = "B";
  165. dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  166. dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  167. dr[8] = B;
  168. dr[9] = dbbom.Rows[i]["pr_spec"].ToString();
  169. dtb.Rows.Add(dr);
  170. }
  171. if (C > 0)
  172. {
  173. DataRow dr = dtc.NewRow();
  174. dr[2] = pr_code.Text;
  175. dr[5] = "C";
  176. dr[6] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  177. dr[7] = dbbom.Rows[i]["BD_SONCODE"].ToString();
  178. dr[8] = C;
  179. dr[9] = dbbom.Rows[i]["pr_spec"].ToString();
  180. dtc.Rows.Add(dr);
  181. }
  182. }
  183. String filepath;
  184. DialogResult result = folderBrowserDialog1.ShowDialog();
  185. if (result == DialogResult.OK)
  186. {
  187. filepath = folderBrowserDialog1.SelectedPath;
  188. if (dta.Rows.Count > 0)
  189. {
  190. eh.ExportExcel(dta, filepath, "A");
  191. }
  192. if (dtb.Rows.Count > 0)
  193. {
  194. eh.ExportExcel(dtb, filepath, "B");
  195. }
  196. if (dtc.Rows.Count > 0)
  197. {
  198. eh.ExportExcel(dtc, filepath, "C");
  199. }
  200. MessageBox.Show("OK");
  201. }
  202. }
  203. public static List<string> ConvertToCollection(string input)
  204. {
  205. var matches = Regex.Matches(input, @"^[A-Z]{1,3}\d{1,3}-[A-Z]{1,3}\d{1,3}");
  206. var collection = new List<string>();
  207. foreach (Match match in matches)
  208. {
  209. var range = match.Value.Split('-');
  210. var start = range[0];
  211. var end = range[1];
  212. var prefix = Regex.Matches(start, @"^[A-Z]{1,3}")[0].Value;
  213. var startNumber = int.Parse(Regex.Matches(start, @"\d{1,3}")[0].Value);
  214. var endNumber = int.Parse(Regex.Matches(end, @"\d{1,3}")[0].Value);
  215. for (int i = startNumber; i <= endNumber; i++)
  216. {
  217. var item = $"{prefix}{i}";
  218. collection.Add(item);
  219. }
  220. }
  221. return collection;
  222. }
  223. }
  224. }