Packing_PackageCollection.cs 61 KB

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