Packing_PalletWightCollection.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. using LabelManager2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.IO.Ports;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicForm;
  13. using UAS_MES_NEW.PublicMethod;
  14. using UAS_MES_NEW.Packing;
  15. using Seagull.BarTender.Print;
  16. using System.Net.Sockets;
  17. using System.Net;
  18. using System.Text.RegularExpressions;
  19. using HslCommunication.Profinet.Knx;
  20. namespace UAS_MES_NEW.Packing
  21. {
  22. public partial class Packing_PalletWightCollection : Form
  23. {
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. DataTable dt;
  27. LogStringBuilder sql = new LogStringBuilder();
  28. Packing_NewPallet NewPallet;
  29. //称量的标准重量
  30. Double Weight;
  31. //最大重量
  32. Double MaxWeight;
  33. //最小重量
  34. Double MinWeight;
  35. //true的时候表示从串口读取数据
  36. bool GetData = true;
  37. string pa_nextstep = "";
  38. //箱类型
  39. string pa_type;
  40. //Package表的主键
  41. string pa_id;
  42. string PR_CHECKCARTONW = "0";
  43. Engine engine;
  44. Thread InitPrint;
  45. Thread thread;
  46. string ErrorMessage = "";
  47. //创建串口实例
  48. SerialPort serialPort1 = new SerialPort();
  49. public Packing_PalletWightCollection()
  50. {
  51. InitializeComponent();
  52. }
  53. //创建打印进程
  54. private void InPrint()
  55. {
  56. try
  57. {
  58. engine = new Engine(true);
  59. BaseUtil.WriteLbl();
  60. }
  61. catch
  62. {
  63. OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
  64. }
  65. }
  66. private void Make_PalletCollection_Load(object sender, EventArgs e)
  67. {
  68. asc.controllInitializeSize(this);
  69. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  70. BaudRate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  71. InitPrint = new Thread(InPrint);
  72. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  73. BaseUtil.SetFormCenter(stw);
  74. stw.ShowDialog();
  75. OutBoxLength.Text = BaseUtil.GetCacheData("PalletLength").ToString();
  76. PalletPreFix.Text = BaseUtil.GetCacheData("PalletPreFix").ToString();
  77. StartWeight.PerformClick();
  78. dh = SystemInf.dh;
  79. StepCount.StepCode = User.CurrentStepCode;
  80. StepCount.Source = User.UserSourceCode;
  81. StepCount.LineCode = User.UserLineCode;
  82. StepCount.Dh = dh;
  83. StepCount.Start();
  84. }
  85. private void Clean_Click(object sender, EventArgs e)
  86. {
  87. OperateResult.Clear();
  88. }
  89. private void palletcode_KeyDown(object sender, KeyEventArgs e)
  90. {
  91. if (e.KeyCode == Keys.Enter)
  92. {
  93. LoadGridData();
  94. sql.Clear();
  95. sql.Append("select pa_width,pa_length,pa_heigth,pa_makecode,pa_id,pa_status,nvl(pa_standardqty,PR_PALLETQTY)pa_standardqty,pa_prodcode,pa_packageqty,pa_totalqty,pa_salecode,pa_currentqty,pr_code pa_prodcode,pa_outboxcode,pa_totalqty,pa_custcode ");
  96. sql.Append("from package left join packagedetail on pa_id =pd_paid left join product on pr_code=pd_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type =3");
  97. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  98. if (dt.Rows.Count > 0)
  99. {
  100. BaseUtil.SetFormValue(Controls, dt);
  101. pa_id = dt.Rows[0]["pa_id"].ToString();
  102. }
  103. if (CheckOutBoxLength())
  104. {
  105. if (pa_standardqty.Text == "")
  106. pa_standardqty.Focus();
  107. else
  108. outboxcode.Focus();
  109. }
  110. }
  111. }
  112. //箱号Enter事件
  113. private void outboxcode_KeyDown(object sender, KeyEventArgs e)
  114. {
  115. if (e.KeyCode == Keys.Enter)
  116. {
  117. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  118. {
  119. if (outboxcode.Text == "")
  120. {
  121. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  122. return;
  123. }
  124. //如果使用的是序列号
  125. DataTable dt = (DataTable)dh.ExecuteSql("select ms_outboxcode from makeserial where ms_sncode='" + outboxcode.Text + "'", "select");
  126. if (dt.Rows.Count > 0)
  127. {
  128. outboxcode.Text = dt.Rows[0]["ms_outboxcode"].ToString();
  129. }
  130. //根据箱号查询表单数据
  131. sql.Clear();
  132. sql.Append("select pr_palletminweight,pr_palletmaxweight,pa_totalqty,ma_code,ma_qty,ma_salecode,pa_prodcode,PA_STANDARDQTY PA_STANDARDQTYCARTON,PA_CURRENTQTY,pr_detail,pr_cartonunit,pr_code,pr_palletweight,");
  133. sql.Append("pr_cartonmaxw,pr_cartonminw,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from package left join packagedetail ");
  134. sql.Append("on pa_id=pd_paid left join makeserial on ms_sncode=pd_barcode and ms_makecode=pa_makecode left join product on pr_code=pd_prodcode left join make on ma_code=pd_makecode ");
  135. sql.Append(" where pa_outboxcode='" + outboxcode.Text + "' and pa_nextstep='" + User.CurrentStepCode + "'");
  136. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  137. //填充打印文件选项的DataGridView
  138. if (dt.Rows.Count > 0)
  139. {
  140. BaseUtil.SetFormValue(this.Controls, dt);
  141. string ErrorMessage;
  142. //重量的临时变量
  143. PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
  144. string _weight = dt.Rows[0]["pr_palletweight"].ToString();
  145. string _maxweight = dt.Rows[0]["pr_palletmaxweight"].ToString();
  146. string _minweight = dt.Rows[0]["pr_palletminweight"].ToString();
  147. string pa_pr_cartonunit = dt.Rows[0]["pr_cartonunit"].ToString();
  148. string PA_STANDARDQTY = dt.Rows[0]["PA_STANDARDQTYCARTON"].ToString();
  149. string PA_CURRENTQTY = dt.Rows[0]["PA_CURRENTQTY"].ToString();
  150. Weight = double.Parse(_weight == "" ? "0" : _weight);
  151. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  152. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  153. if (Weight - MinWeight == MaxWeight - Weight)
  154. pr_palletweight.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  155. else
  156. pr_palletweight.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  157. double ActualWeight = double.Parse(weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim());
  158. //需要检查称重重量
  159. if (PA_STANDARDQTY == PA_CURRENTQTY)
  160. {
  161. //称量合格或不合格都记录重量
  162. if (ActualWeight >= MinWeight && ActualWeight <= MaxWeight && ActualWeight != 0)
  163. {
  164. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量合格:" + weight.Text.Trim(), outboxcode.Text, "");
  165. LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  166. OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测合格\n", Color.Green);
  167. }
  168. else
  169. {
  170. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不合格:" + weight.Text.Trim(), outboxcode.Text, "");
  171. LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  172. OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测未通过\n", Color.Red, outboxcode);
  173. return;
  174. }
  175. }
  176. else
  177. {
  178. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), outboxcode.Text, "");
  179. LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  180. }
  181. OperateResult.AppendText(">>箱号" + outboxcode.Text + "称重完成\n", Color.Green);
  182. if (LogicHandler.CartonBoxStepPass(ma_code.Text, User.UserSourceCode, outboxcode.Text, User.UserCode, "卡通箱:" + outboxcode.Text + "整箱过站", out ErrorMessage))
  183. {
  184. dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode.Text + "'");
  185. 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='" + outboxcode.Text + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode.Text + "'");
  186. }
  187. else
  188. {
  189. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  190. }
  191. }
  192. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "当前执行工序不是" + User.CurrentStepCode + "\n", Color.Black);
  193. sql.Clear();
  194. sql.Append("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_makecode pd_makecode,nvl(pa_downstatus,0)pa_downstatus,pa_salecode pd_salecode,pr_packrule,pa_id,pa_prodcode pd_prodcode,pa_status,pa_mothercode,pa_nextstep ");
  195. sql.Append("from packagedetail left join package on pd_paid=pa_id left join product on pd_prodcode=pr_code where pd_outboxcode='" + outboxcode.Text + "'");
  196. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  197. if (dt.Rows.Count > 0)
  198. {
  199. BaseUtil.SetFormValue(this.Controls, dt);
  200. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  201. {
  202. OperateResult.AppendText(">>箱号" + outboxcode.Text + "下地状态不允许采集\n", Color.Red, outboxcode);
  203. return;
  204. }
  205. if (dt.Rows[0]["pa_outno"].ToString() != "")
  206. {
  207. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  208. return;
  209. }
  210. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  211. {
  212. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已入库不允许采集\n", Color.Red, outboxcode);
  213. return;
  214. }
  215. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  216. {
  217. if (pa_outboxcode.Text == "")
  218. {
  219. pa_outboxcode.Text = dt.Rows[0]["pa_mothercode"].ToString();
  220. palletcode_KeyDown(sender, e);
  221. }
  222. }
  223. string unfinpack = dh.getFieldDataByCondition("Line", "nvl(li_allowUnFinPack,0)", "li_code='" + User.UserLineCode + "'").ToString();
  224. pa_nextstep = dt.Rows[0]["pa_nextstep"].ToString();
  225. if (pa_nextstep != User.CurrentStepCode && pa_nextstep != "" && (unfinpack == "0" || unfinpack == ""))
  226. {
  227. OperateResult.AppendText(">>箱号" + outboxcode.Text + "的下一工序不是当前岗位资源对应工序\n", Color.Red, outboxcode);
  228. return;
  229. }
  230. sql.Clear();
  231. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  232. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  233. if (dt.Rows.Count > 0)
  234. {
  235. if (dt.Rows[0]["pa_outno"].ToString() != "")
  236. {
  237. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  238. return;
  239. }
  240. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  241. {
  242. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  243. return;
  244. }
  245. }
  246. //为空表示线外
  247. if (pa_nextstep == "")
  248. {
  249. //判断线外,必须已完工并且未入库
  250. dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view left join makeserial on v_barcode=ms_sncode where v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select");
  251. if (dt.Rows[0][0].ToString() != "" && (unfinpack != "0" || unfinpack == ""))
  252. {
  253. OperateResult.AppendText(">>序列号" + dt.Rows[0][0].ToString() + "尚未完工\n", Color.Red);
  254. return;
  255. }
  256. }
  257. }
  258. else
  259. {
  260. OperateResult.AppendText(">>箱号" + outboxcode.Text + "未采集内容或不存在,不允许装栈板\n", Color.Red, outboxcode);
  261. return;
  262. }
  263. if (!Cancel.Checked)
  264. {
  265. pa_status.Text = dh.getFieldDataByCondition("package", "nvl(pa_status,0)pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  266. if (pa_outboxcode.Text == "" && AutoOutBoxCode.Checked)
  267. {
  268. //箱已采集满并且未勾选自动生成
  269. if (pa_standardqty.Text == pa_totalqty.Text && !AutoOutBoxCode.Checked)
  270. {
  271. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已采集满\n", Color.Red, outboxcode);
  272. return;
  273. }
  274. else
  275. {
  276. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", pa_makecode.Text, pa_prodcode.Text, User.UserCode);
  277. }
  278. }
  279. else if (pa_outboxcode.Text != "" && pa_status.Text == "1" && AutoOutBoxCode.Checked)
  280. {
  281. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", pa_makecode.Text, pa_prodcode.Text, User.UserCode);
  282. }
  283. else if (pa_outboxcode.Text == "")
  284. {
  285. OperateResult.AppendText(">>栈板号不能为空\n", Color.Red);
  286. return;
  287. }
  288. if (!CheckOutBoxLength())
  289. {
  290. return;
  291. }
  292. dt = (DataTable)dh.ExecuteSql("select pa_id from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  293. if (dt.Rows.Count == 0)
  294. {
  295. pa_id = dh.GetSEQ("package_seq");
  296. sql.Clear();
  297. sql.Append("insert into package (pa_id,pa_outboxcode,PA_STANDARDQTY,pa_makecode,pa_indate,pa_packageqty,pa_type,pa_prodcode,pa_level,PA_STATUS,pa_sccode,pa_currentstep,pa_salecode)values");
  298. sql.Append("(" + pa_id + ",'" + pa_outboxcode.Text + "','" + pa_standardqty.Text + "','" + pd_makecode.Text + "',sysdate,'0',3,'" + pd_prodcode.Text + "',0,0,'" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + pd_salecode.Text + "')");
  299. dh.ExecuteSql(sql.GetString(), "insert");
  300. }
  301. else
  302. {
  303. pa_id = dt.Rows[0]["pa_id"].ToString();
  304. }
  305. palletcode_KeyDown(sender, e);
  306. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) > 0)
  307. {
  308. if (!LogicHandler.CheckPackRule(pr_packrule.Text, pa_outboxcode.Text, outboxcode.Text, pa_makecode.Text, pa_salecode.Text, pa_prodcode.Text, "栈板", out ErrorMessage))
  309. {
  310. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, outboxcode);
  311. return;
  312. }
  313. }
  314. dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_mothercode,nvl(pa_status,0) pa_status from package where pa_outboxcode='" + outboxcode.Text + "'", "select");
  315. if (dt.Rows.Count > 0)
  316. {
  317. //判断是否已经装箱
  318. int sonboxtotalqty = int.Parse(dt.Rows[0]["pa_totalqty"].ToString());
  319. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  320. {
  321. if (dt.Rows[0]["pa_status"].ToString() == "1")
  322. {
  323. pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  324. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) + sonboxtotalqty > int.Parse(pa_standardqty.Text == "" ? "0" : pa_standardqty.Text))
  325. {
  326. OperateResult.AppendText(">>采集箱号" + outboxcode.Text + "后超出容量\n", Color.Red, outboxcode);
  327. return;
  328. }
  329. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) == 0)
  330. {
  331. dh.ExecuteSql("update package set pa_prodcode='" + pd_prodcode.Text + "',pa_salecode='" + pd_salecode.Text + "',pa_makecode='" + pd_makecode.Text + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  332. }
  333. List<string> SQLS = new List<string>();
  334. sql.Clear();
  335. sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_makecode,pd_prodcode,pd_innerboxcode, pd_innerqty,pd_builddate)");
  336. sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + pa_outboxcode.Text + "','" + pd_makecode.Text + "','" + pd_prodcode.Text + "','" + outboxcode.Text + "' ");
  337. sql.Append(",(select nvl(sum(pd_innerqty),0) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode=");
  338. sql.Append("'" + outboxcode.Text + "'),sysdate from package where pa_outboxcode='" + outboxcode.Text + "'");
  339. SQLS.Add(sql.GetString());
  340. //如果采集完这个超出了容量提示
  341. SQLS.Add("update package set PA_CURRENTQTY=nvl(PA_CURRENTQTY,0)+1,PA_PACKAGEQTY=nvl(PA_PACKAGEQTY,0)+1,PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "') where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3");
  342. SQLS.Add("update package set pa_mothercode='" + pa_outboxcode.Text + "' where pa_outboxcode='" + outboxcode.Text + "'");
  343. dh.ExecuteSQLTran(SQLS.ToArray());
  344. //更新大箱的栈板号
  345. if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "")
  346. {
  347. string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
  348. pa_makecode.Text = carton_macode;
  349. dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  350. }
  351. //如果是线内并且下一工序等于当前岗位资源工序
  352. if (pa_nextstep != "" && pa_nextstep == User.CurrentStepCode)
  353. {
  354. LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "栈板采集成功,栈板号:" + pa_outboxcode.Text, "栈板采集", out ErrorMessage);
  355. }
  356. if (pa_totalqty.Text == "1")
  357. {
  358. string nextstepcode = dh.getFieldDataByCondition("mes_package_view left join makeserial on ms_sncode=v_barcode", "ms_nextstepcode", "v_outboxcode='" + outboxcode.Text + "'").ToString();
  359. dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  360. }
  361. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "栈板采集", "栈板" + pa_outboxcode.Text + "采集箱" + outboxcode.Text + "成功", pa_outboxcode.Text, "");
  362. dh.ExecuteSql("update package set pa_remark='" + pa_remark.Text + "' where pa_outboxcode='" + outboxcode.Text + "'", "update");
  363. OperateResult.AppendText(">>箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode);
  364. LoadCollectNum();
  365. palletcode_KeyDown(sender, e);
  366. if (pa_standardqty.Text == pa_totalqty.Text)
  367. {
  368. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  369. OperateResult.AppendText("栈板" + pa_outboxcode.Text + "已装满,封栈板成功\n");
  370. pa_outboxcode.Focus();
  371. pa_outboxcode.SelectAll();
  372. if (AutoPrint.Checked)
  373. {
  374. OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + ",自动打印!\n", Color.Green);
  375. Printlab.PerformClick();
  376. }
  377. }
  378. }
  379. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode);
  380. }
  381. else
  382. {
  383. if (dt.Rows[0]["pa_mothercode"].ToString() == pa_outboxcode.Text)
  384. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已在本栈板内\n", Color.Red, outboxcode);
  385. else
  386. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已采集至栈板" + dt.Rows[0]["pa_mothercode"].ToString() + "\n", Color.Red, outboxcode);
  387. }
  388. }
  389. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode);
  390. }
  391. //进行拆箱操作
  392. else
  393. {
  394. sql.Clear();
  395. sql.Append("select nvl(pa_iostatus,0)pa_iostatus from packagedetail left join package on pa_id =pd_paid where pd_outboxcode='" + pa_outboxcode.Text + "' ");
  396. sql.Append("and pd_innerboxcode='" + outboxcode.Text + "'");
  397. DataTable dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  398. if (dta.Rows.Count > 0)
  399. {
  400. if (dta.Rows[0]["pa_iostatus"].ToString() == "0")
  401. {
  402. List<string> SQLS = new List<string>();
  403. //删除明细
  404. SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "' and pd_innerboxcode='" + outboxcode.Text + "'");
  405. //减少箱内容量
  406. SQLS.Add("update package set pa_packageqty=pa_packageqty-1,pa_totalqty=pa_totalqty-(select pa_totalqty from package where pa_outboxcode='" + outboxcode.Text + "'),pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  407. SQLS.Add("update package set pa_mothercode='' where pa_outboxcode='" + outboxcode.Text + "'");
  408. dh.ExecuteSQLTran(SQLS.ToArray());
  409. OperateResult.AppendText(">>箱号" + outboxcode.Text + "取消采集成功\n", Color.Green);
  410. LoadCollectNum();
  411. palletcode_KeyDown(sender, e);
  412. outboxcode.Clear();
  413. }
  414. else OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已入库,不允许取消采集\n", Color.Red);
  415. }
  416. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不在栈板" + pa_outboxcode.Text + "\n", Color.Red);
  417. }
  418. }
  419. }
  420. }
  421. private void LoadGridData()
  422. {
  423. sql.Clear();
  424. sql.Append("select pd_prodcode,nvl(pd_barcode,PD_INNERBOXCODE) code ,pd_innerqty,pa_salecode");
  425. sql.Append(",pd_makecode,pa_prodcode,pa_custcode,pa_packageqty from packagedetail left join package on pd_paid=pa_id left ");
  426. sql.Append("join product on pr_code=pa_prodcode where pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3");
  427. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  428. if (dt.Rows.Count == 0 && dh.CheckExist("package", "pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3"))
  429. {
  430. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_makecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  431. }
  432. BaseUtil.FillDgvWithDataTable(PackageInf, dt);
  433. }
  434. private void FillPrintLabel()
  435. {
  436. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='栈板标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  437. PrintLabel.DataSource = _dt;
  438. PrintLabel.DisplayMember = "la_url";
  439. PrintLabel.ValueMember = "la_id";
  440. }
  441. private void LoadCollectNum()
  442. {
  443. pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3").ToString();
  444. }
  445. private void Make_PalletCollection_SizeChanged(object sender, EventArgs e)
  446. {
  447. weight.Location = new Point(weight_label.Location.X + weight_label.Size.Width - 10, weight_label.Location.Y - 20);
  448. asc.controlAutoSize(this);
  449. }
  450. private void NewPallet_Click(object sender, EventArgs e)
  451. {
  452. NewPallet = new Packing_NewPallet("PALLET", pa_makecode.Text);
  453. NewPallet.Controls["Confirm"].Click += Make_PalletCollection_Click;
  454. BaseUtil.SetFormCenter(NewPallet);
  455. NewPallet.ShowDialog();
  456. }
  457. private void Make_PalletCollection_Click(object sender, EventArgs e)
  458. {
  459. pa_outboxcode.Text = NewPallet.OutBoxCode;
  460. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  461. NewPallet.Close();
  462. }
  463. private void Print_Click(object sender, EventArgs e)
  464. {
  465. if (PrintLabel.Items.Count != 0)
  466. {
  467. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  468. {
  469. if (pa_length.Text == "" || pa_width.Text == "" || pa_heigth.Text == "")
  470. {
  471. OperateResult.AppendText(">>长宽高不允许为空" + pa_outboxcode.Text + "\n", Color.Black);
  472. return;
  473. }
  474. if (!AutoOutBoxCode.Checked)
  475. {
  476. pa_outboxcode.Focus();
  477. pa_outboxcode.SelectAll();
  478. }
  479. //doc = lbl.Documents.Open(PrintLabel.Text);
  480. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "栈板标", "0", out ErrorMessage))
  481. {
  482. OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + "\n", Color.Black);
  483. }
  484. else
  485. {
  486. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  487. }
  488. if (PrintSecond.Checked)
  489. {
  490. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel1.Text, PrintLabel1.SelectedValue.ToString(), PrintList1.Text, pa_outboxcode.Text, int.Parse(PrintNum1.Text), pa_makecode.Text, pr_code.Text, "栈板标", "0", out ErrorMessage))
  491. {
  492. OperateResult.AppendText(">>打印栈板:" + pa_outboxcode.Text + "打印结束\n", Color.Green);
  493. }
  494. else
  495. {
  496. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  497. }
  498. }
  499. if (PrintThird.Checked)
  500. {
  501. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel2.Text, PrintLabel1.SelectedValue.ToString(), PrintList2.Text, pa_outboxcode.Text, int.Parse(PrintNum1.Text), pa_makecode.Text, pr_code.Text, "栈板标", "0", out ErrorMessage))
  502. {
  503. OperateResult.AppendText(">>打印栈板:" + pa_outboxcode.Text + "打印结束\n", Color.Green);
  504. }
  505. else
  506. {
  507. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  508. }
  509. }
  510. }
  511. else OperateResult.AppendText(">>必须封栈板才能进行打印\n", Color.Red);
  512. }
  513. else OperateResult.AppendText(">>产品" + pa_prodcode.Text + "未维护打印标签\n", Color.Red);
  514. }
  515. private void ReleasePallet_Click(object sender, EventArgs e)
  516. {
  517. if (dh.getRowCount("packagedetail", "pd_outboxcode='" + pa_outboxcode.Text + "'") > 0)
  518. {
  519. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  520. if (Delete == "Yes")
  521. {
  522. sql.Clear();
  523. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  524. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  525. if (dt.Rows.Count > 0)
  526. {
  527. if (dt.Rows[0]["pa_outno"].ToString() != "")
  528. {
  529. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  530. return;
  531. }
  532. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  533. {
  534. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  535. return;
  536. }
  537. }
  538. //如果含有下一执行步骤的撤销过站,否则直接删除
  539. if (dh.getFieldDataByCondition("package", "pa_nextstep", "pa_mothercode='" + pa_outboxcode.Text + "'").ToString() != "")
  540. LogicHandler.OutBoxDrawStepPass(pa_outboxcode.Text, pa_makecode.Text, User.UserSourceCode);
  541. else
  542. {
  543. List<string> SQLS = new List<string>();
  544. SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  545. SQLS.Add("update package set pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  546. SQLS.Add("update package set pa_mothercode='' where pa_mothercode='" + pa_outboxcode.Text + "'");
  547. dh.ExecuteSQLTran(SQLS.ToArray());
  548. }
  549. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "解除栈板" + pa_outboxcode.Text + "成功", pa_outboxcode.Text, "");
  550. OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "解除成功\n", Color.Green);
  551. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  552. }
  553. }
  554. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集箱\n", Color.Red);
  555. }
  556. private void Make_PalletCollection_FormClosing(object sender, FormClosingEventArgs e)
  557. {
  558. //BaseUtil.ClosePrint(lbl);
  559. StopWeight.PerformClick();
  560. InitPrint.Abort();
  561. if (serialPort1.IsOpen)
  562. {
  563. GetData = false;
  564. serialPort1.Close();
  565. SystemInf.OpenPort.Remove(serialPort1.PortName);
  566. thread.Interrupt();
  567. }
  568. //thread.Abort();
  569. }
  570. private void Packing_Click(object sender, EventArgs e)
  571. {
  572. if (pa_outboxcode.Text != "")
  573. {
  574. sql.Clear();
  575. sql.Append("select nvl(pa_status,0) pa_status from packagedetail left join package ");
  576. sql.Append("on pa_id=pd_paid where pd_outboxcode='" + pa_outboxcode.Text + "'");
  577. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  578. if (dt.Rows.Count > 0)
  579. {
  580. if (dt.Rows[0]["pa_status"].ToString() == "0")
  581. {
  582. string Seal = MessageBox.Show(this.ParentForm, "是否确认封栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  583. if (Seal == "Yes")
  584. {
  585. OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "装栈板成功\n", Color.Green);
  586. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "封栈板" + pa_outboxcode.Text + "成功", outboxcode.Text, "");
  587. dh.ExecuteSql("update package set pa_status=1,PA_WEIGHT='" + weight.Text + "',PA_WIDTH='" + pa_width.Text + "', PA_HEIGTH='" + pa_heigth.Text + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  588. pa_status.Text = "1";
  589. }
  590. }
  591. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "已封栈板\n", Color.Red);
  592. }
  593. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集内容\n", Color.Red);
  594. }
  595. else OperateResult.AppendText(">>栈板号不能为空\n", Color.Red);
  596. }
  597. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  598. {
  599. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  600. {
  601. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  602. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  603. }
  604. }
  605. private void pa_prodcode_TextChanged(object sender, EventArgs e)
  606. {
  607. FillPrintLabel();
  608. }
  609. private void pa_standardqty_KeyDown(object sender, KeyEventArgs e)
  610. {
  611. if (e.KeyCode == Keys.Enter)
  612. {
  613. ResetPackageQTY();
  614. }
  615. }
  616. private void ResetPackageQTY()
  617. {
  618. if (pa_outboxcode.Text != "")
  619. {
  620. DataTable dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_status from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  621. if (dt.Rows.Count > 0)
  622. {
  623. string total = dt.Rows[0]["pa_totalqty"].ToString();
  624. if (int.Parse(pa_standardqty.Text) >= int.Parse(total))
  625. {
  626. dh.UpdateByCondition("package", "pa_standardqty='" + pa_standardqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  627. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "修改容量成功,已修改为" + pa_standardqty.Text + "\n", Color.Green);
  628. outboxcode.Focus();
  629. return;
  630. }
  631. else OperateResult.AppendText(">>容量不能小于已装数量\n", Color.Red);
  632. }
  633. else outboxcode.Focus();
  634. }
  635. }
  636. private bool CheckOutBoxLength()
  637. {
  638. //勾选了检验长度进行校验
  639. if (OutBoxLength.Text != "")
  640. {
  641. try
  642. {
  643. int.Parse(OutBoxLength.Text);
  644. }
  645. catch (Exception)
  646. {
  647. MessageBox.Show("请填写正确的箱号长度");
  648. return false;
  649. }
  650. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  651. {
  652. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  653. return false;
  654. }
  655. else return true;
  656. }
  657. if (PalletPreFix.Text != "")
  658. {
  659. try
  660. {
  661. if (pa_outboxcode.Text.Substring(0, PalletPreFix.Text.Length) != PalletPreFix.Text)
  662. {
  663. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  664. return false;
  665. }
  666. }
  667. catch (Exception)
  668. {
  669. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  670. return false;
  671. }
  672. }
  673. return true;
  674. }
  675. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  676. {
  677. if (e.KeyCode == Keys.Enter)
  678. {
  679. try
  680. {
  681. if (OutBoxLength.Text != "")
  682. {
  683. int.Parse(OutBoxLength.Text);
  684. }
  685. BaseUtil.SetCacheData("PalletLength", OutBoxLength.Text);
  686. pa_outboxcode.Focus();
  687. }
  688. catch (Exception)
  689. {
  690. OutBoxLength.Clear();
  691. MessageBox.Show("请输入正确的长度");
  692. }
  693. }
  694. }
  695. private void PalletPreFix_KeyDown(object sender, KeyEventArgs e)
  696. {
  697. if (e.KeyCode == Keys.Enter)
  698. {
  699. BaseUtil.SetCacheData("PalletPreFix", PalletPreFix.Text);
  700. pa_outboxcode.Focus();
  701. }
  702. }
  703. Thread threadWatch = null; //负责监听客户端的线程
  704. private void StartWeight_Click(object sender, EventArgs e)
  705. {
  706. thread = new Thread(getSerialData);
  707. try
  708. {
  709. GetData = true;
  710. serialPort1.PortName = this.ComList.Text;
  711. serialPort1.BaudRate = int.Parse(BaudRate.Text);
  712. serialPort1.Open();
  713. thread.Start();
  714. }
  715. catch (Exception mes)
  716. {
  717. if (BaudRate.Text == "" || ComList.Text == "")
  718. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  719. else
  720. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  721. }
  722. }
  723. Regex re = new Regex("\\d+.\\d+");
  724. private void getSerialData()
  725. {
  726. if (serialPort1.IsOpen)
  727. {
  728. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  729. {
  730. SystemInf.OpenPort.Add(serialPort1.PortName);
  731. try
  732. {
  733. while (GetData)
  734. {
  735. try
  736. {
  737. weight.Text = re.Match(serialPort1.ReadLine()).Groups[0].Value;
  738. }
  739. catch (Exception)
  740. {
  741. GetData = false;
  742. }
  743. }
  744. }
  745. catch (IOException ex) { OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, outboxcode); }
  746. }
  747. else OperateResult.AppendText(">>端口已被占用,请关闭其他窗口\n", Color.Red, outboxcode);
  748. }
  749. }
  750. private void StopWeight_Click(object sender, EventArgs e)
  751. {
  752. if (serialPort1.IsOpen)
  753. {
  754. GetData = false;
  755. serialPort1.Close();
  756. SystemInf.OpenPort.Remove(serialPort1.PortName);
  757. thread.Abort();
  758. }
  759. }
  760. private void RefreshWeigh_Click(object sender, EventArgs e)
  761. {
  762. sql.Clear();
  763. sql.Append("select pr_palletminweight,pr_palletmaxweight,pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_palletweight from product where pr_code='" + pr_code.Text + "'");
  764. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  765. //填充打印文件选项的DataGridView
  766. if (dt.Rows.Count > 0)
  767. {
  768. string _weight = dt.Rows[0]["pr_palletweight"].ToString();
  769. string _maxweight = dt.Rows[0]["pr_palletmaxweight"].ToString();
  770. string _minweight = dt.Rows[0]["pr_palletminweight"].ToString();
  771. Weight = double.Parse(_weight == "" ? "0" : _weight);
  772. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  773. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  774. if (Weight - MinWeight == MaxWeight - Weight)
  775. pr_palletweight.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  776. else
  777. pr_palletweight.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  778. }
  779. }
  780. }
  781. }