华恒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.

522 lines
20 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 FormICSLotSplitIn : 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. private decimal ngnumber = 0;
  35. private String FPTYPE = "";
  36. #endregion
  37. #region 构造函数
  38. public FormICSLotSplitIn()
  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 FormICSLotSplitIn(string id,string type)
  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. this.FPTYPE = type;
  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,FXQTY,
  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. if(FPTYPE=="返修分批")
  248. ngnumber= Convert.ToDecimal(dt.Rows[0]["FXQTY"].ToString());
  249. else
  250. ngnumber = Convert.ToDecimal(dt.Rows[0]["NGQTY"].ToString());
  251. txtLOTNORemainQTY.Text = ngnumber.ToString();
  252. txtNowQty.Text = txtLOTNORemainQTY.Text;
  253. txtNowPackQty.Text = txtLOTNORemainQTY.Text;
  254. txtNowNum.Text = "1";
  255. LotNo = dt.Rows[0]["LOTNO"].ToString();
  256. MoCode = dt.Rows[0]["MOCODE"].ToString();
  257. MoSeq = dt.Rows[0]["MOSEQ"].ToString();
  258. sql = @"SELECT DISTINCT '' isSelect,a.ID,a.MOCODE,
  259. --b.MOSEQ,
  260. a.LOTNO,a.ITEMCODE,c.INVNAME AS ITEMNAME,
  261. a.ROUTECODE,d.ROUTEDESC,a.OPCODE,e.OPDESC,a.LOTQTY,a.GOODQTY,
  262. case when a.NGQTY>0 then a.ngqty
  263. when a.fxqty>0 then fxqty end as NGQTY
  264. ,a.MUSERName,a.MTIME
  265. FROM ICSLOTSIMULATION a
  266. LEFT JOIN ICSMO b ON a.MOCODE = b.MOCODE
  267. LEFT JOIN ICSINVENTORY c ON a.ITEMCODE = c.INVCODE
  268. LEFT JOIN ICSROUTE d ON d.ROUTECODE = a.ROUTECODE
  269. LEFT JOIN ICSOP e ON a.OPCODE = e.OPCODE
  270. WHERE a.LOTNO = '{0}'
  271. --OR a.LOTNO IN (SELECT LOTNOSplit FROM ICSLotSplitINCollectionLog)
  272. ORDER BY MTIME DESC"; //WHERE LOTNO = a.LOTNO
  273. sql = string.Format(sql, LotNo);
  274. dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  275. grdDetail.DataSource = dt;
  276. grvDetail.BestFitColumns();
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  282. }
  283. }
  284. private void txtNowQty_EditValueChanged(object sender, EventArgs e)
  285. {
  286. decimal Qty = 0;
  287. decimal Pack = 0;
  288. decimal Num = 0;
  289. decimal Sqty = 0;
  290. decimal.TryParse(txtNowQty.Text, out Qty);
  291. decimal.TryParse(txtNowPackQty.Text, out Pack);
  292. decimal.TryParse(txtNowNum.Text, out Num);
  293. if (Qty != 0 && Pack != 0)
  294. {
  295. Sqty = Math.Ceiling(Qty / Pack);
  296. txtNowNum.Text = Sqty.ToString();
  297. }
  298. }
  299. private void txtNowNum_EditValueChanged(object sender, EventArgs e)
  300. {
  301. decimal Qty = 0;
  302. decimal Pack = 0;
  303. decimal Num = 0;
  304. decimal Sqty = 0;
  305. decimal.TryParse(txtNowQty.Text, out Qty);
  306. decimal.TryParse(txtNowPackQty.Text, out Pack);
  307. decimal.TryParse(txtNowNum.Text, out Num);
  308. if (Qty != 0 && Num != 0)
  309. {
  310. if (Num * Pack >= Pack + Qty || Num * Pack <= Qty)
  311. {
  312. Sqty = Math.Ceiling(Qty / Num);
  313. txtNowPackQty.Text = Sqty.ToString();
  314. }
  315. else
  316. return;
  317. }
  318. }
  319. private void btnLot_Click(object sender, EventArgs e)
  320. {
  321. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
  322. try
  323. {
  324. ICSITEMLOTBLL.SpliteLotNo(LotNo, ngnumber, FPTYPE, AppConfig.AppConnectString);
  325. ICSBaseSimpleCode.AppshowMessageBox("分批成功");
  326. _wait.Close();
  327. }
  328. catch (Exception ex)
  329. {
  330. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  331. _wait.Close();
  332. }
  333. }
  334. private void CreatLot(List<ICSITEMLot> Infolist)
  335. {
  336. bool isnew = false;
  337. List<ICSLOTSIMULATION> simList = new List<ICSLOTSIMULATION>();
  338. List<ICSLotSplitINCollectionLog> loginfolist = new List<ICSLotSplitINCollectionLog>();
  339. ICSLOTSIMULATION lotSimulation = ICSITEMLOTBLL.GetICSLOTSIMULATION(SimID, AppConfig.AppConnectString);
  340. List<ICSMO2User> mo2UserList = new List<ICSMO2User>();
  341. if (lotSimulation == null)
  342. {
  343. isnew = true;
  344. }
  345. foreach (ICSITEMLot info in Infolist)
  346. {
  347. #region 获取原条码ICSLOTSIMULATION数据并扣减数量
  348. #endregion
  349. if (isnew == false)
  350. {
  351. #region ICSLOTSIMULATION
  352. ICSLOTSIMULATION simInfo = new ICSLOTSIMULATION();
  353. simInfo.ID = AppConfig.GetGuid();
  354. simInfo.LOTNO = info.LotNO;
  355. simInfo.SEQ = lotSimulation.SEQ;
  356. simInfo.MOCODE = lotSimulation.MOCODE;
  357. simInfo.LOTSEQ = lotSimulation.LOTSEQ + 1;
  358. simInfo.LOTQTY = info.LOTQTY;
  359. simInfo.GOODQTY = info.LOTQTY;
  360. simInfo.NGQTY = 0;
  361. simInfo.LOTStatus = lotSimulation.LOTStatus;
  362. simInfo.MODELCODE = lotSimulation.MODELCODE;
  363. simInfo.ITEMCODE = lotSimulation.ITEMCODE;
  364. simInfo.FROMROUTE = lotSimulation.FROMROUTE;
  365. simInfo.FROMOP = lotSimulation.FROMOP;
  366. simInfo.ROUTECODE = lotSimulation.ROUTECODE;
  367. simInfo.OPCODE = lotSimulation.OPCODE;
  368. simInfo.RESCODE = lotSimulation.RESCODE;
  369. simInfo.EQPCODE = lotSimulation.EQPCODE;
  370. simInfo.CHECKLOTNO = lotSimulation.CHECKLOTNO;
  371. simInfo.CARTONCODE = lotSimulation.CARTONCODE;
  372. simInfo.PALLETCODE = lotSimulation.PALLETCODE;
  373. simInfo.PRODUCTSTATUS = lotSimulation.PRODUCTSTATUS;
  374. simInfo.LACTION = lotSimulation.LACTION;
  375. simInfo.ACTIONLIST = lotSimulation.ACTIONLIST;
  376. simInfo.NGTIMES = lotSimulation.NGTIMES;
  377. simInfo.ISCOM = lotSimulation.ISCOM;
  378. simInfo.ISHOLD = lotSimulation.ISHOLD;
  379. simInfo.SHELFNO = lotSimulation.SHELFNO;
  380. simInfo.MOSEQ = lotSimulation.MOSEQ;
  381. simInfo.CollectStatus = lotSimulation.CollectStatus;
  382. simInfo.BeginTime = lotSimulation.BeginTime;
  383. simInfo.EndTime = lotSimulation.EndTime;
  384. simInfo.MUSER = AppConfig.UserCode;
  385. simInfo.MUSERName = AppConfig.UserName;
  386. simInfo.MTIME = DateTime.Now;
  387. simInfo.WorkPoint = AppConfig.WorkPointCode;
  388. simList.Add(simInfo);
  389. #endregion
  390. }
  391. #region ICSLotSplitINCollectionLog
  392. ICSLotSplitINCollectionLog loginfo = new ICSLotSplitINCollectionLog();
  393. loginfo.ID = AppConfig.GetGuid();
  394. loginfo.LOTNO = LotNo;
  395. loginfo.LOTNOSplit = info.LotNO;
  396. if (isnew == false)
  397. {
  398. loginfo.OPCode = lotSimulation.OPCODE;
  399. }
  400. else
  401. {
  402. loginfo.OPCode = "";
  403. }
  404. loginfo.MUSER = AppConfig.UserCode;
  405. loginfo.MUSERNAME = AppConfig.UserName;
  406. loginfo.MTIME = DateTime.Now;
  407. loginfo.WorkPoint = AppConfig.WorkPointCode;
  408. loginfolist.Add(loginfo);
  409. #endregion
  410. string sql = @"SELECT ROUTECODE,OPCODE,OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}'
  411. AND OPSEQ > (SELECT OPSEQ FROM ICSROUTE2OP WHERE ROUTECODE = '{0}' AND OPCODE = '{1}')
  412. ORDER BY OPSEQ";
  413. sql = string.Format(sql, lotSimulation.ROUTECODE, lotSimulation.OPCODE);
  414. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  415. foreach (DataRow row in dt.Rows)
  416. {
  417. ICSMO2User user = new ICSMO2User();
  418. user.ID = AppConfig.GetGuid().ToString();
  419. user.MOCODE = lotSimulation.MOCODE;
  420. user.MOSEQ = lotSimulation.MOSEQ;
  421. user.LOTNO = info.LotNO;
  422. user.SEGCODE = "";
  423. user.RouteCode = lotSimulation.ROUTECODE;
  424. user.OPCODE = row["OPCODE"].ToString();
  425. user.USERCODE = "";
  426. user.USERName = "";
  427. user.EQPCode = "";
  428. user.EQPName = "";
  429. user.StartPlanDate = DateTime.Now;
  430. user.EndPlanDate = DateTime.Now;
  431. user.MUSER = AppConfig.UserCode;
  432. user.MUSERName = AppConfig.UserName;
  433. user.MTIME = DateTime.Now;
  434. user.WorkPoint = AppConfig.WorkPointCode;
  435. mo2UserList.Add(user);
  436. }
  437. }
  438. try
  439. {
  440. ICSITEMLOTBLL.SplitAdd(SimID, LotNo, Infolist, simList, loginfolist,mo2UserList, isnew, AppConfig.AppConnectString);
  441. ICSBaseSimpleCode.AppshowMessageBox("分批成功");
  442. btnFalsh_Click(null, null);
  443. }
  444. catch (Exception ex)
  445. {
  446. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  447. }
  448. }
  449. private void btnPrint_Click(object sender, EventArgs e)
  450. {
  451. try
  452. {
  453. List<PrintPara> parasList = new List<PrintPara>();
  454. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  455. for (int i = 0; i < grvDetail.RowCount; i++)
  456. {
  457. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  458. {
  459. PrintPara para = new PrintPara();
  460. para.PrintKey = "LOTNO";
  461. para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLOTNO).ToString() };
  462. parasList.Add(para);
  463. }
  464. }
  465. if (parasList.Count == 0)
  466. {
  467. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  468. return;
  469. }
  470. //FormPrintDialog f = new FormPrintDialog("001", this.Text, parasList, false, null);
  471. FormPrintDialog f = new FormPrintDialog("007", "ICSProduct", parasList, false, null);
  472. f.ShowDialog();
  473. }
  474. catch (Exception ex)
  475. {
  476. MessageBox.Show(ex.ToString());
  477. }
  478. }
  479. }
  480. }