Make_PackageCollectionWeigh.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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 oMsStatus = "";
  32. string PR_CHECKCARTONW = "0";
  33. //称量的标准重量
  34. double Weight;
  35. //最大重量
  36. double MaxWeight;
  37. //最小重量
  38. double MinWeight;
  39. string ActWeigh = "0";
  40. Regex re = new Regex("\\d+.\\d+\\w+");
  41. decimal StandardQTY = 0;
  42. string oOutBoxCode = "";
  43. string LastSncode;
  44. //创建串口实例
  45. SerialPort serialPort1 = new SerialPort();
  46. //true的时候表示从串口读取数据
  47. bool GetData = true;
  48. public Make_PackageCollectionWeigh()
  49. {
  50. InitializeComponent();
  51. }
  52. //创建打印进程
  53. private void NewPrint()
  54. {
  55. try
  56. {
  57. lbl = new ApplicationClass();
  58. BaseUtil.WriteLbl();
  59. }
  60. catch (Exception ex)
  61. {
  62. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  63. }
  64. }
  65. private void Make_PackageCollectionWeigh_Load(object sender, EventArgs e)
  66. {
  67. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  68. Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  69. //设置DbFind的必须的数据
  70. PrintNum.Text = "1";
  71. asc.controllInitializeSize(this);
  72. thread = new Thread(NewPrint);
  73. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  74. BaseUtil.SetFormCenter(stw);
  75. stw.ShowDialog();
  76. try
  77. {
  78. OutBoxLength.Text = BaseUtil.GetCacheData("OutBoxLength").ToString();
  79. PreFix.Text = BaseUtil.GetCacheData("PreFix").ToString();
  80. }
  81. catch (Exception) { }
  82. thread = new Thread(getSerialData);
  83. try
  84. {
  85. GetData = true;
  86. serialPort1.PortName = ComList.Text;
  87. serialPort1.BaudRate = int.Parse(Baurate.Text);
  88. serialPort1.Open();
  89. thread.Start();
  90. }
  91. catch (Exception mes)
  92. {
  93. if (Baurate.Text == "" || ComList.Text == "")
  94. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  95. else
  96. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  97. }
  98. sn_code.Focus();
  99. dh = SystemInf.dh;
  100. StepCount.StepCode = User.CurrentStepCode;
  101. StepCount.Source = User.UserSourceCode;
  102. StepCount.LineCode = User.UserLineCode;
  103. StepCount.Dh = dh;
  104. StepCount.Start();
  105. }
  106. private void getSerialData()
  107. {
  108. if (serialPort1.IsOpen)
  109. {
  110. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  111. {
  112. SystemInf.OpenPort.Add(serialPort1.PortName);
  113. try
  114. {
  115. while (GetData)
  116. {
  117. try
  118. {
  119. weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
  120. }
  121. catch (Exception)
  122. {
  123. GetData = false;
  124. }
  125. }
  126. }
  127. catch (IOException ex) { MessageBox.Show(ex.Message); }
  128. }
  129. else
  130. MessageBox.Show("端口已被占用,请关闭其他窗口");
  131. }
  132. }
  133. private void Make_PackageCollectionWeigh_SizeChanged(object sender, EventArgs e)
  134. {
  135. asc.controlAutoSize(this);
  136. }
  137. private void Make_PackageCollectionWeigh_Activated(object sender, EventArgs e)
  138. {
  139. pa_outboxcode.Focus();
  140. }
  141. //刷新表单的数据的数据
  142. private void LoadData()
  143. {
  144. //加载表单数据
  145. string Err = "";
  146. sql.Clear();
  147. sql.Append("select pa_prodcode,pr_cartonmaxw,pa_salecode,pa_remark,pa_makecode,pr_cartonunit,pr_code,pr_cartonminw,pr_cartongw,pa_outboxcode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,");
  148. sql.Append("pa_status,pr_packrule,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_packageqty,nvl(pa_standardqty,0)pa_standardqty,nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pa_currentqty from package left join ");
  149. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  150. Err = "箱号";
  151. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  152. if (dt.Rows.Count > 0)
  153. {
  154. //重量的临时变量
  155. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  156. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  157. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  158. PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
  159. if (dt.Rows[0]["pa_salecode"].ToString() != "")
  160. {
  161. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  162. }
  163. if (PR_CHECKCARTONW != "0")
  164. checkweightlabel.Text = "需要检测重量";
  165. else
  166. checkweightlabel.Text = "不需检测重量";
  167. //赋值重量单位
  168. Weight = double.Parse(_weight == "" ? "0" : _weight);
  169. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  170. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  171. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  172. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  173. BaseUtil.SetFormValue(this.Controls, dt);
  174. if (pa_standardqty.Text != "0")
  175. pr_outboxinnerqty.Text = pa_standardqty.Text;
  176. if (Weight - MinWeight == MaxWeight - Weight)
  177. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  178. else
  179. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  180. }
  181. LoadCheckQTY();
  182. LoadCollectedNum();
  183. }
  184. private void LoadGridData()
  185. {
  186. //加载Grid数据
  187. 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");
  188. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  189. //更新界面的采集数量
  190. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  191. }
  192. private void Print_Click(object sender, EventArgs e)
  193. {
  194. if (PrintLabel.Items.Count != 0)
  195. {
  196. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  197. {
  198. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  199. //doc = lbl.Documents.Open(PrintLabel.Text);
  200. if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  201. {
  202. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  203. }
  204. else
  205. {
  206. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  207. }
  208. if (!AutoGenBoxCode.Checked)
  209. {
  210. pa_outboxcode.Focus();
  211. pa_outboxcode.SelectAll();
  212. }
  213. }
  214. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  215. }
  216. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  217. }
  218. //加载工单信息和装箱明细信息
  219. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  220. {
  221. if (e.KeyCode == Keys.Enter)
  222. {
  223. if (CheckOutBoxLength())
  224. {
  225. LoadData();
  226. LoadGridData();
  227. sn_code.Focus();
  228. }
  229. }
  230. }
  231. //输入序列号的回车事件
  232. private void barcode_KeyDown(object sender, KeyEventArgs e)
  233. {
  234. //当用户输入回车键的时候
  235. if (e.KeyCode == Keys.Enter)
  236. {
  237. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  238. {
  239. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  240. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
  241. {
  242. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  243. {
  244. oMsID = dt.Rows[0]["ms_id"].ToString();
  245. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  246. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  247. }
  248. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  249. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  250. {
  251. OperateResult.AppendText("当前序列号下一道工序为" + nextstepcode + ",当前资源不允许采集\n", Color.Red);
  252. return;
  253. }
  254. //PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  255. sql.Clear();
  256. sql.Append("select nvl(ms_iostatus,0) ms_iostatus,ms_outno,ms_salecode,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
  257. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  258. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  259. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  260. string ms_makecode = "";
  261. string ms_prodcode = "";
  262. string ms_iostatus = "";
  263. string ms_outno = "";
  264. string ms_salecode_text = "";
  265. if (dt.Rows.Count > 0)
  266. {
  267. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  268. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  269. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  270. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  271. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  272. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  273. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  274. {
  275. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  276. return;
  277. }
  278. BaseUtil.SetFormValue(this.Controls, dt);
  279. }
  280. if (dt.Rows[0]["ms_outno"].ToString() != "")
  281. {
  282. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  283. return;
  284. }
  285. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  286. {
  287. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  288. return;
  289. }
  290. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  291. {
  292. pr_outboxinnerqty.Text = pa_standardqty.Text;
  293. }
  294. if (pa_outboxcode.Text == "")
  295. {
  296. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  297. if (boxcode != "")
  298. {
  299. pa_outboxcode.Text = boxcode;
  300. LoadGridData();
  301. }
  302. else
  303. {
  304. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  305. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  306. }
  307. }
  308. if (pa_outboxcode.Text == "")
  309. {
  310. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  311. return;
  312. }
  313. //判断箱内总数必须大于0
  314. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  315. {
  316. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  317. return;
  318. }
  319. sql.Clear();
  320. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_mothercode from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  321. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  322. string MotherBoxCode = "";
  323. if (dt.Rows.Count > 0)
  324. {
  325. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  326. {
  327. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  328. }
  329. if (dt.Rows[0]["pa_outno"].ToString() != "")
  330. {
  331. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  332. return;
  333. }
  334. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  335. {
  336. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  337. return;
  338. }
  339. }
  340. //如果未勾选了取消录入
  341. if (!Cancel.Checked)
  342. {
  343. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  344. if (ms_outboxcode != "")
  345. {
  346. if (ms_outboxcode == pa_outboxcode.Text)
  347. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  348. else
  349. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  350. LoadData();
  351. }
  352. else
  353. {
  354. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  355. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  356. {
  357. pa_currentqty.Text = "";
  358. pa_outboxcode.Text = "";
  359. pa_status.Text = "0";
  360. BaseUtil.CleanDGVData(PackageDetail);
  361. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  362. }
  363. if (!CheckOutBoxLength())
  364. {
  365. return;
  366. }
  367. ////箱号不存在的情况
  368. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  369. {
  370. //提示正确返回时传递的信息
  371. if (ErrorMessage.Contains("AFTERSUCCESS"))
  372. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  373. LoadCheckQTY();
  374. LoadCollectedNum();
  375. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  376. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
  377. LastSncode = sn_code.Text;
  378. //满箱更新状态为1
  379. LoadData();
  380. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  381. //如果母箱号不为空,需要更新总数
  382. if (MotherBoxCode != "")
  383. {
  384. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  385. if (dt.Rows.Count > 0)
  386. {
  387. if (dt.Rows[0]["pa_type"].ToString() == "2")
  388. {
  389. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  390. //更新大箱数量
  391. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  392. //外层有栈板则更新栈板数量
  393. if (MotherCode2 != "")
  394. {
  395. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  396. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  397. }
  398. }
  399. if (dt.Rows[0]["pa_type"] == "3")
  400. {
  401. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  402. }
  403. }
  404. }
  405. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  406. if (pa_currentqty.Text == "1")
  407. {
  408. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  409. }
  410. LoadGridData();
  411. sn_code.Clear();
  412. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  413. {
  414. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  415. float weigh = float.Parse(ActWeigh);
  416. if (PR_CHECKCARTONW != "0")
  417. {
  418. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  419. {
  420. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  421. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  422. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  423. return;
  424. }
  425. }
  426. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  427. pa_standardqty.Text = "";
  428. pa_status.Text = "1";
  429. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
  430. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  431. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  432. LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站");
  433. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  434. LoadCheckQTY();
  435. LoadCollectedNum();
  436. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量完成\n", Color.Green);
  437. if (AutoPrint.Checked)
  438. Print_Click(new object(), new EventArgs());
  439. if (!CollecRemark.Checked)
  440. {
  441. if (!AutoGenBoxCode.Checked)
  442. {
  443. pa_outboxcode.Focus();
  444. pa_outboxcode.SelectAll();
  445. }
  446. }
  447. else
  448. {
  449. pa_remark.SelectAll();
  450. pa_remark.Focus();
  451. }
  452. }
  453. }
  454. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  455. }
  456. }
  457. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  458. else
  459. {
  460. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  461. {
  462. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  463. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  464. //如果母箱号不为空,需要更新总数
  465. if (MotherBoxCode != "")
  466. {
  467. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  468. if (dt.Rows.Count > 0)
  469. {
  470. if (dt.Rows[0]["pa_type"].ToString() == "2")
  471. {
  472. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  473. //更新大箱数量
  474. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  475. //外层有栈板则更新栈板数量
  476. if (MotherCode2 != "")
  477. {
  478. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  479. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  480. }
  481. }
  482. if (dt.Rows[0]["pa_type"] == "3")
  483. {
  484. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  485. }
  486. }
  487. }
  488. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  489. LoadGridData();
  490. pa_status.Text = "0";
  491. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  492. }
  493. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  494. }
  495. }
  496. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  497. }
  498. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  499. }
  500. }
  501. private void Clean_Click(object sender, EventArgs e)
  502. {
  503. OperateResult.Clear();
  504. }
  505. private void pr_code_TextChanged(object sender, EventArgs e)
  506. {
  507. LoadCheckQTY();
  508. 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");
  509. PrintLabel.DataSource = dt;
  510. PrintLabel.DisplayMember = "la_url";
  511. PrintLabel.ValueMember = "la_id";
  512. }
  513. private void Make_PackageCollectionWeigh_FormClosing(object sender, FormClosingEventArgs e)
  514. {
  515. BaseUtil.ClosePrint(lbl);
  516. if (serialPort1.IsOpen)
  517. {
  518. GetData = false;
  519. serialPort1.Close();
  520. SystemInf.OpenPort.Remove(serialPort1.PortName);
  521. thread.Interrupt();
  522. }
  523. //thread.Abort();
  524. }
  525. private void Packing_Click(object sender, EventArgs e)
  526. {
  527. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  528. {
  529. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  530. if (Seal == "Yes")
  531. {
  532. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  533. float weigh = float.Parse(ActWeigh);
  534. if (PR_CHECKCARTONW != "0" && pa_standardqty.Text == pa_currentqty.Text)
  535. {
  536. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  537. {
  538. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量,不能完成工序过站\n", Color.Red);
  539. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  540. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  541. return;
  542. }
  543. }
  544. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  545. pa_status.Text = "1";
  546. pa_standardqty.Text = "";
  547. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "封箱成功", pa_outboxcode.Text, "");
  548. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  549. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  550. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  551. LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode.Text, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站");
  552. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  553. LoadCheckQTY();
  554. if (!CollecRemark.Checked)
  555. {
  556. if (!AutoGenBoxCode.Checked)
  557. {
  558. pa_outboxcode.Focus();
  559. pa_outboxcode.SelectAll();
  560. }
  561. }
  562. else
  563. {
  564. pa_remark.SelectAll();
  565. pa_remark.Focus();
  566. }
  567. }
  568. }
  569. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  570. }
  571. private void SendCheck_Click(object sender, EventArgs e)
  572. {
  573. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  574. {
  575. 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");
  576. if (dt.Rows[0][0].ToString() != "")
  577. {
  578. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  579. return;
  580. }
  581. sql.Clear();
  582. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  583. dh.ExecuteSql(sql.GetString(), "select");
  584. ob_nowcheckqty.Text = "";
  585. ob_batchqty.Text = "";
  586. ob_nowcheckqty.ForeColor = Color.Black;
  587. SendCheck.Enabled = false;
  588. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  589. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  590. //记录操作日志
  591. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  592. ob_checkno.Text = "";
  593. }
  594. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  595. }
  596. bool AutoCut;
  597. private void LoadCheckQTY()
  598. {
  599. sql.Clear();
  600. string condition = "";
  601. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  602. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  603. if (nowcheckqty + 1 == batchqty && AutoCut)
  604. {
  605. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  606. }
  607. else
  608. {
  609. condition = "and ob_status='ENTERING' ";
  610. }
  611. if (pr_sendchecktype.Text == "SaleCode")
  612. {
  613. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  614. }
  615. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  616. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  617. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  618. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  619. if (dt.Rows.Count > 0)
  620. {
  621. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  622. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  623. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  624. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  625. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  626. if (nowcheckqty >= batchqty)
  627. {
  628. ob_nowcheckqty.ForeColor = Color.Red;
  629. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  630. if (AutoCut)
  631. {
  632. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  633. }
  634. }
  635. }
  636. else
  637. {
  638. ob_batchqty.Text = "";
  639. ob_nowcheckqty.Text = "";
  640. ob_checkno.Text = "";
  641. SendCheck.Enabled = false;
  642. }
  643. if (ob_batchqty.Text != "")
  644. {
  645. SendCheck.Enabled = true;
  646. }
  647. else
  648. {
  649. SendCheck.Enabled = false;
  650. }
  651. }
  652. private void ob_checkno_TextChanged(object sender, EventArgs e)
  653. {
  654. if (ob_checkno.Text != "")
  655. {
  656. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  657. if (Cut == "" || Cut == "0")
  658. AutoCut = false;
  659. else
  660. AutoCut = true;
  661. SendCheck.Enabled = true;
  662. }
  663. }
  664. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  665. {
  666. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  667. {
  668. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  669. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  670. }
  671. }
  672. private void DeleteAll_Click(object sender, EventArgs e)
  673. {
  674. if (pa_outboxcode.Text == "")
  675. {
  676. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  677. return;
  678. }
  679. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  680. if (Delete == "Yes")
  681. {
  682. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_checkno,ob_status,pa_mothercode,nvl(pa_downstatus,0)pa_downstatus from package left join oqcbatch on pa_checkno=ob_checkno where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  683. if (dt.Rows.Count > 0)
  684. {
  685. if (dt.Rows[0]["pa_outno"].ToString() != "")
  686. {
  687. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  688. return;
  689. }
  690. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  691. {
  692. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  693. return;
  694. }
  695. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  696. {
  697. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  698. {
  699. string ob_status = dt.Rows[0]["ob_status"].ToString();
  700. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  701. //不存在抽检批次或者还未检验可以拆解
  702. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  703. {
  704. sql.Clear();
  705. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  706. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  707. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  708. List<string> SQLS1 = new List<string>();
  709. for (int i = 0; i < dt.Rows.Count; i++)
  710. {
  711. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  712. string num = dt.Rows[i]["num"].ToString();
  713. SQLS1.Add("delete from makeprocess where mp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and mp_makecode='" + ma_code + "' and mp_stepcode='" + User.CurrentStepCode + "'");
  714. SQLS1.Add("delete from steppassed where sp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and sp_makecode='" + ma_code + "' and sp_stepcode='" + User.CurrentStepCode + "'");
  715. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-" + num + ",mcd_outqty=mcd_outqty-" + num + ",mcd_okqty=mcd_okqty-" + num + " where mcd_macode='" + ma_code + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  716. //扣减已完工数
  717. SQLS1.Add("update make set ma_madeqty=ma_madeqty-(select count(1) from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "' and ms_status=2) where ma_code='" + ma_code + "'");
  718. }
  719. if (pa_checkno != "")
  720. {
  721. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  722. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-(select count(1) from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "') where ob_checkno='" + pa_checkno + "'");
  723. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  724. }
  725. //更新序列号状态
  726. SQLS1.Add("update makeserial set ms_status=1,ms_outboxcode='',ms_nextstepcode= (case when ms_nextstepcode='" + User.CurrentStepCode + "' then ms_nextstepcode else ms_stepcode end ),ms_paststep=replace(ms_paststep,'," + User.CurrentStepCode + "','') where ms_outboxcode='" + pa_outboxcode.Text + "'");
  727. //抽检批次不为空的时候进行移除
  728. dh.ExecuteSQLTran(SQLS1.ToArray());
  729. List<string> SQLS2 = new List<string>();
  730. //置空原箱
  731. SQLS2.Add("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  732. pa_status.Text = "0";
  733. //删除箱的明细
  734. SQLS2.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  735. dh.ExecuteSQLTran(SQLS2.ToArray());
  736. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  737. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  738. LoadGridData();
  739. LoadCheckQTY();
  740. }
  741. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  742. }
  743. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  744. }
  745. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  746. }
  747. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  748. }
  749. }
  750. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  751. {
  752. if (e.KeyCode == Keys.Enter)
  753. {
  754. try
  755. {
  756. if (OutBoxLength.Text != "")
  757. {
  758. int.Parse(OutBoxLength.Text);
  759. }
  760. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  761. if (!AutoGenBoxCode.Checked)
  762. {
  763. pa_outboxcode.Focus();
  764. pa_outboxcode.SelectAll();
  765. }
  766. else
  767. {
  768. sn_code.Focus();
  769. }
  770. }
  771. catch (Exception)
  772. {
  773. OutBoxLength.Clear();
  774. MessageBox.Show("请输入正确的长度");
  775. }
  776. }
  777. }
  778. private bool CheckOutBoxLength()
  779. {
  780. //勾选了检验长度进行校验
  781. if (OutBoxLength.Text != "")
  782. {
  783. try
  784. {
  785. int.Parse(OutBoxLength.Text);
  786. }
  787. catch (Exception)
  788. {
  789. MessageBox.Show("请填写正确的箱号长度");
  790. return false;
  791. }
  792. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  793. {
  794. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  795. return false;
  796. }
  797. }
  798. if (PreFix.Text != "")
  799. {
  800. try
  801. {
  802. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  803. {
  804. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  805. return false;
  806. }
  807. }
  808. catch (Exception)
  809. {
  810. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  811. return false;
  812. }
  813. }
  814. return true;
  815. }
  816. private void RefreshWeigh_Click(object sender, EventArgs e)
  817. {
  818. sql.Clear();
  819. sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + pr_code.Text + "'");
  820. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  821. if (dt.Rows.Count > 0)
  822. {
  823. //重量的临时变量
  824. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  825. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  826. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  827. Weight = double.Parse(_weight == "" ? "0" : _weight);
  828. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  829. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  830. if (Weight - MinWeight == MaxWeight - Weight)
  831. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  832. else
  833. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  834. }
  835. }
  836. private void LoadCollectedNum()
  837. {
  838. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  839. BaseUtil.SetFormValue(Controls, dt);
  840. }
  841. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  842. {
  843. if (Keys.Enter == e.KeyCode)
  844. {
  845. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  846. {
  847. if (!AllowRepeat.Checked)
  848. {
  849. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  850. if (dt.Rows.Count > 0)
  851. {
  852. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  853. return;
  854. }
  855. }
  856. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  857. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  858. pa_remark.Text = "";
  859. pa_outboxcode.Focus();
  860. }
  861. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  862. }
  863. }
  864. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  865. {
  866. if (e.KeyCode == Keys.Enter)
  867. {
  868. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  869. if (!AutoGenBoxCode.Checked)
  870. {
  871. pa_outboxcode.Focus();
  872. pa_outboxcode.SelectAll();
  873. }
  874. else
  875. {
  876. sn_code.Focus();
  877. }
  878. }
  879. }
  880. }
  881. }