Make_PackageCollectionWeigh.cs 60 KB

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