Packing_PackageCollectionZX.cs 69 KB

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