Make_SpecialCartonPack.cs 30 KB

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