Make_PackageCollectionWeigh.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. Document doc;
  24. ApplicationClass lbl;
  25. Thread thread;
  26. DataTable Dbfind;
  27. string ErrorMessage = "";
  28. string oMakeCode = "";
  29. string oMsID = "";
  30. //称量的标准重量
  31. double Weight;
  32. //最大重量
  33. double MaxWeight;
  34. //最小重量
  35. double MinWeight;
  36. decimal StandardQTY = 0;
  37. string oOutBoxCode = "";
  38. string LastSncode;
  39. //创建串口实例
  40. SerialPort serialPort1 = new SerialPort();
  41. //true的时候表示从串口读取数据
  42. bool GetData = true;
  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. doc = lbl.Documents.Open(ftpOperater.DownLoadTo + PrintLabel.Text);
  177. Print.CodeSoft(Tag.ToString(), doc, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text));
  178. }
  179. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  180. }
  181. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  182. }
  183. //加载工单信息和装箱明细信息
  184. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  185. {
  186. if (e.KeyCode == Keys.Enter)
  187. {
  188. LoadData();
  189. LoadGridData();
  190. }
  191. }
  192. //输入序列号的回车事件
  193. private void barcode_KeyDown(object sender, KeyEventArgs e)
  194. {
  195. //当用户输入回车键的时候
  196. if (e.KeyCode == Keys.Enter)
  197. {
  198. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  199. {
  200. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  201. {
  202. sql.Clear();
  203. sql.Append("select ms_makecode,pr_code,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,pr_code,pr_detail,");
  204. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  205. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  206. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  207. if (dt.Rows.Count > 0)
  208. {
  209. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  210. BaseUtil.SetFormValue(this.Controls, dt);
  211. }
  212. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  213. {
  214. pr_outboxinnerqty.Value = int.Parse(pa_standardqty.Text);
  215. }
  216. if (pa_outboxcode.Text == "")
  217. {
  218. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  219. if (boxcode != "")
  220. {
  221. pa_outboxcode.Text = boxcode;
  222. LoadGridData();
  223. }
  224. else
  225. {
  226. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  227. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  228. }
  229. }
  230. if (pa_outboxcode.Text == "")
  231. {
  232. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  233. return;
  234. }
  235. if (pa_status.Text != "1")
  236. {
  237. //按工单核对装箱
  238. switch (pr_packrule.Text.ToUpper())
  239. {
  240. case "MAKE":
  241. if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != pa_makecode.Text && pa_makecode.Text != "")
  242. {
  243. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
  244. return;
  245. }
  246. break;
  247. case "SALE":
  248. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  249. {
  250. sql.Clear();
  251. sql.Append("select 1 from package left join make on pa_salecode=ma_salecode and pa_prodcode=ma_prodcode left join makeserial ");
  252. sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
  253. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  254. if (dt.Rows.Count == 0)
  255. {
  256. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
  257. return;
  258. }
  259. }
  260. break;
  261. case "PROD":
  262. if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
  263. {
  264. OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
  265. return;
  266. }
  267. break;
  268. case "MIX":
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. //判断箱内总数必须大于0
  275. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  276. {
  277. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  278. return;
  279. }
  280. //如果未勾选了取消录入
  281. if (!Cancel.Checked)
  282. {
  283. //判断序列号是否已经装箱
  284. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  285. {
  286. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
  287. }
  288. else
  289. {
  290. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  291. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  292. {
  293. pa_currentqty.Text = "";
  294. pa_outboxcode.Text = "";
  295. pa_status.Text = "0";
  296. BaseUtil.CleanDGVData(PackageDetail);
  297. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  298. }
  299. ////箱号不存在的情况
  300. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  301. {
  302. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
  303. {
  304. //提示正确返回时传递的信息
  305. if (ErrorMessage.Contains("AFTERSUCCESS"))
  306. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  307. LoadCheckQTY();
  308. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  309. //满箱更新状态为1
  310. LoadData();
  311. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  312. if (pa_currentqty.Text == "1")
  313. {
  314. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  315. dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  316. }
  317. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  318. {
  319. //检查重量合格
  320. if (float.Parse(weight.Text) > MinWeight && float.Parse(weight.Text) < MaxWeight)
  321. {
  322. dh.UpdateByCondition("package", "pa_status=1,pa_packageqty=pa_currentqty,pa_weight='" + weight.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  323. pa_standardqty.Text = "";
  324. pa_status.Text = "1";
  325. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量合格\n", Color.Green);
  326. LastSncode = sn_code.Text;
  327. if (AutoPrint.Checked)
  328. Print_Click(new object(), new EventArgs());
  329. }
  330. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  331. }
  332. LoadGridData();
  333. sn_code.Clear();
  334. }
  335. }
  336. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  337. }
  338. }
  339. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  340. else
  341. {
  342. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  343. {
  344. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "取消采集成功", sn_code.Text, "");
  345. LoadGridData();
  346. pa_status.Text = "0";
  347. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  348. }
  349. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  350. }
  351. }
  352. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  353. }
  354. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  355. }
  356. }
  357. private void Clean_Click(object sender, EventArgs e)
  358. {
  359. OperateResult.Clear();
  360. }
  361. private void pr_code_TextChanged(object sender, EventArgs e)
  362. {
  363. LoadCheckQTY();
  364. pa_outboxcode.MakeCode = pa_makecode.Text;
  365. pa_outboxcode.ProdCode = pr_code.Text;
  366. pa_outboxcode.Caller = "PACKAGE";
  367. dt = (DataTable)dh.ExecuteSql("select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  368. PrintLabel.DataSource = dt;
  369. PrintLabel.DisplayMember = "la_name";
  370. PrintLabel.ValueMember = "la_id";
  371. ftpOperater ftp = new ftpOperater();
  372. for (int i = 0; i < dt.Rows.Count; i++)
  373. {
  374. BaseUtil.GetPrintLabel(dt.Rows[i]["la_name"].ToString(), dt.Rows[i]["la_url"].ToString());
  375. }
  376. }
  377. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  378. {
  379. BaseUtil.ClosePrint(lbl);
  380. if (serialPort1.IsOpen)
  381. {
  382. GetData = false;
  383. serialPort1.Close();
  384. SystemInf.OpenPort.Remove(serialPort1.PortName);
  385. thread.Interrupt();
  386. }
  387. dh.Dispose();
  388. }
  389. private void Packing_Click(object sender, EventArgs e)
  390. {
  391. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_status<>1"))
  392. {
  393. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  394. pa_status.Text = "1";
  395. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "封箱成功", pa_outboxcode.Text, "");
  396. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  397. }
  398. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  399. }
  400. private void SendCheck_Click(object sender, EventArgs e)
  401. {
  402. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "0")
  403. {
  404. 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");
  405. if (dt.Rows[0][0].ToString() != "")
  406. {
  407. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  408. return;
  409. }
  410. sql.Clear();
  411. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  412. dh.ExecuteSql(sql.GetString(), "select");
  413. ob_nowcheckqty.Text = "";
  414. ob_batchqty.Text = "";
  415. ob_nowcheckqty.ForeColor = Color.Black;
  416. SendCheck.Enabled = false;
  417. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  418. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  419. //记录操作日志
  420. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  421. ob_checkno.Text = "";
  422. }
  423. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  424. }
  425. bool AutoCut;
  426. private void LoadCheckQTY()
  427. {
  428. sql.Clear();
  429. string condition = "";
  430. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  431. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  432. if (nowcheckqty + 1 == batchqty && AutoCut)
  433. {
  434. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  435. }
  436. else
  437. {
  438. condition = "and ob_status='ENTERING' ";
  439. }
  440. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  441. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  442. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  443. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  444. if (dt.Rows.Count > 0)
  445. {
  446. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  447. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  448. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  449. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  450. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  451. if (nowcheckqty == batchqty)
  452. {
  453. ob_nowcheckqty.ForeColor = Color.Red;
  454. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  455. if (AutoCut)
  456. {
  457. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  458. }
  459. }
  460. }
  461. else
  462. {
  463. ob_batchqty.Text = "";
  464. ob_nowcheckqty.Text = "";
  465. ob_checkno.Text = "";
  466. SendCheck.Enabled = false;
  467. }
  468. if (ob_batchqty.Text != "")
  469. {
  470. SendCheck.Enabled = true;
  471. }
  472. else
  473. {
  474. SendCheck.Enabled = false;
  475. }
  476. }
  477. private void ob_checkno_TextChanged(object sender, EventArgs e)
  478. {
  479. if (ob_checkno.Text != "")
  480. {
  481. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  482. if (Cut == "" || Cut == "0")
  483. AutoCut = false;
  484. else
  485. AutoCut = true;
  486. SendCheck.Enabled = true;
  487. }
  488. }
  489. private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  490. {
  491. if (e.KeyCode == Keys.Enter)
  492. ResetPackQTY();
  493. }
  494. private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  495. {
  496. ResetPackQTY();
  497. }
  498. private void ResetPackQTY()
  499. {
  500. //数据不符合限制的时候保持原有值
  501. int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  502. if (!(pr_outboxinnerqty.Value >= curretnqty))
  503. {
  504. pr_outboxinnerqty.Value = StandardQTY;
  505. }
  506. else
  507. {
  508. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  509. {
  510. string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  511. if (checknostatus == "" || checknostatus == "ENTERING")
  512. {
  513. if (pa_downstatus.Text == "0")
  514. {
  515. if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  516. {
  517. dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Value + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  518. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Value + "'", pa_outboxcode.Text, pa_checkno.Text);
  519. return;
  520. }
  521. else
  522. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  523. }
  524. else
  525. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  526. }
  527. else
  528. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  529. }
  530. else
  531. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  532. pr_outboxinnerqty.Value = StandardQTY;
  533. }
  534. }
  535. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  536. {
  537. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  538. {
  539. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  540. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  541. }
  542. }
  543. }
  544. }