Make_PalletWightCollection.cs 43 KB

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