private void gridViewServiceShift_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                int Id = 0;
                int.TryParse(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "Id").ToString(), out Id);
                if (Id == 0 && string.IsNullOrEmpty(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "Index").ToString()))
                {
                    goto End;
                }
                else if (Id == 0 && string.IsNullOrEmpty(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "ShiftId").ToString()))
                {
                    goto End;
                }

                if (Id != 0 && string.IsNullOrEmpty(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "Index").ToString()))
                {
                    MessageBox.Show("Vui lòng nhập số thứ tự", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (Id != 0 && string.IsNullOrEmpty(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "ShiftId").ToString()))
                {
                    MessageBox.Show("Vui lòng chọn thời gian cấp phiếu dịch vụ.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var obj = new Q_ServiceShift();
                    obj.Id        = Id;
                    obj.ShiftId   = int.Parse(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "ShiftId").ToString());
                    obj.ServiceId = serId;
                    obj.Index     = int.Parse(gridViewServiceShift.GetRowCellValue(gridViewServiceShift.FocusedRowHandle, "Index").ToString());

                    if (obj.Id == 0)
                    {
                        int result = BLLServiceShift.Instance.Insert(connect, obj);
                        if (result == 0)
                        {
                            MessageBox.Show("Dịch vụ đã tồn tại thời gian cấp phiếu này. Xin chọn lại", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    else
                    {
                        bool result = BLLServiceShift.Instance.Update(connect, obj);
                        if (result == false)
                        {
                            MessageBox.Show("Dịch vụ đã tồn tại thời gian cấp phiếu này. Xin chọn lại", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto End;
                        }
                    }
                    GetGridServiceShift();
                }
            }
            catch (Exception ex) { }
            End : { }
        }
Beispiel #2
0
 public int Insert(Q_ServiceShift obj)
 {
     using (db = new QMSSystemEntities()){
         if (!CheckExists(obj))
         {
             db.Q_ServiceShift.Add(obj);
             db.SaveChanges();
         }
         return(obj.Id);
     }
 }
Beispiel #3
0
 public bool Update(Q_ServiceShift model)
 {
     using (db = new QMSSystemEntities()){
         var obj = db.Q_ServiceShift.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExists(model))
             {
                 obj.ServiceId = model.ServiceId;
                 obj.ShiftId   = model.ShiftId;
                 obj.Index     = model.Index;
                 db.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
 }
Beispiel #4
0
        private bool CheckExists(Q_ServiceShift model)
        {
            var obj = db.Q_ServiceShift.FirstOrDefault(x => !x.IsDeleted && x.Id != model.Id && x.ServiceId == model.ServiceId && x.ShiftId == model.ShiftId);

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