Packing_PackageCollection.cs 61 KB

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