Packing_PalletWightCollection.cs 48 KB

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