Packing_BigBoxCollection.cs 36 KB

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