Packing_PackageCollection.cs 62 KB

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