Packing_PackageCollectionWeigh_ReadLine1.cs 65 KB

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