Packing_PackageCollectionWeigh_HAOQ.cs 63 KB

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