Packing_BigBoxCollection.cs 37 KB

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