Make_SpecialCartonPack.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. namespace UAS_MES_NEW.Make
  17. {
  18. public partial class Make_SpecialCartonPack : Form
  19. {
  20. DataHelper dh;
  21. DataTable dt;
  22. LogStringBuilder sql = new LogStringBuilder();
  23. AutoSizeFormClass asc = new AutoSizeFormClass();
  24. ApplicationClass lbl;
  25. Thread thread;
  26. string ErrorMessage = "";
  27. string oMakeCode = "";
  28. string oMsID = "";
  29. string ActWeigh;
  30. string oMsStatus = "";
  31. Regex re = new Regex("\\d+.\\d+\\w+");
  32. //称量的标准重量
  33. double Weight;
  34. //最大重量
  35. double MaxWeight;
  36. //最小重量
  37. double MinWeight;
  38. decimal StandardQTY = 0;
  39. string LastSncode;
  40. string oOutBoxCode = "";
  41. //创建串口实例
  42. SerialPort serialPort1 = new SerialPort();
  43. //true的时候表示从串口读取数据
  44. bool GetData = true;
  45. public Make_SpecialCartonPack()
  46. {
  47. InitializeComponent();
  48. }
  49. //创建打印进程
  50. private void NewPrint()
  51. {
  52. try
  53. {
  54. lbl = new ApplicationClass();
  55. BaseUtil.WriteLbl();
  56. }
  57. catch (Exception)
  58. {
  59. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  60. }
  61. }
  62. private void 包装采集_Load(object sender, EventArgs e)
  63. {
  64. ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
  65. Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
  66. //设置DbFind的必须的数据
  67. PrintNum.Text = "1";
  68. asc.controllInitializeSize(this);
  69. thread = new Thread(NewPrint);
  70. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  71. BaseUtil.SetFormCenter(stw);
  72. stw.ShowDialog();
  73. dh = SystemInf.dh;
  74. thread = new Thread(getSerialData);
  75. try
  76. {
  77. GetData = true;
  78. serialPort1.PortName = ComList.Text;
  79. serialPort1.BaudRate = int.Parse(Baurate.Text);
  80. serialPort1.Open();
  81. thread.Start();
  82. }
  83. catch (Exception mes)
  84. {
  85. if (Baurate.Text == "" || ComList.Text == "")
  86. OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
  87. else
  88. OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
  89. }
  90. StepCount.StepCode = User.CurrentStepCode;
  91. StepCount.Source = User.UserSourceCode;
  92. StepCount.LineCode = User.UserLineCode;
  93. StepCount.Dh = dh;
  94. StepCount.Start();
  95. }
  96. private void getSerialData()
  97. {
  98. if (serialPort1.IsOpen)
  99. {
  100. if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
  101. {
  102. SystemInf.OpenPort.Add(serialPort1.PortName);
  103. try
  104. {
  105. while (GetData)
  106. {
  107. try
  108. {
  109. weight.Text = re.Match(serialPort1.ReadLine().Trim()).Groups[0].Value;
  110. ActWeigh = weight.Text.Replace("kg", "").Trim();
  111. }
  112. catch (Exception)
  113. {
  114. GetData = false;
  115. }
  116. }
  117. }
  118. catch (IOException ex) { MessageBox.Show(ex.Message); }
  119. }
  120. else OperateResult.AppendText(">>端口已被占用,请关闭其他窗口\n", Color.Red);
  121. }
  122. }
  123. private void 包装采集_SizeChanged(object sender, EventArgs e)
  124. {
  125. asc.controlAutoSize(this);
  126. }
  127. private void 包装采集_Activated(object sender, EventArgs e)
  128. {
  129. pa_outboxcode.Focus();
  130. }
  131. //刷新表单的数据的数据
  132. private void LoadData()
  133. {
  134. //加载表单数据
  135. sql.Clear();
  136. sql.Append("select pa_prodcode,pr_cartonmaxw,pa_salecode,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_makecode,pr_cartonunit,pr_code,pr_cartonminw,pr_cartongw,pa_outboxcode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,");
  137. sql.Append("pa_status,pr_packrule,pr_detail,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 ");
  138. sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  139. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  140. if (dt.Rows.Count > 0)
  141. {
  142. //重量的临时变量
  143. string _weight = dt.Rows[0]["pr_cartongw"].ToString();
  144. string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
  145. string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
  146. Weight = double.Parse(_weight == "" ? "0" : _weight);
  147. MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
  148. MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
  149. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  150. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  151. BaseUtil.SetFormValue(this.Controls, dt);
  152. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  153. if (pa_standardqty.Text != "0")
  154. pr_outboxinnerqty.Text = pa_standardqty.Text;
  155. if (Weight - MinWeight == MaxWeight - Weight)
  156. pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
  157. else
  158. pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
  159. }
  160. else sn_code.Focus();
  161. LoadCheckQTY();
  162. }
  163. private void LoadGridData()
  164. {
  165. //加载Grid数据
  166. 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");
  167. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  168. }
  169. private void Print_Click(object sender, EventArgs e)
  170. {
  171. if (PrintLabel.Items.Count != 0)
  172. {
  173. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  174. {
  175. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  176. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  177. //doc = lbl.Documents.Open(PrintLabel.Text);
  178. if (!Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  179. {
  180. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  181. }
  182. pa_outboxcode.Focus();
  183. pa_outboxcode.SelectAll();
  184. }
  185. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  186. }
  187. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  188. }
  189. //加载工单信息和装箱明细信息
  190. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  191. {
  192. if (e.KeyCode == Keys.Enter)
  193. {
  194. LoadData();
  195. LoadGridData();
  196. }
  197. }
  198. //输入序列号的回车事件
  199. private void barcode_KeyDown(object sender, KeyEventArgs e)
  200. {
  201. //当用户输入回车键的时候
  202. if (e.KeyCode == Keys.Enter)
  203. {
  204. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  205. {
  206. dt = (DataTable)dh.ExecuteSql("select ms_id,ms_status,ms_makecode from makeserial where ms_sncode ='" + sn_code.Text + "' and ms_status=2 order by ms_id desc", "select");
  207. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || dt.Rows.Count > 0)
  208. {
  209. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  210. {
  211. oMsID = dt.Rows[0]["ms_id"].ToString();
  212. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  213. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  214. }
  215. //获取序列号信息
  216. sql.Clear();
  217. sql.Append("select 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,");
  218. 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 ");
  219. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  220. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  221. string ms_makecode = "";
  222. string ms_prodcode = "";
  223. string ms_iostatus = "";
  224. string ms_outno = "";
  225. string ms_salecode_text = "";
  226. if (dt.Rows.Count > 0)
  227. {
  228. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  229. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  230. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  231. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  232. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  233. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  234. BaseUtil.SetFormValue(this.Controls, dt);
  235. }
  236. //保证箱内容量不会被重置
  237. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  238. {
  239. pr_outboxinnerqty.Text = pa_standardqty.Text;
  240. }
  241. if (pa_outboxcode.Text == "")
  242. {
  243. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  244. //序列号存在箱号的情况下获取所有的装箱数据
  245. if (boxcode != "")
  246. {
  247. pa_outboxcode.Text = boxcode;
  248. pa_makecode.Text = "";
  249. LoadGridData();
  250. }
  251. else
  252. {
  253. //如果勾选了自动生成箱号,在封箱或者首次
  254. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == "" || pa_status.Text == "0"))
  255. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  256. }
  257. }
  258. if (pa_outboxcode.Text == "")
  259. {
  260. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  261. return;
  262. }
  263. //判断箱内总数必须大于0
  264. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  265. {
  266. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  267. return;
  268. }
  269. string MotherBoxCode = dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString(); ;
  270. //如果未勾选了取消录入
  271. if (!Cancel.Checked)
  272. {
  273. //判断序列号是否已经装箱
  274. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  275. if (ms_outboxcode != "")
  276. {
  277. if (ms_outboxcode == pa_outboxcode.Text)
  278. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  279. else
  280. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  281. LoadData();
  282. }
  283. else
  284. {
  285. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  286. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  287. {
  288. pa_currentqty.Text = "";
  289. pa_outboxcode.Text = "";
  290. pa_status.Text = "0";
  291. BaseUtil.CleanDGVData(PackageDetail);
  292. pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  293. }
  294. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "特殊", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  295. {
  296. DataTable dt = (DataTable)dh.ExecuteSql("select pd_barcode from packagedetail where pd_outboxcode = '" + pa_outboxcode.Text + "'", "select");
  297. if (dt.Rows.Count > 0 && dt.Rows.Count == 1)
  298. {
  299. dh.UpdateByCondition("package", "pa_makecode = '" + ms_makecode + "',pa_prodcode = '" + ms_prodcode + "',pa_salecode = '" + ms_salecode.Text + "'", "pa_outboxcode = '" + pa_outboxcode.Text + "'");
  300. }
  301. if (ErrorMessage.Contains("AFTERSUCCESS"))
  302. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  303. LoadCheckQTY();
  304. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  305. LastSncode = sn_code.Text;
  306. if (MotherBoxCode != "")
  307. {
  308. 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 + "' and pa_type=3", "update");
  309. }
  310. LoadData();
  311. LoadGridData();
  312. //满箱更新状态为1
  313. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  314. {
  315. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  316. float weigh = float.Parse(ActWeigh);
  317. dh.UpdateByCondition("package", "pa_status=1,pa_packageqty=pa_currentqty,pa_weight='" + weigh + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  318. pa_standardqty.Text = "";
  319. pa_status.Text = "1";
  320. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
  321. LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
  322. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
  323. if (LogicHandler.CartonBoxStepPass(pa_makecode.Text, User.UserSourceCode, pa_outboxcode.Text, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", out ErrorMessage))
  324. {
  325. 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 + "'");
  326. }
  327. else
  328. {
  329. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  330. }
  331. if (AutoPrint.Checked)
  332. Print_Click(new object(), new EventArgs());
  333. }
  334. LoadCheckQTY();
  335. sn_code.Clear();
  336. }
  337. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  338. }
  339. }
  340. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  341. else
  342. {
  343. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "特殊", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  344. {
  345. 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");
  346. //如果母箱号不为空,需要更新总数
  347. if (MotherBoxCode != "")
  348. {
  349. 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 + "' and pa_type=3", "update");
  350. }
  351. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "取消采集成功", sn_code.Text, "");
  352. LoadData();
  353. LoadGridData();
  354. pa_status.Text = "0";
  355. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  356. }
  357. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  358. }
  359. }
  360. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  361. }
  362. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  363. }
  364. }
  365. private void Clean_Click(object sender, EventArgs e)
  366. {
  367. OperateResult.Clear();
  368. }
  369. //private void pr_code_TextChanged(object sender, EventArgs e)
  370. //{
  371. //}
  372. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  373. {
  374. BaseUtil.ClosePrint(lbl);
  375. if (serialPort1.IsOpen)
  376. {
  377. GetData = false;
  378. serialPort1.Close();
  379. SystemInf.OpenPort.Remove(serialPort1.PortName);
  380. thread.Interrupt();
  381. }
  382. //thread.Abort();
  383. }
  384. private void Packing_Click(object sender, EventArgs e)
  385. {
  386. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  387. {
  388. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  389. if (Seal == "Yes")
  390. {
  391. ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim();
  392. float weigh = float.Parse(ActWeigh);
  393. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集完成,手动封箱成功\n", Color.Green);
  394. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  395. pa_status.Text = "1";
  396. pa_standardqty.Text = "";
  397. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "装箱采集", "封箱成功", pa_outboxcode.Text, "");
  398. if (LogicHandler.CartonBoxStepPass(pa_makecode.Text, User.UserSourceCode, pa_outboxcode.Text, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", out ErrorMessage))
  399. {
  400. 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 + "'");
  401. }
  402. else
  403. {
  404. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  405. }
  406. LoadCheckQTY();
  407. pa_outboxcode.SelectAll();
  408. pa_outboxcode.Focus();
  409. }
  410. }
  411. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  412. }
  413. private void SendCheck_Click(object sender, EventArgs e)
  414. {
  415. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  416. {
  417. 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");
  418. if (dt.Rows[0][0].ToString() != "")
  419. {
  420. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  421. return;
  422. }
  423. sql.Clear();
  424. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  425. dh.ExecuteSql(sql.GetString(), "select");
  426. ob_nowcheckqty.Text = "";
  427. ob_batchqty.Text = "";
  428. ob_nowcheckqty.ForeColor = Color.Black;
  429. SendCheck.Enabled = false;
  430. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  431. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  432. //记录操作日志
  433. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  434. ob_checkno.Text = "";
  435. }
  436. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  437. }
  438. bool AutoCut;
  439. private void LoadCheckQTY()
  440. {
  441. sql.Clear();
  442. string condition = "";
  443. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  444. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  445. if (nowcheckqty + 1 == batchqty && AutoCut)
  446. {
  447. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  448. }
  449. else
  450. {
  451. condition = "and ob_status='ENTERING' ";
  452. }
  453. if (pr_sendchecktype.Text == "SaleCode")
  454. {
  455. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  456. }
  457. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  458. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  459. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  460. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  461. if (dt.Rows.Count > 0)
  462. {
  463. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  464. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  465. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  466. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  467. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  468. if (nowcheckqty == batchqty)
  469. {
  470. ob_nowcheckqty.ForeColor = Color.Red;
  471. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  472. if (AutoCut)
  473. {
  474. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  475. }
  476. }
  477. }
  478. else
  479. {
  480. ob_batchqty.Text = "";
  481. ob_nowcheckqty.Text = "";
  482. ob_checkno.Text = "";
  483. SendCheck.Enabled = false;
  484. }
  485. if (ob_batchqty.Text != "")
  486. {
  487. SendCheck.Enabled = true;
  488. }
  489. else
  490. {
  491. SendCheck.Enabled = false;
  492. }
  493. }
  494. private void ob_checkno_TextChanged(object sender, EventArgs e)
  495. {
  496. if (ob_checkno.Text != "")
  497. {
  498. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  499. if (Cut == "" || Cut == "0")
  500. AutoCut = false;
  501. else
  502. AutoCut = true;
  503. SendCheck.Enabled = true;
  504. }
  505. }
  506. //private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  507. //{
  508. // if (e.KeyCode == Keys.Enter)
  509. // ResetPackQTY();
  510. //}
  511. //private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  512. //{
  513. // ResetPackQTY();
  514. //}
  515. //private void ResetPackQTY()
  516. //{
  517. // //数据不符合限制的时候保持原有值
  518. // int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  519. // if (!(pr_outboxinnerqty.Value >= curretnqty))
  520. // {
  521. // pr_outboxinnerqty.Value = StandardQTY;
  522. // }
  523. // else
  524. // {
  525. // if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  526. // {
  527. // string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  528. // if (checknostatus == "" || checknostatus == "ENTERING")
  529. // {
  530. // if (pa_downstatus.Text == "0")
  531. // {
  532. // if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  533. // {
  534. // dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Value + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  535. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Value + "'", pa_outboxcode.Text, pa_checkno.Text);
  536. // return;
  537. // }
  538. // else
  539. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  540. // }
  541. // else
  542. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  543. // }
  544. // else
  545. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  546. // }
  547. // else
  548. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  549. // pr_outboxinnerqty.Value = StandardQTY;
  550. // }
  551. //}
  552. //private void PackageDetail_DataSourceChanged(object sender, EventArgs e)
  553. //{
  554. // if (PackageDetail.RowCount == 1)
  555. // {
  556. // LoadCheckQTY();
  557. // pr_code.Text = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + PackageDetail.Rows[0].Cells["pd_barcode"].Value.ToString() + "' order by ms_id desc").ToString();
  558. // 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");
  559. // PrintLabel.DataSource = dt;
  560. // PrintLabel.DisplayMember = "la_name";
  561. // PrintLabel.ValueMember = "la_id";
  562. // ftpOperater ftp = new ftpOperater();
  563. // for (int i = 0; i < dt.Rows.Count; i++)
  564. // {
  565. // BaseUtil.GetPrintLabel(dt.Rows[i]["la_name"].ToString(), dt.Rows[i]["la_url"].ToString());
  566. // }
  567. // }
  568. //}
  569. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  570. {
  571. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  572. {
  573. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  574. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  575. }
  576. }
  577. private void DeleteAll_Click(object sender, EventArgs e)
  578. {
  579. if (pa_outboxcode.Text == "")
  580. {
  581. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  582. return;
  583. }
  584. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  585. if (Delete == "Yes")
  586. {
  587. DataTable dt = (DataTable)dh.ExecuteSql("select 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");
  588. if (dt.Rows.Count > 0)
  589. {
  590. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  591. {
  592. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  593. {
  594. string ob_status = dt.Rows[0]["ob_status"].ToString();
  595. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  596. //不存在抽检批次或者还未检验可以拆解
  597. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  598. {
  599. sql.Clear();
  600. sql.Append("select pd_makecode,pd_barcode,pd_prodcode,ms_status,ms_stepcode from packagedetail left join makeserial ");
  601. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "'");
  602. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  603. for (int i = 0; i < dt.Rows.Count; i++)
  604. {
  605. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  606. string ms_sncode = dt.Rows[i]["pd_barcode"].ToString();
  607. string pr_code = dt.Rows[i]["pd_prodcode"].ToString();
  608. string ms_status = dt.Rows[i]["ms_status"].ToString();
  609. string ms_stepcode = dt.Rows[i]["ms_stepcode"].ToString();
  610. List<string> SQLS1 = new List<string>();
  611. if (ms_status == "2")
  612. {
  613. //已完工数-1
  614. SQLS1.Add("update make set ma_madeqty=ma_madeqty-1 where ma_code='" + ma_code + "'");
  615. }
  616. //更新序列号状态
  617. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1,mcd_okqty=mcd_okqty-1 where mcd_macode='" + ma_code + "' and mcd_stepcode='" + ms_stepcode + "'");
  618. SQLS1.Add("update makeserial set ms_status=1,ms_nextstepcode=ms_stepcode,ms_outboxcode='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  619. SQLS1.Add("delete from makeprocess where mp_sncode='" + ms_sncode + "' and mp_makecode='" + ma_code + "' and mp_stepcode='" + ms_stepcode + "'");
  620. SQLS1.Add("delete from steppassed where sp_sncode='" + ms_sncode + "' and sp_makecode='" + ma_code + "' and sp_stepcode='" + ms_stepcode + "'");
  621. //抽检批次不为空的时候进行移除
  622. if (pa_checkno != "")
  623. {
  624. SQLS1.Add("update makeserial set ms_checkno='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  625. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + pa_checkno + "'");
  626. SQLS1.Add("delete from oqcbatchdetail where obd_checkno='" + pa_checkno + "' and obd_sncode='" + ms_sncode + "'");
  627. }
  628. dh.ExecuteSQLTran(SQLS1.ToArray());
  629. }
  630. List<string> SQLS2 = new List<string>();
  631. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  632. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  633. if (standqty != "")
  634. {
  635. //置空原箱
  636. 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");
  637. }
  638. else
  639. //置空原箱
  640. 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");
  641. pa_status.Text = "0";
  642. //删除箱的明细
  643. SQLS2.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  644. dh.ExecuteSQLTran(SQLS2.ToArray());
  645. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  646. LoadGridData();
  647. LoadCheckQTY();
  648. }
  649. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  650. }
  651. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  652. }
  653. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱,不允许解除\n", Color.Red);
  654. }
  655. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  656. }
  657. }
  658. private void pr_code_TextChanged_1(object sender, EventArgs e)
  659. {
  660. LoadCheckQTY();
  661. 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");
  662. PrintLabel.DataSource = dt;
  663. PrintLabel.DisplayMember = "la_url";
  664. PrintLabel.ValueMember = "la_id";
  665. }
  666. }
  667. }