华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

559 lines
22 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Base.Language.Tool;
  10. using ICSSoft.Base.UserControl.MessageControl;
  11. using System.Data.SqlClient;
  12. using ICSSoft.Base.Config.AppConfig;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Frame.Data.DAL;
  18. using ICSSoft.Frame.Data.BLL;
  19. using ICSSoft.Frame.Data.Entity;
  20. using ICSSoft.Base.Lable.PrintTool;
  21. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormICSLotSplitInCollection : DevExpress.XtraEditors.XtraForm
  24. {
  25. #region 基础参数
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. private string SimID = "";
  31. private string LotNo = "";
  32. private string MoCode = "";
  33. private string MoSeq = "";
  34. string itemcode = "";
  35. int monum;
  36. #endregion
  37. #region 构造函数
  38. public FormICSLotSplitInCollection()
  39. {
  40. InitializeComponent();
  41. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  42. this.WindowState = FormWindowState.Maximized;
  43. }
  44. #endregion
  45. public FormICSLotSplitInCollection(string id,String lotno)
  46. {
  47. InitializeComponent();
  48. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  49. this.WindowState = FormWindowState.Maximized;
  50. SimID = id;
  51. LotNo = lotno;
  52. }
  53. #region 移动窗体
  54. private const int WM_NCHITTEST = 0x84;
  55. private const int HTCLIENT = 0x1;
  56. private const int HTCAPTION = 0x2;
  57. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  58. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  59. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  60. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  61. //重写窗体,使窗体可以不通过自带标题栏实现移动
  62. protected override void WndProc(ref Message m)
  63. {
  64. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  65. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  66. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  67. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  68. switch (m.Msg)
  69. {
  70. case WM_NCHITTEST:
  71. base.WndProc(ref m);
  72. if ((int)m.Result == HTCLIENT)
  73. m.Result = (IntPtr)HTCAPTION;
  74. return;
  75. }
  76. //拦截双击标题栏、移动窗体的系统消息
  77. if (m.Msg != 0xA3)
  78. {
  79. base.WndProc(ref m);
  80. }
  81. }
  82. #endregion
  83. #region SystemOptition
  84. /// <summary>
  85. /// 操作权限
  86. /// </summary>
  87. /// <returns></returns>
  88. public DataTable RightOfExute()
  89. {
  90. DataTable rData = new DataTable();
  91. rData.Columns.Add("BtnName");
  92. rData.Columns.Add("ActionName");
  93. //查看权限(必须有)
  94. DataRow seeRow = rData.NewRow();
  95. seeRow["BtnName"] = "see";
  96. seeRow["ActionName"] = "查看";
  97. rData.Rows.Add(seeRow);
  98. List<Control> ControlList = new List<Control>();
  99. //ControlList.Add(btnDelLable);
  100. foreach (Control ctr in ControlList)
  101. {
  102. if (ctr.GetType() == typeof(SimpleButton))
  103. {
  104. DataRow dr = rData.NewRow();
  105. dr["BtnName"] = ctr.Name;
  106. dr["ActionName"] = ctr.Text;
  107. rData.Rows.Add(dr);
  108. }
  109. }
  110. rData.AcceptChanges();
  111. return rData;
  112. }
  113. /// <summary>
  114. /// 数据权限
  115. /// </summary>
  116. /// <returns></returns>
  117. public DataTable RightOfData()
  118. {
  119. DataTable rData = new DataTable();
  120. rData.Columns.Add("BodyName");
  121. rData.Columns.Add("ControlName");
  122. rData.Columns.Add("ControlCaption");
  123. rData.AcceptChanges();
  124. return rData;
  125. }
  126. #endregion
  127. #region 退出
  128. private void btnClose_Click(object sender, EventArgs e)
  129. {
  130. AppConfig.CloseFormShow(this.Text);
  131. this.Close();
  132. }
  133. private void btnExit_Click(object sender, EventArgs e)
  134. {
  135. AppConfig.CloseFormShow(this.Text);
  136. this.Close();
  137. }
  138. #endregion
  139. #region 全选
  140. private void btnSelectAll_Click(object sender, EventArgs e)
  141. {
  142. grvDetail.PostEditor();
  143. this.Validate();
  144. for (int i = 0; i < grvDetail.RowCount; i++)
  145. {
  146. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  147. }
  148. }
  149. #endregion
  150. #region 全消
  151. private void btnCancelAll_Click(object sender, EventArgs e)
  152. {
  153. grvDetail.PostEditor();
  154. this.Validate();
  155. for (int i = 0; i < grvDetail.RowCount; i++)
  156. {
  157. grvDetail.SetRowCellValue(i, colisSelect, "");
  158. }
  159. }
  160. #endregion
  161. #region 刷新
  162. private void btnFalsh_Click(object sender, EventArgs e)
  163. {
  164. FormICSLotSplitInCollection_Load(null, null);
  165. }
  166. #endregion
  167. #region 列表
  168. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  169. {
  170. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  171. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  172. }
  173. #endregion
  174. #region 双击选择
  175. private void grvDetail_DoubleClick(object sender, EventArgs e)
  176. {
  177. if (grvDetail.FocusedRowHandle < 0)
  178. {
  179. return;
  180. }
  181. if (grvDetail.FocusedColumn == colisSelect)
  182. {
  183. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  184. {
  185. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  186. }
  187. else
  188. {
  189. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  190. }
  191. }
  192. }
  193. #endregion
  194. #region 导出
  195. private void btnOutPut_Click(object sender, EventArgs e)
  196. {
  197. try
  198. {
  199. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  200. foe.ShowDialog();
  201. }
  202. catch (Exception ex)
  203. {
  204. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  205. }
  206. //FormOutExcel foe = new FormOutExcel();
  207. //if (foe.ShowDialog() == DialogResult.OK)
  208. //{
  209. // try
  210. // {
  211. // string outtype = foe._OutType;
  212. // string exceltype = foe._ExcelType;
  213. // string filename = foe._FileName;
  214. // string url = foe._Url;
  215. // string sheetname = foe._SheetName;
  216. // if (outtype.ToLower() == "excel")
  217. // {
  218. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  219. // op.SheetName = sheetname;
  220. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  221. // }
  222. // else
  223. // {
  224. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  225. // }
  226. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  227. // }
  228. // catch (Exception ex)
  229. // {
  230. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  231. // }
  232. //}
  233. }
  234. #endregion
  235. private void FormICSLotSplitInCollection_Load(object sender, EventArgs e)
  236. {
  237. try
  238. {
  239. txtNowQty.Focus();
  240. string sql = @"SELECT LOTNO,SEQ,MOCODE,LOTSEQ,LOTQTY,GOODQTY,NGQTY,LOTStatus,ITEMCODE,ROUTECODE,OPCODE,
  241. RESCODE,EQPCODE,PRODUCTSTATUS,LACTION,ACTIONLIST,NGTIMES,ISCOM,ISHOLD,MOSEQ,CollectStatus
  242. FROM ICSLOTSIMULATION WHERE ID = '{0}'";
  243. sql = string.Format(sql, SimID);
  244. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  245. if (dt != null && dt.Rows.Count > 0)
  246. {
  247. txtLOTNORemainQTY.Text = dt.Rows[0]["LOTQTY"].ToString();
  248. txtNowQty.Text = txtLOTNORemainQTY.Text;
  249. txtNowPackQty.Text = txtLOTNORemainQTY.Text;
  250. txtNowNum.Text = "1";
  251. LotNo = dt.Rows[0]["LOTNO"].ToString();
  252. MoCode = dt.Rows[0]["MOCODE"].ToString();
  253. MoSeq = dt.Rows[0]["MOSEQ"].ToString();
  254. sql = @"SELECT '' isSelect,a.ID,b.transno as MOCODE,b.transline as MOSEQ,a.LOTNO,a.ITEMCODE,c.INVNAME AS ITEMNAME,
  255. a.ROUTECODE,d.ROUTEDESC,a.OPCODE,e.OPDESC,a.LOTQTY,a.GOODQTY,a.NGQTY,a.MUSERName,a.MTIME
  256. FROM ICSLOTSIMULATION a
  257. LEFT JOIN icsitemlot b ON a.lotno = b.lotno
  258. LEFT JOIN ICSINVENTORY c ON a.ITEMCODE = c.INVCODE
  259. LEFT JOIN ICSROUTE d ON d.ROUTECODE = a.ROUTECODE
  260. LEFT JOIN ICSOP e ON a.OPCODE = e.OPCODE
  261. WHERE a.LOTNO = '{0}'
  262. OR a.LOTNO IN (SELECT LOTNOSplit FROM ICSLotSplitINCollectionLog where LOTNO='{0}')
  263. ORDER BY MTIME DESC"; //WHERE LOTNO = a.LOTNO
  264. sql = string.Format(sql, LotNo);
  265. dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  266. grdDetail.DataSource = dt;
  267. grvDetail.BestFitColumns();
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  273. }
  274. }
  275. private void txtNowQty_EditValueChanged(object sender, EventArgs e)
  276. {
  277. decimal Qty = 0;
  278. decimal Pack = 0;
  279. decimal Num = 0;
  280. decimal Sqty = 0;
  281. decimal.TryParse(txtNowQty.Text, out Qty);
  282. decimal.TryParse(txtNowPackQty.Text, out Pack);
  283. decimal.TryParse(txtNowNum.Text, out Num);
  284. if (Qty != 0 && Pack != 0)
  285. {
  286. Sqty = Math.Ceiling(Qty / Pack);
  287. txtNowNum.Text = Sqty.ToString();
  288. }
  289. }
  290. private void txtNowNum_EditValueChanged(object sender, EventArgs e)
  291. {
  292. decimal Qty = 0;
  293. decimal Pack = 0;
  294. decimal Num = 0;
  295. decimal Sqty = 0;
  296. decimal.TryParse(txtNowQty.Text, out Qty);
  297. decimal.TryParse(txtNowPackQty.Text, out Pack);
  298. decimal.TryParse(txtNowNum.Text, out Num);
  299. if (Qty != 0 && Num != 0)
  300. {
  301. if (Num * Pack >= Pack + Qty || Num * Pack <= Qty)
  302. {
  303. Sqty = Math.Ceiling(Qty / Num);
  304. txtNowPackQty.Text = Sqty.ToString();
  305. }
  306. else
  307. return;
  308. }
  309. }
  310. private void btnLot_Click(object sender, EventArgs e)
  311. {
  312. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
  313. try
  314. {
  315. _wait.Show();
  316. decimal totalQty = decimal.Parse(txtNowQty.Text);
  317. decimal pieceQty = decimal.Parse(txtNowPackQty.Text);
  318. decimal Num = Convert.ToDecimal(txtNowNum.Text);
  319. if (totalQty > Convert.ToDecimal(txtLOTNORemainQTY.Text))
  320. {
  321. throw new Exception("生成的条码总数不能超出条码剩余未生成数量!");
  322. }
  323. if (pieceQty > totalQty)
  324. {
  325. throw new Exception("批次数量不能大于生成的条码总数!");
  326. }
  327. if (pieceQty * Num < totalQty || pieceQty * (Num - 1) >= totalQty)
  328. {
  329. throw new Exception("条码数量计算出错,请重新计算");
  330. }
  331. decimal Qty = decimal.Parse(txtNowPackQty.Text);
  332. if (Num <= 0)
  333. {
  334. throw new Exception("条码张数不能为0");
  335. }
  336. if (Qty <= 0)
  337. {
  338. throw new Exception("条码数量不能为0");
  339. }
  340. DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd");
  341. string timeStr = time.ToString("yyMMdd");
  342. ICSMO2LotBLL.SplitMOLotNew(LotNo, Convert.ToInt32(totalQty), Convert.ToInt32(Qty), Convert.ToInt32(Num), AppConfig.AppConnectString);
  343. _wait.Close();
  344. ICSBaseSimpleCode.AppshowMessageBox("分批成功");
  345. btnFalsh_Click(null, null);
  346. }
  347. catch (Exception ex)
  348. {
  349. _wait.Close();
  350. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  351. }
  352. }
  353. private void CreatLot(List<ICSITEMLot> Infolist)
  354. {
  355. bool isnew = false;
  356. List<ICSLOTSIMULATION> simList = new List<ICSLOTSIMULATION>();
  357. List<ICSLotSplitINCollectionLog> loginfolist = new List<ICSLotSplitINCollectionLog>();
  358. ICSLOTSIMULATION lotSimulation = ICSITEMLOTBLL.GetICSLOTSIMULATION(SimID, AppConfig.AppConnectString);
  359. List<ICSMO2User> mo2UserList = new List<ICSMO2User>();
  360. if (lotSimulation == null)
  361. {
  362. isnew = true;
  363. }
  364. foreach (ICSITEMLot info in Infolist)
  365. {
  366. #region 获取原条码ICSLOTSIMULATION数据并扣减数量
  367. #endregion
  368. if (isnew == false)
  369. {
  370. #region ICSLOTSIMULATION
  371. ICSLOTSIMULATION simInfo = new ICSLOTSIMULATION();
  372. simInfo.ID = AppConfig.GetGuid();
  373. simInfo.LOTNO = info.LotNO;
  374. simInfo.SEQ = lotSimulation.SEQ;
  375. simInfo.MOCODE = lotSimulation.MOCODE;
  376. simInfo.LOTSEQ = lotSimulation.LOTSEQ + 1;
  377. simInfo.LOTQTY = info.LOTQTY;
  378. simInfo.GOODQTY = info.LOTQTY;
  379. simInfo.NGQTY = 0;
  380. simInfo.LOTStatus = lotSimulation.LOTStatus;
  381. simInfo.MODELCODE = lotSimulation.MODELCODE;
  382. simInfo.ITEMCODE = lotSimulation.ITEMCODE;
  383. simInfo.FROMROUTE = lotSimulation.FROMROUTE;
  384. simInfo.FROMOP = lotSimulation.FROMOP;
  385. simInfo.ROUTECODE = lotSimulation.ROUTECODE;
  386. simInfo.OPCODE = lotSimulation.OPCODE;
  387. simInfo.RESCODE = lotSimulation.RESCODE;
  388. simInfo.EQPCODE = lotSimulation.EQPCODE;
  389. simInfo.CHECKLOTNO = lotSimulation.CHECKLOTNO;
  390. simInfo.CARTONCODE = lotSimulation.CARTONCODE;
  391. simInfo.PALLETCODE = lotSimulation.PALLETCODE;
  392. simInfo.PRODUCTSTATUS = lotSimulation.PRODUCTSTATUS;
  393. simInfo.LACTION = lotSimulation.LACTION;
  394. simInfo.ACTIONLIST = lotSimulation.ACTIONLIST;
  395. simInfo.NGTIMES = lotSimulation.NGTIMES;
  396. simInfo.ISCOM = lotSimulation.ISCOM;
  397. simInfo.ISHOLD = lotSimulation.ISHOLD;
  398. simInfo.SHELFNO = lotSimulation.SHELFNO;
  399. simInfo.MOSEQ = lotSimulation.MOSEQ;
  400. simInfo.CollectStatus = lotSimulation.CollectStatus;
  401. simInfo.BeginTime = lotSimulation.BeginTime;
  402. simInfo.EndTime = lotSimulation.EndTime;
  403. simInfo.MUSER = AppConfig.UserCode;
  404. simInfo.MUSERName = AppConfig.UserName;
  405. simInfo.MTIME = DateTime.Now;
  406. simInfo.WorkPoint = AppConfig.WorkPointCode;
  407. simList.Add(simInfo);
  408. #endregion
  409. }
  410. #region ICSLotSplitINCollectionLog
  411. ICSLotSplitINCollectionLog loginfo = new ICSLotSplitINCollectionLog();
  412. loginfo.ID = AppConfig.GetGuid();
  413. loginfo.LOTNO = LotNo;
  414. loginfo.LOTNOSplit = info.LotNO;
  415. if (isnew == false)
  416. {
  417. loginfo.OPCode = lotSimulation.OPCODE;
  418. }
  419. else
  420. {
  421. loginfo.OPCode = "";
  422. }
  423. loginfo.MUSER = AppConfig.UserCode;
  424. loginfo.MUSERNAME = AppConfig.UserName;
  425. loginfo.MTIME = DateTime.Now;
  426. loginfo.WorkPoint = AppConfig.WorkPointCode;
  427. loginfolist.Add(loginfo);
  428. #endregion
  429. string sql = @"SELECT ROUTECODE,OPCODE,OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}'
  430. AND OPSEQ > (SELECT OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}' AND OPCODE = '{1}')
  431. ORDER BY OPSEQ";
  432. sql = string.Format(sql, lotSimulation.ROUTECODE, lotSimulation.OPCODE);
  433. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  434. foreach (DataRow row in dt.Rows)
  435. {
  436. ICSMO2User user = new ICSMO2User();
  437. user.ID = AppConfig.GetGuid().ToString();
  438. user.MOCODE = lotSimulation.MOCODE;
  439. user.MOSEQ = lotSimulation.MOSEQ;
  440. user.LOTNO = info.LotNO;
  441. user.SEGCODE = "";
  442. user.RouteCode = lotSimulation.ROUTECODE;
  443. user.OPCODE = row["OPCODE"].ToString();
  444. user.USERCODE = "";
  445. user.USERName = "";
  446. user.EQPCode = "";
  447. user.EQPName = "";
  448. user.StartPlanDate = DateTime.Now;
  449. user.EndPlanDate = DateTime.Now;
  450. user.MUSER = AppConfig.UserCode;
  451. user.MUSERName = AppConfig.UserName;
  452. user.MTIME = DateTime.Now;
  453. user.WorkPoint = AppConfig.WorkPointCode;
  454. mo2UserList.Add(user);
  455. }
  456. }
  457. try
  458. {
  459. ICSITEMLOTBLL.SplitAdd(SimID, LotNo, Infolist, simList, loginfolist,mo2UserList, isnew, AppConfig.AppConnectString);
  460. ICSBaseSimpleCode.AppshowMessageBox("分批成功");
  461. btnFalsh_Click(null, null);
  462. }
  463. catch (Exception ex)
  464. {
  465. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  466. }
  467. }
  468. private void btnPrint_Click(object sender, EventArgs e)
  469. {
  470. try
  471. {
  472. List<PrintPara> parasList = new List<PrintPara>();
  473. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  474. for (int i = 0; i < grvDetail.RowCount; i++)
  475. {
  476. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  477. {
  478. PrintPara para = new PrintPara();
  479. para.PrintKey = "LOTNO";
  480. para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLOTNO).ToString() };
  481. parasList.Add(para);
  482. }
  483. }
  484. if (parasList.Count == 0)
  485. {
  486. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  487. return;
  488. }
  489. //FormPrintDialog f = new FormPrintDialog("001", this.Text, parasList, false, null);
  490. FormPrintDialog f = new FormPrintDialog("007", "ICSProduct", parasList, false, null);
  491. f.ShowDialog();
  492. }
  493. catch (Exception ex)
  494. {
  495. MessageBox.Show(ex.ToString());
  496. }
  497. }
  498. private void txtNowPackQty_EditValueChanged(object sender, EventArgs e)
  499. {
  500. decimal Qty = 0;
  501. decimal Pack = 0;
  502. decimal Num = 0;
  503. decimal Sqty = 0;
  504. decimal.TryParse(txtNowQty.Text, out Qty);
  505. decimal.TryParse(txtNowPackQty.Text, out Pack);
  506. decimal.TryParse(txtNowNum.Text, out Num);
  507. if (Qty != 0 && Pack != 0)
  508. {
  509. decimal qty = Math.Ceiling(Qty / Pack);
  510. txtNowNum.Text = qty.ToString();
  511. }
  512. }
  513. }
  514. }