コード例 #1
0
ファイル: BLLProcess.cs プロジェクト: dovanduy/QMS_System
        private bool CheckExists(Q_Process model)
        {
            Q_Process obj = null;

            if (!string.IsNullOrEmpty(model.Name))
            {
                obj = db.Q_Process.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.Name.Trim().ToUpper().Equals(model.Name.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
コード例 #2
0
ファイル: BLLProcess.cs プロジェクト: dovanduy/QMS_System
 public int Insert(Q_Process obj)
 {
     using (db = new QMSSystemEntities())
     {
         if (!CheckExists(obj))
         {
             db.Q_Process.Add(obj);
             db.SaveChanges();
         }
         return(obj.Id);
     }
 }
コード例 #3
0
ファイル: frmProcess.cs プロジェクト: dovanduy/QMS_System
        private void gridViewProcess_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                int Id = 0;
                int.TryParse(gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Id").ToString(), out Id);
                if (Id == 0 && string.IsNullOrEmpty(gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Name").ToString()))
                {
                    goto End;
                }
                if (Id != 0 && string.IsNullOrEmpty(gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Name").ToString()))
                {
                    MessageBox.Show("Vui lòng nhập tên tiến trình.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var obj = new Q_Process();
                    obj.Id    = Id;
                    obj.Name  = gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Name").ToString();
                    obj.Index = int.Parse(gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Index").ToString());
                    obj.Note  = gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Note") != null?gridViewProcess.GetRowCellValue(gridViewProcess.FocusedRowHandle, "Note").ToString() : "";

                    if (obj.Id == 0)
                    {
                        int result = BLLProcess.Instance.Insert(obj);
                        if (result == 0)
                        {
                            MessageBox.Show("Tên tiến trình đã tồn tại. Xin nhập tên khác.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    else
                    {
                        bool result = BLLProcess.Instance.Update(obj);
                        if (result == false)
                        {
                            MessageBox.Show("Tên tiến trình đã tồn tại. Xin nhập tên khác.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    GetGridProcess();
                }
            }
            catch (Exception ex)
            {
            }
End:
            {
            }
        }
コード例 #4
0
ファイル: BLLProcess.cs プロジェクト: dovanduy/QMS_System
 public bool Update(Q_Process model)
 {
     using (db = new QMSSystemEntities())
     {
         var obj = db.Q_Process.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExists(model))
             {
                 obj.Name  = model.Name;
                 obj.Index = model.Index;
                 obj.Note  = model.Note;
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         return(false);
     }
 }