Make_PackageCollectionWeigh.cs 27 KB

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