Packing_PackageCollection.cs 61 KB

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