Make_PackageCollection.cs 22 KB

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