Make_SpecialCartonPack.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  322. if (Seal == "Yes")
  323. {
  324. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  325. pa_status.Text = "1";
  326. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  327. }
  328. }
  329. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  330. }
  331. private void SendCheck_Click(object sender, EventArgs e)
  332. {
  333. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  334. {
  335. 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");
  336. if (dt.Rows[0][0].ToString() != "")
  337. {
  338. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  339. return;
  340. }
  341. sql.Clear();
  342. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  343. dh.ExecuteSql(sql.GetString(), "select");
  344. ob_nowcheckqty.Text = "";
  345. ob_batchqty.Text = "";
  346. ob_nowcheckqty.ForeColor = Color.Black;
  347. SendCheck.Enabled = false;
  348. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  349. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  350. //记录操作日志
  351. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  352. ob_checkno.Text = "";
  353. }
  354. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  355. }
  356. bool AutoCut;
  357. private void LoadCheckQTY()
  358. {
  359. sql.Clear();
  360. string condition = "";
  361. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  362. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  363. if (nowcheckqty + 1 == batchqty && AutoCut)
  364. {
  365. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  366. }
  367. else
  368. {
  369. condition = "and ob_status='ENTERING' ";
  370. }
  371. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  372. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  373. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  374. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  375. if (dt.Rows.Count > 0)
  376. {
  377. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  378. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  379. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  380. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  381. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  382. if (nowcheckqty == batchqty)
  383. {
  384. ob_nowcheckqty.ForeColor = Color.Red;
  385. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  386. if (AutoCut)
  387. {
  388. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  389. }
  390. }
  391. }
  392. else
  393. {
  394. ob_batchqty.Text = "";
  395. ob_nowcheckqty.Text = "";
  396. ob_checkno.Text = "";
  397. SendCheck.Enabled = false;
  398. }
  399. if (ob_batchqty.Text != "")
  400. {
  401. SendCheck.Enabled = true;
  402. }
  403. else
  404. {
  405. SendCheck.Enabled = false;
  406. }
  407. }
  408. private void ob_checkno_TextChanged(object sender, EventArgs e)
  409. {
  410. if (ob_checkno.Text != "")
  411. {
  412. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  413. if (Cut == "" || Cut == "0")
  414. AutoCut = false;
  415. else
  416. AutoCut = true;
  417. SendCheck.Enabled = true;
  418. }
  419. }
  420. private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  421. {
  422. if (e.KeyCode == Keys.Enter)
  423. ResetPackQTY();
  424. }
  425. private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  426. {
  427. ResetPackQTY();
  428. }
  429. private void ResetPackQTY()
  430. {
  431. //数据不符合限制的时候保持原有值
  432. int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  433. if (!(pr_outboxinnerqty.Value >= curretnqty))
  434. {
  435. pr_outboxinnerqty.Value = StandardQTY;
  436. }
  437. else
  438. {
  439. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  440. {
  441. string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  442. if (checknostatus == "" || checknostatus == "ENTERING")
  443. {
  444. if (pa_downstatus.Text == "0")
  445. {
  446. if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  447. {
  448. dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Value + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  449. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Value + "'", pa_outboxcode.Text, pa_checkno.Text);
  450. return;
  451. }
  452. else
  453. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  454. }
  455. else
  456. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  457. }
  458. else
  459. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  460. }
  461. else
  462. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  463. pr_outboxinnerqty.Value = StandardQTY;
  464. }
  465. }
  466. private void PackageDetail_DataSourceChanged(object sender, EventArgs e)
  467. {
  468. if (PackageDetail.RowCount == 1)
  469. {
  470. LoadCheckQTY();
  471. pr_code.Text = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + PackageDetail.Rows[0].Cells["pd_barcode"].Value.ToString() + "' order by ms_id desc").ToString();
  472. 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");
  473. PrintLabel.DataSource = dt;
  474. PrintLabel.DisplayMember = "la_name";
  475. PrintLabel.ValueMember = "la_id";
  476. ftpOperater ftp = new ftpOperater();
  477. for (int i = 0; i < dt.Rows.Count; i++)
  478. {
  479. BaseUtil.GetPrintLabel(dt.Rows[i]["la_name"].ToString(), dt.Rows[i]["la_url"].ToString());
  480. }
  481. }
  482. }
  483. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  484. {
  485. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  486. {
  487. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  488. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  489. }
  490. }
  491. private void DeleteAll_Click(object sender, EventArgs e)
  492. {
  493. if (pa_outboxcode.Text == "")
  494. {
  495. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  496. return;
  497. }
  498. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  499. if (Delete == "Yes")
  500. {
  501. 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");
  502. if (dt.Rows.Count > 0)
  503. {
  504. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  505. {
  506. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  507. {
  508. string ob_status = dt.Rows[0]["ob_status"].ToString();
  509. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  510. //不存在抽检批次或者还未检验可以拆解
  511. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  512. {
  513. sql.Clear();
  514. sql.Append("select pd_makecode,pd_barcode,pd_prodcode,ms_status,ms_stepcode from packagedetail left join makeserial ");
  515. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "'");
  516. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  517. for (int i = 0; i < dt.Rows.Count; i++)
  518. {
  519. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  520. string ms_sncode = dt.Rows[i]["pd_barcode"].ToString();
  521. string pr_code = dt.Rows[i]["pd_prodcode"].ToString();
  522. string ms_status = dt.Rows[i]["ms_status"].ToString();
  523. string ms_stepcode = dt.Rows[i]["ms_stepcode"].ToString();
  524. List<string> SQLS1 = new List<string>();
  525. if (ms_status == "2")
  526. {
  527. //已完工数-1
  528. SQLS1.Add("update make set ma_madeqty=ma_madeqty-1 where ma_code='" + ma_code + "'");
  529. }
  530. //更新序列号状态
  531. 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 + "'");
  532. SQLS1.Add("update makeserial set ms_status=1,ms_nextstepcode=ms_stepcode,ms_outboxcode='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  533. SQLS1.Add("delete from makeprocess where mp_sncode='" + ms_sncode + "' and mp_makecode='" + ma_code + "' and mp_stepcode='" + ms_stepcode + "'");
  534. SQLS1.Add("delete from steppassed where sp_sncode='" + ms_sncode + "' and sp_makecode='" + ma_code + "' and sp_stepcode='" + ms_stepcode + "'");
  535. //抽检批次不为空的时候进行移除
  536. if (pa_checkno != "")
  537. {
  538. SQLS1.Add("update makeserial set ms_checkno='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code + "'");
  539. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + pa_checkno + "'");
  540. SQLS1.Add("delete from oqcbatchdetail where obd_checkno='" + pa_checkno + "' and obd_sncode='" + ms_sncode + "'");
  541. }
  542. dh.ExecuteSQLTran(SQLS1.ToArray());
  543. }
  544. List<string> SQLS2 = new List<string>();
  545. ////置空原箱
  546. SQLS2.Add("update package set pa_checkno='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'");
  547. pa_status.Text = "0";
  548. //删除箱的明细
  549. SQLS2.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'");
  550. dh.ExecuteSQLTran(SQLS2.ToArray());
  551. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  552. LoadGridData();
  553. LoadCheckQTY();
  554. }
  555. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  556. }
  557. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  558. }
  559. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱,不允许解除\n", Color.Red);
  560. }
  561. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  562. }
  563. }
  564. }
  565. }