Make_PackageCollectionWeigh.cs 59 KB

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