Packing_PalletCollection.cs 40 KB

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