Packing_PackageCollectionYLF.cs 69 KB

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