Packing_PackageCollection.cs 60 KB

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