Packing_PackageCollection.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4. using UAS_MES_NEW.DataOperate;
  5. using UAS_MES_NEW.Entity;
  6. using UAS_MES_NEW.PublicMethod;
  7. using System.Drawing;
  8. using System.Threading;
  9. using UAS_MES_NEW.PublicForm;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using Seagull.BarTender.Print;
  13. namespace UAS_MES_NEW.Packing
  14. {
  15. public partial class Packing_PackageCollection : Form
  16. {
  17. DataHelper dh;
  18. DataTable dt;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. Thread thread;
  22. BarTender.Application engine;
  23. DataTable Dbfind;
  24. string ErrorMessage = "";
  25. string oMakeCode = "";
  26. string oMsID = "";
  27. string oMsStatus = "";
  28. string oOutBoxCode = "";
  29. decimal StandardQTY = 0;
  30. string LastSncode;
  31. string PR_CHECKCARTONW = "0";
  32. ModeBusTCPServer md;
  33. public Packing_PackageCollection()
  34. {
  35. InitializeComponent();
  36. }
  37. //创建打印进程
  38. private void NewPrint()
  39. {
  40. try
  41. {
  42. engine = new BarTender.Application();
  43. }
  44. catch (Exception ex)
  45. {
  46. OperateResult.AppendText("未正确安装BarTender软件\n" + ex.Message, Color.Red);
  47. }
  48. }
  49. private void PackCollection_Load(object sender, EventArgs e)
  50. {
  51. // 杀死之前全部未关闭的进程
  52. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  53. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  54. for (int i = 0; i < processes1.Length; i++)
  55. {
  56. processes1[i].Kill();
  57. }
  58. for (int i = 0; i < processes.Length; i++)
  59. {
  60. processes[i].Kill();
  61. }
  62. IP.Text = BaseUtil.GetCacheData("IP").ToString();
  63. Port.Text = BaseUtil.GetCacheData("IPPort").ToString();
  64. //设置DbFind的必须的数据
  65. PrintNum.Text = "1";
  66. asc.controllInitializeSize(this);
  67. thread = new Thread(NewPrint);
  68. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  69. BaseUtil.SetFormCenter(stw);
  70. md = new ModeBusTCPServer();
  71. stw.ShowDialog();
  72. try
  73. {
  74. OutBoxLength.Text = BaseUtil.GetCacheData("OutBoxLength").ToString();
  75. PreFix.Text = BaseUtil.GetCacheData("PreFix").ToString();
  76. Remark_PreFix.Text = BaseUtil.GetCacheData("Remark_PreFix").ToString();
  77. }
  78. catch (Exception) { }
  79. sn_code.Focus();
  80. dh = SystemInf.dh;
  81. StepCount.StepCode = User.CurrentStepCode;
  82. StepCount.Source = User.UserSourceCode;
  83. StepCount.LineCode = User.UserLineCode;
  84. StepCount.Dh = dh;
  85. StepCount.Start();
  86. }
  87. private void PackCollection_SizeChanged(object sender, EventArgs e)
  88. {
  89. asc.controlAutoSize(this);
  90. }
  91. private void PackCollection_Activated(object sender, EventArgs e)
  92. {
  93. pa_outboxcode.Focus();
  94. }
  95. //刷新表单的数据的数据
  96. private void LoadData()
  97. {
  98. //加载表单数据
  99. sql.Clear();
  100. sql.Append("select pr_code,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_remark,pa_outboxcode,pa_prodcode,pa_salecode,pa_makecode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,pa_status,pr_packrule,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pr_detail,pa_packageqty,nvl(pa_standardqty,0) pa_standardqty,nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,pa_currentqty from package left join product on pa_prodcode=");
  101. sql.Append("pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  102. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  103. if (dt.Rows.Count > 0)
  104. {
  105. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  106. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  107. if (dt.Rows[0]["pa_salecode"].ToString() != "")
  108. {
  109. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  110. }
  111. BaseUtil.SetFormValue(this.Controls, dt);
  112. if (pa_standardqty.Text != "0")
  113. {
  114. pr_outboxinnerqty.Text = pa_standardqty.Text;
  115. }
  116. }
  117. else
  118. {
  119. pa_makecode.Text = "";
  120. }
  121. LoadCollectedNum();
  122. LoadCheckQTY();
  123. }
  124. private void LoadGridData()
  125. {
  126. //加载Grid数据
  127. dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pa_prodcode,pd_barcode,pd_innerqty,pd_makecode,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  128. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  129. if (dt.Rows.Count > 0)
  130. {
  131. string choose_pd_barcode = dt.Rows[0]["pd_barcode"].ToString();
  132. string choose_pd_makecode = dt.Rows[0]["pd_makecode"].ToString();
  133. PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + choose_pd_barcode + "' and ms_makecode='" + choose_pd_makecode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  134. }
  135. //更新界面的采集数量
  136. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  137. }
  138. private void Print_Click(object sender, EventArgs e)
  139. {
  140. if (PrintLabel.Items.Count != 0)
  141. {
  142. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  143. {
  144. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1,pa_remark='" + PrintLabel.Text + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  145. if (Print.SinglePrint(Tag.ToString(), engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  146. {
  147. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  148. }
  149. else
  150. {
  151. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  152. }
  153. if (!AutoGenBoxCode.Checked)
  154. {
  155. pa_outboxcode.SelectAll();
  156. pa_outboxcode.Focus();
  157. }
  158. else
  159. {
  160. sn_code.Focus();
  161. sn_code.SelectAll();
  162. }
  163. }
  164. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  165. }
  166. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  167. }
  168. //加载工单信息和装箱明细信息
  169. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  170. {
  171. //try
  172. //{
  173. if (e.KeyCode == Keys.Enter)
  174. {
  175. LoadData();
  176. LoadGridData();
  177. if (CheckOutBoxLength())
  178. {
  179. sn_code.Focus();
  180. }
  181. }
  182. //}
  183. //catch (Exception ex)
  184. //{
  185. // MessageBox.Show(ex.Message);
  186. //}
  187. }
  188. //输入序列号的回车事件
  189. private void barcode_KeyDown(object sender, KeyEventArgs e)
  190. {
  191. //当用户输入回车键的时候
  192. if (e.KeyCode == Keys.Enter)
  193. {
  194. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  195. {
  196. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sn_code.Text + "' order by ms_id desc", "select");
  197. if (dt.Rows.Count > 0)
  198. {
  199. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  200. }
  201. else
  202. {
  203. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sn_code.Text + "' order by ms_id desc", "select");
  204. if (dt.Rows.Count > 0)
  205. {
  206. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  207. }
  208. else
  209. {
  210. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sn_code.Text + "' order by mil_id desc", "select");
  211. if (dt.Rows.Count > 0)
  212. {
  213. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  214. }
  215. else
  216. {
  217. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sn_code.Text + "' order by mil_id desc", "select");
  218. if (dt.Rows.Count > 0)
  219. {
  220. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  221. }
  222. }
  223. }
  224. }
  225. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_nextstepcode,ms_craftcode,ms_prodcode from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  226. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
  227. {
  228. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  229. {
  230. oMsID = dt.Rows[0]["ms_id"].ToString();
  231. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  232. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  233. }
  234. //如果是已完工序列号验证装箱工序是否存在于途程中
  235. if (oMsStatus == "2")
  236. {
  237. string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  238. string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  239. string craftstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id =cd_crid", "(cd_stepcode)", "cr_prodcode='" + prodcode + "' and cr_code='" + craftcode + "' and cd_stepcode='" + User.CurrentStepCode + "'").ToString();
  240. if (craftstepcode == "")
  241. {
  242. OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
  243. return;
  244. }
  245. }
  246. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  247. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  248. {
  249. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  250. OperateResult.AppendText("<<序列号:" + sn_code.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sn_code);
  251. return;
  252. }
  253. PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  254. //获取序列号信息
  255. sql.Clear();
  256. sql.Append("select nvl(ms_iostatus,0) ms_iostatus,pa_salecode,ms_salecode,ms_outno,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
  257. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  258. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  259. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  260. string ms_makecode = "";
  261. string ms_prodcode = "";
  262. string ms_iostatus = "";
  263. string ms_outno = "";
  264. string ms_salecode_text = "";
  265. if (dt.Rows.Count > 0)
  266. {
  267. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  268. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  269. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  270. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  271. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  272. ms_salecode_text = dt.Rows[0]["ms_makecode"].ToString();
  273. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  274. {
  275. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  276. if (md.IsOpen)
  277. {
  278. md.SendOrder("M502_ON");
  279. }
  280. return;
  281. }
  282. BaseUtil.SetFormValue(this.Controls, dt);
  283. }
  284. if (dt.Rows[0]["ms_outno"].ToString() != "")
  285. {
  286. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  287. if (md.IsOpen)
  288. {
  289. md.SendOrder("M502_ON");
  290. }
  291. return;
  292. }
  293. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  294. {
  295. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  296. if (md.IsOpen)
  297. {
  298. md.SendOrder("M502_ON");
  299. }
  300. return;
  301. }
  302. //保证箱内容量不会被重置
  303. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  304. {
  305. pr_outboxinnerqty.Text = pa_standardqty.Text;
  306. }
  307. if (pa_outboxcode.Text == "")
  308. {
  309. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  310. //序列号存在箱号的情况下获取所有的装箱数据
  311. if (boxcode != "")
  312. {
  313. pa_outboxcode.Text = boxcode;
  314. pa_makecode.Text = "";
  315. LoadGridData();
  316. }
  317. else
  318. {
  319. //如果勾选了自动生成箱号,在封箱或者首次
  320. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == "" || pa_status.Text == "0"))
  321. {
  322. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  323. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  324. }
  325. }
  326. }
  327. if (pa_outboxcode.Text == "")
  328. {
  329. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  330. return;
  331. }
  332. //判断箱内总数必须大于0
  333. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  334. {
  335. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  336. return;
  337. }
  338. sql.Clear();
  339. sql.Append("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_mothercode,pa_type from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  340. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  341. string MotherBoxCode = "";
  342. if (dt.Rows.Count > 0)
  343. {
  344. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  345. {
  346. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  347. }
  348. if (dt.Rows[0]["pa_outno"].ToString() != "")
  349. {
  350. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  351. if (md.IsOpen)
  352. {
  353. md.SendOrder("M502_ON");
  354. }
  355. return;
  356. }
  357. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  358. {
  359. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  360. if (md.IsOpen)
  361. {
  362. md.SendOrder("M502_ON");
  363. }
  364. return;
  365. }
  366. }
  367. //如果未勾选了取消录入
  368. if (!Cancel.Checked)
  369. {
  370. //判断序列号是否已经装箱
  371. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  372. if (ms_outboxcode != "")
  373. {
  374. if (ms_outboxcode == pa_outboxcode.Text)
  375. {
  376. if (md.IsOpen)
  377. {
  378. md.SendOrder("M501_ON");
  379. }
  380. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  381. }
  382. else
  383. {
  384. if (md.IsOpen)
  385. {
  386. md.SendOrder("M502_ON");
  387. }
  388. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  389. }
  390. LoadData();
  391. }
  392. else
  393. {
  394. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  395. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  396. {
  397. pa_currentqty.Text = "";
  398. pa_outboxcode.Text = "";
  399. pa_status.Text = "0";
  400. BaseUtil.CleanDGVData(PackageDetail);
  401. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  402. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  403. }
  404. if (!CheckOutBoxLength(ms_salecode_text))
  405. {
  406. return;
  407. }
  408. ////箱号不存在的情况
  409. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  410. {
  411. if (md.IsOpen)
  412. {
  413. md.SendOrder("M501_ON");
  414. }
  415. //提示正确返回时传递的信息
  416. if (ErrorMessage.Contains("AFTERSUCCESS"))
  417. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  418. LastSncode = sn_code.Text;
  419. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  420. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
  421. //满箱更新状态为1
  422. LoadData();
  423. LoadGridData();
  424. LoadCheckQTY();
  425. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  426. if (MotherBoxCode != "")
  427. {
  428. dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  429. //如果母箱号不为空,需要更新总数
  430. if (dt.Rows.Count > 0)
  431. {
  432. if (dt.Rows[0]["pa_type"].ToString() == "2")
  433. {
  434. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  435. //更新大箱数量
  436. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  437. //外层有栈板则更新栈板数量
  438. if (MotherCode2 != "")
  439. {
  440. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  441. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  442. }
  443. }
  444. if (dt.Rows[0]["pa_type"].ToString() == "3")
  445. {
  446. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  447. }
  448. }
  449. }
  450. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  451. if (pa_currentqty.Text == "1")
  452. {
  453. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  454. }
  455. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  456. {
  457. dh.UpdateByCondition("package", "pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  458. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱采集完成,封箱成功\n", Color.Green);
  459. pa_status.Text = "1";
  460. pa_standardqty.Text = "";
  461. if (AutoPrint.Checked)
  462. Print_Click(new object(), new EventArgs());
  463. if (!CollecRemark.Checked)
  464. {
  465. if (!AutoGenBoxCode.Checked)
  466. {
  467. pa_outboxcode.SelectAll();
  468. pa_outboxcode.Focus();
  469. }
  470. else
  471. {
  472. sn_code.Focus();
  473. sn_code.SelectAll();
  474. }
  475. }
  476. else
  477. {
  478. pa_remark.SelectAll();
  479. pa_remark.Focus();
  480. }
  481. if (PR_CHECKCARTONW != "0")
  482. {
  483. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "满箱处于称重工序,请在卡通箱称重界面进行称重打印\n", Color.Black, sn_code);
  484. return;
  485. }
  486. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  487. {
  488. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  489. }
  490. else
  491. {
  492. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  493. }
  494. LoadCollectedNum();
  495. LoadCheckQTY();
  496. }
  497. sn_code.Clear();
  498. }
  499. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  500. }
  501. }
  502. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  503. else
  504. {
  505. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  506. {
  507. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  508. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  509. //如果母箱号不为空,需要更新总数
  510. if (MotherBoxCode != "")
  511. {
  512. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  513. if (dt.Rows.Count > 0)
  514. {
  515. if (dt.Rows[0]["pa_type"].ToString() == "2")
  516. {
  517. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  518. //更新大箱数量
  519. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  520. //外层有栈板则更新栈板数量
  521. if (MotherCode2 != "")
  522. {
  523. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  524. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  525. }
  526. }
  527. if (dt.Rows[0]["pa_type"].ToString() == "3")
  528. {
  529. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  530. }
  531. }
  532. }
  533. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  534. LoadGridData();
  535. pa_status.Text = "0";
  536. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  537. }
  538. else
  539. {
  540. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  541. if (md.IsOpen)
  542. {
  543. md.SendOrder("M502_ON");
  544. }
  545. }
  546. }
  547. }
  548. else
  549. {
  550. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  551. if (md.IsOpen)
  552. {
  553. md.SendOrder("M502_ON");
  554. }
  555. }
  556. }
  557. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  558. }
  559. }
  560. private void Clean_Click(object sender, EventArgs e)
  561. {
  562. OperateResult.Clear();
  563. }
  564. DataTable _dt;
  565. private void pr_code_TextChanged(object sender, EventArgs e)
  566. {
  567. LoadCheckQTY();
  568. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  569. if (_dt.Rows.Count == 0)
  570. {
  571. _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");
  572. }
  573. if (_dt.Rows.Count > 0)
  574. {
  575. string la_id = _dt.Rows[0]["la_id"].ToString();
  576. _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");
  577. PrintLabel.DataSource = _dt;
  578. PrintLabel.DisplayMember = "la_url";
  579. PrintLabel.ValueMember = "la_id";
  580. }
  581. }
  582. private void PackCollection_FormClosing(object sender, FormClosingEventArgs e)
  583. {
  584. //BaseUtil.ClosePrint(lbl);
  585. dh.Dispose();
  586. if (engine != null)
  587. engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  588. }
  589. private void Packing_Click(object sender, EventArgs e)
  590. {
  591. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  592. {
  593. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  594. if (Seal == "Yes")
  595. {
  596. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集完成,手动封箱成功\n", Color.Green);
  597. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  598. pa_status.Text = "1";
  599. pa_standardqty.Text = "";
  600. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "装箱采集", "卡通箱" + pa_outboxcode.Text + "封箱成功", pa_outboxcode.Text, "");
  601. if (!CollecRemark.Checked)
  602. {
  603. if (!AutoGenBoxCode.Checked)
  604. {
  605. pa_outboxcode.SelectAll();
  606. pa_outboxcode.Focus();
  607. }
  608. else
  609. {
  610. sn_code.Focus();
  611. sn_code.SelectAll();
  612. }
  613. }
  614. else
  615. {
  616. pa_remark.SelectAll();
  617. pa_remark.Focus();
  618. }
  619. if (PR_CHECKCARTONW != "0")
  620. {
  621. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于称重工序,请在卡通箱称重界面进行操作\n", Color.Black, sn_code);
  622. return;
  623. }
  624. string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  625. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  626. {
  627. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  628. }
  629. else
  630. {
  631. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  632. }
  633. LoadCheckQTY();
  634. }
  635. }
  636. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  637. }
  638. private void SendCheck_Click(object sender, EventArgs e)
  639. {
  640. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  641. {
  642. DataTable dt = (DataTable)dh.ExecuteSql("select wm_concat(pa_outboxcode) pa_outboxcode from package where pa_checkno='" + ob_checkno.Text + "' and pa_status=0 ", "select");
  643. if (dt.Rows[0][0].ToString() != "")
  644. {
  645. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  646. return;
  647. }
  648. sql.Clear();
  649. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  650. dh.ExecuteSql(sql.GetString(), "select");
  651. ob_nowcheckqty.Text = "";
  652. ob_batchqty.Text = "";
  653. ob_nowcheckqty.ForeColor = Color.Black;
  654. SendCheck.Enabled = false;
  655. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  656. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  657. //记录操作日志
  658. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  659. ob_checkno.Text = "";
  660. }
  661. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  662. }
  663. bool AutoCut;
  664. private void LoadCheckQTY()
  665. {
  666. sql.Clear();
  667. string condition = "";
  668. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  669. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  670. if (nowcheckqty + 1 == batchqty && AutoCut)
  671. {
  672. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  673. }
  674. else
  675. {
  676. condition = "and ob_status='ENTERING' ";
  677. }
  678. if (pr_sendchecktype.Text == "SaleCode")
  679. {
  680. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  681. }
  682. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  683. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  684. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  685. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  686. if (dt.Rows.Count > 0)
  687. {
  688. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  689. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  690. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  691. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  692. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  693. if (nowcheckqty >= batchqty)
  694. {
  695. ob_nowcheckqty.ForeColor = Color.Red;
  696. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  697. if (AutoCut)
  698. {
  699. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  700. }
  701. }
  702. }
  703. else
  704. {
  705. ob_batchqty.Text = "";
  706. ob_nowcheckqty.Text = "";
  707. ob_checkno.Text = "";
  708. SendCheck.Enabled = false;
  709. }
  710. if (ob_batchqty.Text != "" && PR_CHECKCARTONW == "0")
  711. {
  712. SendCheck.Enabled = true;
  713. }
  714. else
  715. {
  716. SendCheck.Enabled = false;
  717. }
  718. }
  719. private void ob_checkno_TextChanged(object sender, EventArgs e)
  720. {
  721. if (ob_checkno.Text != "")
  722. {
  723. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  724. if (Cut == "" || Cut == "0")
  725. AutoCut = false;
  726. else
  727. AutoCut = true;
  728. SendCheck.Enabled = true;
  729. }
  730. }
  731. //private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  732. //{
  733. // if (e.KeyCode == Keys.Enter)
  734. // ResetPackQTY();
  735. //}
  736. //private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  737. //{
  738. // ResetPackQTY();
  739. //}
  740. //private void ResetPackQTY()
  741. //{
  742. // //数据不符合限制的时候保持原有值
  743. // int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  744. // if (!(int.Parse(pr_outboxinnerqty.Text) >= curretnqty))
  745. // {
  746. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  747. // }
  748. // else
  749. // {
  750. // if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  751. // {
  752. // string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  753. // if (checknostatus == "" || checknostatus == "ENTERING")
  754. // {
  755. // if (pa_downstatus.Text == "0")
  756. // {
  757. // if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  758. // {
  759. // dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  760. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Text + "'", pa_outboxcode.Text, pa_checkno.Text);
  761. // return;
  762. // }
  763. // else
  764. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  765. // }
  766. // else
  767. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  768. // }
  769. // else
  770. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  771. // }
  772. // else
  773. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  774. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  775. // }
  776. //}
  777. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  778. {
  779. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  780. {
  781. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  782. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  783. }
  784. }
  785. private void DeleteAll_Click(object sender, EventArgs e)
  786. {
  787. if (pa_outboxcode.Text == "")
  788. {
  789. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  790. return;
  791. }
  792. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  793. if (Delete == "Yes")
  794. {
  795. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_checkno,ob_status,pa_mothercode,nvl(pa_downstatus,0)pa_downstatus from package left join oqcbatch on pa_checkno=ob_checkno where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  796. if (dt.Rows.Count > 0)
  797. {
  798. if (dt.Rows[0]["pa_outno"].ToString() != "")
  799. {
  800. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  801. return;
  802. }
  803. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  804. {
  805. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  806. return;
  807. }
  808. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  809. {
  810. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  811. {
  812. string ob_status = dt.Rows[0]["ob_status"].ToString();
  813. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  814. //不存在抽检批次或者还未检验可以拆解
  815. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  816. {
  817. sql.Clear();
  818. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  819. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  820. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  821. List<string> SQLS1 = new List<string>();
  822. for (int i = 0; i < dt.Rows.Count; i++)
  823. {
  824. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  825. string num = dt.Rows[i]["num"].ToString();
  826. SQLS1.Add("delete from makeprocess where mp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and mp_makecode='" + ma_code + "' and mp_stepcode='" + User.CurrentStepCode + "'");
  827. SQLS1.Add("delete from steppassed where sp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and sp_makecode='" + ma_code + "' and sp_stepcode='" + User.CurrentStepCode + "'");
  828. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-" + num + ",mcd_outqty=mcd_outqty-" + num + ",mcd_okqty=mcd_okqty-" + num + " where mcd_macode='" + ma_code + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  829. //扣减已完工数
  830. SQLS1.Add("update make set ma_endqty=ma_endqty-(select count(1) from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "' and ms_status=2) where ma_code='" + ma_code + "'");
  831. }
  832. if (pa_checkno != "")
  833. {
  834. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  835. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-(select count(1) from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "') where ob_checkno='" + pa_checkno + "'");
  836. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  837. }
  838. //更新序列号状态
  839. SQLS1.Add("update makeserial set ms_status=1,ms_outboxcode='',ms_nextstepcode= (case when ms_nextstepcode='" + User.CurrentStepCode + "' then ms_nextstepcode else ms_stepcode end ),ms_paststep=replace(ms_paststep,'," + User.CurrentStepCode + "','') where ms_outboxcode='" + pa_outboxcode.Text + "'");
  840. //抽检批次不为空的时候进行移除
  841. dh.ExecuteSQLTran(SQLS1.ToArray());
  842. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  843. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  844. if (standqty != "")
  845. {
  846. //置空原箱
  847. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0,PA_STANDARDQTY = '" + standqty + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  848. }
  849. else
  850. //置空原箱
  851. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  852. pa_status.Text = "0";
  853. //删除箱的明细
  854. dh.ExecuteSql("delete from labelprintlog where lpl_value='"+pa_outboxcode.Text+"'","delete");
  855. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'", "delete");
  856. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  857. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  858. LoadGridData();
  859. LoadCheckQTY();
  860. }
  861. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  862. }
  863. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  864. }
  865. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  866. }
  867. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  868. }
  869. }
  870. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  871. {
  872. if (e.KeyCode == Keys.Enter)
  873. {
  874. try
  875. {
  876. if (OutBoxLength.Text != "")
  877. {
  878. int.Parse(OutBoxLength.Text);
  879. }
  880. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  881. if (!AutoGenBoxCode.Checked)
  882. {
  883. pa_outboxcode.SelectAll();
  884. pa_outboxcode.Focus();
  885. }
  886. else
  887. {
  888. sn_code.Focus();
  889. }
  890. }
  891. catch (Exception)
  892. {
  893. OutBoxLength.Clear();
  894. MessageBox.Show("请输入正确的长度");
  895. }
  896. }
  897. }
  898. private bool CheckOutBoxLength()
  899. {
  900. //勾选了检验长度进行校验
  901. if (OutBoxLength.Text != "")
  902. {
  903. try
  904. {
  905. int.Parse(OutBoxLength.Text);
  906. }
  907. catch (Exception)
  908. {
  909. MessageBox.Show("请填写正确的箱号长度");
  910. return false;
  911. }
  912. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  913. {
  914. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  915. return false;
  916. }
  917. }
  918. if (PreFix.Text != "")
  919. {
  920. try
  921. {
  922. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  923. {
  924. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  925. return false;
  926. }
  927. }
  928. catch (Exception)
  929. {
  930. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  931. return false;
  932. }
  933. }
  934. return true;
  935. }
  936. private void LoadCollectedNum()
  937. {
  938. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  939. BaseUtil.SetFormValue(Controls, dt);
  940. }
  941. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  942. {
  943. if (Keys.Enter == e.KeyCode)
  944. {
  945. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  946. {
  947. if (Remark_PreFix.Text != "")
  948. {
  949. try
  950. {
  951. if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
  952. {
  953. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  954. return;
  955. }
  956. }
  957. catch (Exception)
  958. {
  959. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  960. return;
  961. }
  962. }
  963. if (!AllowRepeat.Checked)
  964. {
  965. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  966. if (dt.Rows.Count > 0)
  967. {
  968. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  969. return;
  970. }
  971. }
  972. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  973. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  974. pa_remark.Text = "";
  975. if (!AutoGenBoxCode.Checked)
  976. {
  977. pa_outboxcode.SelectAll();
  978. pa_outboxcode.Focus();
  979. }
  980. else
  981. {
  982. sn_code.Focus();
  983. }
  984. }
  985. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  986. }
  987. }
  988. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  989. {
  990. if (e.KeyCode == Keys.Enter)
  991. {
  992. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  993. if (!AutoGenBoxCode.Checked)
  994. {
  995. pa_outboxcode.SelectAll();
  996. pa_outboxcode.Focus();
  997. }
  998. else
  999. {
  1000. sn_code.Focus();
  1001. sn_code.SelectAll();
  1002. }
  1003. }
  1004. }
  1005. private void BuildServer_Click(object sender, EventArgs e)
  1006. {
  1007. if (!md.IsOpen)
  1008. {
  1009. md.IP = IP.Text;
  1010. md.Port = Port.Text;
  1011. if (md.Open())
  1012. {
  1013. BaseUtil.SetCacheData("IP", IP.Text);
  1014. BaseUtil.SetCacheData("IPPort", Port.Text);
  1015. OperateResult.AppendText(">>服务开启成功\n");
  1016. }
  1017. }
  1018. else
  1019. OperateResult.AppendText(">>服务已经开启\n");
  1020. }
  1021. private void CloseServer_Click(object sender, EventArgs e)
  1022. {
  1023. if (md.IsOpen)
  1024. {
  1025. md.Close();
  1026. OperateResult.AppendText(">>服务关闭成功\n");
  1027. }
  1028. else
  1029. OperateResult.AppendText(">>服务尚未开启\n");
  1030. }
  1031. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  1032. {
  1033. if (e.KeyCode == Keys.Enter)
  1034. {
  1035. BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
  1036. if (CollecRemark.Checked)
  1037. {
  1038. pa_remark.SelectAll();
  1039. pa_remark.Focus();
  1040. }
  1041. }
  1042. }
  1043. private bool CheckOutBoxLength(string ms_salecode_text)
  1044. {
  1045. if (AutoGenBoxCode.Checked)
  1046. {
  1047. if (ms_salecode_text != "")
  1048. {
  1049. DataTable dt = (DataTable)dh.ExecuteSql(" select pn_number,pn_id,pn_caller,pn_numberlength,pn_leadcode from PACKAGENUMBER where pn_caller='" + pr_code.Text + "'", "select");
  1050. if (dt.Rows.Count > 0)
  1051. {
  1052. string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
  1053. int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
  1054. if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
  1055. {
  1056. OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
  1057. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  1058. }
  1059. if (PreFix.Text != pn_leadcode)
  1060. {
  1061. PreFix.Text = pn_leadcode;
  1062. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1063. }
  1064. }
  1065. else
  1066. {
  1067. //OperateResult.AppendText(">>产品" + pr_code.Text + "未维护箱号规则\n", Color.Black);
  1068. }
  1069. }
  1070. return true;
  1071. }
  1072. return CheckOutBoxLength();
  1073. }
  1074. private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
  1075. {
  1076. if (AutoGenBoxCode.Checked)
  1077. {
  1078. OutBoxLength.Enabled = false;
  1079. PreFix.Enabled = false;
  1080. pa_outboxcode.Enabled = false;
  1081. }
  1082. else
  1083. {
  1084. OutBoxLength.Enabled = true;
  1085. PreFix.Enabled = true;
  1086. pa_outboxcode.Enabled = true;
  1087. }
  1088. }
  1089. }
  1090. }