Packing_PackageCollection.cs 63 KB

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