Make_SMTBind.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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 )
  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. if (LabelDataGridView.Rows.Count == pr_pcbacount.Value)
  159. {
  160. OperateResult.AppendText(">>拼版主码" + sn_code.Text + "绑定完成\n", Color.Green);
  161. sn_code.Text = "";
  162. }
  163. code.Text = "";
  164. }
  165. }
  166. else
  167. {
  168. if (ma_code.Text == "")
  169. {
  170. OperateResult.AppendText(">>请先选择工单号\n", Color.Red, code);
  171. return;
  172. }
  173. if (!LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
  174. {
  175. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  176. return;
  177. }
  178. if (dh.CheckExist("smtbind", "sb_barcode='" + code.Text + "'"))
  179. {
  180. OperateResult.AppendText(">>条码" + code.Text + "已绑定\n", Color.Red, code);
  181. return;
  182. }
  183. sql.Clear();
  184. sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  185. sql.Append("values(smtbind_seq.nextval,'" + sn_code.Text + "','" + code.Text + "','" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  186. sql.Append("'" + User.UserCode + "',sysdate,0)");
  187. dh.ExecuteSql(sql.GetString(), "insert");
  188. RefreshData();
  189. sql.Clear();
  190. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  191. sql.Append("where sb_barcode='" + code.Text + "')");
  192. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  193. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  194. if (LabelDataGridView.Rows.Count == pr_pcbacount.Value)
  195. {
  196. OperateResult.AppendText(">>拼版主码" + sn_code.Text + "绑定完成\n", Color.Green);
  197. sn_code.Text = "";
  198. }
  199. code.Text = "";
  200. }
  201. }
  202. }
  203. //勾选了下料的时候
  204. else if (UnLoading.Checked)
  205. {
  206. sql.Clear();
  207. sql.Append("select rownum,sb_maincode,sb_makecode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  208. sql.Append("where sb_barcode='" + code.Text + "')");
  209. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  210. if (dt1.Rows.Count > 0)
  211. {
  212. string sb_makecode = dt1.Rows[0]["sb_makecode"].ToString();
  213. if (ma_code.Text != "" && ma_code.Text != sb_makecode)
  214. {
  215. OperateResult.AppendText(">>条码已绑定至工单" + sb_makecode + "\n", Color.Red, code);
  216. return;
  217. }
  218. ma_code.Text = dt1.Rows[0]["sb_makecode"].ToString();
  219. LockMakeCode.Checked = true;
  220. ma_code_UserControlTextChanged(sender, e);
  221. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  222. string sb_maincode = dt1.Rows[0]["sb_maincode"].ToString();
  223. //如果采集的是主条码则拆分所有的条码
  224. if (sb_maincode == code.Text)
  225. {
  226. string closetab_confirm = MessageBox.Show(this.ParentForm, "确认拆解所有条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  227. if (closetab_confirm == "Yes")
  228. {
  229. dh.ExecuteSql("delete from smtbind where sb_maincode='" + code.Text + "'", "delete");
  230. }
  231. }
  232. else
  233. {
  234. dh.ExecuteSql("delete from smtbind where sb_barcode='" + code.Text + "'", "delete");
  235. }
  236. sql.Clear();
  237. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode='" + sb_maincode + "'");
  238. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  239. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  240. sn_code.Text = "";
  241. code.Text = "";
  242. RefreshData();
  243. }
  244. }
  245. }
  246. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  247. }
  248. }
  249. private void ClearSn_code_Click(object sender, EventArgs e)
  250. {
  251. sn_code.Clear();
  252. SPID.Clear();
  253. TSN.Clear();
  254. CheckBarcode.Clear();
  255. CollectData.Clear();
  256. CollectDataSonCode.Clear();
  257. if (dt1 != null)
  258. BaseUtil.CleanDataTableData(dt1);
  259. BaseUtil.CleanDGVData(LabelDataGridView);
  260. OperateResult.AppendText(">>请采集序列号\n", Color.Black);
  261. }
  262. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  263. {
  264. if (ma_code.Text.Length > 5)
  265. {
  266. string ErrMessage = "";
  267. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  268. {
  269. mcd_inqty.Text = "";
  270. mcd_remainqty.Text = "";
  271. sql.Clear();
  272. sql.Append("select ma_qty,ma_prodcode,pr_detail,pr_pcbacount ");
  273. sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join product on ma_prodcode=pr_code where ");
  274. sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  275. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  276. if (dt.Rows.Count > 0)
  277. BaseUtil.SetFormValue(Controls, dt);
  278. RefreshData();
  279. sql.Clear();
  280. sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_makecode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
  281. sql.Append("where sb_barcode='" + code.Text + "')");
  282. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  283. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  284. }
  285. }
  286. }
  287. /// <summary>
  288. /// 刷新采集数据
  289. /// </summary>
  290. private void RefreshData()
  291. {
  292. sql.Clear();
  293. 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 + "' ");
  294. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  295. if (dt.Rows.Count > 0)
  296. BaseUtil.SetFormValue(Controls, dt);
  297. }
  298. string mincode;
  299. int sncount;
  300. int startsn;
  301. string firstsn;
  302. string lastsn;
  303. private void Crbut_Click(object sender, EventArgs e)
  304. {
  305. if(ma_code.Text==""|| Prefix.Text == "" || Num.Text == "" || Rn.Text == "" || pr_pcbacount.Value == 0 || Rnle.Value == 0)
  306. {
  307. OperateResult.AppendText(">>有关信息未录入或拼版数,流水长度未维护\n", Color.Red);
  308. return;
  309. }
  310. try
  311. {
  312. sncount = int.Parse(Num.Text);
  313. int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
  314. int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
  315. if (nowqty + sncount > maqty)
  316. {
  317. OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + sncount + "大于工单数" + maqty + "不允许操作\n", Color.Red);
  318. return;
  319. }
  320. if (DSCIN.Checked)
  321. {
  322. startsn = int.Parse(Rn.Text);
  323. }
  324. else {
  325. startsn = int.Parse(Hex2Ten(Rn.Text));
  326. }
  327. if (sncount % pr_pcbacount.Value != 0)
  328. {
  329. OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
  330. return;
  331. }
  332. if (DSCIN.Checked)
  333. {
  334. if ((startsn + (sncount - 1)*(sqit.Value)).ToString().Length > Rnle.Value)
  335. {
  336. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  337. return;
  338. }
  339. }
  340. else {
  341. if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()).Length > Rnle.Value)
  342. {
  343. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  344. return;
  345. }
  346. }
  347. if (DSCIN.Checked)
  348. {
  349. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
  350. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
  351. }
  352. else {
  353. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
  354. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()));
  355. }
  356. if (dh.CheckExist("SMTBIND", "sb_barcode between '"+ firstsn + "' and '"+ lastsn + "' "))
  357. {
  358. OperateResult.AppendText(">>SN导入重复\n", Color.Red);
  359. return;
  360. }
  361. thread = new Thread(NewPrint);
  362. SetLoadingWindow stw = new SetLoadingWindow(thread, "请稍候...");
  363. BaseUtil.SetFormCenter(stw);
  364. stw.ShowDialog();
  365. RefreshData();
  366. }
  367. catch (Exception ex)
  368. {
  369. OperateResult.AppendText(">>"+ex.Message+"\n", Color.Red);
  370. }
  371. }
  372. private void NewPrint()
  373. {
  374. List<string> maincodelist = new List<string>();
  375. List<string> nowcodelist = new List<string>();
  376. if (DSCIN.Checked)
  377. {
  378. for (int i = 0; i < sncount; i++)
  379. {
  380. string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + i*(sqit.Value)).ToString());
  381. if (i % pr_pcbacount.Value == 0)
  382. mincode = nowsn;
  383. maincodelist.Add(mincode);
  384. nowcodelist.Add(nowsn);
  385. }
  386. }
  387. else {
  388. for (int i = 0; i < sncount; i++)
  389. {
  390. string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + i * (sqit.Value )).ToString()));
  391. if (i % pr_pcbacount.Value == 0)
  392. mincode = nowsn;
  393. maincodelist.Add(mincode);
  394. nowcodelist.Add(nowsn);
  395. }
  396. }
  397. sql.Clear();
  398. sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
  399. sql.Append("values(smtbind_seq.nextval,:maincode,:nowcode,'" + ma_code.Text + "','" + ma_prodcode.Text + "',");
  400. sql.Append("'" + User.UserCode + "',sysdate,0)");
  401. dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
  402. MessageBox.Show("导入成功!");
  403. OperateResult.AppendText(">>生成完毕\n", Color.Black);
  404. OperateResult.AppendText(">>起始号:" + firstsn + "\n", Color.Black);
  405. OperateResult.AppendText(">>截止号:" + lastsn + "\n", Color.Black);
  406. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "SMT拼版绑定", firstsn+"到"+lastsn+"绑定成功,数量"+ sncount+",间隔"+ sqit.Value, "","");
  407. }
  408. private static string lpad(int length, string number)
  409. {
  410. while (number.Length < length)
  411. {
  412. number = "0" + number;
  413. }
  414. number = number.Substring(number.Length - length, length);
  415. return number;
  416. }
  417. private void Debut_Click(object sender, EventArgs e)
  418. {
  419. //if (!(ma_code.Text == ""))
  420. //{
  421. // string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除此工单拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  422. // if (logout_confirm == "Yes")
  423. // {
  424. // dh.ExecuteSql("delete SMTBIND where sb_makecode ='"+ma_code.Text+"'", "delete");
  425. // OperateResult.AppendText(">>工单"+ma_code.Text+ "拼版绑定记录清除成功\n", Color.Green);
  426. // }
  427. //}
  428. //else {
  429. // OperateResult.AppendText(">>工单号不能为空\n", Color.Red);
  430. //}
  431. try
  432. {
  433. sncount = int.Parse(Num.Text);
  434. if (DSCIN.Checked)
  435. {
  436. startsn = int.Parse(Rn.Text);
  437. }
  438. else
  439. {
  440. startsn = int.Parse(Hex2Ten(Rn.Text));
  441. }
  442. if (sncount % pr_pcbacount.Value != 0)
  443. {
  444. OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
  445. return;
  446. }
  447. if (DSCIN.Checked)
  448. {
  449. if ((startsn + (sncount - 1) * (sqit.Value)).ToString().Length > Rnle.Value)
  450. {
  451. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  452. return;
  453. }
  454. }
  455. else
  456. {
  457. if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()).Length > Rnle.Value)
  458. {
  459. OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
  460. return;
  461. }
  462. }
  463. if (DSCIN.Checked)
  464. {
  465. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
  466. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
  467. }
  468. else
  469. {
  470. firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
  471. lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()));
  472. }
  473. string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除SN: "+ firstsn + " 到 "+ lastsn + " 拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  474. if (logout_confirm == "Yes")
  475. {
  476. dh.ExecuteSql("delete SMTBIND where sb_barcode between '" + firstsn + "' and '" + lastsn + "'", "delete");
  477. OperateResult.AppendText(">>SN: " + firstsn + " 到 " + lastsn + " 拼版绑定记录清除成功\n", Color.Green);
  478. }
  479. }
  480. catch (Exception ex)
  481. {
  482. OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red);
  483. }
  484. }
  485. /// <summary>
  486. /// 从十进制转换到十六进制
  487. /// </summary>
  488. /// <param name="ten"></param>
  489. /// <returns></returns>
  490. public static string ConvertNumToHex(string ten)
  491. {
  492. ulong Numb = Convert.ToUInt64(ten);
  493. ulong divValue, resValue;
  494. string hex = "";
  495. do
  496. {
  497. divValue = (ulong)Math.Floor((decimal)(Numb / 16));
  498. resValue = Numb % 16;
  499. hex = GetNumb(resValue) + hex;
  500. Numb = divValue;
  501. }
  502. while (Numb >= 16);
  503. if (Numb != 0)
  504. hex = GetNumb(Numb) + hex;
  505. return hex;
  506. }
  507. public static string GetNumb(ulong Numb)
  508. {
  509. switch (Numb)
  510. {
  511. case 0:
  512. case 1:
  513. case 2:
  514. case 3:
  515. case 4:
  516. case 5:
  517. case 6:
  518. case 7:
  519. case 8:
  520. case 9:
  521. return Numb.ToString();
  522. case 10:
  523. return "A";
  524. case 11:
  525. return "B";
  526. case 12:
  527. return "C";
  528. case 13:
  529. return "D";
  530. case 14:
  531. return "E";
  532. case 15:
  533. return "F";
  534. default:
  535. return "";
  536. }
  537. }
  538. public static string Hex2Ten(string hex)
  539. {
  540. int ten = 0;
  541. for (int i = 0, j = hex.Length - 1; i < hex.Length; i++)
  542. {
  543. ten += HexChar2Value(hex.Substring(i, 1)) * ((int)Math.Pow(16, j));
  544. j--;
  545. }
  546. return ten.ToString();
  547. }
  548. public static int HexChar2Value(string hexChar)
  549. {
  550. switch (hexChar)
  551. {
  552. case "0":
  553. case "1":
  554. case "2":
  555. case "3":
  556. case "4":
  557. case "5":
  558. case "6":
  559. case "7":
  560. case "8":
  561. case "9":
  562. return Convert.ToInt32(hexChar);
  563. case "a":
  564. case "A":
  565. return 10;
  566. case "b":
  567. case "B":
  568. return 11;
  569. case "c":
  570. case "C":
  571. return 12;
  572. case "d":
  573. case "D":
  574. return 13;
  575. case "e":
  576. case "E":
  577. return 14;
  578. case "f":
  579. case "F":
  580. return 15;
  581. default:
  582. return 0;
  583. }
  584. }
  585. private void normalButton2_Click(object sender, EventArgs e)
  586. {
  587. DialogResult result = openFileDialog1.ShowDialog();
  588. if (result == DialogResult.OK)
  589. {
  590. textBox1.Text = openFileDialog1.FileName;
  591. }
  592. }
  593. private void normalButton3_Click(object sender, EventArgs e)
  594. {
  595. if (ma_code.Text == "" || textBox1.Text == "" || ma_prodcode.Text == "")
  596. {
  597. MessageBox.Show("工单号,产品编号与文件地址不可为空");
  598. return;
  599. }
  600. dt = eh.ImportExcel(textBox1.Text, "test");
  601. int number = 0;
  602. //for (int i = 0; i < dt.Rows.Count; i++)
  603. //{
  604. // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
  605. //}
  606. //BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  607. List<string> maincodelist = new List<string>();
  608. List<string> nowcodelist = new List<string>();
  609. for (int i = 0; i < dt.Rows.Count; i++)
  610. {
  611. if (dt.Rows[i]["工单"].ToString().Trim()==ma_code.Text&&dt.Rows[i]["拼板号"].ToString().Trim().Length >2 && dt.Rows[i]["打码内容"].ToString().Trim().Length > 7 && dt.Rows[i]["拼板号"].ToString().Trim().Substring(0, 2)
  612. == dt.Rows[i]["打码内容"].ToString().Trim().Substring(0, 2))
  613. {
  614. maincodelist.Add(dt.Rows[i]["拼板号"].ToString().Trim());
  615. nowcodelist.Add(dt.Rows[i]["打码内容"].ToString().Trim());
  616. //number++;
  617. }
  618. }
  619. sql.Clear();
  620. sql.Append("insert into smtbind_temp(MAINCODE,BARCODE)");
  621. sql.Append("values(:maincode,:nowcode)");
  622. dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
  623. number = int.Parse(dh.getFieldDataByCondition("smtbind_temp", "count(1) cn ", "BARCODE not in (select sb_barcode from smtbind )").ToString());
  624. int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
  625. int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
  626. if (nowqty + number > maqty)
  627. {
  628. OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + number + "大于工单数" + maqty + "不允许操作\n", Color.Red);
  629. dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
  630. return;
  631. }
  632. sql.Clear();
  633. 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)");
  634. sql.Append(" values (SMTBIND_seq.nextval ,maincode,barcode,'" + ma_code.Text + "','"+ma_prodcode.Text+"','"+User.UserCode+"',sysdate,0)");
  635. dh.ExecuteSql(sql.GetString(), "insert");
  636. dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
  637. MessageBox.Show("导入成功"+ number + "条!");
  638. OperateResult.AppendText(">>导入成功" + number + "条!\n", Color.Green);
  639. RefreshData();
  640. }
  641. }
  642. }