Make_PackageCollection.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. namespace UAS_MES.Make
  13. {
  14. public partial class Make_PackageCollection : Form
  15. {
  16. DataHelper dh;
  17. DataTable dt;
  18. LogStringBuilder sql = new LogStringBuilder();
  19. AutoSizeFormClass asc = new AutoSizeFormClass();
  20. ApplicationClass lbl;
  21. Thread thread;
  22. DataTable Dbfind;
  23. string ErrorMessage = "";
  24. string oMakeCode = "";
  25. string oMsID = "";
  26. System.DateTime[] indate;
  27. public Make_PackageCollection()
  28. {
  29. InitializeComponent();
  30. }
  31. //创建打印进程
  32. private void NewPrint()
  33. {
  34. try
  35. {
  36. lbl = new ApplicationClass();
  37. BaseUtil.WriteLbl(lbl);
  38. }
  39. catch (Exception ex)
  40. {
  41. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  42. }
  43. }
  44. private void 包装采集_Load(object sender, EventArgs e)
  45. {
  46. pa_outboxcode.ShowClickIcon = false;
  47. //设置DbFind的必须的数据
  48. PrintNum.Value = 1;
  49. asc.controllInitializeSize(this);
  50. thread = new Thread(NewPrint);
  51. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  52. BaseUtil.SetFormCenter(stw);
  53. stw.ShowDialog();
  54. dh = new DataHelper();
  55. }
  56. private void 包装采集_SizeChanged(object sender, EventArgs e)
  57. {
  58. asc.controlAutoSize(this);
  59. }
  60. private void 包装采集_Activated(object sender, EventArgs e)
  61. {
  62. pa_outboxcode.Focus();
  63. }
  64. //刷新表单的数据的数据
  65. private void LoadData()
  66. {
  67. //加载表单数据
  68. string Err = "";
  69. if (pa_outboxcode.Text != "")
  70. {
  71. sql.Clear();
  72. sql.Append("select pa_outboxcode,pa_status,pr_packrule,pr_detail,pa_packageqty,pr_outboxinnerqty,pa_standardqty,pa_currentqty from package left join product on pa_prodcode=");
  73. sql.Append("pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  74. Err = "箱号";
  75. }
  76. else
  77. {
  78. sql.Clear();
  79. sql.Append("select ms_makecode,pa_status,pr_packrule,pr_code,pr_detail,pr_outboxinnerqty,pa_standardqty,pa_packageqty,pa_currentqty,");
  80. sql.Append("pa_outboxcode from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  81. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_sncode='" + sn_code.Text + "'");
  82. Err = "序列号";
  83. }
  84. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  85. if (dt.Rows.Count > 0)
  86. {
  87. if (pr_code.Text != "")
  88. {
  89. dt.Columns.Remove(dt.Columns["pa_standardqty"]);
  90. }
  91. BaseUtil.SetFormValue(this.Controls, dt);
  92. }
  93. else OperateResult.AppendText(">>" + Err + "不存在\n", Color.Red);
  94. }
  95. private void LoadGridData()
  96. {
  97. //加载Grid数据
  98. dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pd_barcode,pd_innerqty,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  99. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  100. //更新界面的采集数量
  101. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  102. }
  103. private void InsertDetail()
  104. {
  105. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) < int.Parse(pr_outboxinnerqty.Text))
  106. {
  107. sql.Clear();
  108. sql.Append("insert into packagedetail(pd_id,pd_paid,pd_outboxcode,pd_innerqty,pd_barcode) ");
  109. sql.Append("select packagedetail_seq.nextval,pa_id,pa_outboxcode,pa_totalqty,'" + sn_code.Text + "' from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  110. dh.ExecuteSql(sql.GetString(), "insert");
  111. dh.UpdateByCondition("Package", "pa_packageqty=pa_packageqty+1,pa_currentqty=pa_currentqty+1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  112. dh.UpdateByCondition("makeserial", "ms_outboxcode='" + pa_outboxcode.Text + "'", "ms_id='" + oMsID + "'");
  113. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code.Text, "包装采集", "装箱成功", User.UserCode, out ErrorMessage))
  114. {
  115. LoadCheckQTY();
  116. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  117. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "采集成功", sn_code.Text, "");
  118. //满箱更新状态为1
  119. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) + 1 == int.Parse(pr_outboxinnerqty.Text))
  120. {
  121. dh.UpdateByCondition("package", "pa_status=1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  122. if (AutoPrint.Checked)
  123. Print_Click(new object(), new EventArgs());
  124. }
  125. LoadGridData();
  126. sn_code.Clear();
  127. }
  128. }
  129. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已采集满\n", Color.Red);
  130. }
  131. private void Print_Click(object sender, EventArgs e)
  132. {
  133. if (PrintLabel.Items.Count != 0)
  134. {
  135. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  136. {
  137. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  138. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Green);
  139. Print.CodeSoft(Tag.ToString(), lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
  140. }
  141. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  142. }
  143. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  144. }
  145. //加载工单信息和装箱明细信息
  146. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  147. {
  148. if (e.KeyCode == Keys.Enter)
  149. {
  150. sql.Clear();
  151. sql.Append("select pr_code,pr_detail,pr_outboxinnerqty,pa_currentqty,pa_packageqty from package left join product ");
  152. sql.Append("on pr_code=pa_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "'");
  153. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  154. if (dt.Rows.Count > 0)
  155. {
  156. BaseUtil.SetFormValue(this.Controls, dt);
  157. dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pd_barcode,pd_innerqty,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  158. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  159. sn_code.Focus();
  160. }
  161. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  162. }
  163. }
  164. //输入序列号的回车事件
  165. private void barcode_KeyDown(object sender, KeyEventArgs e)
  166. {
  167. //当用户输入回车键的时候
  168. if (e.KeyCode == Keys.Enter)
  169. {
  170. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  171. {
  172. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  173. {
  174. if (pa_outboxcode.Text == "")
  175. {
  176. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  177. {
  178. LoadData();
  179. LoadGridData();
  180. }
  181. else
  182. {
  183. LoadData();
  184. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  185. }
  186. }
  187. //按工单核对装箱
  188. switch (pr_packrule.Text)
  189. {
  190. case "M":
  191. if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != ms_makecode.Text)
  192. {
  193. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
  194. return;
  195. }
  196. break;
  197. case "S":
  198. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  199. {
  200. sql.Clear();
  201. sql.Append("select 1 from package left join make on pa_salecode=ma_salecode left join makeserial ");
  202. sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
  203. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  204. if (dt.Rows.Count == 0)
  205. {
  206. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
  207. return;
  208. }
  209. }
  210. break;
  211. case "P":
  212. if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
  213. {
  214. OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
  215. return;
  216. }
  217. break;
  218. default:
  219. break;
  220. }
  221. //判断箱内总数必须大于0
  222. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  223. {
  224. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  225. return;
  226. }
  227. //如果未勾选了取消录入
  228. if (!Cancel.Checked)
  229. {
  230. //判断序列号是否已经装箱
  231. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  232. {
  233. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
  234. }
  235. else
  236. {
  237. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  238. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || pa_status.Text == "1")
  239. {
  240. pa_currentqty.Text = "";
  241. pa_outboxcode.Text = "";
  242. pa_status.Text = "0";
  243. BaseUtil.CleanDGVData(PackageDetail);
  244. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  245. }
  246. //箱号不存在的情况
  247. if (!dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  248. {
  249. //插入Package主表箱号信息
  250. sql.Clear();
  251. sql.Append("insert into package (pa_id,pa_outboxcode,pa_packageqty,pa_totalqty,pa_status,pa_indate,pa_makecode,pa_prodcode,pa_salecode,");
  252. sql.Append("pa_custcode,pa_type,pa_packtype) select package_seq.nextval,'" + pa_outboxcode.Text + "',0," + pr_outboxinnerqty.Text + ",0,");
  253. sql.Append("sysdate,'" + oMakeCode + "', ma_prodcode,ma_salecode,ma_custcode,1,'" + pr_packrule.Text + "' from make where ma_code = '" + oMakeCode + "'");
  254. dh.ExecuteSql(sql.GetString(), "insert");
  255. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集成功!\n", Color.Green);
  256. InsertDetail();
  257. }
  258. else
  259. {
  260. if (dh.getRowCount("makeserial", "ms_sncode='" + sn_code.Text + "'") > 0)
  261. InsertDetail();
  262. else
  263. OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在\n", Color.Red, sn_code);
  264. }
  265. }
  266. }
  267. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  268. else
  269. {
  270. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "1")
  271. {
  272. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  273. if (outboxcode != "")
  274. {
  275. if (outboxcode == pa_outboxcode.Text)
  276. {
  277. //删除明细行的数据
  278. dh.ExecuteSql("delete from packagedetail where pd_barcode='" + sn_code.Text + "' and pd_paid=(select pa_id from package where pa_outboxcode='" + pa_outboxcode.Text + "')", "delete");
  279. //更新已装数
  280. dh.UpdateByCondition("Package", "pa_packageqty=pa_packageqty-1,pa_currentqty=pa_currentqty-1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  281. //清除序列号箱号
  282. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  283. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "取消采集成功", sn_code.Text, "");
  284. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green);
  285. LoadGridData();
  286. }
  287. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不在箱" + pa_outboxcode.Text + "内\n", Color.Red);
  288. }
  289. else OperateResult.AppendText(">>序列号" + sn_code.Text + "尚未装箱\n", Color.Red);
  290. }
  291. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已经封箱,不允许取消采集\n", Color.Red);
  292. }
  293. }
  294. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  295. }
  296. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  297. }
  298. }
  299. private void Clean_Click(object sender, EventArgs e)
  300. {
  301. OperateResult.Clear();
  302. }
  303. private void pr_code_TextChanged(object sender, EventArgs e)
  304. {
  305. LoadCheckQTY();
  306. pa_outboxcode.MakeCode = ms_makecode.Text;
  307. pa_outboxcode.ProdCode = pr_code.Text;
  308. pa_outboxcode.Caller = "PACKAGE";
  309. dt = (DataTable)dh.ExecuteSql("select pl_labelcode||':'||pl_labelname pl_laname,pl_labelname,pl_labelcode,pl_labelurl,pl_indate from productlabel where pl_prodcode='" + pr_code.Text + "' order by pl_isdefault desc ", "select");
  310. PrintLabel.DataSource = dt;
  311. PrintLabel.DisplayMember = "pl_laname";
  312. PrintLabel.ValueMember = "pl_labelcode";
  313. ftpOperater ftp = new ftpOperater();
  314. indate = new System.DateTime[dt.Rows.Count];
  315. for (int i = 0; i < dt.Rows.Count; i++)
  316. {
  317. BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
  318. indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
  319. }
  320. }
  321. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  322. {
  323. BaseUtil.ClosePrint(lbl);
  324. dh.Dispose();
  325. }
  326. private void Packing_Click(object sender, EventArgs e)
  327. {
  328. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_status<>1"))
  329. {
  330. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  331. pa_status.Text = "1";
  332. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "装箱采集", "封箱成功", pa_outboxcode.Text, "");
  333. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  334. }
  335. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  336. }
  337. private void SendCheck_Click(object sender, EventArgs e)
  338. {
  339. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "0")
  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(sn_code.Text, 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. }
  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 ms_makecode_TextChanged(object sender, EventArgs e)
  417. {
  418. LoadCheckQTY();
  419. }
  420. }
  421. }