Make_PackageCollectionWeigh.cs 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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. if (pa_standardqty.Text == pa_currentqty.Text && pa_currentqty.Text != "")
  235. pa_remark.Focus();
  236. }
  237. }
  238. }
  239. //输入序列号的回车事件
  240. private void barcode_KeyDown(object sender, KeyEventArgs e)
  241. {
  242. //当用户输入回车键的时候
  243. if (e.KeyCode == Keys.Enter)
  244. {
  245. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  246. {
  247. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_craftcode,ms_prodcode,nvl(ms_checkpack,0) ms_checkpack from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  248. 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"))
  249. {
  250. if (oMsID == "" || oMsID == "null" || oMsID == "0"||(dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
  251. {
  252. oMsID = dt.Rows[0]["ms_id"].ToString();
  253. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  254. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  255. }
  256. if (oMsStatus == "2")
  257. {
  258. string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  259. string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  260. 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();
  261. if (craftstepcode == "")
  262. {
  263. OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
  264. return;
  265. }
  266. }
  267. //if (dh.CheckExist("makeserial LEFT JOIN craft ON ms_craftcode = cr_code and ms_prodcode = cr_prodcode LEFT JOIN craftdetail ON cr_id = cd_crid LEFT JOIN STEP ON CD_NEXTSTEPCODE = ST_CODE ", "ms_id = '" + oMsID + "' AND CD_STEPCODE = '" + User.CurrentStepCode + "' AND NVL(MS_BADTIMES,0)>0 AND ST_IFOQC = -1"))
  268. //{
  269. // OperateResult.AppendText(">>" + sn_code.Text + " 序列号即将送检,此序列号经过维修,提示\n", Color.Purple);
  270. //}
  271. string mscode = dh.getFieldDataByCondition("makeserial LEFT JOIN craft ON ms_craftcode = cr_code and ms_prodcode = cr_prodcode LEFT JOIN craftdetail ON cr_id = cd_crid LEFT JOIN STEP ON CD_NEXTSTEPCODE = ST_CODE", "ms_code", "ms_id = '" + oMsID + "' AND CD_STEPCODE = '" + User.CurrentStepCode + "' AND ST_IFOQC = -1").ToString();
  272. if (mscode != "" && (dh.CheckExist("makeserial", "ms_id = '" + oMsID + "' and NVL(MS_BADTIMES,0)>0 ") || dh.CheckExist("makeserial", "ms_sncode = '" + mscode + "' and NVL(MS_BADTIMES,0)>0 ")))
  273. {
  274. OperateResult.AppendText(">>" + sn_code.Text + " 序列号即将送检,此序列号经过维修,提示\n", Color.Purple);
  275. }
  276. //if (dh.CheckExist("configs", "code = 'checkpack' and data = '1'"))
  277. //{
  278. // if (dt.Rows[0]["ms_checkpack"].ToString() != "0")
  279. // {
  280. // OperateResult.AppendText(sn_code.Text + "处于故障品完工装箱限制状态,不允许采集装箱\n", Color.Red);
  281. // return;
  282. // }
  283. //}
  284. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  285. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  286. {
  287. OperateResult.AppendText("当前序列号下一道工序为" + nextstepcode + ",当前资源不允许采集\n", Color.Red);
  288. return;
  289. }
  290. //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();
  291. sql.Clear();
  292. sql.Append("select nvl(ms_iostatus,0) ms_iostatus,nvl(pr_iffai_user,0)pr_iffai_user,ms_outno,ms_salecode,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
  293. 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 ");
  294. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  295. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  296. string ms_makecode = "";
  297. string ms_prodcode = "";
  298. string ms_iostatus = "";
  299. string ms_outno = "";
  300. string ms_salecode_text = "";
  301. if (dt.Rows.Count > 0)
  302. {
  303. string pr_iffai_user = dt.Rows[0]["pr_iffai_user"].ToString();
  304. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  305. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  306. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  307. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  308. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  309. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  310. if (pr_iffai_user == "-1")
  311. {
  312. if (!LogicHandler.CheckFirst(ms_makecode, out ErrorMessage))
  313. {
  314. OperateResult.AppendText(">工单" + ms_makecode + "首件未通过\n", Color.Red, sn_code);
  315. return;
  316. }
  317. }
  318. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  319. {
  320. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  321. return;
  322. }
  323. BaseUtil.SetFormValue(this.Controls, dt);
  324. }
  325. if (dt.Rows[0]["ms_outno"].ToString() != "")
  326. {
  327. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  328. return;
  329. }
  330. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  331. {
  332. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  333. return;
  334. }
  335. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  336. {
  337. pr_outboxinnerqty.Text = pa_standardqty.Text;
  338. }
  339. if (pa_outboxcode.Text == "")
  340. {
  341. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  342. if (boxcode != "")
  343. {
  344. pa_outboxcode.Text = boxcode;
  345. LoadGridData();
  346. }
  347. else
  348. {
  349. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  350. {
  351. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  352. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  353. }
  354. }
  355. }
  356. if (pa_outboxcode.Text == "")
  357. {
  358. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  359. return;
  360. }
  361. //判断箱内总数必须大于0
  362. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  363. {
  364. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  365. return;
  366. }
  367. sql.Clear();
  368. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_mothercode from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  369. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  370. string MotherBoxCode = "";
  371. if (dt.Rows.Count > 0)
  372. {
  373. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  374. {
  375. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  376. }
  377. if (dt.Rows[0]["pa_outno"].ToString() != "")
  378. {
  379. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  380. return;
  381. }
  382. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  383. {
  384. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  385. return;
  386. }
  387. }
  388. //如果未勾选了取消录入
  389. if (!Cancel.Checked)
  390. {
  391. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  392. if (ms_outboxcode != "")
  393. {
  394. if (ms_outboxcode == pa_outboxcode.Text)
  395. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  396. else
  397. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  398. LoadData();
  399. }
  400. else
  401. {
  402. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  403. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  404. {
  405. pa_currentqty.Text = "";
  406. pa_outboxcode.Text = "";
  407. pa_status.Text = "0";
  408. BaseUtil.CleanDGVData(PackageDetail);
  409. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  410. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text+":"+ OutBoxLength.Text);
  411. }
  412. if (!CheckOutBoxLength(ms_salecode_text))
  413. {
  414. return;
  415. }
  416. if (checkbox11.Checked)
  417. {
  418. if (outinfo.Text == "" || ininfo.Text == "")
  419. {
  420. OperateResult.AppendText("彩箱信息校验,请输入彩箱信息\n", Color.Red);
  421. ininfo.Focus();
  422. ininfo.SelectAll();
  423. return;
  424. }
  425. if (outinfo.Text != ininfo.Text)
  426. {
  427. OperateResult.AppendText("彩箱信息校验,整箱信息与彩箱信息不一致\n", Color.Red);
  428. ininfo.Focus();
  429. ininfo.SelectAll();
  430. return;
  431. }
  432. }
  433. ////箱号不存在的情况
  434. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  435. {
  436. //提示正确返回时传递的信息
  437. if (ErrorMessage.Contains("AFTERSUCCESS"))
  438. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  439. LoadCheckQTY();
  440. LoadCollectedNum();
  441. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  442. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功,额外信息:" + ininfo.Text, sn_code.Text, "");
  443. ininfo.Clear();
  444. LastSncode = sn_code.Text;
  445. //满箱更新状态为1
  446. LoadData();
  447. 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");
  448. //如果母箱号不为空,需要更新总数
  449. if (MotherBoxCode != "")
  450. {
  451. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  452. if (dt.Rows.Count > 0)
  453. {
  454. if (dt.Rows[0]["pa_type"].ToString() == "2")
  455. {
  456. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  457. //更新大箱数量
  458. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  459. //外层有栈板则更新栈板数量
  460. if (MotherCode2 != "")
  461. {
  462. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  463. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  464. }
  465. }
  466. if (dt.Rows[0]["pa_type"].ToString() == "3")
  467. {
  468. 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");
  469. }
  470. }
  471. }
  472. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  473. if (pa_currentqty.Text == "1")
  474. {
  475. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  476. }
  477. LoadGridData();
  478. sn_code.Clear();
  479. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  480. {
  481. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  482. float weigh = float.Parse(ActWeigh);
  483. if (PR_CHECKCARTONW != "0")
  484. {
  485. if (MinWeight == 0 || MaxWeight == 0)
  486. {
  487. OperateResult.AppendText(">>产品" + pr_code.Text + "未维护卡通箱重量范围\n", Color.Red);
  488. return;
  489. }
  490. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  491. {
  492. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  493. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  494. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  495. return;
  496. }
  497. }
  498. DataTable dt1 = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from makeserial where ms_downstatus=-1 and ms_outboxcode='" + pa_outboxcode.Text + "'", "select");
  499. if (dt1.Rows.Count > 0)
  500. {
  501. if (dt1.Rows[0][0].ToString() != "")
  502. {
  503. OperateResult.AppendText(">序列号:" + dt1.Rows[0][0].ToString() + "处于下地状态,箱不允许过站\n", Color.Red, sn_code);
  504. return;
  505. }
  506. }
  507. if (CollecRemark.Checked && pa_remark.Text == "")
  508. {
  509. OperateResult.AppendText(">已勾选采集备注,备注信息必须填写,如不需采集,请取消勾选\n", Color.Red, sn_code);
  510. pa_remark.SelectAll();
  511. pa_remark.Focus();
  512. return;
  513. }
  514. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  515. pa_standardqty.Text = "";
  516. pa_status.Text = "1";
  517. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
  518. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  519. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  520. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  521. {
  522. 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 + "'");
  523. }
  524. else
  525. {
  526. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  527. }
  528. LoadCheckQTY();
  529. LoadCollectedNum();
  530. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量完成\n", Color.Green);
  531. if (AutoPrint.Checked)
  532. Print_Click(new object(), new EventArgs());
  533. if (!CollecRemark.Checked)
  534. {
  535. if (!AutoGenBoxCode.Checked)
  536. {
  537. pa_outboxcode.Focus();
  538. pa_outboxcode.SelectAll();
  539. }
  540. else
  541. {
  542. sn_code.Focus();
  543. sn_code.SelectAll();
  544. }
  545. }
  546. else
  547. {
  548. pa_remark.SelectAll();
  549. pa_remark.Focus();
  550. }
  551. }
  552. }
  553. else
  554. {
  555. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  556. ininfo.Clear();
  557. }
  558. }
  559. }
  560. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  561. else
  562. {
  563. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  564. {
  565. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  566. 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");
  567. //如果母箱号不为空,需要更新总数
  568. if (MotherBoxCode != "")
  569. {
  570. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  571. if (dt.Rows.Count > 0)
  572. {
  573. if (dt.Rows[0]["pa_type"].ToString() == "2")
  574. {
  575. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  576. //更新大箱数量
  577. 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");
  578. //外层有栈板则更新栈板数量
  579. if (MotherCode2 != "")
  580. {
  581. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  582. 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");
  583. }
  584. }
  585. if (dt.Rows[0]["pa_type"].ToString() == "3")
  586. {
  587. 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");
  588. }
  589. }
  590. }
  591. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  592. LoadGridData();
  593. pa_status.Text = "0";
  594. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  595. ininfo.Clear();
  596. }
  597. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  598. }
  599. }
  600. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  601. }
  602. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  603. }
  604. }
  605. private void Clean_Click(object sender, EventArgs e)
  606. {
  607. OperateResult.Clear();
  608. }
  609. private void pr_code_TextChanged(object sender, EventArgs e)
  610. {
  611. LoadCheckQTY();
  612. 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");
  613. PrintLabel.DataSource = dt;
  614. PrintLabel.DisplayMember = "la_url";
  615. PrintLabel.ValueMember = "la_id";
  616. }
  617. private void Make_PackageCollectionWeigh_FormClosing(object sender, FormClosingEventArgs e)
  618. {
  619. BaseUtil.ClosePrint(lbl);
  620. if (serialPort1.IsOpen)
  621. {
  622. GetData = false;
  623. serialPort1.Close();
  624. SystemInf.OpenPort.Remove(serialPort1.PortName);
  625. thread.Interrupt();
  626. }
  627. //thread.Abort();
  628. }
  629. private void Packing_Click(object sender, EventArgs e)
  630. {
  631. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  632. {
  633. string Seal = "";
  634. if (sender != "true")
  635. {
  636. Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  637. }
  638. else
  639. Seal = "Yes";
  640. if (Seal == "Yes")
  641. {
  642. LoadData();
  643. LoadGridData();
  644. DataTable dt1 = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from makeserial where ms_downstatus=-1 and ms_outboxcode='" + pa_outboxcode.Text + "'", "select");
  645. if (dt1.Rows.Count > 0)
  646. {
  647. if (dt1.Rows[0][0].ToString() != "")
  648. {
  649. OperateResult.AppendText(">序列号:" + dt1.Rows[0][0].ToString() + "处于下地状态,箱不允许过站\n", Color.Red, sn_code);
  650. return;
  651. }
  652. }
  653. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  654. float weigh = float.Parse(ActWeigh);
  655. if (PR_CHECKCARTONW != "0" && pa_standardqty.Text == pa_currentqty.Text)
  656. {
  657. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  658. {
  659. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量,不能完成工序过站\n", Color.Red);
  660. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  661. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  662. return;
  663. }
  664. }
  665. if (CollecRemark.Checked && pa_remark.Text == "")
  666. {
  667. OperateResult.AppendText(">已勾选采集备注,备注信息必须填写,如不需采集,请取消勾选\n", Color.Red, sn_code);
  668. pa_remark.SelectAll();
  669. pa_remark.Focus();
  670. return;
  671. }
  672. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  673. pa_status.Text = "1";
  674. pa_standardqty.Text = "";
  675. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "封箱成功", pa_outboxcode.Text, "");
  676. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  677. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  678. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  679. string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  680. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  681. {
  682. 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 + "'");
  683. }
  684. else
  685. {
  686. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  687. }
  688. if (AutoPrint.Checked)
  689. Print_Click(new object(), new EventArgs());
  690. LoadCheckQTY();
  691. if (!CollecRemark.Checked)
  692. {
  693. if (!AutoGenBoxCode.Checked)
  694. {
  695. pa_outboxcode.Focus();
  696. pa_outboxcode.SelectAll();
  697. }
  698. else
  699. {
  700. sn_code.Focus();
  701. sn_code.SelectAll();
  702. }
  703. }
  704. else
  705. {
  706. pa_remark.SelectAll();
  707. pa_remark.Focus();
  708. }
  709. }
  710. }
  711. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  712. }
  713. private void SendCheck_Click(object sender, EventArgs e)
  714. {
  715. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  716. {
  717. 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");
  718. if (dt.Rows[0][0].ToString() != "")
  719. {
  720. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  721. return;
  722. }
  723. sql.Clear();
  724. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  725. dh.ExecuteSql(sql.GetString(), "select");
  726. ob_nowcheckqty.Text = "";
  727. ob_batchqty.Text = "";
  728. ob_nowcheckqty.ForeColor = Color.Black;
  729. SendCheck.Enabled = false;
  730. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  731. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  732. //记录操作日志
  733. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  734. ob_checkno.Text = "";
  735. }
  736. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  737. }
  738. bool AutoCut;
  739. private void LoadCheckQTY()
  740. {
  741. sql.Clear();
  742. string condition = "";
  743. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  744. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  745. if (nowcheckqty + 1 == batchqty && AutoCut)
  746. {
  747. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  748. }
  749. else
  750. {
  751. condition = "and ob_status='ENTERING' ";
  752. }
  753. if (pr_sendchecktype.Text == "SaleCode")
  754. {
  755. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  756. }
  757. else if (pr_sendchecktype.Text == "MakeCode")
  758. {
  759. condition += " and ob_makecode='" + ms_makecode.Text + "'";
  760. }
  761. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  762. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  763. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  764. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  765. if (dt.Rows.Count > 0)
  766. {
  767. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  768. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  769. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  770. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  771. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  772. if (nowcheckqty >= batchqty)
  773. {
  774. ob_nowcheckqty.ForeColor = Color.Red;
  775. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  776. if (AutoCut)
  777. {
  778. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  779. }
  780. }
  781. }
  782. else
  783. {
  784. ob_batchqty.Text = "";
  785. ob_nowcheckqty.Text = "";
  786. ob_checkno.Text = "";
  787. SendCheck.Enabled = false;
  788. }
  789. if (ob_batchqty.Text != "")
  790. {
  791. SendCheck.Enabled = true;
  792. }
  793. else
  794. {
  795. SendCheck.Enabled = false;
  796. }
  797. }
  798. private void ob_checkno_TextChanged(object sender, EventArgs e)
  799. {
  800. if (ob_checkno.Text != "")
  801. {
  802. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  803. if (Cut == "" || Cut == "0")
  804. AutoCut = false;
  805. else
  806. AutoCut = true;
  807. SendCheck.Enabled = true;
  808. }
  809. }
  810. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  811. {
  812. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  813. {
  814. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  815. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  816. }
  817. }
  818. private void DeleteAll_Click(object sender, EventArgs e)
  819. {
  820. if (pa_outboxcode.Text == "")
  821. {
  822. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  823. return;
  824. }
  825. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  826. if (Delete == "Yes")
  827. {
  828. 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");
  829. if (dt.Rows.Count > 0)
  830. {
  831. if (dt.Rows[0]["pa_outno"].ToString() != "")
  832. {
  833. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  834. return;
  835. }
  836. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  837. {
  838. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  839. return;
  840. }
  841. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  842. {
  843. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  844. {
  845. string ob_status = dt.Rows[0]["ob_status"].ToString();
  846. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  847. //不存在抽检批次或者还未检验可以拆解
  848. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  849. {
  850. sql.Clear();
  851. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  852. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  853. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  854. List<string> SQLS1 = new List<string>();
  855. for (int i = 0; i < dt.Rows.Count; i++)
  856. {
  857. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  858. string num = dt.Rows[i]["num"].ToString();
  859. // 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 + "'");
  860. // 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 + "'");
  861. 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 + "'");
  862. //扣减已完工数
  863. 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 + "'");
  864. }
  865. if (pa_checkno != "")
  866. {
  867. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  868. 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 + "'");
  869. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  870. }
  871. //更新序列号状态
  872. 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 + "'");
  873. //抽检批次不为空的时候进行移除
  874. dh.ExecuteSQLTran(SQLS1.ToArray());
  875. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  876. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  877. //if (standqty != "")
  878. //{
  879. // //置空原箱
  880. // 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");
  881. //}
  882. //else
  883. // //置空原箱
  884. // 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");
  885. dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "insert");
  886. dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'", "insert");
  887. dh.ExecuteSql("delete from package where pa_outboxcode = '"+ pa_outboxcode.Text + "'","delete");
  888. pa_status.Text = "0";
  889. //删除箱的明细
  890. dh.ExecuteSql("delete from labelprintlog where lpl_value='" + pa_outboxcode.Text + "'", "delete");
  891. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'","delete");
  892. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  893. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  894. LoadGridData();
  895. LoadCheckQTY();
  896. }
  897. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  898. }
  899. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  900. }
  901. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  902. }
  903. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  904. }
  905. }
  906. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  907. {
  908. if (e.KeyCode == Keys.Enter)
  909. {
  910. try
  911. {
  912. if (OutBoxLength.Text != "")
  913. {
  914. int.Parse(OutBoxLength.Text);
  915. }
  916. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  917. if (!AutoGenBoxCode.Checked)
  918. {
  919. pa_outboxcode.Focus();
  920. pa_outboxcode.SelectAll();
  921. }
  922. else
  923. {
  924. sn_code.Focus();
  925. }
  926. }
  927. catch (Exception)
  928. {
  929. OutBoxLength.Clear();
  930. MessageBox.Show("请输入正确的长度");
  931. }
  932. }
  933. }
  934. private bool CheckOutBoxLength()
  935. {
  936. //勾选了检验长度进行校验
  937. if (OutBoxLength.Text != "")
  938. {
  939. try
  940. {
  941. int.Parse(OutBoxLength.Text);
  942. }
  943. catch (Exception)
  944. {
  945. MessageBox.Show("请填写正确的箱号长度");
  946. return false;
  947. }
  948. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  949. {
  950. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  951. pa_outboxcode.SelectAll();
  952. return false;
  953. }
  954. }
  955. if (PreFix.Text != "")
  956. {
  957. try
  958. {
  959. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  960. {
  961. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  962. pa_outboxcode.SelectAll();
  963. return false;
  964. }
  965. }
  966. catch (Exception)
  967. {
  968. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  969. pa_outboxcode.SelectAll();
  970. return false;
  971. }
  972. }
  973. return true;
  974. }
  975. private void RefreshWeigh_Click(object sender, EventArgs e)
  976. {
  977. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  978. sql.Clear();
  979. sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + prcode + "'");
  980. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  981. if (dt.Rows.Count > 0)
  982. {
  983. //重量的临时变量
  984. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  985. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  986. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  987. Weight = double.Parse(_weight == "" ? "0" : _weight);
  988. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  989. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  990. if (Weight - MinWeight == MaxWeight - Weight)
  991. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  992. else
  993. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  994. }
  995. }
  996. private void LoadCollectedNum()
  997. {
  998. 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");
  999. BaseUtil.SetFormValue(Controls, dt);
  1000. }
  1001. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  1002. {
  1003. if (Keys.Enter == e.KeyCode)
  1004. {
  1005. if (pa_remark.Text.Trim(' ') != "")
  1006. {
  1007. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  1008. {
  1009. if (Remark_PreFix.Text != "")
  1010. {
  1011. try
  1012. {
  1013. if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
  1014. {
  1015. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  1016. return;
  1017. }
  1018. }
  1019. catch (Exception)
  1020. {
  1021. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  1022. return;
  1023. }
  1024. }
  1025. if (!AllowRepeat.Checked)
  1026. {
  1027. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  1028. if (dt.Rows.Count > 0)
  1029. {
  1030. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  1031. return;
  1032. }
  1033. }
  1034. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  1035. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  1036. pa_remark.Text = "";
  1037. LoadGridData();
  1038. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  1039. {
  1040. Packing_Click("true", new EventArgs());
  1041. }
  1042. if (!AutoGenBoxCode.Checked)
  1043. {
  1044. pa_outboxcode.SelectAll();
  1045. pa_outboxcode.Focus();
  1046. }
  1047. else
  1048. {
  1049. sn_code.Focus();
  1050. }
  1051. }
  1052. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  1053. }else OperateResult.AppendText(">>备注信息不可为空\n", Color.Red);
  1054. }
  1055. }
  1056. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  1057. {
  1058. if (e.KeyCode == Keys.Enter)
  1059. {
  1060. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1061. if (!AutoGenBoxCode.Checked)
  1062. {
  1063. pa_outboxcode.Focus();
  1064. pa_outboxcode.SelectAll();
  1065. }
  1066. else
  1067. {
  1068. sn_code.Focus();
  1069. }
  1070. }
  1071. }
  1072. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  1073. {
  1074. if (e.KeyCode == Keys.Enter)
  1075. {
  1076. BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
  1077. if (CollecRemark.Checked)
  1078. {
  1079. pa_remark.SelectAll();
  1080. pa_remark.Focus();
  1081. }
  1082. }
  1083. }
  1084. private bool CheckOutBoxLength(string ms_salecode_text)
  1085. {
  1086. if (AutoGenBoxCode.Checked)
  1087. {
  1088. if (ms_salecode_text != "")
  1089. {
  1090. 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");
  1091. if (dt.Rows.Count > 0)
  1092. {
  1093. string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
  1094. int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
  1095. if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
  1096. {
  1097. OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
  1098. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  1099. }
  1100. if (PreFix.Text != pn_leadcode)
  1101. {
  1102. PreFix.Text = pn_leadcode;
  1103. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1104. }
  1105. }
  1106. else
  1107. {
  1108. OperateResult.AppendText(">>订单号" + ms_salecode_text + "未维护箱号规则\n", Color.Black);
  1109. }
  1110. }
  1111. return true;
  1112. }
  1113. return CheckOutBoxLength();
  1114. }
  1115. private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
  1116. {
  1117. if (AutoGenBoxCode.Checked)
  1118. {
  1119. OutBoxLength.Enabled = false;
  1120. PreFix.Enabled = false;
  1121. }
  1122. else
  1123. {
  1124. OutBoxLength.Enabled = true;
  1125. PreFix.Enabled = true;
  1126. }
  1127. }
  1128. private void ininfo_KeyDown(object sender, KeyEventArgs e)
  1129. {
  1130. if (e.KeyCode == Keys.Enter)
  1131. {
  1132. if (checkbox11.Checked && ininfo.Text != "")
  1133. {
  1134. sn_code.Focus();
  1135. sn_code.SelectAll();
  1136. barcode_KeyDown(sender, e);
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }