Make_PackageCollectionWeigh.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. using LabelManager2;
  2. using System;
  3. using System.Data;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES.DataOperate;
  7. using UAS_MES.Entity;
  8. using UAS_MES.PublicMethod;
  9. using System.Drawing;
  10. using System.Threading;
  11. using UAS_MES.PublicForm;
  12. using System.IO.Ports;
  13. using System.IO;
  14. using System.Text.RegularExpressions;
  15. using System.Collections.Generic;
  16. namespace UAS_MES.Make
  17. {
  18. public partial class Make_PackageCollectionWeigh : Form
  19. {
  20. DataHelper dh;
  21. DataTable dt;
  22. LogStringBuilder sql = new LogStringBuilder();
  23. AutoSizeFormClass asc = new AutoSizeFormClass();
  24. Document doc;
  25. ApplicationClass lbl;
  26. Thread thread;
  27. DataTable Dbfind;
  28. string ErrorMessage = "";
  29. string oMakeCode = "";
  30. string oMsID = "";
  31. string PR_CHECKCARTONW = "";
  32. //称量的标准重量
  33. double Weight;
  34. //最大重量
  35. double MaxWeight;
  36. //最小重量
  37. double MinWeight;
  38. decimal StandardQTY = 0;
  39. string oOutBoxCode = "";
  40. string LastSncode;
  41. //创建串口实例
  42. SerialPort serialPort1 = new SerialPort();
  43. //true的时候表示从串口读取数据
  44. bool GetData = true;
  45. public Make_PackageCollectionWeigh()
  46. {
  47. InitializeComponent();
  48. }
  49. //创建打印进程
  50. private void NewPrint()
  51. {
  52. try
  53. {
  54. lbl = new ApplicationClass();
  55. BaseUtil.WriteLbl(lbl);
  56. }
  57. catch (Exception ex)
  58. {
  59. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  60. }
  61. }
  62. private void 包装采集_Load(object sender, EventArgs e)
  63. {
  64. pa_outboxcode.ShowClickIcon = false;
  65. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  66. Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  67. pr_outboxinnerqty.Controls[0].Visible = false;
  68. //设置DbFind的必须的数据
  69. PrintNum.Value = 1;
  70. asc.controllInitializeSize(this);
  71. thread = new Thread(NewPrint);
  72. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  73. BaseUtil.SetFormCenter(stw);
  74. stw.ShowDialog();
  75. dh = new DataHelper();
  76. thread = new Thread(getSerialData);
  77. try
  78. {
  79. GetData = true;
  80. serialPort1.PortName = ComList.Text;
  81. serialPort1.BaudRate = int.Parse(Baurate.Text);
  82. serialPort1.Open();
  83. thread.Start();
  84. }
  85. catch (Exception mes)
  86. {
  87. if (Baurate.Text == "" || ComList.Text == "")
  88. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  89. else
  90. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  91. }
  92. }
  93. private void getSerialData()
  94. {
  95. if (serialPort1.IsOpen)
  96. {
  97. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  98. {
  99. SystemInf.OpenPort.Add(serialPort1.PortName);
  100. try
  101. {
  102. while (GetData)
  103. {
  104. try
  105. {
  106. weight.Text = serialPort1.ReadLine();
  107. //if (pr_cartonunit.Text == "kg")
  108. // weight.Text = (double.Parse(weight.Text) / 1000).ToString();
  109. }
  110. catch (Exception)
  111. {
  112. GetData = false;
  113. }
  114. }
  115. }
  116. catch (IOException ex) { MessageBox.Show(ex.Message); }
  117. }
  118. else
  119. MessageBox.Show("端口已被占用,请关闭其他窗口");
  120. }
  121. }
  122. private void 包装采集_SizeChanged(object sender, EventArgs e)
  123. {
  124. asc.controlAutoSize(this);
  125. }
  126. private void 包装采集_Activated(object sender, EventArgs e)
  127. {
  128. pa_outboxcode.Focus();
  129. }
  130. //刷新表单的数据的数据
  131. private void LoadData()
  132. {
  133. //加载表单数据
  134. string Err = "";
  135. sql.Clear();
  136. 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,");
  137. sql.Append("pa_status,pr_packrule,pr_detail,pa_packageqty,nvl(pa_standardqty,0)pa_standardqty,pr_outboxinnerqty,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pa_currentqty from package left join ");
  138. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  139. Err = "箱号";
  140. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  141. if (dt.Rows.Count > 0)
  142. {
  143. //重量的临时变量
  144. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  145. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  146. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  147. PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
  148. if (PR_CHECKCARTONW != "0")
  149. {
  150. checkweight.Checked = true;
  151. }
  152. //赋值重量单位
  153. Weight = double.Parse(_weight == "" ? "0" : _weight);
  154. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  155. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  156. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  157. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  158. BaseUtil.SetFormValue(this.Controls, dt);
  159. if (pa_standardqty.Text != "0")
  160. pr_outboxinnerqty.Text = pa_standardqty.Text;
  161. if (Weight - MinWeight == MaxWeight - Weight)
  162. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight);
  163. else
  164. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight;
  165. }
  166. else sn_code.Focus();
  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 Print_Click(object sender, EventArgs e)
  177. {
  178. if (PrintLabel.Items.Count != 0)
  179. {
  180. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  181. {
  182. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  183. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  184. doc = lbl.Documents.Open(ftpOperater.DownLoadTo + PrintLabel.Text);
  185. Print.CodeSoft(Tag.ToString(), doc, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text));
  186. }
  187. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  188. }
  189. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  190. }
  191. //加载工单信息和装箱明细信息
  192. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  193. {
  194. if (e.KeyCode == Keys.Enter)
  195. {
  196. LoadData();
  197. LoadGridData();
  198. }
  199. }
  200. //输入序列号的回车事件
  201. private void barcode_KeyDown(object sender, KeyEventArgs e)
  202. {
  203. //当用户输入回车键的时候
  204. if (e.KeyCode == Keys.Enter)
  205. {
  206. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  207. {
  208. dt = (DataTable)dh.ExecuteSql("select ms_id from makeserial where ms_sncode ='" + sn_code.Text + "' and ms_status=2 order by ms_id desc", "select");
  209. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0))
  210. {
  211. if (oMsID == "" || oMsID == "null")
  212. {
  213. oMsID = dt.Rows[0]["ms_id"].ToString();
  214. }
  215. sql.Clear();
  216. sql.Append("select ms_makecode,pr_code,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,pr_code,pr_detail,");
  217. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  218. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  219. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  220. if (dt.Rows.Count > 0)
  221. {
  222. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  223. BaseUtil.SetFormValue(this.Controls, dt);
  224. }
  225. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  226. {
  227. pr_outboxinnerqty.Value = int.Parse(pa_standardqty.Text);
  228. }
  229. if (pa_outboxcode.Text == "")
  230. {
  231. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  232. if (boxcode != "")
  233. {
  234. pa_outboxcode.Text = boxcode;
  235. LoadGridData();
  236. }
  237. else
  238. {
  239. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  240. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  241. }
  242. }
  243. if (pa_outboxcode.Text == "")
  244. {
  245. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  246. return;
  247. }
  248. if (pa_status.Text != "1")
  249. {
  250. //按工单核对装箱
  251. switch (pr_packrule.Text.ToUpper())
  252. {
  253. case "MAKE":
  254. if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != pa_makecode.Text && pa_makecode.Text != "")
  255. {
  256. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
  257. return;
  258. }
  259. break;
  260. case "SALE":
  261. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  262. {
  263. sql.Clear();
  264. sql.Append("select 1 from package left join make on pa_salecode=ma_salecode and pa_prodcode=ma_prodcode left join makeserial ");
  265. sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
  266. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  267. if (dt.Rows.Count == 0)
  268. {
  269. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
  270. return;
  271. }
  272. }
  273. break;
  274. case "PROD":
  275. if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
  276. {
  277. OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
  278. return;
  279. }
  280. break;
  281. case "MIX":
  282. break;
  283. default:
  284. break;
  285. }
  286. }
  287. //判断箱内总数必须大于0
  288. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  289. {
  290. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  291. return;
  292. }
  293. //如果未勾选了取消录入
  294. if (!Cancel.Checked)
  295. {
  296. //判断序列号是否已经装箱
  297. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  298. {
  299. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
  300. }
  301. else
  302. {
  303. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  304. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  305. {
  306. pa_currentqty.Text = "";
  307. pa_outboxcode.Text = "";
  308. pa_status.Text = "0";
  309. BaseUtil.CleanDGVData(PackageDetail);
  310. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  311. }
  312. ////箱号不存在的情况
  313. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  314. {
  315. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
  316. {
  317. //提示正确返回时传递的信息
  318. if (ErrorMessage.Contains("AFTERSUCCESS"))
  319. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  320. LoadCheckQTY();
  321. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  322. //满箱更新状态为1
  323. LoadData();
  324. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  325. if (pa_currentqty.Text == "1")
  326. {
  327. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  328. dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  329. }
  330. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  331. {
  332. if (checkweight.Checked)
  333. {
  334. //检查重量合格
  335. float weigh = float.Parse(weight.Text.Replace("kg", "").Trim());
  336. if (weigh > MinWeight && weigh < MaxWeight)
  337. {
  338. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight='" + weigh + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  339. pa_standardqty.Text = "";
  340. pa_status.Text = "1";
  341. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量合格\n", Color.Green);
  342. LastSncode = sn_code.Text;
  343. if (AutoPrint.Checked)
  344. Print_Click(new object(), new EventArgs());
  345. }
  346. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  347. }
  348. }
  349. LoadGridData();
  350. sn_code.Clear();
  351. }
  352. }
  353. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  354. }
  355. }
  356. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  357. else
  358. {
  359. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  360. {
  361. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "取消采集成功", sn_code.Text, "");
  362. LoadGridData();
  363. pa_status.Text = "0";
  364. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  365. }
  366. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  367. }
  368. }
  369. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  370. }
  371. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  372. }
  373. }
  374. private void Clean_Click(object sender, EventArgs e)
  375. {
  376. OperateResult.Clear();
  377. }
  378. private void pr_code_TextChanged(object sender, EventArgs e)
  379. {
  380. LoadCheckQTY();
  381. pa_outboxcode.MakeCode = pa_makecode.Text;
  382. pa_outboxcode.ProdCode = pr_code.Text;
  383. pa_outboxcode.Caller = "PACKAGE";
  384. 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");
  385. PrintLabel.DataSource = dt;
  386. PrintLabel.DisplayMember = "la_name";
  387. PrintLabel.ValueMember = "la_id";
  388. ftpOperater ftp = new ftpOperater();
  389. for (int i = 0; i < dt.Rows.Count; i++)
  390. {
  391. BaseUtil.GetPrintLabel(dt.Rows[i]["la_name"].ToString(), dt.Rows[i]["la_url"].ToString());
  392. }
  393. }
  394. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  395. {
  396. BaseUtil.ClosePrint(lbl);
  397. if (serialPort1.IsOpen)
  398. {
  399. GetData = false;
  400. serialPort1.Close();
  401. SystemInf.OpenPort.Remove(serialPort1.PortName);
  402. thread.Interrupt();
  403. }
  404. dh.Dispose();
  405. }
  406. private void Packing_Click(object sender, EventArgs e)
  407. {
  408. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  409. {
  410. if (checkweight.Checked)
  411. {
  412. //检查重量合格
  413. float weigh = float.Parse(weight.Text.Replace("kg", "").Trim());
  414. if (!(weigh > MinWeight && weigh < MaxWeight))
  415. {
  416. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  417. return;
  418. }
  419. }
  420. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  421. if (Seal == "Yes")
  422. {
  423. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  424. pa_status.Text = "1";
  425. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "封箱成功", pa_outboxcode.Text, "");
  426. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  427. }
  428. }
  429. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  430. }
  431. private void SendCheck_Click(object sender, EventArgs e)
  432. {
  433. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  434. {
  435. 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");
  436. if (dt.Rows[0][0].ToString() != "")
  437. {
  438. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  439. return;
  440. }
  441. sql.Clear();
  442. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  443. dh.ExecuteSql(sql.GetString(), "select");
  444. ob_nowcheckqty.Text = "";
  445. ob_batchqty.Text = "";
  446. ob_nowcheckqty.ForeColor = Color.Black;
  447. SendCheck.Enabled = false;
  448. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  449. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  450. //记录操作日志
  451. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  452. ob_checkno.Text = "";
  453. }
  454. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  455. }
  456. bool AutoCut;
  457. private void LoadCheckQTY()
  458. {
  459. sql.Clear();
  460. string condition = "";
  461. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  462. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  463. if (nowcheckqty + 1 == batchqty && AutoCut)
  464. {
  465. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  466. }
  467. else
  468. {
  469. condition = "and ob_status='ENTERING' ";
  470. }
  471. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  472. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  473. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  474. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  475. if (dt.Rows.Count > 0)
  476. {
  477. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  478. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  479. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  480. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  481. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  482. if (nowcheckqty == batchqty)
  483. {
  484. ob_nowcheckqty.ForeColor = Color.Red;
  485. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  486. if (AutoCut)
  487. {
  488. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  489. }
  490. }
  491. }
  492. else
  493. {
  494. ob_batchqty.Text = "";
  495. ob_nowcheckqty.Text = "";
  496. ob_checkno.Text = "";
  497. SendCheck.Enabled = false;
  498. }
  499. if (ob_batchqty.Text != "")
  500. {
  501. SendCheck.Enabled = true;
  502. }
  503. else
  504. {
  505. SendCheck.Enabled = false;
  506. }
  507. }
  508. private void ob_checkno_TextChanged(object sender, EventArgs e)
  509. {
  510. if (ob_checkno.Text != "")
  511. {
  512. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  513. if (Cut == "" || Cut == "0")
  514. AutoCut = false;
  515. else
  516. AutoCut = true;
  517. SendCheck.Enabled = true;
  518. }
  519. }
  520. private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  521. {
  522. if (e.KeyCode == Keys.Enter)
  523. ResetPackQTY();
  524. }
  525. private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  526. {
  527. ResetPackQTY();
  528. }
  529. private void ResetPackQTY()
  530. {
  531. //数据不符合限制的时候保持原有值
  532. int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  533. if (!(pr_outboxinnerqty.Value >= curretnqty))
  534. {
  535. pr_outboxinnerqty.Value = StandardQTY;
  536. }
  537. else
  538. {
  539. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  540. {
  541. string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  542. if (checknostatus == "" || checknostatus == "ENTERING")
  543. {
  544. if (pa_downstatus.Text == "0")
  545. {
  546. if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  547. {
  548. dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Value + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  549. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Value + "'", pa_outboxcode.Text, pa_checkno.Text);
  550. return;
  551. }
  552. else
  553. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  554. }
  555. else
  556. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  557. }
  558. else
  559. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  560. }
  561. else
  562. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  563. pr_outboxinnerqty.Value = StandardQTY;
  564. }
  565. }
  566. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  567. {
  568. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  569. {
  570. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  571. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  572. }
  573. }
  574. private void DeleteAll_Click(object sender, EventArgs e)
  575. {
  576. if (pa_outboxcode.Text == "")
  577. {
  578. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  579. return;
  580. }
  581. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  582. if (Delete == "Yes")
  583. {
  584. DataTable dt = (DataTable)dh.ExecuteSql("select 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");
  585. if (dt.Rows.Count > 0)
  586. {
  587. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  588. {
  589. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  590. {
  591. string ob_status = dt.Rows[0]["ob_status"].ToString();
  592. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  593. //不存在抽检批次或者还未检验可以拆解
  594. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  595. {
  596. sql.Clear();
  597. sql.Append("select pd_makecode,pd_barcode,pd_prodcode,ms_status,ms_stepcode from packagedetail left join makeserial ");
  598. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "'");
  599. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  600. for (int i = 0; i < dt.Rows.Count; i++)
  601. {
  602. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  603. string ms_sncode = dt.Rows[i]["pd_barcode"].ToString();
  604. string pr_code = dt.Rows[i]["pd_prodcode"].ToString();
  605. string ms_status = dt.Rows[i]["ms_status"].ToString();
  606. string ms_stepcode = dt.Rows[i]["ms_stepcode"].ToString();
  607. List<string> SQLS1 = new List<string>();
  608. if (ms_status == "2")
  609. {
  610. //已完工数-1
  611. SQLS1.Add("update make set ma_madeqty=ma_madeqty-1 where ma_code='" + ma_code + "'");
  612. }
  613. //更新序列号状态
  614. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1,mcd_okqty=mcd_okqty-1 where mcd_macode='" + ma_code + "' and mcd_stepcode='" + ms_stepcode + "'");
  615. SQLS1.Add("update makeserial set ms_status=1,ms_nextstepcode=ms_stepcode,ms_outboxcode='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  616. SQLS1.Add("delete from makeprocess where mp_sncode='" + ms_sncode + "' and mp_makecode='" + ma_code + "' and mp_stepcode='" + ms_stepcode + "'");
  617. SQLS1.Add("delete from steppassed where sp_sncode='" + ms_sncode + "' and sp_makecode='" + ma_code + "' and sp_stepcode='" + ms_stepcode + "'");
  618. //抽检批次不为空的时候进行移除
  619. if (pa_checkno != "")
  620. {
  621. SQLS1.Add("update makeserial set ms_checkno='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  622. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + pa_checkno + "'");
  623. SQLS1.Add("delete from oqcbatchdetail where obd_checkno='" + pa_checkno + "' and obd_sncode='" + ms_sncode + "'");
  624. }
  625. dh.ExecuteSQLTran(SQLS1.ToArray());
  626. }
  627. List<string> SQLS2 = new List<string>();
  628. ////置空原箱
  629. SQLS2.Add("update package set pa_checkno='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  630. pa_status.Text = "0";
  631. //删除箱的明细
  632. SQLS2.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  633. dh.ExecuteSQLTran(SQLS2.ToArray());
  634. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  635. LoadGridData();
  636. LoadCheckQTY();
  637. }
  638. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  639. }
  640. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  641. }
  642. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱,不允许解除\n", Color.Red);
  643. }
  644. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  645. }
  646. }
  647. }
  648. }