Packing_PackageCollectionWeigh.cs 64 KB

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