Make_SMTBind.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. using System.Drawing;
  10. using System.Text.RegularExpressions;
  11. using System.Collections.Generic;
  12. using System.Threading;
  13. using UAS_MES_NEW.PublicForm;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_SMTBind : Form
  17. {
  18. string ErrorMessage = "";
  19. List<string> TSN = new List<string>();
  20. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  21. DataHelper dh;
  22. LogStringBuilder sql = new LogStringBuilder();
  23. DataTable DBFind;
  24. //保存ListB中的数据
  25. DataTable dt1;
  26. DataTable dt = new DataTable();
  27. DataTable dbfind;
  28. ExcelHandler eh;
  29. Thread thread;
  30. AutoSizeFormClass asc = new AutoSizeFormClass();
  31. List<string> CollectData = new List<string>();
  32. List<string> CollectDataSonCode = new List<string>();
  33. List<string> SPID = new List<string>();
  34. public Make_SMTBind()
  35. {
  36. InitializeComponent();
  37. }
  38. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  39. {
  40. asc.controllInitializeSize(this);
  41. LockMakeCode.GetMakeCodeCtl(ma_code);
  42. ma_code.SetLockCheckBox(LockMakeCode);
  43. //工单号放大镜配置
  44. eh = new ExcelHandler();
  45. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  46. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号,pr_pcbacount # 拼版数";
  47. ma_code.FormName = Name;
  48. ma_code.DBTitle = "工单查询";
  49. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode", "pr_pcbacount" };
  50. ma_code.Condition = "ma_statuscode='STARTED'";
  51. ma_code.DbChange += Ma_code_DBChange;
  52. code.GotFocus+= text_getfocus;
  53. code.Focus();
  54. dh = SystemInf.dh;
  55. StepCount.StepCode = User.CurrentStepCode;
  56. StepCount.Source = User.UserSourceCode;
  57. StepCount.LineCode = User.UserLineCode;
  58. StepCount.Dh = dh;
  59. StepCount.Start();
  60. }
  61. private void text_getfocus(object sender, EventArgs e)
  62. {
  63. code.ImeMode = ImeMode.Close;
  64. }
  65. private void Ma_code_DBChange(object sender, EventArgs e)
  66. {
  67. DBFind = ma_code.ReturnData;
  68. BaseUtil.SetFormValue(this.Controls, DBFind);
  69. }
  70. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  71. {
  72. asc.controlAutoSize(this);
  73. }
  74. private void Clean_Click(object sender, EventArgs e)
  75. {
  76. OperateResult.Clear();
  77. }
  78. private void Confirm_Click(object sender, EventArgs e)
  79. {
  80. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  81. code_KeyDown(sender, e2);
  82. }
  83. private void code_KeyDown(object sender, KeyEventArgs e)
  84. {
  85. if (e.KeyCode == Keys.Enter)
  86. {
  87. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  88. {
  89. if (Loading.Checked)
  90. {
  91. if (code.Text.Replace(" ", "") == ""||pr_pcbacount.Value == 0 || pr_pcbacount.Value == 1)
  92. {
  93. OperateResult.AppendText(">>采集数据与拼版数不可为空\n", Color.Red);
  94. return;
  95. }
  96. else
  97. {
  98. if (sn_code.Text == "")
  99. {
  100. if (ma_code.Text != "" && !LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
  101. {
  102. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  103. return;
  104. }
  105. int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
  106. int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
  107. if (nowqty+ pr_pcbacount.Value > maqty)
  108. {
  109. OperateResult.AppendText(">>已绑定数"+ nowqty + "+拼版数"+ pr_pcbacount.Value + "大于工单数"+ maqty + "不允许操作\n", Color.Red);
  110. return;
  111. }
  112. sql.Clear();
  113. sql.Append("select rownum,sb_maincode,sb_makecode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  114. sql.Append("where sb_barcode='" + code.Text + "')");
  115. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  116. if (dt1.Rows.Count > 0)
  117. {
  118. string sb_makecode = dt1.Rows[0]["sb_makecode"].ToString();
  119. if (ma_code.Text != "" && ma_code.Text != sb_makecode)
  120. {
  121. OperateResult.AppendText(">>条码已绑定至工单" + sb_makecode + "\n", Color.Red, code);
  122. return;
  123. }
  124. ma_code.Text = dt1.Rows[0]["sb_makecode"].ToString();
  125. LockMakeCode.Checked = true;
  126. ma_code_UserControlTextChanged(sender, e);
  127. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  128. if (dt1.Rows.Count < pr_pcbacount.Value)
  129. {
  130. sn_code.Text = dt1.Rows[0]["sb_maincode"].ToString();
  131. }
  132. code.Text = "";
  133. }
  134. else
  135. {
  136. if (ma_code.Text == "")
  137. {
  138. OperateResult.AppendText(">>请先选择工单号\n", Color.Red, code);
  139. return;
  140. }
  141. if (!LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
  142. {
  143. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  144. return;
  145. }
  146. sn_code.Text = code.Text;
  147. sql.Clear();
  148. sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  149. sql.Append("values(smtbind_seq.nextval,'" + sn_code.Text + "','" + code.Text + "','" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  150. sql.Append("'" + User.UserCode + "',sysdate,0)");
  151. dh.ExecuteSql(sql.GetString(), "insert");
  152. RefreshData();
  153. sql.Clear();
  154. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  155. sql.Append("where sb_barcode='" + code.Text + "')");
  156. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  157. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  158. code.Text = "";
  159. }
  160. }
  161. else
  162. {
  163. if (ma_code.Text == "")
  164. {
  165. OperateResult.AppendText(">>请先选择工单号\n", Color.Red, code);
  166. return;
  167. }
  168. if (!LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
  169. {
  170. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  171. return;
  172. }
  173. if (dh.CheckExist("smtbind", "sb_barcode='" + code.Text + "'"))
  174. {
  175. OperateResult.AppendText(">>条码" + code.Text + "已绑定\n", Color.Red, code);
  176. return;
  177. }
  178. sql.Clear();
  179. sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  180. sql.Append("values(smtbind_seq.nextval,'" + sn_code.Text + "','" + code.Text + "','" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  181. sql.Append("'" + User.UserCode + "',sysdate,0)");
  182. dh.ExecuteSql(sql.GetString(), "insert");
  183. RefreshData();
  184. sql.Clear();
  185. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  186. sql.Append("where sb_barcode='" + code.Text + "')");
  187. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  188. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  189. if (LabelDataGridView.Rows.Count == pr_pcbacount.Value)
  190. {
  191. sn_code.Text = "";
  192. }
  193. code.Text = "";
  194. }
  195. }
  196. }
  197. //勾选了下料的时候
  198. else if (UnLoading.Checked)
  199. {
  200. sql.Clear();
  201. sql.Append("select rownum,sb_maincode,sb_makecode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  202. sql.Append("where sb_barcode='" + code.Text + "')");
  203. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  204. if (dt1.Rows.Count > 0)
  205. {
  206. string sb_makecode = dt1.Rows[0]["sb_makecode"].ToString();
  207. if (ma_code.Text != "" && ma_code.Text != sb_makecode)
  208. {
  209. OperateResult.AppendText(">>条码已绑定至工单" + sb_makecode + "\n", Color.Red, code);
  210. return;
  211. }
  212. ma_code.Text = dt1.Rows[0]["sb_makecode"].ToString();
  213. LockMakeCode.Checked = true;
  214. ma_code_UserControlTextChanged(sender, e);
  215. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  216. string sb_maincode = dt1.Rows[0]["sb_maincode"].ToString();
  217. //如果采集的是主条码则拆分所有的条码
  218. if (sb_maincode == code.Text)
  219. {
  220. string closetab_confirm = MessageBox.Show(this.ParentForm, "确认拆解所有条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  221. if (closetab_confirm == "Yes")
  222. {
  223. dh.ExecuteSql("delete from smtbind where sb_maincode='" + code.Text + "'", "delete");
  224. }
  225. }
  226. else
  227. {
  228. dh.ExecuteSql("delete from smtbind where sb_barcode='" + code.Text + "'", "delete");
  229. }
  230. sql.Clear();
  231. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode='" + sb_maincode + "'");
  232. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  233. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  234. sn_code.Text = "";
  235. code.Text = "";
  236. RefreshData();
  237. }
  238. }
  239. }
  240. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  241. }
  242. }
  243. private void ClearSn_code_Click(object sender, EventArgs e)
  244. {
  245. sn_code.Clear();
  246. SPID.Clear();
  247. TSN.Clear();
  248. CheckBarcode.Clear();
  249. CollectData.Clear();
  250. CollectDataSonCode.Clear();
  251. if (dt1 != null)
  252. BaseUtil.CleanDataTableData(dt1);
  253. BaseUtil.CleanDGVData(LabelDataGridView);
  254. OperateResult.AppendText(">>请采集序列号\n", Color.Black);
  255. }
  256. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  257. {
  258. if (ma_code.Text.Length > 5)
  259. {
  260. string ErrMessage = "";
  261. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  262. {
  263. mcd_inqty.Text = "";
  264. mcd_remainqty.Text = "";
  265. sql.Clear();
  266. sql.Append("select ma_qty,ma_prodcode,pr_detail,pr_pcbacount ");
  267. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join product on ma_prodcode=pr_code where ");
  268. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  269. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  270. if (dt.Rows.Count > 0)
  271. BaseUtil.SetFormValue(Controls, dt);
  272. RefreshData();
  273. sql.Clear();
  274. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_makecode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  275. sql.Append("where sb_barcode='" + code.Text + "')");
  276. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  277. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  278. }
  279. }
  280. }
  281. /// <summary>
  282. /// 刷新采集数据
  283. /// </summary>
  284. private void RefreshData()
  285. {
  286. sql.Clear();
  287. sql.Append("select count(1) mcd_inqty,max(ma_qty)-count(1) mcd_remainqty from smtbind left join make on ma_code= sb_makecode where sb_makecode='" + ma_code.Text + "' ");
  288. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  289. if (dt.Rows.Count > 0)
  290. BaseUtil.SetFormValue(Controls, dt);
  291. }
  292. string mincode;
  293. int sncount;
  294. int startsn;
  295. string firstsn;
  296. string lastsn;
  297. private void Crbut_Click(object sender, EventArgs e)
  298. {
  299. if(ma_code.Text==""|| Prefix.Text == "" || Num.Text == "" || Rn.Text == "" || pr_pcbacount.Value == 0 || Rnle.Value == 0)
  300. {
  301. OperateResult.AppendText(">>有关信息未录入或拼版数,流水长度未维护\n", Color.Red);
  302. return;
  303. }
  304. try
  305. {
  306. sncount = int.Parse(Num.Text);
  307. int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
  308. int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
  309. if (nowqty + sncount > maqty)
  310. {
  311. OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + sncount + "大于工单数" + maqty + "不允许操作\n", Color.Red);
  312. return;
  313. }
  314. if (DSCIN.Checked)
  315. {
  316. startsn = int.Parse(Rn.Text);
  317. }
  318. else {
  319. startsn = int.Parse(Hex2Ten(Rn.Text));
  320. }
  321. if (sncount % pr_pcbacount.Value != 0)
  322. {
  323. OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
  324. return;
  325. }
  326. if (DSCIN.Checked)
  327. {
  328. if ((startsn + (sncount - 1)*(sqit.Value)).ToString().Length > Rnle.Value)
  329. {
  330. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  331. return;
  332. }
  333. }
  334. else {
  335. if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()).Length > Rnle.Value)
  336. {
  337. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  338. return;
  339. }
  340. }
  341. if (DSCIN.Checked)
  342. {
  343. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
  344. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
  345. }
  346. else {
  347. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
  348. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()));
  349. }
  350. if (dh.CheckExist("SMTBIND", "sb_barcode between '"+ firstsn + "' and '"+ lastsn + "' "))
  351. {
  352. OperateResult.AppendText(">>SN导入重复\n", Color.Red);
  353. return;
  354. }
  355. thread = new Thread(NewPrint);
  356. SetLoadingWindow stw = new SetLoadingWindow(thread, "请稍候...");
  357. BaseUtil.SetFormCenter(stw);
  358. stw.ShowDialog();
  359. }
  360. catch (Exception ex)
  361. {
  362. OperateResult.AppendText(">>"+ex.Message+"\n", Color.Red);
  363. }
  364. }
  365. private void NewPrint()
  366. {
  367. List<string> maincodelist = new List<string>();
  368. List<string> nowcodelist = new List<string>();
  369. if (DSCIN.Checked)
  370. {
  371. for (int i = 0; i < sncount; i++)
  372. {
  373. string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + i*(sqit.Value)).ToString());
  374. if (i % pr_pcbacount.Value == 0)
  375. mincode = nowsn;
  376. maincodelist.Add(mincode);
  377. nowcodelist.Add(nowsn);
  378. }
  379. }
  380. else {
  381. for (int i = 0; i < sncount; i++)
  382. {
  383. string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + i * (sqit.Value )).ToString()));
  384. if (i % pr_pcbacount.Value == 0)
  385. mincode = nowsn;
  386. maincodelist.Add(mincode);
  387. nowcodelist.Add(nowsn);
  388. }
  389. }
  390. sql.Clear();
  391. sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  392. sql.Append("values(smtbind_seq.nextval,:maincode,:nowcode,'" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  393. sql.Append("'" + User.UserCode + "',sysdate,0)");
  394. dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
  395. MessageBox.Show("导入成功!");
  396. OperateResult.AppendText(">>生成完毕\n", Color.Black);
  397. OperateResult.AppendText(">>起始号:" + firstsn + "\n", Color.Black);
  398. OperateResult.AppendText(">>截止号:" + lastsn + "\n", Color.Black);
  399. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "SMT拼版绑定", firstsn+"到"+lastsn+"绑定成功,数量"+ sncount+",间隔"+ sqit.Value, "","");
  400. }
  401. private static string lpad(int length, string number)
  402. {
  403. while (number.Length < length)
  404. {
  405. number = "0" + number;
  406. }
  407. number = number.Substring(number.Length - length, length);
  408. return number;
  409. }
  410. private void Debut_Click(object sender, EventArgs e)
  411. {
  412. //if (!(ma_code.Text == ""))
  413. //{
  414. // string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除此工单拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  415. // if (logout_confirm == "Yes")
  416. // {
  417. // dh.ExecuteSql("delete SMTBIND where sb_makecode ='"+ma_code.Text+"'", "delete");
  418. // OperateResult.AppendText(">>工单"+ma_code.Text+ "拼版绑定记录清除成功\n", Color.Green);
  419. // }
  420. //}
  421. //else {
  422. // OperateResult.AppendText(">>工单号不能为空\n", Color.Red);
  423. //}
  424. try
  425. {
  426. sncount = int.Parse(Num.Text);
  427. if (DSCIN.Checked)
  428. {
  429. startsn = int.Parse(Rn.Text);
  430. }
  431. else
  432. {
  433. startsn = int.Parse(Hex2Ten(Rn.Text));
  434. }
  435. if (sncount % pr_pcbacount.Value != 0)
  436. {
  437. OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
  438. return;
  439. }
  440. if (DSCIN.Checked)
  441. {
  442. if ((startsn + (sncount - 1) * (sqit.Value)).ToString().Length > Rnle.Value)
  443. {
  444. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  445. return;
  446. }
  447. }
  448. else
  449. {
  450. if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()).Length > Rnle.Value)
  451. {
  452. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  453. return;
  454. }
  455. }
  456. if (DSCIN.Checked)
  457. {
  458. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
  459. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
  460. }
  461. else
  462. {
  463. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
  464. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()));
  465. }
  466. string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除SN: "+ firstsn + " 到 "+ lastsn + " 拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  467. if (logout_confirm == "Yes")
  468. {
  469. dh.ExecuteSql("delete SMTBIND where sb_barcode between '" + firstsn + "' and '" + lastsn + "'", "delete");
  470. OperateResult.AppendText(">>SN: " + firstsn + " 到 " + lastsn + " 拼版绑定记录清除成功\n", Color.Green);
  471. }
  472. }
  473. catch (Exception ex)
  474. {
  475. OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red);
  476. }
  477. }
  478. /// <summary>
  479. /// 从十进制转换到十六进制
  480. /// </summary>
  481. /// <param name="ten"></param>
  482. /// <returns></returns>
  483. public static string ConvertNumToHex(string ten)
  484. {
  485. ulong Numb = Convert.ToUInt64(ten);
  486. ulong divValue, resValue;
  487. string hex = "";
  488. do
  489. {
  490. divValue = (ulong)Math.Floor((decimal)(Numb / 16));
  491. resValue = Numb % 16;
  492. hex = GetNumb(resValue) + hex;
  493. Numb = divValue;
  494. }
  495. while (Numb >= 16);
  496. if (Numb != 0)
  497. hex = GetNumb(Numb) + hex;
  498. return hex;
  499. }
  500. public static string GetNumb(ulong Numb)
  501. {
  502. switch (Numb)
  503. {
  504. case 0:
  505. case 1:
  506. case 2:
  507. case 3:
  508. case 4:
  509. case 5:
  510. case 6:
  511. case 7:
  512. case 8:
  513. case 9:
  514. return Numb.ToString();
  515. case 10:
  516. return "A";
  517. case 11:
  518. return "B";
  519. case 12:
  520. return "C";
  521. case 13:
  522. return "D";
  523. case 14:
  524. return "E";
  525. case 15:
  526. return "F";
  527. default:
  528. return "";
  529. }
  530. }
  531. public static string Hex2Ten(string hex)
  532. {
  533. int ten = 0;
  534. for (int i = 0, j = hex.Length - 1; i < hex.Length; i++)
  535. {
  536. ten += HexChar2Value(hex.Substring(i, 1)) * ((int)Math.Pow(16, j));
  537. j--;
  538. }
  539. return ten.ToString();
  540. }
  541. public static int HexChar2Value(string hexChar)
  542. {
  543. switch (hexChar)
  544. {
  545. case "0":
  546. case "1":
  547. case "2":
  548. case "3":
  549. case "4":
  550. case "5":
  551. case "6":
  552. case "7":
  553. case "8":
  554. case "9":
  555. return Convert.ToInt32(hexChar);
  556. case "a":
  557. case "A":
  558. return 10;
  559. case "b":
  560. case "B":
  561. return 11;
  562. case "c":
  563. case "C":
  564. return 12;
  565. case "d":
  566. case "D":
  567. return 13;
  568. case "e":
  569. case "E":
  570. return 14;
  571. case "f":
  572. case "F":
  573. return 15;
  574. default:
  575. return 0;
  576. }
  577. }
  578. private void normalButton2_Click(object sender, EventArgs e)
  579. {
  580. DialogResult result = openFileDialog1.ShowDialog();
  581. if (result == DialogResult.OK)
  582. {
  583. textBox1.Text = openFileDialog1.FileName;
  584. }
  585. }
  586. private void normalButton3_Click(object sender, EventArgs e)
  587. {
  588. if (ma_code.Text == "" || textBox1.Text == "" || ma_prodcode.Text == "")
  589. {
  590. MessageBox.Show("工单号,产品编号与文件地址不可为空");
  591. return;
  592. }
  593. dt = eh.ImportExcel(textBox1.Text, "test");
  594. int number = 0;
  595. //for (int i = 0; i < dt.Rows.Count; i++)
  596. //{
  597. // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
  598. //}
  599. //BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  600. List<string> maincodelist = new List<string>();
  601. List<string> nowcodelist = new List<string>();
  602. for (int i = 0; i < dt.Rows.Count; i++)
  603. {
  604. if (dt.Rows[i]["工单"].ToString().Trim()==ma_code.Text&&dt.Rows[i]["拼板号"].ToString().Trim().Length >2 && dt.Rows[i]["读码内容"].ToString().Trim().Length > 2 && dt.Rows[i]["拼板号"].ToString().Trim().Substring(0, 2)
  605. == dt.Rows[i]["读码内容"].ToString().Trim().Substring(0, 2))
  606. {
  607. maincodelist.Add(dt.Rows[i]["拼板号"].ToString().Trim());
  608. nowcodelist.Add(dt.Rows[i]["读码内容"].ToString().Trim());
  609. //number++;
  610. }
  611. }
  612. sql.Clear();
  613. sql.Append("insert into smtbind_temp(MAINCODE,BARCODE)");
  614. sql.Append("values(:maincode,:nowcode)");
  615. dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
  616. number = int.Parse(dh.getFieldDataByCondition("smtbind_temp", "count(1) cn ", "BARCODE not in (select sb_barcode from smtbind )").ToString());
  617. int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
  618. int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
  619. if (nowqty + number > maqty)
  620. {
  621. OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + number + "大于工单数" + maqty + "不允许操作\n", Color.Red);
  622. dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
  623. return;
  624. }
  625. sql.Clear();
  626. sql.Append("merge into smtbind using SMTBIND_TEMP on (sb_barcode = barcode) when not MATCHED then insert (sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  627. sql.Append(" values (SMTBIND_seq.nextval ,maincode,barcode,'" + ma_code.Text + "','"+ma_prodcode.Text+"','"+User.UserCode+"',sysdate,0)");
  628. dh.ExecuteSql(sql.GetString(), "insert");
  629. dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
  630. MessageBox.Show("导入成功"+ number + "条!");
  631. OperateResult.AppendText(">>导入成功" + number + "条!\n", Color.Green);
  632. }
  633. }
  634. }