Packing_PackageCollection.cs 62 KB

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