Packing_PackageCollection.cs 62 KB

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