Packing_PackageCollection1.cs 62 KB

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