Make_PackageCollectionWeigh.cs 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. Remark_PreFix.Text = BaseUtil.GetCacheData("Remark_PreFix").ToString();
  81. }
  82. catch (Exception) { }
  83. thread = new Thread(getSerialData);
  84. try
  85. {
  86. GetData = true;
  87. serialPort1.PortName = ComList.Text;
  88. serialPort1.BaudRate = int.Parse(Baurate.Text);
  89. serialPort1.Open();
  90. thread.Start();
  91. }
  92. catch (Exception mes)
  93. {
  94. if (Baurate.Text == "" || ComList.Text == "")
  95. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  96. else
  97. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  98. }
  99. sn_code.Focus();
  100. dh = SystemInf.dh;
  101. StepCount.StepCode = User.CurrentStepCode;
  102. StepCount.Source = User.UserSourceCode;
  103. StepCount.LineCode = User.UserLineCode;
  104. StepCount.Dh = dh;
  105. StepCount.Start();
  106. }
  107. private void getSerialData()
  108. {
  109. if (serialPort1.IsOpen)
  110. {
  111. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  112. {
  113. SystemInf.OpenPort.Add(serialPort1.PortName);
  114. try
  115. {
  116. while (GetData)
  117. {
  118. try
  119. {
  120. weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
  121. }
  122. catch (Exception)
  123. {
  124. GetData = false;
  125. }
  126. }
  127. }
  128. catch (IOException ex) { MessageBox.Show(ex.Message); }
  129. }
  130. else
  131. MessageBox.Show("端口已被占用,请关闭其他窗口");
  132. }
  133. }
  134. private void Make_PackageCollectionWeigh_SizeChanged(object sender, EventArgs e)
  135. {
  136. asc.controlAutoSize(this);
  137. }
  138. private void Make_PackageCollectionWeigh_Activated(object sender, EventArgs e)
  139. {
  140. pa_outboxcode.Focus();
  141. }
  142. //刷新表单的数据的数据
  143. private void LoadData()
  144. {
  145. //加载表单数据
  146. string Err = "";
  147. sql.Clear();
  148. 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,");
  149. 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 ");
  150. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  151. Err = "箱号";
  152. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  153. if (dt.Rows.Count > 0)
  154. {
  155. //重量的临时变量
  156. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  157. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  158. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  159. PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
  160. if (dt.Rows[0]["pa_salecode"].ToString() != "")
  161. {
  162. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  163. }
  164. if (PR_CHECKCARTONW != "0")
  165. checkweightlabel.Text = "需要检测重量";
  166. else
  167. checkweightlabel.Text = "不需检测重量";
  168. //赋值重量单位
  169. Weight = double.Parse(_weight == "" ? "0" : _weight);
  170. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  171. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  172. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  173. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  174. BaseUtil.SetFormValue(this.Controls, dt);
  175. if (pa_standardqty.Text != "0")
  176. pr_outboxinnerqty.Text = pa_standardqty.Text;
  177. if (Weight - MinWeight == MaxWeight - Weight)
  178. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  179. else
  180. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  181. }
  182. LoadCheckQTY();
  183. LoadCollectedNum();
  184. }
  185. private void LoadGridData()
  186. {
  187. //加载Grid数据
  188. 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");
  189. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  190. //更新界面的采集数量
  191. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  192. }
  193. private void Print_Click(object sender, EventArgs e)
  194. {
  195. if (PrintLabel.Items.Count != 0)
  196. {
  197. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  198. {
  199. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  200. //doc = lbl.Documents.Open(PrintLabel.Text);
  201. 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))
  202. {
  203. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  204. }
  205. else
  206. {
  207. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  208. }
  209. if (!AutoGenBoxCode.Checked)
  210. {
  211. pa_outboxcode.Focus();
  212. pa_outboxcode.SelectAll();
  213. }
  214. else
  215. {
  216. sn_code.Focus();
  217. sn_code.SelectAll();
  218. }
  219. }
  220. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  221. }
  222. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  223. }
  224. //加载工单信息和装箱明细信息
  225. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  226. {
  227. if (e.KeyCode == Keys.Enter)
  228. {
  229. if (CheckOutBoxLength())
  230. {
  231. LoadData();
  232. LoadGridData();
  233. sn_code.Focus();
  234. if (pa_standardqty.Text == pa_currentqty.Text && pa_currentqty.Text != "")
  235. pa_remark.Focus();
  236. }
  237. }
  238. }
  239. //输入序列号的回车事件
  240. private void barcode_KeyDown(object sender, KeyEventArgs e)
  241. {
  242. //当用户输入回车键的时候
  243. if (e.KeyCode == Keys.Enter)
  244. {
  245. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  246. {
  247. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_craftcode,ms_prodcode,nvl(ms_checkpack,0) ms_checkpack from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  248. 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"))
  249. {
  250. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  251. {
  252. oMsID = dt.Rows[0]["ms_id"].ToString();
  253. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  254. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  255. }
  256. if (oMsStatus == "2")
  257. {
  258. string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  259. string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  260. string craftstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id =cd_crid", "cd_stepcode", "cr_prodcode='" + prodcode + "' and cr_code='" + craftcode + "' and cd_stepcode='" + User.CurrentStepCode + "'").ToString();
  261. if (craftstepcode == "")
  262. {
  263. OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
  264. return;
  265. }
  266. }
  267. //if (dt.Rows[0]["ms_checkpack"].ToString() != "0")
  268. //{
  269. // OperateResult.AppendText(sn_code.Text + "处于故障品完工装箱限制状态,不允许采集装箱\n", Color.Red);
  270. // return;
  271. //}
  272. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  273. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  274. {
  275. OperateResult.AppendText("当前序列号下一道工序为" + nextstepcode + ",当前资源不允许采集\n", Color.Red);
  276. return;
  277. }
  278. //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();
  279. sql.Clear();
  280. 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,");
  281. 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 ");
  282. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  283. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  284. string ms_makecode = "";
  285. string ms_prodcode = "";
  286. string ms_iostatus = "";
  287. string ms_outno = "";
  288. string ms_salecode_text = "";
  289. if (dt.Rows.Count > 0)
  290. {
  291. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  292. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  293. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  294. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  295. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  296. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  297. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  298. {
  299. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  300. return;
  301. }
  302. BaseUtil.SetFormValue(this.Controls, dt);
  303. }
  304. if (dt.Rows[0]["ms_outno"].ToString() != "")
  305. {
  306. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  307. return;
  308. }
  309. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  310. {
  311. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  312. return;
  313. }
  314. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  315. {
  316. pr_outboxinnerqty.Text = pa_standardqty.Text;
  317. }
  318. if (pa_outboxcode.Text == "")
  319. {
  320. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  321. if (boxcode != "")
  322. {
  323. pa_outboxcode.Text = boxcode;
  324. LoadGridData();
  325. }
  326. else
  327. {
  328. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
  329. {
  330. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  331. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  332. }
  333. }
  334. }
  335. if (pa_outboxcode.Text == "")
  336. {
  337. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  338. return;
  339. }
  340. //判断箱内总数必须大于0
  341. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  342. {
  343. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  344. return;
  345. }
  346. sql.Clear();
  347. sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_mothercode from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  348. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  349. string MotherBoxCode = "";
  350. if (dt.Rows.Count > 0)
  351. {
  352. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  353. {
  354. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  355. }
  356. if (dt.Rows[0]["pa_outno"].ToString() != "")
  357. {
  358. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  359. return;
  360. }
  361. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  362. {
  363. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  364. return;
  365. }
  366. }
  367. //如果未勾选了取消录入
  368. if (!Cancel.Checked)
  369. {
  370. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  371. if (ms_outboxcode != "")
  372. {
  373. if (ms_outboxcode == pa_outboxcode.Text)
  374. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  375. else
  376. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  377. LoadData();
  378. }
  379. else
  380. {
  381. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  382. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  383. {
  384. pa_currentqty.Text = "";
  385. pa_outboxcode.Text = "";
  386. pa_status.Text = "0";
  387. BaseUtil.CleanDGVData(PackageDetail);
  388. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  389. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text+":"+ OutBoxLength.Text);
  390. }
  391. if (!CheckOutBoxLength(ms_salecode_text))
  392. {
  393. return;
  394. }
  395. ////箱号不存在的情况
  396. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  397. {
  398. //提示正确返回时传递的信息
  399. if (ErrorMessage.Contains("AFTERSUCCESS"))
  400. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  401. LoadCheckQTY();
  402. LoadCollectedNum();
  403. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  404. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
  405. LastSncode = sn_code.Text;
  406. //满箱更新状态为1
  407. LoadData();
  408. 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");
  409. //如果母箱号不为空,需要更新总数
  410. if (MotherBoxCode != "")
  411. {
  412. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  413. if (dt.Rows.Count > 0)
  414. {
  415. if (dt.Rows[0]["pa_type"].ToString() == "2")
  416. {
  417. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  418. //更新大箱数量
  419. 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");
  420. //外层有栈板则更新栈板数量
  421. if (MotherCode2 != "")
  422. {
  423. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  424. 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");
  425. }
  426. }
  427. if (dt.Rows[0]["pa_type"].ToString() == "3")
  428. {
  429. 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");
  430. }
  431. }
  432. }
  433. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  434. if (pa_currentqty.Text == "1")
  435. {
  436. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  437. }
  438. LoadGridData();
  439. sn_code.Clear();
  440. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  441. {
  442. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  443. float weigh = float.Parse(ActWeigh);
  444. if (PR_CHECKCARTONW != "0")
  445. {
  446. if (MinWeight == 0 || MaxWeight == 0)
  447. {
  448. OperateResult.AppendText(">>产品" + pr_code.Text + "未维护卡通箱重量范围\n", Color.Red);
  449. return;
  450. }
  451. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  452. {
  453. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
  454. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  455. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  456. return;
  457. }
  458. }
  459. DataTable dt1 = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from makeserial where ms_downstatus=-1 and ms_outboxcode='" + pa_outboxcode.Text + "'", "select");
  460. if (dt1.Rows.Count > 0)
  461. {
  462. if (dt1.Rows[0][0].ToString() != "")
  463. {
  464. OperateResult.AppendText(">序列号:" + dt1.Rows[0][0].ToString() + "处于下地状态,箱不允许过站\n", Color.Red, sn_code);
  465. return;
  466. }
  467. }
  468. if (CollecRemark.Checked && pa_remark.Text == "")
  469. {
  470. OperateResult.AppendText(">已勾选采集备注,备注信息必须填写,如不需采集,请取消勾选\n", Color.Red, sn_code);
  471. pa_remark.SelectAll();
  472. pa_remark.Focus();
  473. return;
  474. }
  475. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  476. pa_standardqty.Text = "";
  477. pa_status.Text = "1";
  478. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
  479. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  480. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  481. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  482. {
  483. 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 + "'");
  484. }
  485. else
  486. {
  487. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  488. }
  489. LoadCheckQTY();
  490. LoadCollectedNum();
  491. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量完成\n", Color.Green);
  492. if (AutoPrint.Checked)
  493. Print_Click(new object(), new EventArgs());
  494. if (!CollecRemark.Checked)
  495. {
  496. if (!AutoGenBoxCode.Checked)
  497. {
  498. pa_outboxcode.Focus();
  499. pa_outboxcode.SelectAll();
  500. }
  501. else
  502. {
  503. sn_code.Focus();
  504. sn_code.SelectAll();
  505. }
  506. }
  507. else
  508. {
  509. pa_remark.SelectAll();
  510. pa_remark.Focus();
  511. }
  512. }
  513. }
  514. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  515. }
  516. }
  517. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  518. else
  519. {
  520. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  521. {
  522. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  523. 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");
  524. //如果母箱号不为空,需要更新总数
  525. if (MotherBoxCode != "")
  526. {
  527. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  528. if (dt.Rows.Count > 0)
  529. {
  530. if (dt.Rows[0]["pa_type"].ToString() == "2")
  531. {
  532. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  533. //更新大箱数量
  534. 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");
  535. //外层有栈板则更新栈板数量
  536. if (MotherCode2 != "")
  537. {
  538. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  539. 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");
  540. }
  541. }
  542. if (dt.Rows[0]["pa_type"].ToString() == "3")
  543. {
  544. 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");
  545. }
  546. }
  547. }
  548. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  549. LoadGridData();
  550. pa_status.Text = "0";
  551. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  552. }
  553. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  554. }
  555. }
  556. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  557. }
  558. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  559. }
  560. }
  561. private void Clean_Click(object sender, EventArgs e)
  562. {
  563. OperateResult.Clear();
  564. }
  565. private void pr_code_TextChanged(object sender, EventArgs e)
  566. {
  567. LoadCheckQTY();
  568. 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");
  569. PrintLabel.DataSource = dt;
  570. PrintLabel.DisplayMember = "la_url";
  571. PrintLabel.ValueMember = "la_id";
  572. }
  573. private void Make_PackageCollectionWeigh_FormClosing(object sender, FormClosingEventArgs e)
  574. {
  575. BaseUtil.ClosePrint(lbl);
  576. if (serialPort1.IsOpen)
  577. {
  578. GetData = false;
  579. serialPort1.Close();
  580. SystemInf.OpenPort.Remove(serialPort1.PortName);
  581. thread.Interrupt();
  582. }
  583. //thread.Abort();
  584. }
  585. private void Packing_Click(object sender, EventArgs e)
  586. {
  587. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  588. {
  589. string Seal = "";
  590. if (sender != "true")
  591. {
  592. Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  593. }
  594. else
  595. Seal = "Yes";
  596. if (Seal == "Yes")
  597. {
  598. LoadData();
  599. LoadGridData();
  600. DataTable dt1 = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from makeserial where ms_downstatus=-1 and ms_outboxcode='" + pa_outboxcode.Text + "'", "select");
  601. if (dt1.Rows.Count > 0)
  602. {
  603. if (dt1.Rows[0][0].ToString() != "")
  604. {
  605. OperateResult.AppendText(">序列号:" + dt1.Rows[0][0].ToString() + "处于下地状态,箱不允许过站\n", Color.Red, sn_code);
  606. return;
  607. }
  608. }
  609. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  610. float weigh = float.Parse(ActWeigh);
  611. if (PR_CHECKCARTONW != "0" && pa_standardqty.Text == pa_currentqty.Text)
  612. {
  613. if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
  614. {
  615. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量,不能完成工序过站\n", Color.Red);
  616. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  617. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  618. return;
  619. }
  620. }
  621. if (CollecRemark.Checked && pa_remark.Text == "")
  622. {
  623. OperateResult.AppendText(">已勾选采集备注,备注信息必须填写,如不需采集,请取消勾选\n", Color.Red, sn_code);
  624. pa_remark.SelectAll();
  625. pa_remark.Focus();
  626. return;
  627. }
  628. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  629. pa_status.Text = "1";
  630. pa_standardqty.Text = "";
  631. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "封箱成功", pa_outboxcode.Text, "");
  632. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  633. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  634. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  635. string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  636. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  637. {
  638. 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 + "'");
  639. }
  640. else
  641. {
  642. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  643. }
  644. if (AutoPrint.Checked)
  645. Print_Click(new object(), new EventArgs());
  646. LoadCheckQTY();
  647. if (!CollecRemark.Checked)
  648. {
  649. if (!AutoGenBoxCode.Checked)
  650. {
  651. pa_outboxcode.Focus();
  652. pa_outboxcode.SelectAll();
  653. }
  654. else
  655. {
  656. sn_code.Focus();
  657. sn_code.SelectAll();
  658. }
  659. }
  660. else
  661. {
  662. pa_remark.SelectAll();
  663. pa_remark.Focus();
  664. }
  665. }
  666. }
  667. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  668. }
  669. private void SendCheck_Click(object sender, EventArgs e)
  670. {
  671. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  672. {
  673. 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");
  674. if (dt.Rows[0][0].ToString() != "")
  675. {
  676. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  677. return;
  678. }
  679. sql.Clear();
  680. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  681. dh.ExecuteSql(sql.GetString(), "select");
  682. ob_nowcheckqty.Text = "";
  683. ob_batchqty.Text = "";
  684. ob_nowcheckqty.ForeColor = Color.Black;
  685. SendCheck.Enabled = false;
  686. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  687. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  688. //记录操作日志
  689. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  690. ob_checkno.Text = "";
  691. }
  692. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  693. }
  694. bool AutoCut;
  695. private void LoadCheckQTY()
  696. {
  697. sql.Clear();
  698. string condition = "";
  699. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  700. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  701. if (nowcheckqty + 1 == batchqty && AutoCut)
  702. {
  703. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  704. }
  705. else
  706. {
  707. condition = "and ob_status='ENTERING' ";
  708. }
  709. if (pr_sendchecktype.Text == "SaleCode")
  710. {
  711. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  712. }
  713. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  714. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  715. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  716. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  717. if (dt.Rows.Count > 0)
  718. {
  719. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  720. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  721. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  722. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  723. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  724. if (nowcheckqty >= batchqty)
  725. {
  726. ob_nowcheckqty.ForeColor = Color.Red;
  727. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  728. if (AutoCut)
  729. {
  730. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  731. }
  732. }
  733. }
  734. else
  735. {
  736. ob_batchqty.Text = "";
  737. ob_nowcheckqty.Text = "";
  738. ob_checkno.Text = "";
  739. SendCheck.Enabled = false;
  740. }
  741. if (ob_batchqty.Text != "")
  742. {
  743. SendCheck.Enabled = true;
  744. }
  745. else
  746. {
  747. SendCheck.Enabled = false;
  748. }
  749. }
  750. private void ob_checkno_TextChanged(object sender, EventArgs e)
  751. {
  752. if (ob_checkno.Text != "")
  753. {
  754. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  755. if (Cut == "" || Cut == "0")
  756. AutoCut = false;
  757. else
  758. AutoCut = true;
  759. SendCheck.Enabled = true;
  760. }
  761. }
  762. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  763. {
  764. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  765. {
  766. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  767. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  768. }
  769. }
  770. private void DeleteAll_Click(object sender, EventArgs e)
  771. {
  772. if (pa_outboxcode.Text == "")
  773. {
  774. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  775. return;
  776. }
  777. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  778. if (Delete == "Yes")
  779. {
  780. 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");
  781. if (dt.Rows.Count > 0)
  782. {
  783. if (dt.Rows[0]["pa_outno"].ToString() != "")
  784. {
  785. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  786. return;
  787. }
  788. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  789. {
  790. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  791. return;
  792. }
  793. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  794. {
  795. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  796. {
  797. string ob_status = dt.Rows[0]["ob_status"].ToString();
  798. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  799. //不存在抽检批次或者还未检验可以拆解
  800. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  801. {
  802. sql.Clear();
  803. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  804. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  805. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  806. List<string> SQLS1 = new List<string>();
  807. for (int i = 0; i < dt.Rows.Count; i++)
  808. {
  809. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  810. string num = dt.Rows[i]["num"].ToString();
  811. 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 + "'");
  812. 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 + "'");
  813. 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 + "'");
  814. //扣减已完工数
  815. 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 + "'");
  816. }
  817. if (pa_checkno != "")
  818. {
  819. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  820. 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 + "'");
  821. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  822. }
  823. //更新序列号状态
  824. 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 + "'");
  825. //抽检批次不为空的时候进行移除
  826. dh.ExecuteSQLTran(SQLS1.ToArray());
  827. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  828. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  829. if (standqty != "")
  830. {
  831. //置空原箱
  832. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0,PA_STANDARDQTY = '" + standqty + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  833. }
  834. else
  835. //置空原箱
  836. dh.ExecuteSql("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 + "'", "update");
  837. pa_status.Text = "0";
  838. //删除箱的明细
  839. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'","delete");
  840. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  841. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  842. LoadGridData();
  843. LoadCheckQTY();
  844. }
  845. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  846. }
  847. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  848. }
  849. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  850. }
  851. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  852. }
  853. }
  854. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  855. {
  856. if (e.KeyCode == Keys.Enter)
  857. {
  858. try
  859. {
  860. if (OutBoxLength.Text != "")
  861. {
  862. int.Parse(OutBoxLength.Text);
  863. }
  864. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  865. if (!AutoGenBoxCode.Checked)
  866. {
  867. pa_outboxcode.Focus();
  868. pa_outboxcode.SelectAll();
  869. }
  870. else
  871. {
  872. sn_code.Focus();
  873. }
  874. }
  875. catch (Exception)
  876. {
  877. OutBoxLength.Clear();
  878. MessageBox.Show("请输入正确的长度");
  879. }
  880. }
  881. }
  882. private bool CheckOutBoxLength()
  883. {
  884. //勾选了检验长度进行校验
  885. if (OutBoxLength.Text != "")
  886. {
  887. try
  888. {
  889. int.Parse(OutBoxLength.Text);
  890. }
  891. catch (Exception)
  892. {
  893. MessageBox.Show("请填写正确的箱号长度");
  894. return false;
  895. }
  896. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  897. {
  898. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  899. return false;
  900. }
  901. }
  902. if (PreFix.Text != "")
  903. {
  904. try
  905. {
  906. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  907. {
  908. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  909. return false;
  910. }
  911. }
  912. catch (Exception)
  913. {
  914. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  915. return false;
  916. }
  917. }
  918. return true;
  919. }
  920. private void RefreshWeigh_Click(object sender, EventArgs e)
  921. {
  922. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  923. sql.Clear();
  924. sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + prcode + "'");
  925. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  926. if (dt.Rows.Count > 0)
  927. {
  928. //重量的临时变量
  929. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  930. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  931. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  932. Weight = double.Parse(_weight == "" ? "0" : _weight);
  933. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  934. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  935. if (Weight - MinWeight == MaxWeight - Weight)
  936. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  937. else
  938. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  939. }
  940. }
  941. private void LoadCollectedNum()
  942. {
  943. 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");
  944. BaseUtil.SetFormValue(Controls, dt);
  945. }
  946. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  947. {
  948. if (Keys.Enter == e.KeyCode)
  949. {
  950. if (pa_remark.Text.Trim(' ') != "")
  951. {
  952. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  953. {
  954. if (Remark_PreFix.Text != "")
  955. {
  956. try
  957. {
  958. if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
  959. {
  960. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  961. return;
  962. }
  963. }
  964. catch (Exception)
  965. {
  966. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  967. return;
  968. }
  969. }
  970. if (!AllowRepeat.Checked)
  971. {
  972. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  973. if (dt.Rows.Count > 0)
  974. {
  975. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  976. return;
  977. }
  978. }
  979. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  980. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  981. pa_remark.Text = "";
  982. LoadGridData();
  983. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  984. {
  985. Packing_Click("true", new EventArgs());
  986. }
  987. if (!AutoGenBoxCode.Checked)
  988. {
  989. pa_outboxcode.SelectAll();
  990. pa_outboxcode.Focus();
  991. }
  992. else
  993. {
  994. sn_code.Focus();
  995. }
  996. }
  997. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  998. }else OperateResult.AppendText(">>备注信息不可为空\n", Color.Red);
  999. }
  1000. }
  1001. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  1002. {
  1003. if (e.KeyCode == Keys.Enter)
  1004. {
  1005. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1006. if (!AutoGenBoxCode.Checked)
  1007. {
  1008. pa_outboxcode.Focus();
  1009. pa_outboxcode.SelectAll();
  1010. }
  1011. else
  1012. {
  1013. sn_code.Focus();
  1014. }
  1015. }
  1016. }
  1017. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  1018. {
  1019. if (e.KeyCode == Keys.Enter)
  1020. {
  1021. BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
  1022. if (CollecRemark.Checked)
  1023. {
  1024. pa_remark.SelectAll();
  1025. pa_remark.Focus();
  1026. }
  1027. }
  1028. }
  1029. private bool CheckOutBoxLength(string ms_salecode_text)
  1030. {
  1031. if (AutoGenBoxCode.Checked)
  1032. {
  1033. if (ms_salecode_text != "")
  1034. {
  1035. DataTable dt = (DataTable)dh.ExecuteSql(" select pn_number,pn_id,pn_caller,pn_numberlength,pn_leadcode from PACKAGENUMBER where pn_caller='" + ms_salecode_text + "'", "select");
  1036. if (dt.Rows.Count > 0)
  1037. {
  1038. string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
  1039. int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
  1040. if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
  1041. {
  1042. OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
  1043. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  1044. }
  1045. if (PreFix.Text != pn_leadcode)
  1046. {
  1047. PreFix.Text = pn_leadcode;
  1048. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1049. }
  1050. }
  1051. else
  1052. {
  1053. OperateResult.AppendText(">>订单号" + ms_salecode_text + "未维护箱号规则\n", Color.Black);
  1054. }
  1055. }
  1056. return true;
  1057. }
  1058. return CheckOutBoxLength();
  1059. }
  1060. private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
  1061. {
  1062. if (AutoGenBoxCode.Checked)
  1063. {
  1064. OutBoxLength.Enabled = false;
  1065. PreFix.Enabled = false;
  1066. }
  1067. else
  1068. {
  1069. OutBoxLength.Enabled = true;
  1070. PreFix.Enabled = true;
  1071. }
  1072. }
  1073. }
  1074. }