コード例 #1
0
        private bool CheckExists(Q_BusinessType model)
        {
            Q_BusinessType obj = null;

            if (!string.IsNullOrEmpty(model.Name))
            {
                obj = db.Q_BusinessType.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.Name.Trim().ToUpper().Equals(model.Name.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
コード例 #2
0
 public int Insert(Q_BusinessType obj)
 {
     using (db = new QMSSystemEntities())
     {
         if (!CheckExists(obj))
         {
             db.Q_BusinessType.Add(obj);
             db.SaveChanges();
         }
         return(obj.Id);
     }
 }
コード例 #3
0
        private void gridViewBusinessType_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                int Id = 0;
                int.TryParse(gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Id").ToString(), out Id);
                if (Id == 0 && string.IsNullOrEmpty(gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Name").ToString()))
                {
                    goto End;
                }
                if (string.IsNullOrEmpty(gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Name").ToString()))
                {
                    MessageBox.Show("Vui lòng nhập tên loại doanh nghiệp.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var obj = new Q_BusinessType();
                    obj.Id   = Id;
                    obj.Name = gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Name").ToString();
                    obj.Note = gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Note") != null?gridViewBusinessType.GetRowCellValue(gridViewBusinessType.FocusedRowHandle, "Note").ToString() : "";

                    if (obj.Id == 0)
                    {
                        int result = BLLBusinessType.Instance.Insert(connect, obj);
                        if (result == 0)
                        {
                            MessageBox.Show("Tên loại doanh nghiệp đã 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 = BLLBusinessType.Instance.Update(connect, obj);
                        if (result == false)
                        {
                            MessageBox.Show("Tên loại doanh nghiệp đã tồn tại. Xin nhập tên khác", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    GetGridBusinessType();
                }
            }
            catch (Exception ex)
            {
            }
End:
            {
            }
        }
コード例 #4
0
 public bool Update(Q_BusinessType model)
 {
     using (db = new QMSSystemEntities())
     {
         var obj = db.Q_BusinessType.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExists(model))
             {
                 obj.Name = model.Name;
                 obj.Note = model.Note;
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         return(false);
     }
 }