Packing_PackageCollectionWeigh.cs 62 KB

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