Make_PackageCollection.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. //满箱更新状态为1
  118. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) + 1 == int.Parse(pr_outboxinnerqty.Text))
  119. {
  120. dh.UpdateByCondition("package", "pa_status=1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  121. if (AutoPrint.Checked)
  122. Print_Click(new object(), new EventArgs());
  123. }
  124. LoadGridData();
  125. sn_code.Clear();
  126. }
  127. }
  128. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已采集满\n", Color.Red);
  129. }
  130. private void Print_Click(object sender, EventArgs e)
  131. {
  132. if (PrintLabel.Items.Count != 0)
  133. {
  134. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  135. {
  136. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  137. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Green);
  138. Print.CodeSoft(lbl, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), indate[PrintLabel.SelectedIndex]);
  139. }
  140. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  141. }
  142. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  143. }
  144. //加载工单信息和装箱明细信息
  145. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  146. {
  147. if (e.KeyCode == Keys.Enter)
  148. {
  149. sql.Clear();
  150. sql.Append("select pr_code,pr_detail,pr_outboxinnerqty,pa_currentqty,pa_packageqty from package left join product ");
  151. sql.Append("on pr_code=pa_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "'");
  152. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  153. if (dt.Rows.Count > 0)
  154. {
  155. BaseUtil.SetFormValue(this.Controls, dt);
  156. 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");
  157. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  158. sn_code.Focus();
  159. }
  160. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  161. }
  162. }
  163. //输入序列号的回车事件
  164. private void barcode_KeyDown(object sender, KeyEventArgs e)
  165. {
  166. //当用户输入回车键的时候
  167. if (e.KeyCode == Keys.Enter)
  168. {
  169. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  170. {
  171. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  172. {
  173. if (pa_outboxcode.Text == "")
  174. {
  175. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  176. {
  177. LoadData();
  178. LoadGridData();
  179. }
  180. else
  181. {
  182. LoadData();
  183. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  184. }
  185. }
  186. //按工单核对装箱
  187. switch (pr_packrule.Text)
  188. {
  189. case "M":
  190. if (dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_id='" + oMsID + "'").ToString() != ms_makecode.Text)
  191. {
  192. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属工单和当前箱号工单不相等\n", Color.Red, sn_code);
  193. return;
  194. }
  195. break;
  196. case "S":
  197. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  198. {
  199. sql.Clear();
  200. sql.Append("select 1 from package left join make on pa_salecode=ma_salecode left join makeserial ");
  201. sql.Append("on ma_code=ms_makecode where pa_outboxcode='" + pa_outboxcode.Text + "' and ms_id='" + oMsID + "'");
  202. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  203. if (dt.Rows.Count == 0)
  204. {
  205. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号和当前箱号订单不相等\n", Color.Red, sn_code);
  206. return;
  207. }
  208. }
  209. break;
  210. case "P":
  211. if (dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsID + "'").ToString() != pr_code.Text)
  212. {
  213. OperateResult.AppendText(">>序列号" + sn_code.Text + "对应物料和该箱所装物料不同\n", Color.Red, sn_code);
  214. return;
  215. }
  216. break;
  217. default:
  218. break;
  219. }
  220. //判断箱内总数必须大于0
  221. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  222. {
  223. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  224. return;
  225. }
  226. //如果未勾选了取消录入
  227. if (!Cancel.Checked)
  228. {
  229. //判断序列号是否已经装箱
  230. if (dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString() != "")
  231. {
  232. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经装箱!\n", Color.Red, sn_code);
  233. }
  234. else
  235. {
  236. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  237. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || pa_status.Text == "1")
  238. {
  239. pa_currentqty.Text = "";
  240. pa_outboxcode.Text = "";
  241. pa_status.Text = "0";
  242. BaseUtil.CleanDGVData(PackageDetail);
  243. pa_outboxcode.GeneratePaCode_Click(new object(), new EventArgs());
  244. }
  245. //箱号不存在的情况
  246. if (!dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  247. {
  248. //插入Package主表箱号信息
  249. sql.Clear();
  250. sql.Append("insert into package (pa_id,pa_outboxcode,pa_packageqty,pa_totalqty,pa_status,pa_indate,pa_makecode,pa_prodcode,pa_salecode,");
  251. sql.Append("pa_custcode,pa_type,pa_packtype) select package_seq.nextval,'" + pa_outboxcode.Text + "',0," + pr_outboxinnerqty.Text + ",0,");
  252. sql.Append("sysdate,'" + oMakeCode + "', ma_prodcode,ma_salecode,ma_custcode,1,'" + pr_packrule.Text + "' from make where ma_code = '" + oMakeCode + "'");
  253. dh.ExecuteSql(sql.GetString(), "insert");
  254. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集成功!\n", Color.Green);
  255. InsertDetail();
  256. }
  257. else
  258. {
  259. if (dh.getRowCount("makeserial", "ms_sncode='" + sn_code.Text + "'") > 0)
  260. InsertDetail();
  261. else
  262. OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在\n", Color.Red, sn_code);
  263. }
  264. }
  265. }
  266. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  267. else
  268. {
  269. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "1")
  270. {
  271. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  272. if (outboxcode != "")
  273. {
  274. if (outboxcode == pa_outboxcode.Text)
  275. {
  276. //删除明细行的数据
  277. 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");
  278. //更新已装数
  279. dh.UpdateByCondition("Package", "pa_packageqty=pa_packageqty-1,pa_currentqty=pa_currentqty-1", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  280. //清除序列号箱号
  281. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  282. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green);
  283. LoadGridData();
  284. }
  285. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不在箱" + pa_outboxcode.Text + "内\n", Color.Red);
  286. }
  287. else OperateResult.AppendText(">>序列号" + sn_code.Text + "尚未装箱\n", Color.Red);
  288. }
  289. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已经封箱,不允许取消采集\n", Color.Red);
  290. }
  291. }
  292. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  293. }
  294. else OperateResult.AppendText(">>"+ErrorMessage+"\n", Color.Red);
  295. }
  296. }
  297. private void Clean_Click(object sender, EventArgs e)
  298. {
  299. OperateResult.Clear();
  300. }
  301. private void pr_code_TextChanged(object sender, EventArgs e)
  302. {
  303. LoadCheckQTY();
  304. pa_outboxcode.MakeCode = ms_makecode.Text;
  305. pa_outboxcode.ProdCode = pr_code.Text;
  306. pa_outboxcode.Caller = "PACKAGE";
  307. 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");
  308. PrintLabel.DataSource = dt;
  309. PrintLabel.DisplayMember = "pl_laname";
  310. PrintLabel.ValueMember = "pl_labelcode";
  311. ftpOperater ftp = new ftpOperater();
  312. indate = new System.DateTime[dt.Rows.Count];
  313. for (int i = 0; i < dt.Rows.Count; i++)
  314. {
  315. BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
  316. indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
  317. }
  318. }
  319. private void 包装采集_FormClosing(object sender, FormClosingEventArgs e)
  320. {
  321. BaseUtil.ClosePrint(lbl);
  322. dh.Dispose();
  323. }
  324. private void Packing_Click(object sender, EventArgs e)
  325. {
  326. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_status<>1"))
  327. {
  328. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  329. pa_status.Text = "1";
  330. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
  331. }
  332. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  333. }
  334. private void SendCheck_Click(object sender, EventArgs e)
  335. {
  336. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "0")
  337. {
  338. sql.Clear();
  339. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  340. dh.ExecuteSql(sql.GetString(), "select");
  341. ob_nowcheckqty.Text = "";
  342. ob_batchqty.Text = "";
  343. ob_nowcheckqty.ForeColor = Color.Black;
  344. SendCheck.Enabled = false;
  345. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  346. LogicHandler.InsertMakeProcess(sn_code.Text, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  347. //记录操作日志
  348. LogicHandler.DoCommandLog(User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  349. ob_checkno.Text = "";
  350. }
  351. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  352. }
  353. bool AutoCut;
  354. private void LoadCheckQTY()
  355. {
  356. sql.Clear();
  357. string condition = "";
  358. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  359. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  360. if (nowcheckqty + 1 == batchqty && AutoCut)
  361. {
  362. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  363. }
  364. else
  365. {
  366. condition = "and ob_status='ENTERING' ";
  367. }
  368. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  369. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  370. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  371. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  372. if (dt.Rows.Count > 0)
  373. {
  374. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  375. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  376. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  377. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  378. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  379. if (nowcheckqty == batchqty)
  380. {
  381. ob_nowcheckqty.ForeColor = Color.Red;
  382. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  383. }
  384. }
  385. else
  386. {
  387. ob_batchqty.Text = "";
  388. ob_nowcheckqty.Text = "";
  389. ob_checkno.Text = "";
  390. SendCheck.Enabled = false;
  391. }
  392. if (ob_batchqty.Text != "")
  393. {
  394. SendCheck.Enabled = true;
  395. }
  396. else
  397. {
  398. SendCheck.Enabled = false;
  399. }
  400. }
  401. private void ob_checkno_TextChanged(object sender, EventArgs e)
  402. {
  403. if (ob_checkno.Text != "")
  404. {
  405. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  406. if (Cut == "" || Cut == "0")
  407. AutoCut = false;
  408. else
  409. AutoCut = true;
  410. SendCheck.Enabled = true;
  411. }
  412. }
  413. private void ms_makecode_TextChanged(object sender, EventArgs e)
  414. {
  415. LoadCheckQTY();
  416. }
  417. }
  418. }