Make_SeqProgramTransform.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  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.Make
  14. {
  15. public partial class Make_SeqProgramTransform : Form
  16. {
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataHelper dh;
  20. //原序列号
  21. string TSN = "";
  22. //转换后序列号
  23. string SN = "";
  24. //错误信息
  25. string errorMessage;
  26. //存放productsnrelation表中的数据
  27. DataTable ListA;
  28. //存放工单信息
  29. DataTable dt;
  30. //存放序列号防呆规则
  31. DataTable rules;
  32. //step 记录检验规则的进度
  33. int step = 0;
  34. //存放关联信息类型
  35. string type;
  36. //存放包含IMEI的规则的值,方便拼接
  37. StringBuilder imei = new StringBuilder();
  38. LogStringBuilder logsql = new LogStringBuilder();
  39. //存放工单中数量
  40. int ma_qty;
  41. //存放所有关联信息的类型和录入的值
  42. Hashtable hs;
  43. string oMakecode = "";
  44. string oMsid = "";
  45. string siid = "";//存储TSN对应的sninfo记录id
  46. DataTable macRange;//记录macBT范围
  47. string macOrBt = "";//存储去掉":"或者"-"的mac和bt
  48. bool onlyPass = false;//自己转自己
  49. string imeif = "";
  50. bool hasSnList = false;//记录是否有转换后SN清单
  51. bool hasMakeRule = false;//记录是否有工单防呆规则
  52. public Make_SeqProgramTransform()
  53. {
  54. InitializeComponent();
  55. }
  56. private void Make_SeqProgramTransform_Load(object sender, EventArgs e)
  57. {
  58. asc.controllInitializeSize(this);
  59. code.Focus();
  60. //提示用户“>>请输入TSN号”
  61. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  62. dh = SystemInf.dh;
  63. StepCount.StepCode = User.CurrentStepCode;
  64. StepCount.Source = User.UserSourceCode;
  65. StepCount.LineCode = User.UserLineCode;
  66. StepCount.Dh = dh;
  67. StepCount.Start();
  68. Seq_Remark_PreFix.Text = BaseUtil.GetCacheData("Seq_Remark_PreFix").ToString();
  69. }
  70. private void code_KeyDown(object sender, KeyEventArgs e)
  71. {
  72. if (e.KeyCode == Keys.Enter)
  73. {
  74. if (code.Text != "")
  75. {
  76. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out errorMessage))
  77. {
  78. //为0,输入TSN
  79. if (step == 0)
  80. {
  81. OperateResult.AppendText(">>TSN号" + code.Text + "\n", Color.Black);
  82. if (!ChangeResult.Checked)//不勾选
  83. {
  84. //核对工序
  85. if (!LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, code.Text, User.UserCode, out oMakecode, out oMsid, out errorMessage))
  86. {
  87. OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
  88. return;
  89. }
  90. }
  91. else//勾选
  92. {
  93. oMsid = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode in (select '" + code.Text + "' from dual union select sn from makesnrelation where beforesn='" + code.Text + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + code.Text + "' and beforesn<>' ')").ToString();
  94. if (oMsid == "")
  95. {
  96. OperateResult.AppendText("<<TSN号错误\n", Color.Red, code);
  97. return;
  98. }
  99. //根据ms_id查询
  100. sql.Clear();
  101. sql.Append("select ms_stepcode,nvl(ms_downstatus,'0') ms_downstatus from makeserial where ms_id='" + oMsid + "' and ms_beforesn='" + code.Text + "' and ms_nextmacode is null and ms_outboxcode is null");
  102. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  103. //如果行数大于0则允许转号
  104. if (dt.Rows.Count > 0)
  105. {
  106. if (dt.Rows[0]["ms_downstatus"].ToString() != "0")
  107. {
  108. OperateResult.AppendText("<<当前TSN号处于下地状态不允许操作\n", Color.Red, code);
  109. return;
  110. }
  111. if (dt.Rows[0]["ms_stepcode"].ToString() == User.CurrentStepCode)
  112. {
  113. step = 1;
  114. TSN = code.Text;
  115. //显示序列号
  116. show_sncode.Text = TSN;
  117. ChangeResult.Enabled = false;
  118. }
  119. else
  120. {
  121. OperateResult.AppendText("<<当前工序不允许重新转号\n", Color.Red, code);
  122. return;
  123. }
  124. }
  125. else
  126. {
  127. OperateResult.AppendText("<<TSN号" + code.Text + "未转号不允许重新转号\n", Color.Red, code);
  128. return;
  129. }
  130. }
  131. //如果用户没有选择工单号
  132. if (ms_macode.Text == "" || ms_macode.Text != oMakecode || ChangeResult.Checked)
  133. {
  134. //按照out出的工单号查出工单相关信息,并赋值到相关控件
  135. sql.Clear();
  136. sql.Append("select ma_code as ms_macode,ma_softversion,mcd_okqty,ma_qty,ma_qty-mcd_inqty as remain_qty,pr_detail,pr_code as ma_prodcode ");
  137. sql.Append("from makeserial left join make on ms_makecode=ma_code left join product on ");
  138. sql.Append("ms_prodcode=pr_code left join makecraftdetail on ms_makecode=mcd_macode where ms_id='" + oMsid + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  139. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  140. if (dt.Rows.Count > 0)
  141. {
  142. //记录数量
  143. ma_qty = int.Parse(dt.Rows[0]["ma_qty"].ToString());
  144. BaseUtil.SetFormValue(this.Controls, dt);
  145. }
  146. else
  147. {
  148. OperateResult.AppendText("<<TSN号" + code.Text + "不存在\n", Color.Red, code);
  149. return;
  150. }
  151. }
  152. //查询TSN对应的sninfo记录id
  153. siid = dh.getFieldDataByCondition("sninfo", "max(si_id) si_id", "si_sn in (select '" + code.Text + "' from dual union select sn from makesnrelation where beforesn = '" + code.Text + "' )").ToString();
  154. //获取需要关联采集的信息,以及校验规则
  155. ListA = (DataTable)dh.ExecuteSql("select * from productsnrelation where psr_prodcode='" + ma_prodcode.Text + "' order by psr_detno", "select");
  156. //没有获取到就提示错误请维护产品对应的关联采集信息
  157. if (ListA.Rows.Count == 0)
  158. {
  159. OperateResult.AppendText("<<请维护产品对应的关联采集信息\n", Color.Red, code);
  160. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  161. if (ChangeResult.Checked)
  162. {
  163. clearInfo();
  164. }
  165. return;
  166. }
  167. if (ChangeResult.Checked)
  168. {
  169. OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
  170. }
  171. //判断重新转换未勾选
  172. if (!ChangeResult.Checked)
  173. {
  174. //没有勾选,只能修改一次
  175. //核对TSN是否正确
  176. //string beforesn = dh.getFieldDataByCondition("makeserial", "ms_beforesn", "ms_sncode='" + code.Text + "'").ToString().Trim();
  177. if (dh.CheckExist("makeserial", "ms_id='" + oMsid + "' and ms_sncode='" + code.Text + "' and ms_beforesn is null"))
  178. {
  179. step = 1;
  180. //记录转换前的序列号
  181. TSN = code.Text;
  182. //显示之前的序列号
  183. show_sncode.Text = TSN;
  184. OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
  185. ChangeResult.Enabled = false;
  186. }
  187. else
  188. //不为空,进行过转换。不勾选修改结果,就不能再修改
  189. {
  190. //修改转换结果时,输入两次SN直接过站
  191. if (dh.CheckExist("MakeSerial", "ms_id='" + oMsid + "' and ms_sncode='" + code.Text + "' and ms_beforesn is not null"))
  192. {
  193. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
  194. if (nextstepcode == User.CurrentStepCode)
  195. {
  196. step = 1;
  197. TSN = code.Text;
  198. //显示序列号
  199. show_sncode.Text = TSN;
  200. OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
  201. ChangeResult.Enabled = false;
  202. onlyPass = true;
  203. }
  204. else
  205. {
  206. OperateResult.AppendText("<<序列号:" + code.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, code);
  207. OperateResult.AppendText(">>请重新输入TSN\n", Color.Black);
  208. }
  209. }
  210. else
  211. {
  212. OperateResult.AppendText("<<序列号:" + code.Text + "已转换过\n", Color.Red, code);
  213. OperateResult.AppendText(">>请重新输入TSN\n", Color.Black);
  214. }
  215. }
  216. }
  217. }
  218. else if (step == 1)
  219. {
  220. OperateResult.AppendText(">>" + code.Text + "\n", Color.Black);
  221. //判断工单是否导入了序列号清单
  222. if (hasSnList)
  223. {
  224. if (!dh.CheckExist("makesnlist", "msl_sncode='" + code.Text + "' and msl_makecode='" + ms_macode.Text + "' and msl_type='after'"))
  225. {
  226. //有序列号清单,输入的序列号却不在范围内
  227. OperateResult.AppendText("<<SN号" + code.Text + "错误,不在工单设定的转换后序列号清单中\n", Color.Red, code);
  228. return;
  229. }
  230. }
  231. else if (hasMakeRule)//判断工单防呆
  232. {
  233. if (!dh.CheckExist("makesnruledetail", "msd_sncode='" + code.Text + "' and msd_makecode='" + ms_macode.Text + "' and msd_type='after'"))
  234. {
  235. OperateResult.AppendText("<<SN号" + code.Text + "校验错误,不在工单防呆规则指定范围内!\n", Color.Red, code);
  236. return;
  237. }
  238. }
  239. else//判断产品防呆
  240. {
  241. //判断用户是否锁定输入SN长度,
  242. if (!checkLengthOrPre(SNLength_checkBox, SNLength, "长度", "SN"))
  243. {
  244. return;
  245. }
  246. //判断用户是否锁定输入SN前缀,
  247. if (!checkLengthOrPre(SNPre_checkBox, SNPre, "前缀", "SN"))
  248. {
  249. return;
  250. }
  251. }
  252. //开始录入SN
  253. if ((!ChangeResult.Checked && (!dh.CheckExist("makeserial", "ms_sncode='" + code.Text + "' and ms_id <>'" + oMsid + "' and nvl(ms_nextmacode,' ') =' '") && !onlyPass || onlyPass && TSN == code.Text)) || (ChangeResult.Checked && !dh.CheckExist("makeserial", "ms_sncode='" + code.Text + "' and ms_id <>'" + oMsid + "' and nvl(ms_nextmacode,' ') =' '")))
  254. {
  255. onlyPass = false;
  256. //SN校验成功,合法,记录下SN
  257. SN = code.Text;
  258. code.Text = "";
  259. //开始进行校验规则
  260. if (ListA.Rows.Count > 0)
  261. {
  262. OperateResult.AppendText(">>请输入" + ListA.Rows[0]["psr_type"] + "\n", Color.Green);
  263. //实例化hashTable的值
  264. hs = new Hashtable();
  265. }
  266. //step+1
  267. step = 2;
  268. }
  269. else
  270. {
  271. if (onlyPass)
  272. {
  273. OperateResult.AppendText("<<SN号" + code.Text + "错误,已完成转号只允许SN转SN\n", Color.Red);
  274. }
  275. else
  276. {
  277. OperateResult.AppendText("<<SN号" + code.Text + "已存在\n", Color.Red);
  278. }
  279. OperateResult.AppendText(">>请输入SN\n", Color.Black, code);
  280. }
  281. }
  282. else if (step < ListA.Rows.Count + 2)
  283. {
  284. OperateResult.AppendText(">>" + code.Text + "\n", Color.Black);
  285. //开始进行校验规则
  286. if (checkRules(step))
  287. {
  288. step += 1;
  289. code.Text = "";
  290. }
  291. }
  292. }
  293. else
  294. {
  295. OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
  296. }
  297. }
  298. else
  299. {
  300. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  301. }
  302. }
  303. }
  304. /// <summary>
  305. /// 检验长度或者前缀是否合法
  306. /// </summary>
  307. /// <param name="checkbox"></param>
  308. /// <param name="c"></param>
  309. /// <param name="info"></param>
  310. private bool checkLengthOrPre(CheckBox checkbox, TextBox textbox, string type, string TSNorSN)
  311. {
  312. if (checkbox.Checked == true)
  313. {
  314. //如果勾选没有填值
  315. if (textbox.Text == "")
  316. {
  317. OperateResult.AppendText("<<勾选长度或者前缀需要填写内容\n", Color.Red);
  318. return false;
  319. }
  320. if (type == "长度")
  321. {
  322. //则判断输入转换前的序列号长度是否合法,不合法则提示
  323. if (code.Text.Trim().Length != int.Parse(textbox.Text))
  324. {
  325. //序列号校验错误,长度错误
  326. OperateResult.AppendText("<<" + TSNorSN + ":" + code.Text + "校验错误,长度错误\n", Color.Red, code);
  327. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  328. return false;
  329. }
  330. }
  331. else if (type == "前缀")
  332. {
  333. string[] pres = textbox.Text.Split('|');
  334. bool f = false;
  335. for (int i = 0; i < pres.Length; i++)
  336. {
  337. if (pres[i] == "" ? true : code.Text.StartsWith(pres[i]))
  338. {
  339. //满足其中一条即可
  340. f = true;
  341. break;
  342. }
  343. }
  344. //则判断输入转换前的序列号前缀是否合法,不合法则提示
  345. if (!f)
  346. {
  347. //序列号校验错误,前缀错误
  348. OperateResult.AppendText("<<" + TSNorSN + ":" + code.Text + "校验错误,前缀错误\n", Color.Red, code);
  349. OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
  350. return false;
  351. }
  352. }
  353. return true;
  354. }
  355. return true;
  356. }
  357. /// <summary>
  358. /// 关联采集的校验
  359. /// </summary>
  360. /// <param name="step"></param>
  361. private bool checkRules(int step)
  362. {
  363. type = ListA.Rows[step - 2]["psr_type"].ToString();
  364. //将type中的mac和bt中的"-"和":"号去掉
  365. if (type == "MAC" || type == "BT")
  366. {
  367. if (code.Text.Length > 40)
  368. {
  369. macOrBt = code.Text.Substring(0, 40).Replace(":", "").Replace("-", "");
  370. }
  371. else
  372. {
  373. macOrBt = code.Text.Replace(":", "").Replace("-", "");
  374. }
  375. }
  376. else
  377. {
  378. if (code.Text.Length > 40)
  379. {
  380. imeif = code.Text.Substring(0, 40);
  381. }
  382. else
  383. {
  384. imeif = code.Text;
  385. }
  386. }
  387. if (code.Text.Length > 40)
  388. {
  389. //如果前缀和长度都满足的话
  390. if ((ListA.Rows[step - 2]["psr_length"].ToString() == "0" ? false : code.Text.Substring(0, 40).Length != int.Parse(ListA.Rows[step - 2]["psr_length"].ToString())))
  391. {
  392. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "长度需为" + ListA.Rows[step - 2]["psr_length"].ToString() + "校验不通过,请重新输入\n", Color.Red);
  393. OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
  394. return false;
  395. }
  396. }
  397. else
  398. {
  399. //如果前缀和长度都满足的话
  400. if ((ListA.Rows[step - 2]["psr_length"].ToString() == "0" ? false : code.Text.Length != int.Parse(ListA.Rows[step - 2]["psr_length"].ToString())))
  401. {
  402. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "长度需为" + ListA.Rows[step - 2]["psr_length"].ToString() + "校验不通过,请重新输入\n", Color.Red);
  403. OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
  404. return false;
  405. }
  406. }
  407. //以|符号分割前缀
  408. string[] preFixs = ListA.Rows[step - 2]["psr_prefix"].ToString().Split('|');
  409. //只要满足其中一个前缀条件即可
  410. bool isfit = false;
  411. for (int i = 0; i < preFixs.Length; i++)
  412. {
  413. if (preFixs[i] == "" ? true : code.Text.StartsWith(preFixs[i]))
  414. {
  415. //满足其中一条即可
  416. isfit = true;
  417. break;
  418. }
  419. }
  420. if (!isfit)
  421. {
  422. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "前缀校验不通过,请重新输入\n", Color.Red);
  423. OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
  424. return false;
  425. }
  426. switch (type)
  427. {
  428. case "IMEI1":
  429. case "IMEI2":
  430. case "IMEI3":
  431. string tempSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "(ms_imei1='" + imeif + "' or ms_imei2 = '" + imeif + "' or ms_imei3 = '" + imeif + "') and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
  432. if (tempSn != "")
  433. {
  434. OperateResult.AppendText("<<" + type + ":" + imeif + "错误,已被序列号" + tempSn + "使用\n", Color.Red);
  435. OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
  436. return false;
  437. }
  438. else
  439. { //校验sninfo中是否已经存在这个
  440. tempSn = dh.getFieldDataByCondition("sninfo", "si_sn", "(si_imei1='" + imeif + "' or si_imei2 = '" + imeif + "' or si_imei3 = '" + imeif + "') and si_id <>'" + siid + "'").ToString();
  441. if (tempSn != "")
  442. {
  443. OperateResult.AppendText("<<" + type + ":" + imeif + "错误,已被序列号" + tempSn + "使用\n", Color.Red);
  444. OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
  445. return false;
  446. }
  447. //判断IMEI1,IMEI2,IMEI3中是否已经有这个号了
  448. if (imei.ToString().Contains(imeif))
  449. {
  450. OperateResult.AppendText("<<" + type + ":" + imeif + "已录,请重新输入\n", Color.Red);
  451. OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
  452. return false;
  453. }
  454. }
  455. //通过校验,将包含IMEI的值拼接
  456. imei.Append("'" + imeif + "',");
  457. break;
  458. case "BT":
  459. case "MAC":
  460. //验证是否符合合同防呆
  461. if (!LogicHandler.checkMacOrBtRange(oMsid, macOrBt, type))
  462. {
  463. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,不在合同防呆范围内\n", Color.Red);
  464. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  465. return false;
  466. }
  467. //验证是否MAC和BT重复
  468. if (hs.ContainsValue(macOrBt))
  469. {
  470. foreach (DictionaryEntry de in hs)
  471. {
  472. //拿到重复的项
  473. if (de.Value.ToString() == macOrBt)
  474. {
  475. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误," + de.Key + "已录\n", Color.Red);
  476. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  477. return false;
  478. }
  479. }
  480. }
  481. //验证是否已被使用
  482. string temSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "(MS_mac='" + macOrBt + "'or ms_bt='" + macOrBt + "') and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
  483. if (temSn != "")
  484. {
  485. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,已被序列号" + temSn + "使用\n", Color.Red);
  486. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  487. return false;
  488. }
  489. else
  490. {
  491. //校验在sninfo表中是否存在
  492. temSn = dh.getFieldDataByCondition("sninfo", "si_sn", "(si_mac='" + macOrBt + "' or si_bt='" + macOrBt + "') and si_id <>'" + siid + "'").ToString();
  493. if (temSn != "")
  494. {
  495. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,已被序列号" + temSn + "使用\n", Color.Red);
  496. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  497. return false;
  498. }
  499. }
  500. break;
  501. case "NETCODE":
  502. //验证是否MAC和BT重复
  503. if (hs.ContainsValue(imeif))
  504. {
  505. foreach (DictionaryEntry de in hs)
  506. {
  507. //拿到重复的项
  508. if (de.Value.ToString() == imeif)
  509. {
  510. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误," + de.Key + "已录\n", Color.Red);
  511. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  512. return false;
  513. }
  514. }
  515. }
  516. //校验网标是否存在
  517. string teSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "MS_" + type + "='" + imeif + "' and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
  518. if (teSn != "")
  519. {
  520. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误,已被序列号" + teSn + "使用\n", Color.Red);
  521. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  522. return false;
  523. }
  524. else
  525. {
  526. //校验在sninfo表中是否存在
  527. teSn = dh.getFieldDataByCondition("sninfo", "si_sn", "si_" + type + "='" + imeif + "' and si_id <>'" + siid + "'").ToString();
  528. if (teSn != "")
  529. {
  530. OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误,已被序列号" + teSn + "使用\n", Color.Red);
  531. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
  532. return false;
  533. }
  534. }
  535. break;
  536. }
  537. if (step == ListA.Rows.Count + 1)
  538. {
  539. if (CollectRemark.Checked || SameReamrk.Checked)
  540. {
  541. if (Remark.Text == "")
  542. {
  543. OperateResult.AppendText(">>备注栏信息为空,录入备注信息\n", Color.Black);
  544. Remark.SelectAll();
  545. Remark.Focus();
  546. imei.Replace(code.Text, "");
  547. return false;
  548. }
  549. if (IFONLY.Checked)
  550. {
  551. if (!CheckPre())
  552. {
  553. imei.Replace(code.Text, "");
  554. return false;
  555. }
  556. string UsedSncode = dh.getFieldDataByCondition("SNRELATIONINFORECORD", "SIR_SNCODE", "sir_remark = '" + Remark.Text + "'").ToString();
  557. if (UsedSncode != "")
  558. {
  559. OperateResult.AppendText(">>备注信息" + Remark.Text + "已被" + UsedSncode + "采集,不可重复采集\n", Color.Red);
  560. Remark.SelectAll();
  561. Remark.Focus();
  562. imei.Replace(code.Text, "");
  563. return false;
  564. }
  565. LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", ms_macode.Text, ma_prodcode.Text, Remark.Text);
  566. OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
  567. if (CollectRemark.Checked)
  568. {
  569. Remark.Text = "";
  570. }
  571. }
  572. else
  573. {
  574. if (!CheckPre())
  575. {
  576. imei.Replace(code.Text, "");
  577. return false;
  578. }
  579. LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", ms_macode.Text, ma_prodcode.Text, Remark.Text);
  580. OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
  581. if (CollectRemark.Checked)
  582. {
  583. Remark.Text = "";
  584. }
  585. }
  586. }
  587. }
  588. //满足规则,则采集
  589. if (type == "MAC" || type == "BT")
  590. {
  591. hs.Add(ListA.Rows[step - 2]["psr_type"].ToString(), macOrBt);
  592. }
  593. else
  594. {
  595. hs.Add(ListA.Rows[step - 2]["psr_type"].ToString(), imeif);
  596. }
  597. //说明已经是最后一个校验规则
  598. if (step == ListA.Rows.Count + 1)
  599. {
  600. return SetStepResult();
  601. }
  602. else
  603. {
  604. OperateResult.AppendText(">>请输入" + ListA.Rows[step - 1]["psr_type"] + "\n", Color.Green, code);
  605. return true;
  606. }
  607. }
  608. //校验备注前缀
  609. private Boolean CheckPre()
  610. {
  611. try
  612. {
  613. if (Remark.Text.Substring(0, Seq_Remark_PreFix.Text.Length) != Seq_Remark_PreFix.Text)
  614. {
  615. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  616. Remark.SelectAll();
  617. Remark.Focus();
  618. return false;
  619. }
  620. }
  621. catch (Exception)
  622. {
  623. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  624. Remark.SelectAll();
  625. Remark.Focus();
  626. return false;
  627. }
  628. return true;
  629. }
  630. //通过存储过程二次校验
  631. private Boolean SetStepResult()
  632. {
  633. if (LogicHandler.snChangeAndBurn(TSN, SN, User.UserSourceCode, User.UserCode, ms_macode.Text, ChangeResult.Checked ? 1 : 0, (hs.ContainsKey("IMEI1") ? hs["IMEI1"].ToString() : ""), (hs.ContainsKey("IMEI2") ? hs["IMEI2"].ToString() : ""), (hs.ContainsKey("IMEI3") ? hs["IMEI3"].ToString() : ""), "", (hs.ContainsKey("NETCODE") ? hs["NETCODE"].ToString() : ""), "", "", "", "", (hs.ContainsKey("MAC") ? hs["MAC"].ToString() : ""), (hs.ContainsKey("BT") ? hs["BT"].ToString() : ""), "", "", "", out errorMessage))
  634. {
  635. OperateResult.AppendText("<<序列号" + TSN + "成功转换为" + SN + "\n<<关联采集成功\n", Color.Green);
  636. //写入日志
  637. LogManager.DoLog("修改序列号:" + TSN + "为" + SN + "成功!" + "操作人:" + User.UserCode);
  638. //记录日志
  639. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_macode.Text, User.UserLineCode, User.UserSourceCode, "序列烧录转换", TSN + "转换为" + SN, SN, "");
  640. //获取剩余数,刷新页面
  641. sql.Clear();
  642. sql.Append("select mcd_inqty from makecraftdetail where mcd_macode='" + ms_macode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  643. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  644. if (dt.Rows.Count > 0)
  645. {
  646. remain_qty.Text = ma_qty - int.Parse(dt.Rows[0]["mcd_inqty"].ToString()) + "";
  647. }
  648. //更新页面计数+1
  649. count.Text = int.Parse(count.Text) + 1 + "";
  650. //完成之后,清除信息
  651. clearInfo();
  652. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  653. }
  654. else
  655. {
  656. OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
  657. OperateResult.AppendText(">>请重新输入TSN\n", Color.Black, code);
  658. // //清空信息
  659. clearInfo();
  660. }
  661. code.Text = "";
  662. return false;
  663. }
  664. /// <summary>
  665. /// 工单号变化时,带出校验规则
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. private void ms_macode_TextChanged(object sender, EventArgs e)
  670. {
  671. hasSnList = false;
  672. hasMakeRule = false;
  673. //清空
  674. TSNPre.Text = "";
  675. TSNLength.Text = "";
  676. SNPre.Text = "";
  677. SNLength.Text = "";
  678. //取消勾选
  679. TSNPre_checkBox.Checked = false;
  680. TSNLength_checkBox.Checked = false;
  681. SNPre_checkBox.Checked = false;
  682. SNLength_checkBox.Checked = false;
  683. //设置可编辑
  684. TSNLength.Enabled = true;
  685. TSNPre.Enabled = true;
  686. SNLength.Enabled = true;
  687. SNPre.Enabled = true;
  688. TSNPre_checkBox.Enabled = true;
  689. TSNLength_checkBox.Enabled = true;
  690. SNPre_checkBox.Enabled = true;
  691. SNLength_checkBox.Enabled = true;
  692. //判断工单是否导入了序列号清单
  693. if (dh.CheckExist("makesnlist", "msl_makecode='" + ms_macode.Text + "' and msl_type='after'"))
  694. {
  695. hasSnList = true;
  696. return;
  697. }
  698. //查询表工单序列号防呆规则表
  699. rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_makecode='" + ms_macode.Text + "' and msr_type='after'", "select");
  700. if (rules.Rows.Count > 0)
  701. {
  702. hasMakeRule = true;
  703. }
  704. else
  705. {
  706. /* 如果转换前没有值,则取 select productsnrule where psr_prodcode=? 产品编号,
  707. * 有值则赋值到 转换前,并且自动勾选不可编辑。*/
  708. rules = (DataTable)dh.ExecuteSql("select psr_prefix,psr_length from productsnrule where psr_prodcode ='" + dt.Rows[0]["ma_prodcode"].ToString() + "' and psr_type='after'", "select");
  709. if (rules.Rows.Count > 0)
  710. {
  711. //将产品序列号防呆规则查出的数据填充
  712. if (rules.Rows[0]["psr_prefix"].ToString() != "")
  713. {
  714. SNPre.Text = rules.Rows[0]["psr_prefix"].ToString();
  715. SNPre.Enabled = false;
  716. SNPre_checkBox.Checked = true;
  717. SNPre_checkBox.Enabled = false;
  718. }
  719. if (rules.Rows[0]["psr_length"].ToString() != "")
  720. {
  721. SNLength.Text = rules.Rows[0]["psr_length"].ToString();
  722. SNLength.Enabled = false;
  723. SNLength_checkBox.Checked = true;
  724. SNLength_checkBox.Enabled = false;
  725. }
  726. }
  727. }
  728. }
  729. private bool checkExist(string fields)
  730. {
  731. //不存在
  732. if (!dh.CheckExist("makeserial", fields))
  733. {
  734. //则记录
  735. return false;
  736. }
  737. else
  738. {
  739. return true;
  740. }
  741. }
  742. private void clearInfo()
  743. {
  744. //步骤重置为0
  745. step = 0;
  746. //关联采集信息清空
  747. if (hs != null)
  748. {
  749. hs.Clear();
  750. }
  751. imei.Clear();
  752. logsql.Clear();
  753. show_sncode.Text = "";
  754. ChangeResult.Enabled = true;
  755. onlyPass = false;
  756. }
  757. private void cancel_Click(object sender, EventArgs e)
  758. {
  759. //清除已经采集的所有信息
  760. clearInfo();
  761. //提示用户输入TSN
  762. OperateResult.AppendText(">>请输入TSN\n", Color.Green);
  763. }
  764. private void ChangeResult_CheckedChanged(object sender, EventArgs e)
  765. {
  766. if (ChangeResult.Checked)
  767. {
  768. //勾选的时候提示输入TSN
  769. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  770. }
  771. }
  772. private void Make_SeqProgramTransform_SizeChanged(object sender, EventArgs e)
  773. {
  774. asc.controlAutoSize(this);
  775. }
  776. private void Seq_Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  777. {
  778. if (e.KeyCode == Keys.Enter)
  779. {
  780. BaseUtil.SetCacheData("Seq_Remark_PreFix", Seq_Remark_PreFix.Text);
  781. if (CollectRemark.Checked || SameReamrk.Checked)
  782. {
  783. Remark.SelectAll();
  784. Remark.Focus();
  785. }
  786. }
  787. }
  788. private void Remark_KeyDown(object sender, KeyEventArgs e)
  789. {
  790. if (e.KeyCode == Keys.Enter)
  791. {
  792. try
  793. {
  794. if (step == ListA.Rows.Count + 1 && (CollectRemark.Checked || SameReamrk.Checked) && Remark.Text != "")
  795. {
  796. code.Enabled = true;
  797. code.Focus();
  798. code_KeyDown(this, new KeyEventArgs(Keys.Enter));
  799. }
  800. else
  801. {
  802. code.Enabled = true;
  803. code.Focus();
  804. }
  805. }
  806. catch
  807. {
  808. code.Enabled = true;
  809. code.Focus();
  810. }
  811. }
  812. }
  813. private void IFONLY_CheckedChanged(object sender, EventArgs e)
  814. {
  815. if (IFONLY.Checked)
  816. {
  817. SameReamrk.Checked = false;
  818. CollectRemark.Checked = true;
  819. }
  820. }
  821. private void SameReamrk_CheckedChanged(object sender, EventArgs e)
  822. {
  823. if (SameReamrk.Checked)
  824. {
  825. IFONLY.Checked = false;
  826. CollectRemark.Checked = false;
  827. }
  828. }
  829. private void CollectRemark_CheckedChanged(object sender, EventArgs e)
  830. {
  831. if (CollectRemark.Checked)
  832. {
  833. SameReamrk.Checked = false;
  834. }
  835. }
  836. private void Remark_Enter(object sender, EventArgs e)
  837. {
  838. code.Enabled = false;
  839. }
  840. private void Remark_Leave(object sender, EventArgs e)
  841. {
  842. code.Enabled = true;
  843. }
  844. }
  845. }