Packing_PackageCollection.cs 65 KB

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