Packing_PackageCollectionWeigh_HUAGUAN.cs 62 KB

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