Packing_PackageCollectionWeigh.cs 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. using LabelManager2;
  2. using System;
  3. using System.Data;
  4. using System.Text;
  5. using System.Windows.Forms;
  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.Threading;
  11. using UAS_MES_NEW.PublicForm;
  12. using System.IO.Ports;
  13. using System.IO;
  14. using System.Text.RegularExpressions;
  15. using System.Collections.Generic;
  16. using Seagull.BarTender.Print;
  17. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  18. namespace UAS_MES_NEW.Packing
  19. {
  20. public partial class Packing_PackageCollectionWeigh : Form
  21. {
  22. DataHelper dh;
  23. DataTable dt;
  24. LogStringBuilder sql = new LogStringBuilder();
  25. AutoSizeFormClass asc = new AutoSizeFormClass();
  26. Document doc;
  27. Engine engine;
  28. Thread thread;
  29. DataTable Dbfind;
  30. string ErrorMessage = "";
  31. string oMakeCode = "";
  32. string oMsID = "";
  33. string oMsStatus = "";
  34. string PR_CHECKCARTONW = "0";
  35. //称量的标准重量
  36. double Weight;
  37. //最大重量
  38. double MaxWeight;
  39. //最小重量
  40. double MinWeight;
  41. string ActWeigh = "0";
  42. Regex re = new Regex("\\d+.\\d+[\\s\\S]+");
  43. decimal StandardQTY = 0;
  44. string oOutBoxCode = "";
  45. string LastSncode;
  46. //创建串口实例
  47. SerialPort serialPort1 = new SerialPort();
  48. //true的时候表示从串口读取数据
  49. bool GetData = true;
  50. public Packing_PackageCollectionWeigh()
  51. {
  52. InitializeComponent();
  53. // 与其他称重窗体保持一致:串口数据在子线程读取,需直接更新 weight/pa_remark 等控件
  54. CheckForIllegalCrossThreadCalls = false;
  55. }
  56. //创建打印进程
  57. private void NewPrint()
  58. {
  59. try
  60. {
  61. engine = new Engine(true);
  62. BaseUtil.WriteLbl();
  63. }
  64. catch (Exception ex)
  65. {
  66. OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
  67. }
  68. }
  69. private void Make_PackageCollectionWeigh_Load(object sender, EventArgs e)
  70. {
  71. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  72. Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  73. //设置DbFind的必须的数据
  74. PrintNum.Text = "1";
  75. asc.controllInitializeSize(this);
  76. thread = new Thread(NewPrint);
  77. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  78. BaseUtil.SetFormCenter(stw);
  79. stw.ShowDialog();
  80. try
  81. {
  82. OutBoxLength.Text = BaseUtil.GetCacheData("OutBoxLength").ToString();
  83. PreFix.Text = BaseUtil.GetCacheData("PreFix").ToString();
  84. Remark_PreFix.Text = BaseUtil.GetCacheData("Remark_PreFix").ToString();
  85. }
  86. catch (Exception) { }
  87. thread = new Thread(getSerialData);
  88. try
  89. {
  90. GetData = true;
  91. serialPort1.PortName = ComList.Text;
  92. serialPort1.BaudRate = int.Parse(Baurate.Text);
  93. // 设置读取超时,避免 ReadLine 在电子秤未发送换行符时无限阻塞导致界面假死
  94. serialPort1.ReadTimeout = 1000;
  95. serialPort1.Open();
  96. thread.Start();
  97. }
  98. catch (Exception mes)
  99. {
  100. if (Baurate.Text == "" || ComList.Text == "")
  101. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  102. else
  103. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  104. }
  105. sn_code.Focus();
  106. dh = SystemInf.dh;
  107. StepCount.StepCode = User.CurrentStepCode;
  108. StepCount.Source = User.UserSourceCode;
  109. StepCount.LineCode = User.UserLineCode;
  110. StepCount.Dh = dh;
  111. StepCount.Start();
  112. }
  113. private void getSerialData()
  114. {
  115. if (serialPort1.IsOpen)
  116. {
  117. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  118. {
  119. SystemInf.OpenPort.Add(serialPort1.PortName);
  120. try
  121. {
  122. while (GetData)
  123. {
  124. try
  125. {
  126. // 先把一行读出来,再更新UI,避免UI异常影响读取流程
  127. string line = serialPort1.ReadLine().Trim();
  128. if (line != "")
  129. {
  130. weight.Text = re.Match(line).Groups[0].Value;
  131. pa_remark.AppendText(weight.Text + "\n");
  132. }
  133. }
  134. // 读取超时属于正常现象(电子秤未持续发送数据),忽略后继续循环
  135. catch (TimeoutException)
  136. {
  137. continue;
  138. }
  139. // 其他异常(串口被拔出、底层IO错误等)才退出循环
  140. catch (Exception)
  141. {
  142. GetData = false;
  143. }
  144. }
  145. }
  146. catch (IOException ex) { MessageBox.Show(ex.Message); }
  147. }
  148. else
  149. MessageBox.Show("端口已被占用,请关闭其他窗口");
  150. }
  151. }
  152. private void Make_PackageCollectionWeigh_SizeChanged(object sender, EventArgs e)
  153. {
  154. asc.controlAutoSize(this);
  155. }
  156. private void Make_PackageCollectionWeigh_Activated(object sender, EventArgs e)
  157. {
  158. pa_outboxcode.Focus();
  159. }
  160. //刷新表单的数据的数据
  161. private void LoadData()
  162. {
  163. //加载表单数据
  164. string Err = "";
  165. sql.Clear();
  166. sql.Append("select pa_prodcode,pr_cartonmaxw,pa_salecode,pa_remark,pa_makecode,pr_cartonunit,pr_code,pr_cartonminw,pr_cartongw,pa_outboxcode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,");
  167. sql.Append("pa_status,pr_packrule,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_packageqty,nvl(pa_standardqty,0)pa_standardqty,nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pa_currentqty from package left join ");
  168. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  169. Err = "箱号";
  170. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  171. if (dt.Rows.Count > 0)
  172. {
  173. //重量的临时变量
  174. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  175. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  176. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  177. PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
  178. if (dt.Rows[0]["pa_salecode"].ToString() != "")
  179. {
  180. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  181. }
  182. if (PR_CHECKCARTONW != "0")
  183. checkweightlabel.Text = "需要检测重量";
  184. else
  185. checkweightlabel.Text = "不需检测重量";
  186. //赋值重量单位
  187. Weight = double.Parse(_weight == "" ? "0" : _weight);
  188. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  189. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  190. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  191. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  192. BaseUtil.SetFormValue(this.Controls, dt);
  193. if (pa_standardqty.Text != "0")
  194. pr_outboxinnerqty.Text = pa_standardqty.Text;
  195. if (Weight - MinWeight == MaxWeight - Weight)
  196. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  197. else
  198. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  199. }
  200. LoadCheckQTY();
  201. LoadCollectedNum();
  202. }
  203. private void LoadGridData()
  204. {
  205. //加载Grid数据
  206. dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pa_prodcode,pd_barcode,pd_innerqty,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  207. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  208. //更新界面的采集数量
  209. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  210. }
  211. private void Print_Click(object sender, EventArgs e)
  212. {
  213. if (PrintLabel.Items.Count != 0)
  214. {
  215. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  216. {
  217. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  218. //doc = lbl.Documents.Open(PrintLabel.Text);
  219. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  220. {
  221. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  222. }
  223. else
  224. {
  225. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  226. }
  227. if (PrintSecond.Checked)
  228. {
  229. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel1.Text, PrintLabel1.SelectedValue.ToString(), PrintList1.Text, pa_outboxcode.Text, int.Parse(PrintNum1.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  230. {
  231. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  232. }
  233. else
  234. {
  235. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  236. }
  237. }
  238. if (!AutoGenBoxCode.Checked)
  239. {
  240. pa_outboxcode.Focus();
  241. pa_outboxcode.SelectAll();
  242. }
  243. else
  244. {
  245. sn_code.Focus();
  246. sn_code.SelectAll();
  247. }
  248. }
  249. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  250. }
  251. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  252. }
  253. //加载工单信息和装箱明细信息
  254. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  255. {
  256. if (e.KeyCode == Keys.Enter)
  257. {
  258. if (CheckOutBoxLength())
  259. {
  260. LoadData();
  261. LoadGridData();
  262. sn_code.Focus();
  263. }
  264. }
  265. }
  266. //输入序列号的回车事件
  267. private void barcode_KeyDown(object sender, KeyEventArgs e)
  268. {
  269. //当用户输入回车键的时候
  270. if (e.KeyCode == Keys.Enter)
  271. {
  272. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  273. {
  274. string mssncode = "";
  275. //if (LogicHandler.GetInfoByMaterial(sn_code.Text, out mssncode, out ErrorMessage))
  276. //{
  277. // sn_code.Text = mssncode;
  278. //}
  279. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_craftcode,ms_prodcode from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  280. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
  281. {
  282. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  283. {
  284. oMsID = dt.Rows[0]["ms_id"].ToString();
  285. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  286. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  287. }
  288. if (oMsStatus == "2")
  289. {
  290. string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  291. string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  292. string craftstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id =cd_crid", "cd_stepcode", "cr_prodcode='" + prodcode + "' and cr_code='" + craftcode + "' and cd_stepcode='" + User.CurrentStepCode + "'").ToString();
  293. if (craftstepcode == "")
  294. {
  295. OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
  296. return;
  297. }
  298. }
  299. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  300. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  301. {
  302. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  303. OperateResult.AppendText("<<序列号:" + sn_code.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sn_code);
  304. return;
  305. }
  306. //PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  307. sql.Clear();
  308. sql.Append("select nvl(ms_iostatus,0) ms_iostatus,ms_outno,ms_salecode,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
  309. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  310. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  311. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  312. string ms_makecode = "";
  313. string ms_prodcode = "";
  314. string ms_iostatus = "";
  315. string ms_outno = "";
  316. string ms_salecode_text = "";
  317. if (dt.Rows.Count > 0)
  318. {
  319. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  320. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  321. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  322. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  323. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  324. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  325. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  326. {
  327. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  328. return;
  329. }
  330. BaseUtil.SetFormValue(this.Controls, dt);
  331. }
  332. if (dt.Rows[0]["ms_outno"].ToString() != "")
  333. {
  334. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  335. return;
  336. }
  337. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  338. {
  339. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  340. return;
  341. }
  342. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  343. {
  344. pr_outboxinnerqty.Text = pa_standardqty.Text;
  345. }
  346. if (pa_outboxcode.Text == "")
  347. {
  348. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  349. if (boxcode != "")
  350. {
  351. pa_outboxcode.Text = boxcode;
  352. LoadGridData();
  353. }
  354. else
  355. {
  356. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  357. {
  358. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  359. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  360. }
  361. }
  362. }
  363. if (pa_outboxcode.Text == "")
  364. {
  365. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  366. return;
  367. }
  368. //判断箱内总数必须大于0
  369. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  370. {
  371. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  372. return;
  373. }
  374. sql.Clear();
  375. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_mothercode from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  376. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  377. string MotherBoxCode = "";
  378. if (dt.Rows.Count > 0)
  379. {
  380. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  381. {
  382. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  383. }
  384. if (dt.Rows[0]["pa_outno"].ToString() != "")
  385. {
  386. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  387. return;
  388. }
  389. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  390. {
  391. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  392. return;
  393. }
  394. }
  395. //如果未勾选了取消录入
  396. if (!Cancel.Checked)
  397. {
  398. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  399. if (ms_outboxcode != "")
  400. {
  401. if (ms_outboxcode == pa_outboxcode.Text)
  402. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  403. else
  404. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  405. LoadData();
  406. }
  407. else
  408. {
  409. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  410. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  411. {
  412. pa_currentqty.Text = "";
  413. pa_outboxcode.Text = "";
  414. pa_status.Text = "0";
  415. BaseUtil.CleanDGVData(PackageDetail);
  416. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  417. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  418. }
  419. if (!CheckOutBoxLength(ms_salecode_text))
  420. {
  421. return;
  422. }
  423. ////箱号不存在的情况
  424. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  425. {
  426. //提示正确返回时传递的信息
  427. if (ErrorMessage.Contains("AFTERSUCCESS"))
  428. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  429. LoadCheckQTY();
  430. LoadCollectedNum();
  431. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  432. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
  433. LastSncode = sn_code.Text;
  434. //满箱更新状态为1
  435. LoadData();
  436. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  437. //如果母箱号不为空,需要更新总数
  438. if (MotherBoxCode != "")
  439. {
  440. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  441. if (dt.Rows.Count > 0)
  442. {
  443. if (dt.Rows[0]["pa_type"].ToString() == "2")
  444. {
  445. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  446. //更新大箱数量
  447. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  448. //外层有栈板则更新栈板数量
  449. if (MotherCode2 != "")
  450. {
  451. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  452. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  453. }
  454. }
  455. if (dt.Rows[0]["pa_type"].ToString() == "3")
  456. {
  457. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  458. }
  459. }
  460. }
  461. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  462. if (pa_currentqty.Text == "1")
  463. {
  464. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  465. }
  466. LoadGridData();
  467. sn_code.Clear();
  468. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  469. {
  470. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Replace("g", "").Trim();
  471. float weigh = float.Parse(ActWeigh);
  472. if (PR_CHECKCARTONW != "0")
  473. {
  474. if (MinWeight == 0 || MaxWeight == 0)
  475. {
  476. OperateResult.AppendText(">>产品" + pr_code.Text + "未维护卡通箱重量范围\n", Color.Red);
  477. return;
  478. }
  479. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  480. {
  481. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  482. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  483. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  484. return;
  485. }
  486. }
  487. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  488. pa_standardqty.Text = "";
  489. pa_status.Text = "1";
  490. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
  491. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  492. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  493. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  494. {
  495. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  496. }
  497. else
  498. {
  499. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  500. }
  501. LoadCheckQTY();
  502. LoadCollectedNum();
  503. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量完成\n", Color.Green);
  504. if (AutoPrint.Checked)
  505. Print_Click(new object(), new EventArgs());
  506. if (!CollecRemark.Checked)
  507. {
  508. if (!AutoGenBoxCode.Checked)
  509. {
  510. pa_outboxcode.Focus();
  511. pa_outboxcode.SelectAll();
  512. }
  513. else
  514. {
  515. sn_code.Focus();
  516. sn_code.SelectAll();
  517. }
  518. }
  519. else
  520. {
  521. pa_remark.SelectAll();
  522. pa_remark.Focus();
  523. }
  524. }
  525. }
  526. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  527. }
  528. }
  529. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  530. else
  531. {
  532. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  533. {
  534. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  535. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  536. //如果母箱号不为空,需要更新总数
  537. if (MotherBoxCode != "")
  538. {
  539. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  540. if (dt.Rows.Count > 0)
  541. {
  542. if (dt.Rows[0]["pa_type"].ToString() == "2")
  543. {
  544. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  545. //更新大箱数量
  546. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  547. //外层有栈板则更新栈板数量
  548. if (MotherCode2 != "")
  549. {
  550. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  551. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  552. }
  553. }
  554. if (dt.Rows[0]["pa_type"].ToString() == "3")
  555. {
  556. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  557. }
  558. }
  559. }
  560. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  561. LoadGridData();
  562. pa_status.Text = "0";
  563. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  564. }
  565. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  566. }
  567. }
  568. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  569. }
  570. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  571. }
  572. }
  573. private void Clean_Click(object sender, EventArgs e)
  574. {
  575. OperateResult.Clear();
  576. }
  577. private void pr_code_TextChanged(object sender, EventArgs e)
  578. {
  579. LoadCheckQTY();
  580. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  581. if (_dt.Rows.Count == 0)
  582. {
  583. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  584. }
  585. if (_dt.Rows.Count > 0)
  586. {
  587. string la_id = _dt.Rows[0]["la_id"].ToString();
  588. _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_id='" + la_id + "') where COLUMN_VALUE is not null)", "select");
  589. PrintLabel.DataSource = _dt;
  590. PrintLabel.DisplayMember = "la_url";
  591. PrintLabel.ValueMember = "la_id";
  592. PrintLabel1.DataSource = _dt.Copy();
  593. PrintLabel1.DisplayMember = "la_url";
  594. PrintLabel1.ValueMember = "la_id";
  595. }
  596. }
  597. private void Make_PackageCollectionWeigh_FormClosing(object sender, FormClosingEventArgs e)
  598. {
  599. // 先通知读取线程停止,再关闭串口,避免线程阻塞在ReadLine上
  600. GetData = false;
  601. try
  602. {
  603. if (serialPort1.IsOpen)
  604. {
  605. serialPort1.Close();
  606. SystemInf.OpenPort.Remove(serialPort1.PortName);
  607. }
  608. }
  609. catch (Exception) { }
  610. try
  611. {
  612. if (thread != null && thread.IsAlive)
  613. thread.Interrupt();
  614. }
  615. catch (Exception) { }
  616. //thread.Abort();
  617. }
  618. private void Packing_Click(object sender, EventArgs e)
  619. {
  620. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  621. {
  622. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  623. if (Seal == "Yes")
  624. {
  625. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Replace("g", "").Trim();
  626. float weigh = float.Parse(ActWeigh);
  627. if (PR_CHECKCARTONW != "0" && pa_standardqty.Text == pa_currentqty.Text)
  628. {
  629. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  630. {
  631. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量,不能完成工序过站\n", Color.Red);
  632. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  633. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  634. return;
  635. }
  636. }
  637. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  638. pa_status.Text = "1";
  639. pa_standardqty.Text = "";
  640. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "封箱成功", pa_outboxcode.Text, "");
  641. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  642. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  643. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  644. string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  645. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  646. {
  647. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  648. }
  649. else
  650. {
  651. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  652. }
  653. LoadCheckQTY();
  654. if (!CollecRemark.Checked)
  655. {
  656. if (!AutoGenBoxCode.Checked)
  657. {
  658. pa_outboxcode.Focus();
  659. pa_outboxcode.SelectAll();
  660. }
  661. else
  662. {
  663. sn_code.Focus();
  664. sn_code.SelectAll();
  665. }
  666. }
  667. else
  668. {
  669. pa_remark.SelectAll();
  670. pa_remark.Focus();
  671. }
  672. }
  673. }
  674. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  675. }
  676. private void SendCheck_Click(object sender, EventArgs e)
  677. {
  678. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  679. {
  680. DataTable dt = (DataTable)dh.ExecuteSql("select wm_concat(pa_outboxcode) pa_outboxcode from package where pa_checkno='" + ob_checkno.Text + "' and pa_status=0 ", "select");
  681. if (dt.Rows[0][0].ToString() != "")
  682. {
  683. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  684. return;
  685. }
  686. sql.Clear();
  687. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  688. dh.ExecuteSql(sql.GetString(), "select");
  689. ob_nowcheckqty.Text = "";
  690. ob_batchqty.Text = "";
  691. ob_nowcheckqty.ForeColor = Color.Black;
  692. SendCheck.Enabled = false;
  693. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  694. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  695. //记录操作日志
  696. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  697. ob_checkno.Text = "";
  698. }
  699. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  700. }
  701. bool AutoCut;
  702. private void LoadCheckQTY()
  703. {
  704. sql.Clear();
  705. string condition = "";
  706. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  707. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  708. if (nowcheckqty + 1 == batchqty && AutoCut)
  709. {
  710. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  711. }
  712. else
  713. {
  714. condition = "and ob_status='ENTERING' ";
  715. }
  716. if (pr_sendchecktype.Text == "SaleCode")
  717. {
  718. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  719. }
  720. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  721. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  722. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  723. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  724. if (dt.Rows.Count > 0)
  725. {
  726. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  727. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  728. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  729. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  730. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  731. if (nowcheckqty >= batchqty)
  732. {
  733. ob_nowcheckqty.ForeColor = Color.Red;
  734. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  735. if (AutoCut)
  736. {
  737. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  738. }
  739. }
  740. }
  741. else
  742. {
  743. ob_batchqty.Text = "";
  744. ob_nowcheckqty.Text = "";
  745. ob_checkno.Text = "";
  746. SendCheck.Enabled = false;
  747. }
  748. if (ob_batchqty.Text != "")
  749. {
  750. SendCheck.Enabled = true;
  751. }
  752. else
  753. {
  754. SendCheck.Enabled = false;
  755. }
  756. }
  757. private void ob_checkno_TextChanged(object sender, EventArgs e)
  758. {
  759. if (ob_checkno.Text != "")
  760. {
  761. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  762. if (Cut == "" || Cut == "0")
  763. AutoCut = false;
  764. else
  765. AutoCut = true;
  766. SendCheck.Enabled = true;
  767. }
  768. }
  769. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  770. {
  771. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  772. {
  773. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  774. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  775. }
  776. }
  777. private void DeleteAll_Click(object sender, EventArgs e)
  778. {
  779. if (pa_outboxcode.Text == "")
  780. {
  781. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  782. return;
  783. }
  784. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  785. if (Delete == "Yes")
  786. {
  787. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_checkno,ob_status,pa_mothercode,nvl(pa_downstatus,0)pa_downstatus from package left join oqcbatch on pa_checkno=ob_checkno where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  788. if (dt.Rows.Count > 0)
  789. {
  790. if (dt.Rows[0]["pa_outno"].ToString() != "")
  791. {
  792. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  793. return;
  794. }
  795. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  796. {
  797. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  798. return;
  799. }
  800. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  801. {
  802. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  803. {
  804. string ob_status = dt.Rows[0]["ob_status"].ToString();
  805. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  806. //不存在抽检批次或者还未检验可以拆解
  807. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  808. {
  809. sql.Clear();
  810. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  811. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  812. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  813. List<string> SQLS1 = new List<string>();
  814. for (int i = 0; i < dt.Rows.Count; i++)
  815. {
  816. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  817. string num = dt.Rows[i]["num"].ToString();
  818. SQLS1.Add("delete from makeprocess where mp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and mp_makecode='" + ma_code + "' and mp_stepcode='" + User.CurrentStepCode + "'");
  819. SQLS1.Add("delete from steppassed where sp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and sp_makecode='" + ma_code + "' and sp_stepcode='" + User.CurrentStepCode + "'");
  820. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-" + num + ",mcd_outqty=mcd_outqty-" + num + ",mcd_okqty=mcd_okqty-" + num + " where mcd_macode='" + ma_code + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  821. //扣减已完工数
  822. SQLS1.Add("update make set ma_endqty=ma_endqty-(select count(1) from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "' and ms_status=2) where ma_code='" + ma_code + "'");
  823. }
  824. if (pa_checkno != "")
  825. {
  826. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  827. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-(select count(1) from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "') where ob_checkno='" + pa_checkno + "'");
  828. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  829. }
  830. //更新序列号状态
  831. SQLS1.Add("update makeserial set ms_status=1,ms_outboxcode='',ms_nextstepcode= (case when ms_nextstepcode='" + User.CurrentStepCode + "' then ms_nextstepcode else ms_stepcode end ),ms_paststep=replace(ms_paststep,'," + User.CurrentStepCode + "','') where ms_outboxcode='" + pa_outboxcode.Text + "'");
  832. //抽检批次不为空的时候进行移除
  833. dh.ExecuteSQLTran(SQLS1.ToArray());
  834. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  835. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  836. if (standqty != "")
  837. {
  838. //置空原箱
  839. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0,PA_STANDARDQTY = '" + standqty + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  840. }
  841. else
  842. //置空原箱
  843. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  844. pa_status.Text = "0";
  845. //删除箱的明细
  846. dh.ExecuteSql("delete from labelprintlog where lpl_value='" + pa_outboxcode.Text + "'", "delete");
  847. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'", "delete");
  848. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  849. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  850. LoadGridData();
  851. LoadCheckQTY();
  852. }
  853. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  854. }
  855. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  856. }
  857. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  858. }
  859. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  860. }
  861. }
  862. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  863. {
  864. if (e.KeyCode == Keys.Enter)
  865. {
  866. try
  867. {
  868. if (OutBoxLength.Text != "")
  869. {
  870. int.Parse(OutBoxLength.Text);
  871. }
  872. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  873. if (!AutoGenBoxCode.Checked)
  874. {
  875. pa_outboxcode.Focus();
  876. pa_outboxcode.SelectAll();
  877. }
  878. else
  879. {
  880. sn_code.Focus();
  881. }
  882. }
  883. catch (Exception)
  884. {
  885. OutBoxLength.Clear();
  886. MessageBox.Show("请输入正确的长度");
  887. }
  888. }
  889. }
  890. private bool CheckOutBoxLength()
  891. {
  892. //勾选了检验长度进行校验
  893. if (OutBoxLength.Text != "")
  894. {
  895. try
  896. {
  897. int.Parse(OutBoxLength.Text);
  898. }
  899. catch (Exception)
  900. {
  901. MessageBox.Show("请填写正确的箱号长度");
  902. return false;
  903. }
  904. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  905. {
  906. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  907. return false;
  908. }
  909. }
  910. if (PreFix.Text != "")
  911. {
  912. try
  913. {
  914. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  915. {
  916. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  917. return false;
  918. }
  919. }
  920. catch (Exception)
  921. {
  922. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  923. return false;
  924. }
  925. }
  926. return true;
  927. }
  928. private void RefreshWeigh_Click(object sender, EventArgs e)
  929. {
  930. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  931. sql.Clear();
  932. sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + prcode + "'");
  933. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  934. if (dt.Rows.Count > 0)
  935. {
  936. //重量的临时变量
  937. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  938. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  939. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  940. Weight = double.Parse(_weight == "" ? "0" : _weight);
  941. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  942. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  943. if (Weight - MinWeight == MaxWeight - Weight)
  944. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  945. else
  946. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  947. }
  948. }
  949. private void LoadCollectedNum()
  950. {
  951. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  952. BaseUtil.SetFormValue(Controls, dt);
  953. }
  954. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  955. {
  956. if (Keys.Enter == e.KeyCode)
  957. {
  958. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  959. {
  960. if (Remark_PreFix.Text != "")
  961. {
  962. try
  963. {
  964. if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
  965. {
  966. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  967. return;
  968. }
  969. }
  970. catch (Exception)
  971. {
  972. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  973. return;
  974. }
  975. }
  976. if (!AllowRepeat.Checked)
  977. {
  978. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  979. if (dt.Rows.Count > 0)
  980. {
  981. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  982. return;
  983. }
  984. }
  985. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  986. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  987. pa_remark.Text = "";
  988. if (!AutoGenBoxCode.Checked)
  989. {
  990. pa_outboxcode.SelectAll();
  991. pa_outboxcode.Focus();
  992. }
  993. else
  994. {
  995. sn_code.Focus();
  996. }
  997. }
  998. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  999. }
  1000. }
  1001. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  1002. {
  1003. if (e.KeyCode == Keys.Enter)
  1004. {
  1005. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1006. if (!AutoGenBoxCode.Checked)
  1007. {
  1008. pa_outboxcode.Focus();
  1009. pa_outboxcode.SelectAll();
  1010. }
  1011. else
  1012. {
  1013. sn_code.Focus();
  1014. }
  1015. }
  1016. }
  1017. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  1018. {
  1019. if (e.KeyCode == Keys.Enter)
  1020. {
  1021. BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
  1022. if (CollecRemark.Checked)
  1023. {
  1024. pa_remark.SelectAll();
  1025. pa_remark.Focus();
  1026. }
  1027. }
  1028. }
  1029. private bool CheckOutBoxLength(string ms_salecode_text)
  1030. {
  1031. if (AutoGenBoxCode.Checked)
  1032. {
  1033. if (ms_salecode_text != "")
  1034. {
  1035. DataTable dt = (DataTable)dh.ExecuteSql(" select pn_number,pn_id,pn_caller,pn_numberlength,pn_leadcode from PACKAGENUMBER where pn_caller='" + ms_salecode_text + "'", "select");
  1036. if (dt.Rows.Count > 0)
  1037. {
  1038. string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
  1039. int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
  1040. if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
  1041. {
  1042. OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
  1043. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  1044. }
  1045. if (PreFix.Text != pn_leadcode)
  1046. {
  1047. PreFix.Text = pn_leadcode;
  1048. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1049. }
  1050. }
  1051. else
  1052. {
  1053. OperateResult.AppendText(">>订单号" + ms_salecode_text + "未维护箱号规则\n", Color.Black);
  1054. }
  1055. }
  1056. return true;
  1057. }
  1058. return CheckOutBoxLength();
  1059. }
  1060. private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
  1061. {
  1062. if (AutoGenBoxCode.Checked)
  1063. {
  1064. OutBoxLength.Enabled = false;
  1065. PreFix.Enabled = false;
  1066. pa_outboxcode.Enabled = false;
  1067. }
  1068. else
  1069. {
  1070. OutBoxLength.Enabled = true;
  1071. PreFix.Enabled = true;
  1072. pa_outboxcode.Enabled = true;
  1073. }
  1074. }
  1075. }
  1076. }