Packing_PalletCollection.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  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. namespace UAS_MES_NEW.Packing
  15. {
  16. public partial class Packing_PalletCollection : Form
  17. {
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataHelper dh;
  20. DataTable dt;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. Packing_NewPallet NewPallet;
  23. string pa_nextstep = "";
  24. //箱类型
  25. string pa_type;
  26. //物料编号
  27. string pr_code;
  28. //Package表的主键
  29. string pa_id;
  30. Engine engine;
  31. Document doc;
  32. Thread thread;
  33. string ErrorMessage = "";
  34. public Packing_PalletCollection()
  35. {
  36. InitializeComponent();
  37. }
  38. //创建打印进程
  39. private void NewPrint()
  40. {
  41. try
  42. {
  43. engine = new Engine(true);
  44. }
  45. catch
  46. {
  47. OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
  48. }
  49. }
  50. private void Make_PalletCollection_Load(object sender, EventArgs e)
  51. {
  52. asc.controllInitializeSize(this);
  53. thread = new Thread(NewPrint);
  54. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  55. BaseUtil.SetFormCenter(stw);
  56. stw.ShowDialog();
  57. OutBoxLength.Text = BaseUtil.GetCacheData("PalletLength").ToString();
  58. PalletPreFix.Text = BaseUtil.GetCacheData("PalletPreFix").ToString();
  59. dh = SystemInf.dh;
  60. StepCount.StepCode = User.CurrentStepCode;
  61. StepCount.Source = User.UserSourceCode;
  62. StepCount.LineCode = User.UserLineCode;
  63. StepCount.Dh = dh;
  64. StepCount.Start();
  65. }
  66. private void Clean_Click(object sender, EventArgs e)
  67. {
  68. OperateResult.Clear();
  69. }
  70. private void palletcode_KeyDown(object sender, KeyEventArgs e)
  71. {
  72. if (e.KeyCode == Keys.Enter)
  73. {
  74. LoadGridData();
  75. sql.Clear();
  76. 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 ");
  77. 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");
  78. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  79. if (dt.Rows.Count > 0)
  80. {
  81. BaseUtil.SetFormValue(Controls, dt);
  82. pa_id = dt.Rows[0]["pa_id"].ToString();
  83. }
  84. if (CheckOutBoxLength())
  85. {
  86. if (pa_standardqty.Text == "")
  87. pa_standardqty.Focus();
  88. else
  89. outboxcode.Focus();
  90. }
  91. }
  92. }
  93. //箱号Enter事件
  94. private void outboxcode_KeyDown(object sender, KeyEventArgs e)
  95. {
  96. if (e.KeyCode == Keys.Enter)
  97. {
  98. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  99. {
  100. if (outboxcode.Text == "")
  101. {
  102. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  103. return;
  104. }
  105. sql.Clear();
  106. sql.Append("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_makecode,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 ");
  107. 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 + "'");
  108. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  109. if (dt.Rows.Count > 0)
  110. {
  111. BaseUtil.SetFormValue(this.Controls, dt);
  112. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  113. {
  114. OperateResult.AppendText(">>箱号" + outboxcode.Text + "下地状态不允许采集\n", Color.Red, outboxcode);
  115. return;
  116. }
  117. if (dt.Rows[0]["pa_outno"].ToString() != "")
  118. {
  119. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  120. return;
  121. }
  122. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  123. {
  124. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已入库不允许采集\n", Color.Red, outboxcode);
  125. return;
  126. }
  127. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  128. {
  129. if (pa_outboxcode.Text == "")
  130. {
  131. pa_outboxcode.Text = dt.Rows[0]["pa_mothercode"].ToString();
  132. palletcode_KeyDown(sender, e);
  133. }
  134. }
  135. string unfinpack = dh.getFieldDataByCondition("Line", "nvl(li_allowUnFinPack,0)", "li_code='" + User.UserLineCode + "'").ToString();
  136. pa_nextstep = dt.Rows[0]["pa_nextstep"].ToString();
  137. if (pa_nextstep != User.CurrentStepCode && pa_nextstep != "" && (unfinpack == "0" || unfinpack == ""))
  138. {
  139. OperateResult.AppendText(">>箱号" + outboxcode.Text + "的下一工序不是当前岗位资源对应工序\n", Color.Red, outboxcode);
  140. return;
  141. }
  142. sql.Clear();
  143. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_type from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  144. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  145. if (dt.Rows.Count > 0)
  146. {
  147. if (dt.Rows[0]["pa_type"].ToString() != "3")
  148. {
  149. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "类型并非栈板,不允许操作\n", Color.Red);
  150. return;
  151. }
  152. if (dt.Rows[0]["pa_outno"].ToString() != "")
  153. {
  154. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  155. return;
  156. }
  157. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  158. {
  159. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  160. return;
  161. }
  162. }
  163. //为空表示线外
  164. if (pa_nextstep == "")
  165. {
  166. //判断线外,必须已完工并且未入库
  167. dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view left join makeserial on v_barcode=ms_sncode and v_makecode = ms_makecode where v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select");
  168. if (dt.Rows[0][0].ToString() != "" && (unfinpack != "0" || unfinpack == ""))
  169. {
  170. OperateResult.AppendText(">>序列号" + dt.Rows[0][0].ToString() + "尚未完工\n", Color.Red);
  171. return;
  172. }
  173. }
  174. }
  175. else
  176. {
  177. OperateResult.AppendText(">>箱号" + outboxcode.Text + "未采集内容或不存在,不允许装栈板\n", Color.Red, outboxcode);
  178. return;
  179. }
  180. if (!Cancel.Checked)
  181. {
  182. pa_status.Text = dh.getFieldDataByCondition("package", "nvl(pa_status,0)pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  183. if (pa_outboxcode.Text == "" && AutoOutBoxCode.Checked)
  184. {
  185. //箱已采集满并且未勾选自动生成
  186. if (pa_standardqty.Text == pa_totalqty.Text && !AutoOutBoxCode.Checked)
  187. {
  188. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已采集满\n", Color.Red, outboxcode);
  189. return;
  190. }
  191. else
  192. {
  193. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", pa_makecode.Text, pd_prodcode.Text, User.UserCode);
  194. }
  195. }
  196. else if (pa_outboxcode.Text != "" && pa_status.Text == "1" && AutoOutBoxCode.Checked)
  197. {
  198. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", pa_makecode.Text, pd_prodcode.Text, User.UserCode);
  199. }
  200. else if (pa_outboxcode.Text == "")
  201. {
  202. OperateResult.AppendText(">>栈板号不能为空\n", Color.Red);
  203. return;
  204. }
  205. if (!CheckOutBoxLength())
  206. {
  207. return;
  208. }
  209. dt = (DataTable)dh.ExecuteSql("select pa_id from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  210. if (dt.Rows.Count == 0)
  211. {
  212. pa_id = dh.GetSEQ("package_seq");
  213. sql.Clear();
  214. 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");
  215. 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 + "')");
  216. dh.ExecuteSql(sql.GetString(), "insert");
  217. }
  218. else
  219. {
  220. pa_id = dt.Rows[0]["pa_id"].ToString();
  221. }
  222. palletcode_KeyDown(sender, e);
  223. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) > 0)
  224. {
  225. if (!LogicHandler.CheckPackRule(pr_packrule.Text, pa_outboxcode.Text, outboxcode.Text, pa_makecode.Text, pa_salecode.Text, pa_prodcode.Text, "栈板", out ErrorMessage))
  226. {
  227. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, outboxcode);
  228. return;
  229. }
  230. }
  231. dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_mothercode,nvl(pa_status,0) pa_status from package where pa_outboxcode='" + outboxcode.Text + "'", "select");
  232. if (dt.Rows.Count > 0)
  233. {
  234. //判断是否已经装箱
  235. int sonboxtotalqty = int.Parse(dt.Rows[0]["pa_totalqty"].ToString());
  236. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  237. {
  238. if (dt.Rows[0]["pa_status"].ToString() == "1")
  239. {
  240. pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  241. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) + sonboxtotalqty > int.Parse(pa_standardqty.Text == "" ? "0" : pa_standardqty.Text))
  242. {
  243. OperateResult.AppendText(">>采集箱号" + outboxcode.Text + "后超出容量\n", Color.Red, outboxcode);
  244. return;
  245. }
  246. if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) == 0)
  247. {
  248. 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");
  249. }
  250. List<string> SQLS = new List<string>();
  251. sql.Clear();
  252. sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_makecode,pd_prodcode,pd_innerboxcode, pd_innerqty,pd_builddate)");
  253. sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + pa_outboxcode.Text + "','" + pd_makecode.Text + "','" + pd_prodcode.Text + "','" + outboxcode.Text + "' ");
  254. sql.Append(",(select nvl(sum(pd_innerqty),0) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode=");
  255. sql.Append("'" + outboxcode.Text + "'),sysdate from package where pa_outboxcode='" + outboxcode.Text + "'");
  256. SQLS.Add(sql.GetString());
  257. //如果采集完这个超出了容量提示
  258. 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");
  259. SQLS.Add("update package set pa_mothercode='" + pa_outboxcode.Text + "' where pa_outboxcode='" + outboxcode.Text + "'");
  260. dh.ExecuteSQLTran(SQLS.ToArray());
  261. //更新大箱的栈板号
  262. if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "")
  263. {
  264. string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
  265. pa_makecode.Text = carton_macode;
  266. dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  267. }
  268. //如果是线内并且下一工序等于当前岗位资源工序
  269. if (pa_nextstep != "" && pa_nextstep == User.CurrentStepCode)
  270. {
  271. LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "栈板采集成功,栈板号:" + pa_outboxcode.Text, "栈板采集", out ErrorMessage);
  272. }
  273. if (pa_totalqty.Text == "1")
  274. {
  275. string nextstepcode = dh.getFieldDataByCondition("mes_package_view left join makeserial on ms_sncode=v_barcode", "ms_nextstepcode", "v_outboxcode='" + outboxcode.Text + "'").ToString();
  276. dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  277. }
  278. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "栈板采集", "栈板" + pa_outboxcode.Text + "采集箱" + outboxcode.Text + "成功", pa_outboxcode.Text, "");
  279. OperateResult.AppendText(">>箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode);
  280. LoadCollectNum();
  281. palletcode_KeyDown(sender, e);
  282. if (pa_standardqty.Text == pa_totalqty.Text)
  283. {
  284. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  285. OperateResult.AppendText("栈板" + pa_outboxcode.Text + "已装满,封栈板成功\n");
  286. if (!AutoOutBoxCode.Checked)
  287. {
  288. pa_outboxcode.Focus();
  289. pa_outboxcode.SelectAll();
  290. }
  291. else
  292. {
  293. outboxcode.Focus();
  294. outboxcode.SelectAll();
  295. }
  296. if (AutoPrint.Checked)
  297. {
  298. OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + ",自动打印!\n", Color.Green);
  299. Printlab.PerformClick();
  300. }
  301. }
  302. }
  303. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode);
  304. }
  305. else
  306. {
  307. if (dt.Rows[0]["pa_mothercode"].ToString() == pa_outboxcode.Text)
  308. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已在本栈板内\n", Color.Red, outboxcode);
  309. else
  310. OperateResult.AppendText(">>箱号" + outboxcode.Text + "已采集至栈板" + dt.Rows[0]["pa_mothercode"].ToString() + "\n", Color.Red, outboxcode);
  311. }
  312. }
  313. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode);
  314. }
  315. //进行拆箱操作
  316. else
  317. {
  318. sql.Clear();
  319. 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 + "' ");
  320. sql.Append("and pd_innerboxcode='" + outboxcode.Text + "'");
  321. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  322. if (dt.Rows.Count > 0)
  323. {
  324. if (dt.Rows[0]["pa_iostatus"].ToString() == "0")
  325. {
  326. List<string> SQLS = new List<string>();
  327. //删除明细
  328. SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "' and pd_innerboxcode='" + outboxcode.Text + "'");
  329. //减少箱内容量
  330. 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 + "'");
  331. SQLS.Add("update package set pa_mothercode='' where pa_outboxcode='" + outboxcode.Text + "'");
  332. dh.ExecuteSQLTran(SQLS.ToArray());
  333. OperateResult.AppendText(">>箱号" + outboxcode.Text + "取消采集成功\n", Color.Green);
  334. LoadCollectNum();
  335. palletcode_KeyDown(sender, e);
  336. outboxcode.Clear();
  337. }
  338. else OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已入库,不允许取消采集\n", Color.Red);
  339. }
  340. else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不在栈板" + pa_outboxcode.Text + "\n", Color.Red);
  341. }
  342. }
  343. }
  344. }
  345. private void LoadGridData()
  346. {
  347. sql.Clear();
  348. sql.Append("select pd_prodcode,nvl(pd_barcode,PD_INNERBOXCODE) code ,pd_innerqty,pa_salecode");
  349. sql.Append(",pd_makecode,pa_prodcode,pa_custcode,pa_packageqty from packagedetail left join package on pd_paid=pa_id left ");
  350. sql.Append("join product on pr_code=pa_prodcode where pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3");
  351. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  352. if (dt.Rows.Count == 0 && dh.CheckExist("package", "pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3"))
  353. {
  354. 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");
  355. }
  356. BaseUtil.FillDgvWithDataTable(PackageInf, dt);
  357. }
  358. private void FillPrintLabel()
  359. {
  360. 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");
  361. PrintLabel.DataSource = _dt;
  362. PrintLabel.DisplayMember = "la_url";
  363. PrintLabel.ValueMember = "la_id";
  364. }
  365. private void LoadCollectNum()
  366. {
  367. pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3").ToString();
  368. }
  369. private void Make_PalletCollection_SizeChanged(object sender, EventArgs e)
  370. {
  371. asc.controlAutoSize(this);
  372. }
  373. private void NewPallet_Click(object sender, EventArgs e)
  374. {
  375. NewPallet = new Packing_NewPallet("PALLET", pa_makecode.Text);
  376. NewPallet.Controls["Confirm"].Click += Make_PalletCollection_Click;
  377. BaseUtil.SetFormCenter(NewPallet);
  378. NewPallet.ShowDialog();
  379. }
  380. private void Make_PalletCollection_Click(object sender, EventArgs e)
  381. {
  382. pa_outboxcode.Text = NewPallet.OutBoxCode;
  383. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  384. NewPallet.Close();
  385. }
  386. private void Print_Click(object sender, EventArgs e)
  387. {
  388. if (PrintLabel.Items.Count != 0)
  389. {
  390. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  391. {
  392. if (!AutoOutBoxCode.Checked)
  393. {
  394. pa_outboxcode.Focus();
  395. pa_outboxcode.SelectAll();
  396. }
  397. else
  398. {
  399. outboxcode.Focus();
  400. outboxcode.SelectAll();
  401. }
  402. //doc = lbl.Documents.Open(PrintLabel.Text);
  403. 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))
  404. {
  405. OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + "\n", Color.Black);
  406. }
  407. else
  408. {
  409. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  410. }
  411. }
  412. else OperateResult.AppendText(">>必须封栈板才能进行打印\n", Color.Red);
  413. }
  414. else OperateResult.AppendText(">>产品" + pa_prodcode.Text + "未维护打印标签\n", Color.Red);
  415. }
  416. private void ReleasePallet_Click(object sender, EventArgs e)
  417. {
  418. if (dh.getRowCount("packagedetail", "pd_outboxcode='" + pa_outboxcode.Text + "'") > 0)
  419. {
  420. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  421. if (Delete == "Yes")
  422. {
  423. sql.Clear();
  424. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno from package where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3");
  425. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  426. if (dt.Rows.Count > 0)
  427. {
  428. if (dt.Rows[0]["pa_outno"].ToString() != "")
  429. {
  430. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  431. return;
  432. }
  433. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  434. {
  435. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  436. return;
  437. }
  438. }
  439. else
  440. {
  441. OperateResult.AppendText(">>" + pa_outboxcode.Text + "不属于栈板类型,不允许拆解\n", Color.Red);
  442. return;
  443. }
  444. //如果含有下一执行步骤的撤销过站,否则直接删除
  445. if (dh.getFieldDataByCondition("package", "pa_nextstep", "pa_mothercode='" + pa_outboxcode.Text + "'").ToString() != "")
  446. LogicHandler.OutBoxDrawStepPass(pa_outboxcode.Text, pa_makecode.Text, User.UserSourceCode);
  447. else
  448. {
  449. List<string> SQLS = new List<string>();
  450. SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  451. SQLS.Add("update package set pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  452. SQLS.Add("update package set pa_mothercode='' where pa_mothercode='" + pa_outboxcode.Text + "'");
  453. dh.ExecuteSQLTran(SQLS.ToArray());
  454. }
  455. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "解除栈板" + pa_outboxcode.Text + "成功", pa_outboxcode.Text, "");
  456. OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "解除成功\n", Color.Green);
  457. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  458. }
  459. }
  460. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集箱\n", Color.Red);
  461. }
  462. private void Make_PalletCollection_FormClosing(object sender, FormClosingEventArgs e)
  463. {
  464. //BaseUtil.ClosePrint(lbl);
  465. }
  466. private void Packing_Click(object sender, EventArgs e)
  467. {
  468. if (pa_outboxcode.Text != "")
  469. {
  470. sql.Clear();
  471. sql.Append("select nvl(pa_status,0) pa_status from packagedetail left join package ");
  472. sql.Append("on pa_id=pd_paid where pd_outboxcode='" + pa_outboxcode.Text + "'");
  473. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  474. if (dt.Rows.Count > 0)
  475. {
  476. if (dt.Rows[0]["pa_status"].ToString() == "0")
  477. {
  478. string Seal = MessageBox.Show(this.ParentForm, "是否确认封栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  479. if (Seal == "Yes")
  480. {
  481. OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "装栈板成功\n", Color.Green);
  482. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "封栈板" + pa_outboxcode.Text + "成功", outboxcode.Text, "");
  483. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  484. pa_status.Text = "1";
  485. if (!AutoOutBoxCode.Checked)
  486. {
  487. pa_outboxcode.Focus();
  488. pa_outboxcode.SelectAll();
  489. }
  490. else
  491. {
  492. outboxcode.Focus();
  493. outboxcode.SelectAll();
  494. }
  495. }
  496. }
  497. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "已封栈板\n", Color.Red);
  498. }
  499. else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集内容\n", Color.Red);
  500. }
  501. else OperateResult.AppendText(">>栈板号不能为空\n", Color.Red);
  502. }
  503. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  504. {
  505. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  506. {
  507. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  508. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  509. }
  510. }
  511. private void pa_prodcode_TextChanged(object sender, EventArgs e)
  512. {
  513. FillPrintLabel();
  514. }
  515. private void pa_standardqty_KeyDown(object sender, KeyEventArgs e)
  516. {
  517. if (e.KeyCode == Keys.Enter)
  518. {
  519. ResetPackageQTY();
  520. }
  521. }
  522. private void ResetPackageQTY()
  523. {
  524. if (pa_outboxcode.Text != "")
  525. {
  526. DataTable dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_status from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  527. if (dt.Rows.Count > 0)
  528. {
  529. string total = dt.Rows[0]["pa_totalqty"].ToString();
  530. if (int.Parse(pa_standardqty.Text) >= int.Parse(total))
  531. {
  532. dh.UpdateByCondition("package", "pa_standardqty='" + pa_standardqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  533. OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "修改容量成功,已修改为" + pa_standardqty.Text + "\n", Color.Green);
  534. outboxcode.Focus();
  535. return;
  536. }
  537. else OperateResult.AppendText(">>容量不能小于已装数量\n", Color.Red);
  538. }
  539. else outboxcode.Focus();
  540. }
  541. }
  542. private bool CheckOutBoxLength()
  543. {
  544. //勾选了检验长度进行校验
  545. if (OutBoxLength.Text != "")
  546. {
  547. try
  548. {
  549. int.Parse(OutBoxLength.Text);
  550. }
  551. catch (Exception)
  552. {
  553. MessageBox.Show("请填写正确的箱号长度");
  554. return false;
  555. }
  556. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  557. {
  558. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  559. return false;
  560. }
  561. else return true;
  562. }
  563. if (PalletPreFix.Text != "")
  564. {
  565. try
  566. {
  567. if (pa_outboxcode.Text.Substring(0, PalletPreFix.Text.Length) != PalletPreFix.Text)
  568. {
  569. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  570. return false;
  571. }
  572. }
  573. catch (Exception)
  574. {
  575. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  576. return false;
  577. }
  578. }
  579. return true;
  580. }
  581. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  582. {
  583. if (e.KeyCode == Keys.Enter)
  584. {
  585. try
  586. {
  587. if (OutBoxLength.Text != "")
  588. {
  589. int.Parse(OutBoxLength.Text);
  590. }
  591. BaseUtil.SetCacheData("PalletLength", OutBoxLength.Text);
  592. pa_outboxcode.Focus();
  593. }
  594. catch (Exception)
  595. {
  596. OutBoxLength.Clear();
  597. MessageBox.Show("请输入正确的长度");
  598. }
  599. }
  600. }
  601. private void PalletPreFix_KeyDown(object sender, KeyEventArgs e)
  602. {
  603. if (e.KeyCode == Keys.Enter)
  604. {
  605. BaseUtil.SetCacheData("PalletPreFix", PalletPreFix.Text);
  606. pa_outboxcode.Focus();
  607. }
  608. }
  609. }
  610. }