Packing_PackageCollection.cs 62 KB

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