Ejemplo n.º 1
0
        private void EditStaff(object sender, DataGridRowEditEndingEventArgs e)
        {
            CinemaContext db         = new();
            staff         staff      = e.Row.Item as staff;
            bool          AllCorrect = true;

            if (!Regex.IsMatch(staff.Surname, @"^[a-zA-Z]+$") && !Regex.IsMatch(staff.Surname, @"^[а-яА-Я]+$"))
            {
                AllCorrect = false;
            }
            if (!Regex.IsMatch(staff.NameStaffer, @"^[a-zA-Z]+$") && !Regex.IsMatch(staff.NameStaffer, @"^[а-яА-Я]+$"))
            {
                AllCorrect = false;
            }
            if (!Regex.IsMatch(staff.NumberTelephon, @"^\+\d\(\d\d\d\)\d\d\d\-\d\d\-\d\d$"))
            {
                AllCorrect = false;
            }
            if (!Regex.IsMatch(staff.Email, @"^[^\.\ ]\S+\@[a-zA-Z0-9]\S+\.\S+$"))
            {
                AllCorrect = false;
            }
            if (!Regex.IsMatch(staff.IdPost.ToString(), @"^\d+$"))
            {
                AllCorrect = false;
            }
            else if (staff.IdPost > maxIdPost)
            {
                AllCorrect = false;
            }
            int         c           = db.staff.Count(u => u.IdPost == staff.IdPost);
            StateCinema stateCinema = db.StateCinemas.Find(staff.IdPost);

            if ((stateCinema.CountStaffers - c) == 0)
            {
                AllCorrect = false;
            }
            if (AllCorrect)
            {
                if (staff.IdStaffer == 0)
                {
                    db.staff.Add(staff);
                }
                else
                {
                    staff updateStaff = db.staff.Find(staff.IdStaffer);
                    updateStaff = new (){ Surname = staff.Surname, NameStaffer = staff.NameStaffer, NumberTelephon = staff.NumberTelephon,
                                          Email   = staff.Email, IdPost = staff.IdPost };
                }
                db.SaveChanges();
                MessageBox.Show("Данные успешно обновлены!");
            }
            else
            {
                MessageBox.Show("Ошибка добавления данных! Некорректные значения.");
            }
        }
Ejemplo n.º 2
0
        private void EditState(object sender, DataGridRowEditEndingEventArgs e)
        {
            CinemaContext db    = new();
            StateCinema   state = e.Row.Item as StateCinema;

            if (Regex.IsMatch(state.CountStaffers.ToString(), @"^\d+$"))
            {
                StateCinema updateState = db.StateCinemas.Find(state.IdPost);
                updateState.CountStaffers = state.CountStaffers;
                db.SaveChanges();
                MessageBox.Show("Данные успешно обновлены!");
            }
            else
            {
                MessageBox.Show("Ошибка добавления данных! Некорректные значения.");
            }
        }