Packing_PalletWightCollection.cs 45 KB

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