Exemplo n.º 1
0
 public int Insert(string connectString, Q_Shift obj)
 {
     using (db = new QMSSystemEntities(connectString)){
         if (!CheckExists(obj))
         {
             db.Q_Shift.Add(obj);
             db.SaveChanges();
         }
         return(obj.Id);
     }
 }
Exemplo n.º 2
0
 public bool Update(string connectString, Q_Shift model)
 {
     using (db = new QMSSystemEntities(connectString)){
         var obj = db.Q_Shift.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExists(model))
             {
                 obj.Name  = model.Name;
                 obj.Start = model.Start;
                 obj.End   = model.End;
                 obj.Note  = model.Note;
                 db.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 3
0
        private bool CheckExists(Q_Shift model)
        {
            var obj = db.Q_Shift.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.Name.Trim().ToUpper().Equals(model.Name.Trim().ToUpper()));

            return(obj != null ? true : false);
        }
Exemplo n.º 4
0
        private void gridViewShift_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                int Id = 0;
                int.TryParse(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Id").ToString(), out Id);

                if (Id == 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Name").ToString()))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Start").ToString()))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "End").ToString()))
                {
                    goto End;
                }

                if (Id != 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Name").ToString()))
                {
                    MessageBox.Show("Vui lòng nhập tên ca làm việc.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Start").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn thời gian bắt đầu ca làm việc.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "End").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn thời gian kết thúc ca làm việc.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                else
                {
                    var obj = new Q_Shift();
                    obj.Id    = Id;
                    obj.Name  = gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Name").ToString();
                    obj.Start = DateTime.Parse(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Start").ToString());
                    obj.End   = DateTime.Parse(gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "End").ToString());
                    obj.Note  = gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Note") != null?gridViewShift.GetRowCellValue(gridViewShift.FocusedRowHandle, "Note").ToString() : "";

                    if (obj.Id == 0)
                    {
                        int result = BLLShift.Instance.Insert(obj);
                        if (result == 0)
                        {
                            MessageBox.Show("Tên ca làm việc này đã tồn tại. Xin chọn lại", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    else
                    {
                        bool result = BLLShift.Instance.Update(obj);
                        if (result == false)
                        {
                            MessageBox.Show("Tên ca làm việc này đã tồn tại. Xin chọn lại", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    GetGridShift();
                }
            }
            catch (Exception ex)
            {
            }
End:
            {
            }
        }