コード例 #1
0
ファイル: BLLAlert.cs プロジェクト: war-man/QMS_System
        //public List<ModelSelectItem> GetLookUp(string connectString)
        //{
        //      using (db = new QMSSystemEntities(connectString)){
        //    return db.Q_Alert.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList();
        //}

        public int Insert(string connectString, Q_Alert obj)
        {
            using (db = new QMSSystemEntities(connectString)){
                if (!CheckExist(obj))
                {
                    db.Q_Alert.Add(obj);
                    db.SaveChanges();
                }
                return(obj.Id);
            }
        }
コード例 #2
0
ファイル: BLLAlert.cs プロジェクト: war-man/QMS_System
 public bool Update(string connectString, Q_Alert model)
 {
     using (db = new QMSSystemEntities(connectString)){
         var obj = db.Q_Alert.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExist(model))
             {
                 obj.SoundId = model.SoundId;
                 obj.Note    = model.Note;
                 obj.Start   = model.Start;
                 obj.End     = model.End;
                 db.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
 }
コード例 #3
0
        private void gridViewAlert_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                int Id = 0;
                int.TryParse(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Id").ToString(), out Id);

                if (Id == 0 && (string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "SoundId").ToString()) || gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "SoundId").ToString() == "0"))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Start").ToString()))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "End").ToString()))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Note").ToString()))
                {
                    goto End;
                }

                if (Id != 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "SoundId").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn âm thanh.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Start").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn thời gian bắt đầu.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "End").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn thời gian kết thúc.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Note").ToString()))
                {
                    MessageBox.Show("Vui lòng nhập diễn giải.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var obj = new Q_Alert();
                    obj.Id      = Id;
                    obj.SoundId = int.Parse(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "SoundId").ToString());
                    obj.Start   = DateTime.Parse(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Start").ToString());
                    obj.End     = DateTime.Parse(gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "End").ToString());
                    obj.Note    = gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Note") != null?gridViewAlert.GetRowCellValue(gridViewAlert.FocusedRowHandle, "Note").ToString() : "";

                    if (obj.Id == 0)
                    {
                        int result = BLLAlert.Instance.Insert(obj);
                        if (result == 0)
                        {
                            MessageBox.Show("Câu hướng dẫn này đã tồn tại. Xin kiểm tra lại.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    else
                    {
                        bool result = BLLAlert.Instance.Update(obj);
                        if (result == false)
                        {
                            MessageBox.Show("Câu hướng dẫn này đã tồn tại. Xin kiểm tra lại.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    GetGridAlert();
                }
            }
            catch (Exception ex)
            {
            }
End:
            {
            }
        }
コード例 #4
0
ファイル: BLLAlert.cs プロジェクト: war-man/QMS_System
        private bool CheckExist(Q_Alert model)
        {
            var obj = db.Q_Alert.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.SoundId == model.SoundId);

            return(obj != null ? true : false);
        }