using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Linq; using System.Linq; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid; using System.IO; using System.Threading; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.UserControl.MessageControl; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.Report.GridReport; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.APP { public partial class FormICSONWIPCheckAll : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; private DataTable dataSource = null; public string id = ""; private OPType type; #region 构造函数 public FormICSONWIPCheckAll(OPType Type) { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; type = Type; } #endregion #region 操作权限 public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有) DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow); List ControlList = new List(); ControlList.Add(btnCreate); ControlList.Add(btnModify); ControlList.Add(btnOutPut); foreach (Control ctr in ControlList) { if (ctr.GetType() == typeof(SimpleButton)) { DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } } rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限 { DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption"); rData.AcceptChanges(); return rData; } #endregion #region 退出 private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } #endregion #region 移动窗体 private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时, //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION , //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。 //重写窗体,使窗体可以不通过自带标题栏实现移动 protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息, //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体, //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。 //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。 switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion #region 列表 private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion #region 全选 private void btnSelectAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, true); } } #endregion #region 全消 private void btnCancelAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, false); } } #endregion #region 导出 private void btnOutPut_Click(object sender, EventArgs e) { FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail); foe.ShowDialog(); } #endregion #region 刷新 private void btnRefresh_Click(object sender, EventArgs e) { SearchData(" AND chk.EndDateTime IS NULL "); } #endregion private void check(int index) { if (type == OPType.Self) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(index, colisCtrlType)) && string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(index, colOKQuantity).ToString())) { throw new Exception(string.Format("第{0}行上道工序未检验,不能执行此操作!", index + 1)); } if (!Convert.ToBoolean(grvDetail.GetRowCellValue(index, colCanCheck))) { throw new Exception(string.Format("第{0}行过程检验未完成,不能执行此操作!", index + 1)); } } else if (type == OPType.Check && string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(index, colID).ToString())) { throw new Exception("第" + (index + 1) + "行未生成巡检单,不能执行此操作!"); } } #region 新增 private void btnCreate_Click(object sender, EventArgs e) { try { saveData("放行"); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 修改 private void btnModify_Click(object sender, EventArgs e) { try { saveData("判退"); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 置顶 private void btnTop_Click(object sender, EventArgs e) { try { int count = 0; string sql = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { if (type == OPType.Check && string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colID).ToString())) { throw new Exception("第" + (i + 1) + "行未生成巡检单,不能执行此操作!"); } count++; // sql = @" INSERT INTO ICSLOTONWIPCheckTop(ID, FORTRANID, Type, TopDateTime, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1) // VALUES (NEWID(),'{0}','{1}',SysDateTime(),'{2}','{3}',GETDATE(),'{4}','1') // "; sql = @" IF NOT EXISTS(SELECT 1 FROM ICSLOTONWIPCheckTop WHERE FORTRANID='{0}') BEGIN INSERT INTO ICSLOTONWIPCheckTop (ID, FORTRANID, Type, TopDateTime, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1) VALUES (NEWID(),'{0}','{1}',SysDateTime(),'{2}','{3}',GETDATE(),'{4}','1') END ELSE BEGIN UPDATE ICSLOTONWIPCheckTop SET TopDateTime=SysDateTime(),EATTRIBUTE1=1 WHERE FORTRANID='{0}' END "; sql = string.Format(sql, grvDetail.GetRowCellValue(i, colID).ToString(), FormICSONWIPCheck.GetEnumDescription(type), AppConfig.UserCode, AppConfig.UserName, AppConfig.WorkPointCode); } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 显示全部 private void btnALL_Click(object sender, EventArgs e) { try { SearchData(""); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion private void FormICSONWIPCheckAll_Load(object sender, EventArgs e) { try { btnCreate.Visible = true; btnModify.Visible = true; btnCheck.Visible = false; colQuantity.OptionsColumn.ReadOnly = true; if (type == OPType.Inspect) { colCode.Caption = "送检单号"; colQuantity.Caption = "送检数量"; colMUSERName.Caption = "送检人"; colMTIME.Caption = "送检时间"; } else if (type == OPType.Check) { colCode.Caption = "产品跟踪单"; colQuantity.Caption = "巡检数量"; btnCheck.Visible = true; colQuantity.OptionsColumn.ReadOnly = false; colMUSERName.Caption = "送检人"; colMTIME.Caption = "送检时间"; } else { btnCreate.Visible = false; btnModify.Visible = false; colCode.Caption = "产品跟踪单"; colQuantity.Caption = "跟踪单数量"; colMUSERName.Caption = "完工人"; colMTIME.Caption = "完工时间"; //if (type == OPType.Self) //{ // btnCreate.Visible = false; // btnModify.Visible = false; //} } SearchData(" AND chk.EndDateTime IS NULL "); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message); } } #region 查询数据 private void SearchData(string where) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); string sql = ""; if (type == OPType.Inspect) { #region 检验 sql = @"SELECT CAST( 0 AS BIT ) AS isSelect,e.ID,e.TransNO AS Code,e.MTIME,a.ITEMCODE,b.INVNAME,b.INVSTD,e.CheckMode,lot.OPSEQ,a.OPCODE,d.OPDESC,e.Quantity,e.MUSERName, u.UserName AS chkMUSERName,chk.BeginDateTime,chk.EndDateTime,a.LOTNO, chk.Status AS Result,CAST(CASE WHEN t.FORTRANID IS NULL THEN '0' ELSE '1' END AS BIT) AS [Top], CASE WHEN ISNULL( chk.Status , '' ) = '' THEN '未检' ELSE '已检' END AS [Status] FROM ICSLOTONWIP a INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint INNER JOIN ICSLOTONWIPDetail det ON det.LOTNO=a.LOTNO AND det.OPCode=a.OPCODE AND a.WorkPoint=det.WorkPoint INNER JOIN ICSLOTONWIPInspection e ON det.ID=e.DetailID AND det.WorkPoint=e.WorkPoint LEFT JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1' LEFT JOIN Sys_User u ON u.UserCode=chk.EATTRIBUTE1 AND u.WorkPointCode=chk.WorkPoint LEFT JOIN ICSLOTONWIPCheckTop t ON e.ID=t.FORTRANID AND e.WorkPoint=t.WorkPoint AND t.EATTRIBUTE1='1' WHERE a.WorkPoint='{0}' {1} ORDER BY e.CheckMode,t.TopDateTime DESC,e.TransNO"; #endregion } else if (type == OPType.Check) { #region 巡检 sql = @"SELECT CAST( 0 AS BIT ) AS isSelect,e.ID,a.LOTNO AS Code,e.MTIME,a.ITEMCODE,b.INVNAME,b.INVSTD,'巡检' AS CheckMode,lot.OPSEQ,a.OPCODE,d.OPDESC,ISNULL(e.Quantity, det.OKQty) AS Quantity,e.MUSERName, u.UserName AS chkMUSERName,chk.BeginDateTime,chk.EndDateTime,a.LOTNO, chk.Status AS Result,CAST(CASE WHEN t.FORTRANID IS NULL THEN '0' ELSE '1' END AS BIT) AS [Top], CASE WHEN ISNULL( chk.Status , '' ) = '' THEN '未检' ELSE '已检' END AS [Status],det.ID AS DetailID FROM ICSLOTONWIP a INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint INNER JOIN ICSLOTONWIPDetail det ON det.LOTNO=a.LOTNO AND det.OPCode=a.OPCODE AND a.WorkPoint=det.WorkPoint LEFT JOIN ICSLOTONWIPInspection e ON det.ID=e.DetailID AND det.WorkPoint=e.WorkPoint LEFT JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1' LEFT JOIN Sys_User u ON u.UserCode=chk.EATTRIBUTE1 AND u.WorkPointCode=chk.WorkPoint LEFT JOIN ICSLOTONWIPCheckTop t ON e.ID=t.FORTRANID AND e.WorkPoint=t.WorkPoint AND t.EATTRIBUTE1='1' WHERE CollectStatus='COLLECT_BEGIN' AND a.WorkPoint='{0}' {1} ORDER BY e.CheckMode,t.TopDateTime DESC,e.TransNO"; #endregion } else if (type == OPType.Self) { #region 完工检验 sql = @"SELECT CAST( 0 AS BIT ) AS isSelect,a.ID,a.LOTNO AS Code,a.MTIME,a.ITEMCODE,b.INVNAME,b.INVSTD,'工序检验' AS CheckMode,lot.OPSEQ,a.OPCODE,d.OPDESC,a.LOTQTY AS Quantity,u.UserName AS MUSERName, u2.UserName AS chkMUSERName,chk.BeginDateTime,chk.EndDateTime,a.LOTNO, chk.Status AS Result,CAST(CASE WHEN t.FORTRANID IS NULL THEN '0' ELSE '1' END AS BIT) AS [Top], CASE WHEN ISNULL( chk.Status , '' ) = '' THEN '未检' ELSE '已检' END AS [Status], CAST(CASE WHEN lot.CtrlType='并行' AND lotlast.CtrlType='并行' THEN '1' ELSE '0' END AS BIT) AS isCtrlType, CASE WHEN lot.CtrlType='并行' AND lotlast.CtrlType='并行' THEN chklast.OKQuantity ELSE a.LOTQTY END AS OKQuantity, CAST(CASE WHEN chk.Status='不良' AND ncr.FORTRANID IS NULL THEN 0 ELSE 1 END AS BIT) AS CanCheck FROM ICSLOTONWIP a INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint INNER JOIN ICSMO2User us ON a.LOTNO=us.LOTNO AND a.OPCODE=us.OPCODE AND a.WorkPoint=us.WorkPoint INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint LEFT JOIN ICSITEMROUTE2OPLot lotlast ON lot.LOTNO=lotlast.LOTNO AND lot.WorkPoint=lotlast.WorkPoint AND lotlast.OPSEQ=(SELECT MAX(OPSEQ) FROM ICSITEMROUTE2OPLot WHERE LotNo=lot.LotNo AND WorkPoint=lot.WorkPoint AND OPSEQ list = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)) && !grvDetail.GetRowCellValue(i, colStatus).Equals("已检")) { check(i); ICSLOTONWIPCheck Info = new ICSLOTONWIPCheck(); Info.ID = AppConfig.GetGuid(); Info.FORTRANID = grvDetail.GetRowCellValue(i, colID).ToString(); Info.Quantity = Convert.ToDecimal(grvDetail.GetRowCellValue(i, colQuantity)); if (status == "放行") { Info.OKQuantity = Info.Quantity; Info.NGQuantity = 0; } else { Info.OKQuantity = 0; Info.NGQuantity = Info.Quantity; } Info.Status = status; Info.BeginDateTime = dt; Info.EndDateTime = dt; Info.Enable = true; Info.FileName = ""; Info.Type = FormICSONWIPCheck.GetEnumDescription(type); Info.MUSER = AppConfig.UserCode; Info.MUSERName = AppConfig.UserName; Info.MTIME = dt; Info.WorkPoint = AppConfig.WorkPointCode; if (type == OPType.Self || type == OPType.Outsourcing) { Info.isBatch = true; } else { Info.isBatch = false; } Info.EATTRIBUTE1 = null; list.Add(Info); } } if (list.Count == 0) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; } ICSLOTONWIPCheckBLL.Add(list, AppConfig.AppConnectString); _wait.Close(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message); _wait.Close(); } } #endregion private void grvDetail_DoubleClick(object sender, EventArgs e) { try { check(grvDetail.FocusedRowHandle); id = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(); this.Close(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message); } } private void grvDetail_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { try { int hand = e.RowHandle; if (hand < 0) return; if (Convert.ToBoolean(grvDetail.GetRowCellValue(hand, colTop))) { e.Appearance.BackColor = Color.Yellow;// 改变行背景颜色 } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message); } } /// /// 送检 /// /// /// private void btnCheck_Click(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存...请稍等..."); try { _wait.Show(); List infos = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { if (!string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colID).ToString())) { throw new Exception("第" + (i + 1) + "行已生成巡检单,不能重复生成!"); } if (string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colQuantity).ToString())) { throw new Exception("第" + (i + 1) + "行数量不能为空!"); } ICSLOTONWIPInspection info = new ICSLOTONWIPInspection(); info.ID = AppConfig.GetGuid(); info.DetailID = grvDetail.GetRowCellValue(i, colDetailID).ToString(); info.CheckMode = grvDetail.GetRowCellValue(i, colCheckMode).ToString(); info.UserCode = AppConfig.UserCode; info.Quantity = grvDetail.GetRowCellValue(i, colQuantity).ToString(); info.WorkPoint = AppConfig.WorkPointCode; info.MTIME = DateTime.Now; info.MUSER = AppConfig.UserCode; info.MUSERName = AppConfig.UserName; info.IsCalc = true; info.EATTRIBUTE1 = "巡检"; infos.Add(info); } } if (infos.Count == 0) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; } ICSLOTONWIPInspectionBLL.AddList(infos, AppConfig.AppConnectString); _wait.Close(); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message); _wait.Close(); } } } }