Make_PackageCollection.cs 21 KB

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