Packing_PackageCollection.cs 62 KB

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