Make_SeqTransform2.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. using HslCommunication.Profinet.Knx;
  2. using NPOI.SS.Formula.Functions;
  3. using System;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  8. using UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicMethod;
  11. namespace UAS_MES_NEW.Make
  12. {
  13. public partial class Make_SeqTransform2 : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. DataTable dt;
  18. DataTable rules;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. string bsncode = "";//转换前序列号
  21. string errorMessage = "";
  22. DataTable ListA;
  23. //存放工单中数量
  24. int ma_qty;
  25. string oMakeCode = "";
  26. string oMsId = "";
  27. bool onlyPass = false;
  28. bool hasSnList = false;//记录是否有转换后SN清单
  29. bool hasMakeRule = false;//记录是否有工单防呆规则
  30. bool hasSaleRule = false;//记录是否有合同防呆规则
  31. public Make_SeqTransform2()
  32. {
  33. InitializeComponent();
  34. }
  35. private void sncode_KeyDown(object sender, KeyEventArgs e)
  36. {
  37. if (e.KeyCode == Keys.Enter)
  38. {
  39. if (sncode.Text != "")
  40. {
  41. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out errorMessage))
  42. {
  43. if (sncode.Text.Length < 10)
  44. {
  45. OperateResult.AppendText(">>" + sncode.Text + "长度不足无法采集\n", Color.Red);
  46. ReCall_Click(this, e);
  47. return;
  48. }
  49. if (sncode.Text.Length > 100)
  50. {
  51. OperateResult.AppendText(">>" + sncode.Text + "长度超过50无法采集\n", Color.Red);
  52. ReCall_Click(this, e);
  53. return;
  54. }
  55. OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
  56. //如果用户没有输入工单号自行去后台查询
  57. //通过工单序列号关系验证
  58. //bsncode为空,就说明是输入转换之前的序列号
  59. if (bsncode == "")
  60. {
  61. if (!ChangeResult.Checked)
  62. {
  63. //用户填写了工单号,那么序列号必须要是该工单的,否则提示错误
  64. if (!LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out errorMessage))
  65. {
  66. OperateResult.AppendText("<<" + errorMessage + "\n", Color.Red, sncode);
  67. return;
  68. }
  69. if (dh.CheckExist("packagedetail", "pd_barcode = '" + sncode.Text + "' and pd_makecode = '" + oMakeCode + "'"))
  70. {
  71. OperateResult.AppendText("<<SN:" + sncode.Text + "已装箱,不可操作\n", Color.Red, sncode);
  72. return;
  73. }
  74. }
  75. else//勾选
  76. {
  77. oMsId = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode in (select '" + sncode.Text + "' from dual union select sn from makesnrelation where beforesn='" + sncode.Text + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + sncode.Text + "' and beforesn<>' ')").ToString();
  78. if (oMsId == "")
  79. {
  80. OperateResult.AppendText("<<TSN号错误\n", Color.Red, sncode);
  81. return;
  82. }
  83. //根据ms_id查询
  84. sql.Clear();
  85. sql.Append("select ms_stepcode,nvl(ms_downstatus,'0') ms_downstatus from makeserial where ms_id='" + oMsId + "' and ms_beforesn='" + sncode.Text + "' and ms_nextmacode is null and ms_outboxcode is null");
  86. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  87. //如果行数大于0则允许转号
  88. if (dt.Rows.Count > 0)
  89. {
  90. if (dt.Rows[0]["ms_downstatus"].ToString() != "0")
  91. {
  92. OperateResult.AppendText("<<当前TSN号处于下地状态不允许操作\n", Color.Red, sncode);
  93. return;
  94. }
  95. bsncode = sncode.Text;
  96. //显示序列号
  97. show_sncode.Text = bsncode;
  98. ChangeResult.Enabled = false;
  99. //if (dt.Rows[0]["ms_stepcode"].ToString() == User.CurrentStepCode)
  100. //{
  101. // bsncode = sncode.Text;
  102. // //显示序列号
  103. // show_sncode.Text = bsncode;
  104. // ChangeResult.Enabled = false;
  105. //}
  106. //else
  107. //{
  108. // OperateResult.AppendText("<<当前工序不允许重新转号\n", Color.Red, sncode);
  109. // return;
  110. //}
  111. }
  112. else
  113. {
  114. OperateResult.AppendText("<<TSN号" + sncode.Text + "未转号不允许重新转号\n", Color.Red, sncode);
  115. return;
  116. }
  117. }
  118. //如果用户没有选择工单号
  119. if (ma_code.Text == "" || ma_code.Text != oMakeCode || ChangeResult.Checked)
  120. {
  121. //按照out出的工单号查出工单相关信息,并赋值到相关控件
  122. sql.Clear();
  123. sql.Append("select ma_code,ma_softversion,ma_prodcode,pr_orispeccode pr_detail,ma_endremark,ma_salecode,ma_qty,ma_qty-mcd_inqty as remain_qty ");
  124. sql.Append("from makeserial left join make on ms_makecode=ma_code left join product on ");
  125. sql.Append("ms_prodcode=pr_code left join makecraftdetail_view on ms_makecode=mcd_macode where ms_id='" + oMsId + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  126. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  127. if (dt.Rows.Count > 0)
  128. {
  129. //记录数量
  130. ma_qty = int.Parse(dt.Rows[0]["ma_qty"].ToString());
  131. BaseUtil.SetFormValue(this.Controls, dt);
  132. }
  133. }
  134. //获取需要关联采集的信息,以及校验规则
  135. ListA = (DataTable)dh.ExecuteSql("select * from productsnrelation where psr_prodcode='" + ma_prodcode.Text + "' order by psr_detno", "select");
  136. //没有获取到就提示错误请维护产品对应的关联采集信息
  137. if (ListA.Rows.Count > 0)
  138. {
  139. OperateResult.AppendText("<<产品已维护关联采集信息,不允许只做转号\n", Color.Red, sncode);
  140. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  141. if (ChangeResult.Checked)
  142. {
  143. bsncode = "";
  144. ChangeResult.Enabled = true;
  145. show_sncode.Text = "";
  146. }
  147. return;
  148. }
  149. if (ChangeResult.Checked)
  150. {
  151. OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode);
  152. }
  153. switch (ChangeResult.CheckState)
  154. {
  155. //勾选是修改已转换的序列,矫正修改错了的序列号
  156. case CheckState.Checked:
  157. break;
  158. case CheckState.Unchecked:
  159. //string beforesn = dh.getFieldDataByCondition("makeserial", "ms_beforesn", "ms_sncode='" + sncode.Text + "'").ToString().Trim();
  160. //为空,就说明,没有进行过序列号的转换
  161. if (dh.CheckExist("makeserial", "ms_id='" + oMsId + "' and ms_sncode='" + sncode.Text + "' and ms_beforesn is null"))
  162. {
  163. //记录转换前的序列号
  164. bsncode = sncode.Text;
  165. //显示序列号
  166. show_sncode.Text = bsncode;
  167. OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode);
  168. ChangeResult.Enabled = false;
  169. }
  170. else
  171. //不为空,进行过转换。不勾选修改结果,就不能再修改
  172. {
  173. //修改转换结果时,输入两次SN直接过站
  174. if (dh.CheckExist("MakeSerial", "ms_id='" + oMsId + "' and ms_sncode='" + sncode.Text + "' and ms_beforesn is not null"))
  175. {
  176. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsId + "'").ToString();
  177. if (nextstepcode == User.CurrentStepCode)
  178. {
  179. bsncode = sncode.Text;
  180. //显示序列号
  181. show_sncode.Text = bsncode;
  182. OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode);
  183. ChangeResult.Enabled = false;
  184. onlyPass = true;
  185. }
  186. else
  187. {
  188. nextstepcode = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  189. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, sncode);
  190. OperateResult.AppendText(">>请重新输入TSN号\n", Color.Black);
  191. }
  192. }
  193. else
  194. {
  195. OperateResult.AppendText("<<序列号:" + sncode.Text + "已转换过\n", Color.Red, sncode);
  196. OperateResult.AppendText(">>请重新输入TSN号\n", Color.Black);
  197. }
  198. }
  199. break;
  200. default:
  201. break;
  202. }
  203. }
  204. //bsncode不为空,说明输入的是转换后的序列号
  205. else
  206. {
  207. ////判断工单是否导入了序列号清单
  208. //if (hasSnList)
  209. //{
  210. // if (!dh.CheckExist("makesnlist", "msl_sncode='" + sncode.Text + "' and msl_makecode='" + ma_code.Text + "' and msl_type='after'"))
  211. // {
  212. // //有序列号清单,输入的序列号却不在范围内
  213. // OperateResult.AppendText("<<SN号" + sncode.Text + "错误,不在工单设定的转换后序列号清单中\n", Color.Red, sncode);
  214. // return;
  215. // }
  216. //}
  217. //else if (hasMakeRule)//判断工单防呆
  218. //{
  219. // if (!dh.CheckExist("makesnruledetail", "msd_sncode='" + sncode.Text + "' and msd_makecode='" + ma_code.Text + "' and msd_type='after'"))
  220. // {
  221. // OperateResult.AppendText("<<SN号" + sncode.Text + "校验错误,不在工单防呆规则指定范围内!\n", Color.Red, sncode);
  222. // return;
  223. // }
  224. //}
  225. //else if (hasSaleRule)//判断合同防呆
  226. //{
  227. // if (!dh.CheckExist("makesnruledetail", "msd_sncode='" + sncode.Text + "' and msd_salecode='" + ma_salecode.Text + "' and msd_type='after'"))
  228. // {
  229. // OperateResult.AppendText("<<SN号" + sncode.Text + "校验错误,不在合同防呆规则指定范围内!\n", Color.Red, sncode);
  230. // return;
  231. // }
  232. //}
  233. //else//判断产品防呆
  234. //{
  235. //判断用户是否锁定输入转换后序列号长度,
  236. //if (!checkLengthOrPre(afterTransSNLength_checkBox, afterTransSNLength, "长度"))
  237. // return;
  238. //判断用户是否锁定输入转换后序列号前缀,
  239. if (!checkLengthOrPre(afterTransSNPre_checkBox, afterTransSNPre, "前缀"))
  240. return;
  241. //}
  242. //防呆验证完成
  243. if ((!ChangeResult.Checked && (!dh.CheckExist("makeserial", "ms_sncode='" + sncode.Text + "'")&& (!dh.CheckExist("makeserial", "ms_code='" + sncode.Text + "' ")) && !onlyPass )) || (ChangeResult.Checked && !dh.CheckExist("makeserial", "ms_sncode='" + sncode.Text + "' ")))
  244. {
  245. //if (CollectRemark.Checked || SameReamrk.Checked)
  246. //{
  247. // if (Remark.Text == "")
  248. // {
  249. // OperateResult.AppendText(">>备注栏信息为空,录入备注信息\n", Color.Black);
  250. // Remark.SelectAll();
  251. // Remark.Focus();
  252. // return;
  253. // }
  254. // if (IFONLY.Checked)
  255. // {
  256. // if (!CheckPre())
  257. // {
  258. // return;
  259. // }
  260. // string UsedSncode = dh.getFieldDataByCondition("SNRELATIONINFORECORD", "SIR_SNCODE", "sir_remark = '" + Remark.Text + "'").ToString();
  261. // if (UsedSncode != "")
  262. // {
  263. // OperateResult.AppendText(">>备注信息" + Remark.Text + "已被" + UsedSncode + "采集,不可重复采集\n", Color.Red);
  264. // Remark.SelectAll();
  265. // Remark.Focus();
  266. // return;
  267. // }
  268. // LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  269. // OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
  270. // if (CollectRemark.Checked)
  271. // {
  272. // Remark.Text = "";
  273. // }
  274. // }
  275. // else
  276. // {
  277. // if (!CheckPre())
  278. // {
  279. // return;
  280. // }
  281. // LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  282. // OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
  283. // if (CollectRemark.Checked)
  284. // {
  285. // Remark.Text = "";
  286. // }
  287. // }
  288. //}
  289. if (/*!ChangeResult.Checked && */!onlyPass)
  290. {
  291. string firstsn = "";
  292. string updateSql = "";
  293. //勾选了修改转换结果
  294. if (ChangeResult.Checked)
  295. {
  296. //查询ms_firstsn
  297. firstsn = dh.getFieldDataByCondition("makeserial", "ms_firstsn", "ms_id='" + oMsId + "' and ms_beforesn='" + bsncode + "'").ToString();
  298. //记录本次修改,存入makesnrelation表中
  299. updateSql = "update makeserial set ms_sncode='" + sncode.Text + "' where ms_id='" + oMsId + "' and ms_beforesn='" + bsncode + "'";
  300. //删除最近一条转换记录
  301. dh.ExecuteSql("delete from makesnrelation where BEFORESN='" + bsncode + "' and makecode='" + ma_code.Text + "'", "delete");
  302. }
  303. //未勾选修改转换结果
  304. else
  305. {
  306. //查询ms_firstsn
  307. firstsn = dh.getFieldDataByCondition("makeserial", "ms_firstsn", "ms_id='" + oMsId + "' and ms_sncode='" + bsncode + "'").ToString();
  308. //记录本次修改,存入makesnrelation表中
  309. updateSql = "update makeserial set ms_sncode='" + sncode.Text + "', ms_beforesn='" + bsncode + "' where ms_id='" + oMsId + "' and ms_sncode='" + bsncode + "'";
  310. }
  311. string insertSql = "insert into makesnrelation (BEFORESN,SN,FIRSTSN,MAKECODE,msr_indate, msr_inman)values('" + bsncode + "','" + sncode.Text + "','" + firstsn + "','" + ma_code.Text + "', sysdate ,'" + User.UserCode + "')";
  312. dh.ExecuteSQLTran(updateSql, insertSql);
  313. }
  314. onlyPass = false;
  315. OperateResult.AppendText("<<序列号" + bsncode + "成功转换为" + sncode.Text + "\n", Color.LawnGreen);
  316. //记录日志
  317. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "序列转换", bsncode + "转换为" + sncode.Text, sncode.Text, "");
  318. //if (CollectRemark.Checked && Remark.Text != "")
  319. //{
  320. // LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  321. //}
  322. LogManager.DoLog("修改序列号:" + bsncode + "为" + sncode.Text + "成功!" + "操作人:" + User.UserCode);
  323. //写入日志
  324. if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sncode.Text, "序列转换", "序列转换成功", User.UserCode, out errorMessage))
  325. {
  326. OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, sncode);
  327. }
  328. dh.ExecuteSql("update makeserial set ms_status = 2,ms_laststep = ms_nextstepcode,ms_nextstepcode = '' where ms_id = " + oMsId + " ", "update");
  329. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "完工采集", "完工采集成功", sncode.Text, oMsId);
  330. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  331. //置空
  332. bsncode = "";
  333. show_sncode.Text = "";
  334. //获取剩余数,刷新页面
  335. sql.Clear();
  336. sql.Append("select mcd_inqty from makecraftdetail_view where mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  337. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  338. if (dt.Rows.Count > 0)
  339. {
  340. BaseUtil.SetFormValue(this.Controls, dt);
  341. remain_qty.Text = ma_qty - int.Parse(dt.Rows[0]["mcd_inqty"].ToString()) + "";
  342. }
  343. //更新数量
  344. changenum.Text = int.Parse(changenum.Text) + 1 + "";
  345. ChangeResult.Enabled = true;
  346. }
  347. else
  348. {
  349. if (onlyPass)
  350. {
  351. OperateResult.AppendText("<<SN号" + sncode.Text + "错误,已完成转号只允许SN转SN\n", Color.Red);
  352. }
  353. else
  354. {
  355. OperateResult.AppendText("<<SN号" + sncode.Text + "已存在,请输入其他序列号\n", Color.Red);
  356. }
  357. ReCall_Click(this,e);
  358. }
  359. sncode.Text = "";
  360. }
  361. }
  362. else
  363. {
  364. OperateResult.AppendText("<<" + errorMessage + "\n", Color.Red, sncode);
  365. }
  366. }
  367. else
  368. {
  369. OperateResult.AppendText("<<序列号不能为空\n", Color.Red);
  370. }
  371. sncode.Text = "";
  372. }
  373. }
  374. private void Confirm_Click(object sender, EventArgs e)
  375. {
  376. KeyEventArgs ky = new KeyEventArgs(Keys.Enter);
  377. sncode_KeyDown(sender, ky);
  378. }
  379. private void ReCall_Click(object sender, EventArgs e)
  380. {
  381. bsncode = "";
  382. OperateResult.AppendText(">>请输入TSN号\n", Color.Black, show_sncode);
  383. ChangeResult.Enabled = true;
  384. onlyPass = false;
  385. }
  386. /// <summary>
  387. /// 工单号keydown
  388. /// </summary>
  389. /// <param name="sender"></param>
  390. /// <param name="e"></param>
  391. private void ms_makecode_KeyDown(object sender, KeyEventArgs e)
  392. {
  393. }
  394. /// <summary>
  395. /// 如果清空了工单号,或者更换了工单号则将 : 转换前序列号长度,转换前序列号前缀
  396. ///转换后序列号长度,转换后序列号前缀 四个字段值清空。
  397. /// </summary>
  398. /// <param name="sender"></param>
  399. /// <param name="e"></param>
  400. private void ms_makecode_UserControlTextChanged(object sender, EventArgs e)
  401. {
  402. hasSnList = false;
  403. hasMakeRule = false;
  404. hasSaleRule = false;
  405. //清空
  406. beforeTransSNPre.Text = "";
  407. beforeTransSNLength.Text = "";
  408. afterTransSNPre.Text = "";
  409. afterTransSNLength.Text = "";
  410. //取消勾选
  411. beforeTransSNPre_checkBox.Checked = false;
  412. beforeTransSNLength_checkBox.Checked = false;
  413. afterTransSNPre_checkBox.Checked = false;
  414. afterTransSNLength_checkBox.Checked = false;
  415. //设置可编辑
  416. beforeTransSNLength.Enabled = true;
  417. beforeTransSNPre.Enabled = true;
  418. afterTransSNLength.Enabled = true;
  419. afterTransSNPre.Enabled = true;
  420. beforeTransSNPre_checkBox.Enabled = true;
  421. beforeTransSNLength_checkBox.Enabled = true;
  422. afterTransSNPre_checkBox.Enabled = true;
  423. afterTransSNLength_checkBox.Enabled = true;
  424. //判断工单是否导入了序列号清单
  425. if (dh.CheckExist("makesnlist", "msl_makecode='" + ma_code.Text + "' and msl_type='after'"))
  426. {
  427. hasSnList = true;
  428. return;
  429. }
  430. //查询表工单序列号防呆规则表
  431. rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_makecode='" + ma_code.Text + "' and msr_type='after'", "select");
  432. if (rules.Rows.Count > 0)
  433. {
  434. hasMakeRule = true;
  435. }
  436. else
  437. {
  438. ma_salecode.Text = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code='" + ma_code.Text + "'").ToString();
  439. //查询表合同序列号防呆规则表
  440. rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_salecode='" + ma_salecode.Text + "' and msr_type='after'", "select");
  441. if (rules.Rows.Count > 0)
  442. {
  443. hasSaleRule = true;
  444. }
  445. else
  446. {
  447. /* 如果转换前没有值,则取 select productsnrule where psr_prodcode=? 产品编号,
  448. * 有值则赋值到 转换前,并且自动勾选不可编辑。*/
  449. 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");
  450. if (rules.Rows.Count > 0)
  451. {
  452. //将产品序列号防呆规则查出的数据填充
  453. if (rules.Rows[0]["psr_prefix"].ToString() != "")
  454. {
  455. afterTransSNPre.Text = rules.Rows[0]["psr_prefix"].ToString();
  456. afterTransSNPre.Enabled = false;
  457. afterTransSNPre_checkBox.Checked = true;
  458. afterTransSNPre_checkBox.Enabled = false;
  459. }
  460. //if (rules.Rows[0]["psr_length"].ToString() != "")
  461. //{
  462. // afterTransSNLength.Text = rules.Rows[0]["psr_length"].ToString();
  463. // afterTransSNLength.Enabled = false;
  464. // afterTransSNLength_checkBox.Checked = true;
  465. // afterTransSNLength_checkBox.Enabled = false;
  466. //}
  467. }
  468. }
  469. }
  470. }
  471. /// <summary>
  472. /// 检验长度或者前缀是否合法
  473. /// </summary>
  474. /// <param name="checkbox"></param>
  475. /// <param name="c"></param>
  476. /// <param name="info"></param>
  477. private bool checkLengthOrPre(CheckBox checkbox, TextBox textbox, string type)
  478. {
  479. if (checkbox.Checked == true)
  480. {
  481. //如果勾选没有填值
  482. if (textbox.Text == "")
  483. {
  484. OperateResult.AppendText("<<勾选长度或者前缀需要填写内容\n", Color.Red);
  485. return false;
  486. }
  487. if (type == "长度")
  488. {
  489. //则判断输入转换前的序列号长度是否合法,不合法则提示
  490. if (sncode.Text.Trim().Length != int.Parse(textbox.Text))
  491. {
  492. //序列号校验错误,长度错误
  493. OperateResult.AppendText("<<序列号" + sncode.Text + "校验错误,长度错误\n", Color.Red, sncode);
  494. OperateResult.AppendText(">>请重新输入SN号\n", Color.Black);
  495. return false;
  496. }
  497. }
  498. else if (type == "前缀")
  499. {
  500. string[] pres = textbox.Text.Split('|');
  501. bool f = false;
  502. for (int i = 0; i < pres.Length; i++)
  503. {
  504. if (pres[i] == "" ? true : sncode.Text.Contains(pres[i]))
  505. {
  506. //满足其中一条即可
  507. f = true;
  508. break;
  509. }
  510. }
  511. //则判断输入转换前的序列号前缀是否合法,不合法则提示
  512. if (!f)
  513. {
  514. //序列号校验错误,前缀错误
  515. OperateResult.AppendText("<<序列号" + sncode.Text + "校验错误,前缀错误\n", Color.Red, sncode);
  516. OperateResult.AppendText(">>请重新输入SN号\n", Color.Black);
  517. return false;
  518. }
  519. }
  520. return true;
  521. }
  522. return true;
  523. }
  524. private void ChangeResult_CheckedChanged(object sender, EventArgs e)
  525. {
  526. if (ChangeResult.Checked)
  527. {
  528. //勾选的时候提示输入TSN
  529. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  530. }
  531. }
  532. private void Make_SeqTransform_Load(object sender, EventArgs e)
  533. {
  534. asc.controllInitializeSize(this);
  535. dh = SystemInf.dh;
  536. sncode.Focus();
  537. OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
  538. StepCount.StepCode = User.CurrentStepCode;
  539. StepCount.Source = User.UserSourceCode;
  540. StepCount.LineCode = User.UserLineCode;
  541. StepCount.Dh = dh;
  542. StepCount.Start();
  543. Seq_Remark_PreFix.Text = BaseUtil.GetCacheData("Seq_Remark_PreFix").ToString();
  544. }
  545. private void Make_SeqTransform_SizeChanged(object sender, EventArgs e)
  546. {
  547. asc.controlAutoSize(this);
  548. }
  549. private void Remark_KeyDown(object sender, KeyEventArgs e)
  550. {
  551. if (e.KeyCode == Keys.Enter)
  552. {
  553. try
  554. {
  555. if ((CollectRemark.Checked || SameReamrk.Checked) && Remark.Text != "")
  556. {
  557. sncode.Enabled = true;
  558. sncode.Focus();
  559. sncode_KeyDown(this, new KeyEventArgs(Keys.Enter));
  560. }
  561. else
  562. {
  563. sncode.Enabled = true;
  564. sncode.Focus();
  565. }
  566. }
  567. catch
  568. {
  569. sncode.Enabled = true;
  570. sncode.Focus();
  571. }
  572. }
  573. }
  574. private void IFONLY_CheckedChanged(object sender, EventArgs e)
  575. {
  576. if (IFONLY.Checked)
  577. {
  578. SameReamrk.Checked = false;
  579. CollectRemark.Checked = true;
  580. }
  581. }
  582. private void SameReamrk_CheckedChanged(object sender, EventArgs e)
  583. {
  584. if (SameReamrk.Checked)
  585. {
  586. IFONLY.Checked = false;
  587. CollectRemark.Checked = false;
  588. }
  589. }
  590. private void Seq_Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  591. {
  592. if (e.KeyCode == Keys.Enter)
  593. {
  594. BaseUtil.SetCacheData("Seq_Remark_PreFix", Seq_Remark_PreFix.Text);
  595. if (CollectRemark.Checked || SameReamrk.Checked)
  596. {
  597. Remark.SelectAll();
  598. Remark.Focus();
  599. }
  600. }
  601. }
  602. //校验备注前缀
  603. private Boolean CheckPre()
  604. {
  605. try
  606. {
  607. if (Remark.Text.Substring(0, Seq_Remark_PreFix.Text.Length) != Seq_Remark_PreFix.Text)
  608. {
  609. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  610. Remark.SelectAll();
  611. Remark.Focus();
  612. return false;
  613. }
  614. }
  615. catch (Exception)
  616. {
  617. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  618. Remark.SelectAll();
  619. Remark.Focus();
  620. return false;
  621. }
  622. return true;
  623. }
  624. private void CollectRemark_CheckedChanged(object sender, EventArgs e)
  625. {
  626. if (CollectRemark.Checked)
  627. {
  628. SameReamrk.Checked = false;
  629. }
  630. }
  631. private void Remark_Leave(object sender, EventArgs e)
  632. {
  633. sncode.Enabled = true;
  634. }
  635. private void Remark_Enter(object sender, EventArgs e)
  636. {
  637. sncode.Enabled = false;
  638. }
  639. }
  640. }