Packing_PackageCollection.cs 62 KB

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