Packing_PackageCollectionWeigh_ReadLine.cs 65 KB

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