Make_PackageCollectionWeigh.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. namespace UAS_MES.Make
  16. {
  17. public partial class Make_PackageCollectionWeigh : Form
  18. {
  19. DataHelper dh;
  20. DataTable dt;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. ApplicationClass lbl;
  24. Thread thread;
  25. DataTable Dbfind;
  26. string ErrorMessage = "";
  27. string oMakeCode = "";
  28. string oMsID = "";
  29. //称量的标准重量
  30. double Weight;
  31. //最大重量
  32. double MaxWeight;
  33. //最小重量
  34. double MinWeight;
  35. decimal StandardQTY = 0;
  36. string oOutBoxCode = "";
  37. //创建串口实例
  38. SerialPort serialPort1 = new SerialPort();
  39. //true的时候表示从串口读取数据
  40. bool GetData = true;
  41. System.DateTime[] indate;
  42. public Make_PackageCollectionWeigh()
  43. {
  44. InitializeComponent();
  45. }
  46. //创建打印进程
  47. private void NewPrint()
  48. {
  49. try
  50. {
  51. lbl = new ApplicationClass();
  52. BaseUtil.WriteLbl(lbl);
  53. }
  54. catch (Exception ex)
  55. {
  56. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  57. }
  58. }
  59. private void 包装采集_Load(object sender, EventArgs e)
  60. {
  61. pa_outboxcode.ShowClickIcon = false;
  62. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  63. Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  64. //设置DbFind的必须的数据
  65. PrintNum.Value = 1;
  66. asc.controllInitializeSize(this);
  67. thread = new Thread(NewPrint);
  68. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  69. BaseUtil.SetFormCenter(stw);
  70. stw.ShowDialog();
  71. dh = new DataHelper();
  72. thread = new Thread(getSerialData);
  73. try
  74. {
  75. GetData = true;
  76. serialPort1.PortName = ComList.Text;
  77. serialPort1.BaudRate = int.Parse(Baurate.Text);
  78. serialPort1.Open();
  79. thread.Start();
  80. }
  81. catch (Exception mes)
  82. {
  83. if (Baurate.Text == "" || ComList.Text == "")
  84. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  85. else
  86. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  87. }
  88. }
  89. private void getSerialData()
  90. {
  91. if (serialPort1.IsOpen)
  92. {
  93. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  94. {
  95. SystemInf.OpenPort.Add(serialPort1.PortName);
  96. try
  97. {
  98. while (GetData)
  99. {
  100. try
  101. {
  102. weight.Text = Regex.Replace(serialPort1.ReadLine(), "\\D+", "");
  103. if (pr_cartonunit.Text == "kg")
  104. weight.Text = (double.Parse(weight.Text) / 1000).ToString();
  105. }
  106. catch (Exception)
  107. {
  108. GetData = false;
  109. }
  110. }
  111. }
  112. catch (IOException ex) { MessageBox.Show(ex.Message); }
  113. }
  114. else
  115. MessageBox.Show("端口已被占用,请关闭其他窗口");
  116. }
  117. }
  118. private void 包装采集_SizeChanged(object sender, EventArgs e)
  119. {
  120. asc.controlAutoSize(this);
  121. }
  122. private void 包装采集_Activated(object sender, EventArgs e)
  123. {
  124. pa_outboxcode.Focus();
  125. }
  126. //刷新表单的数据的数据
  127. private void LoadData()
  128. {
  129. //加载表单数据
  130. string Err = "";
  131. if (pa_outboxcode.Text != "")
  132. {
  133. sql.Clear();
  134. sql.Append("select pr_cartonmaxw,pa_makecode,pr_cartonunit,pr_cartonminw,pr_cartongw,pa_outboxcode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,");
  135. sql.Append("pa_status,pr_packrule,pr_detail,pa_packageqty,nvl(pa_standardqty,pr_outboxinnerqty)pr_outboxinnerqty,pa_currentqty from package left join ");
  136. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  137. Err = "箱号";
  138. }
  139. else
  140. {
  141. sql.Clear();
  142. sql.Append("select pr_cartonmaxw,pa_makecode,pr_cartonunit,pr_cartonminw,pr_cartongw,ms_makecode,pa_status,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,");
  143. sql.Append("pa_checkno,pr_packrule,pr_code,pr_detail,nvl(pa_standardqty,pr_outboxinnerqty) pr_outboxinnerqty,pa_packageqty,pa_currentqty,");
  144. sql.Append("pa_outboxcode from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  145. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  146. Err = "序列号";
  147. }
  148. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  149. if (dt.Rows.Count > 0)
  150. {
  151. //重量的临时变量
  152. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  153. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  154. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  155. //赋值重量单位
  156. Weight = double.Parse(_weight == "" ? "0" : _weight);
  157. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  158. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  159. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  160. BaseUtil.SetFormValue(this.Controls, dt);
  161. if (Weight - MinWeight == MaxWeight - Weight)
  162. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight);
  163. else
  164. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight;
  165. }
  166. else OperateResult.AppendText(">>" + Err + "不存在\n", Color.Red);
  167. }
  168. private void LoadGridData()
  169. {
  170. //加载Grid数据
  171. 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");
  172. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  173. //更新界面的采集数量
  174. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  175. }
  176. private void InsertDetail()
  177. {
  178. if (dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_id='" + oMsID + "'").ToString() == sn_code.Text)
  179. {
  180. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) < int.Parse(pr_outboxinnerqty.Text))
  181. {
  182. if (LogicHandler.SetStepResult(pa_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
  183. {
  184. LoadCheckQTY();
  185. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  186. //满箱更新状态为1
  187. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) + 1 == int.Parse(pr_outboxinnerqty.Text))
  188. {
  189. //检查重量合格
  190. if (float.Parse(weight.Text) > MinWeight && float.Parse(weight.Text) < MaxWeight)
  191. {
  192. dh.UpdateByCondition("package", "pa_status=1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  193. if (AutoPrint.Checked)
  194. Print_Click(new object(), new EventArgs());
  195. }
  196. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  197. }
  198. LoadGridData();
  199. sn_code.Clear();
  200. }
  201. }
  202. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已采集满\n", Color.Red);
  203. }
  204. else OperateResult.AppendText("序列号" + sn_code.Text + "不存在", Color.Red, sn_code);
  205. }
  206. private void Print_Click(object sender, EventArgs e)
  207. {
  208. if (PrintLabel.Items.Count != 0)
  209. {
  210. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  211. {
  212. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  213. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  214. Print.CodeSoft(Tag.ToString(), lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
  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. if (e.KeyCode == Keys.Enter)
  224. {
  225. LoadData();
  226. LoadGridData();
  227. }
  228. }
  229. //输入序列号的回车事件
  230. private void barcode_KeyDown(object sender, KeyEventArgs e)
  231. {
  232. //当用户输入回车键的时候
  233. if (e.KeyCode == Keys.Enter)
  234. {
  235. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  236. {
  237. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  238. {
  239. if (pa_outboxcode.Text == "")
  240. {
  241. LoadData();
  242. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  243. LoadGridData();
  244. else
  245. {
  246. pa_outboxcode.MakeCode = pa_makecode.Text;
  247. pa_outboxcode.ProdCode = pr_code.Text;
  248. pa_outboxcode.Caller = "PACKAGE";
  249. if (AutoGenBoxCode.Checked)
  250. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  251. }
  252. }
  253. if (pa_outboxcode.Text == "")
  254. {
  255. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  256. return;
  257. }
  258. //按工单核对装箱
  259. switch (pr_packrule.Text.ToUpper())
  260. {
  261. case "MAKE":
  262. if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != pa_makecode.Text)
  263. {
  264. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
  265. return;
  266. }
  267. break;
  268. case "SALE":
  269. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  270. {
  271. sql.Clear();
  272. sql.Append("select 1 from package left join make on pa_salecode=ma_salecode left join makeserial ");
  273. sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
  274. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  275. if (dt.Rows.Count == 0)
  276. {
  277. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
  278. return;
  279. }
  280. }
  281. break;
  282. case "PROD":
  283. if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
  284. {
  285. OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
  286. return;
  287. }
  288. break;
  289. default:
  290. break;
  291. }
  292. //判断箱内总数必须大于0
  293. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  294. {
  295. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  296. return;
  297. }
  298. //如果未勾选了取消录入
  299. if (!Cancel.Checked)
  300. {
  301. //判断序列号是否已经装箱
  302. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  303. {
  304. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
  305. }
  306. else
  307. {
  308. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  309. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || pa_status.Text == "1")
  310. {
  311. pa_currentqty.Text = "";
  312. pa_outboxcode.Text = "";
  313. pa_status.Text = "0";
  314. BaseUtil.CleanDGVData(PackageDetail);
  315. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  316. }
  317. ////箱号不存在的情况
  318. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  319. {
  320. if (LogicHandler.SetStepResult(pa_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
  321. {
  322. LoadCheckQTY();
  323. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  324. //满箱更新状态为1
  325. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) + 1 == int.Parse(pr_outboxinnerqty.Text))
  326. {
  327. //检查重量合格
  328. if (float.Parse(weight.Text) > MinWeight && float.Parse(weight.Text) < MaxWeight)
  329. {
  330. dh.UpdateByCondition("package", "pa_status=1,pa_weight='" + weight.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  331. if (AutoPrint.Checked)
  332. Print_Click(new object(), new EventArgs());
  333. }
  334. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  335. }
  336. LoadData();
  337. LoadGridData();
  338. sn_code.Clear();
  339. }
  340. }
  341. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  342. }
  343. }
  344. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  345. else
  346. {
  347. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  348. {
  349. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "取消采集成功", sn_code.Text, "");
  350. LoadGridData();
  351. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  352. }
  353. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  354. }
  355. }
  356. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  357. }
  358. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  359. }
  360. }
  361. private void Clean_Click(object sender, EventArgs e)
  362. {
  363. OperateResult.Clear();
  364. }
  365. private void pr_code_TextChanged(object sender, EventArgs e)
  366. {
  367. LoadCheckQTY();
  368. pa_outboxcode.MakeCode = pa_makecode.Text;
  369. pa_outboxcode.ProdCode = pr_code.Text;
  370. pa_outboxcode.Caller = "PACKAGE";
  371. dt = (DataTable)dh.ExecuteSql("select pl_labelcode||':'||pl_labelname pl_laname,pl_labelname,pl_labelcode,pl_labelurl,pl_indate from productlabel where pl_prodcode='" + pr_code.Text + "' order by pl_isdefault desc ", "select");
  372. PrintLabel.DataSource = dt;
  373. PrintLabel.DisplayMember = "pl_laname";
  374. PrintLabel.ValueMember = "pl_labelcode";
  375. ftpOperater ftp = new ftpOperater();
  376. indate = new System.DateTime[dt.Rows.Count];
  377. for (int i = 0; i < dt.Rows.Count; i++)
  378. {
  379. BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
  380. indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
  381. }
  382. }
  383. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  384. {
  385. BaseUtil.ClosePrint(lbl);
  386. if (serialPort1.IsOpen)
  387. {
  388. GetData = false;
  389. serialPort1.Close();
  390. SystemInf.OpenPort.Remove(serialPort1.PortName);
  391. thread.Interrupt();
  392. }
  393. dh.Dispose();
  394. }
  395. private void Packing_Click(object sender, EventArgs e)
  396. {
  397. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_status<>1"))
  398. {
  399. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  400. pa_status.Text = "1";
  401. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  402. }
  403. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  404. }
  405. private void SendCheck_Click(object sender, EventArgs e)
  406. {
  407. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "0")
  408. {
  409. sql.Clear();
  410. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  411. dh.ExecuteSql(sql.GetString(), "select");
  412. ob_nowcheckqty.Text = "";
  413. ob_batchqty.Text = "";
  414. ob_nowcheckqty.ForeColor = Color.Black;
  415. SendCheck.Enabled = false;
  416. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  417. LogicHandler.InsertMakeProcess(sn_code.Text, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  418. //记录操作日志
  419. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  420. ob_checkno.Text = "";
  421. }
  422. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  423. }
  424. bool AutoCut;
  425. private void LoadCheckQTY()
  426. {
  427. sql.Clear();
  428. string condition = "";
  429. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  430. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  431. if (nowcheckqty + 1 == batchqty && AutoCut)
  432. {
  433. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  434. }
  435. else
  436. {
  437. condition = "and ob_status='ENTERING' ";
  438. }
  439. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  440. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  441. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  442. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  443. if (dt.Rows.Count > 0)
  444. {
  445. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  446. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  447. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  448. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  449. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  450. if (nowcheckqty == batchqty)
  451. {
  452. ob_nowcheckqty.ForeColor = Color.Red;
  453. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  454. }
  455. }
  456. else
  457. {
  458. ob_batchqty.Text = "";
  459. ob_nowcheckqty.Text = "";
  460. ob_checkno.Text = "";
  461. SendCheck.Enabled = false;
  462. }
  463. if (ob_batchqty.Text != "")
  464. {
  465. SendCheck.Enabled = true;
  466. }
  467. else
  468. {
  469. SendCheck.Enabled = false;
  470. }
  471. }
  472. private void ob_checkno_TextChanged(object sender, EventArgs e)
  473. {
  474. if (ob_checkno.Text != "")
  475. {
  476. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  477. if (Cut == "" || Cut == "0")
  478. AutoCut = false;
  479. else
  480. AutoCut = true;
  481. SendCheck.Enabled = true;
  482. }
  483. }
  484. private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  485. {
  486. if (e.KeyCode == Keys.Enter)
  487. ResetPackQTY();
  488. }
  489. private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  490. {
  491. ResetPackQTY();
  492. }
  493. private void ResetPackQTY()
  494. {
  495. //数据不符合限制的时候保持原有值
  496. int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  497. if (!(pr_outboxinnerqty.Value >= curretnqty))
  498. {
  499. pr_outboxinnerqty.Value = StandardQTY;
  500. }
  501. else
  502. {
  503. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  504. {
  505. string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  506. if (checknostatus == "" || checknostatus == "ENTERING")
  507. {
  508. if (pa_downstatus.Text == "0")
  509. {
  510. if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  511. {
  512. dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Value + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  513. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Value + "'", pa_outboxcode.Text, pa_checkno.Text);
  514. return;
  515. }
  516. else
  517. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  518. }
  519. else
  520. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  521. }
  522. else
  523. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  524. }
  525. else
  526. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  527. pr_outboxinnerqty.Value = StandardQTY;
  528. }
  529. }
  530. }
  531. }