Packing_PackageCollectionZX.cs 69 KB

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