Esempio n. 1
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (FirstNameTextBox.Text == "" || LastNameTextBox.Text == "" || AgeTextBox.Text == "" || EmailTextBox.Text == "")
                {
                    MessageBox.Show("Пожалуйста, заполните поля имени, фамилии, возраста и почты.");
                    return;
                }
                Worker worker = new Worker();
                worker.FirstName  = FirstNameTextBox.Text;
                worker.LastName   = LastNameTextBox.Text;
                worker.Phone      = PhoneTextBox.Text;
                worker.Email      = EmailTextBox.Text;
                worker.DivisionId = database.Division.ToList().FirstOrDefault(d => d.Title == DivisionComboBox.SelectedItem as string).Id;
                worker.Age        = Convert.ToInt32(AgeTextBox.Text);
                worker.Photo      = FullFileName;
                if (ContentTextBlock.Text.ToString() == "Сохранить")
                {
                    Worker oldWorker = database.Worker.First(w => w.Id == CurrentWorker.Id);
                    database.Worker.Remove(oldWorker);
                }
                database.Worker.Add(worker);
                database.SaveChanges();

                MessageBox.Show("Успешное сохранение данных");
                ViewEmployees window = new ViewEmployees();
                window.Show();
                this.Close();
            }
            catch
            {
                MessageBox.Show("Ошибка сохранения данных");
            }
        }
Esempio n. 2
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            if (MainDatagrid.SelectedItem == null)
            {
                MessageBox.Show("Необходимо выбрать нужного пользователя");
                return;
            }

            MessageBoxResult response = MessageBox.Show("Вы точно хотите удалить данного пользователя?", "Удаление", MessageBoxButton.YesNo);

            if (response == MessageBoxResult.Yes)
            {
                try
                {
                    database.Worker.Remove(MainDatagrid.SelectedItem as Worker);
                    database.SaveChanges();

                    ViewEmployees window = new ViewEmployees();
                    window.Show();
                    this.Close();

                    MessageBox.Show("Удаление прошло успешно");
                }
                catch
                {
                    MessageBox.Show("Произошла ошибка");
                }
            }
        }
Esempio n. 3
0
        private void GoBackButton_Click(object sender, RoutedEventArgs e)
        {
            ViewEmployees nextWindow = new ViewEmployees();

            nextWindow.Show();
            this.Close();
        }
Esempio n. 4
0
        private void InputButton_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(Login.Text) || String.IsNullOrEmpty(Password.Password))
            {
                MessageBox.Show("Заполните все поля");
                return;
            }
            ARMEntities  database = new ARMEntities();
            List <Admin> admins   = database.Admin.ToList();

            foreach (var admin in admins)
            {
                if (admin.Login == Login.Text && admin.Password == Password.Password)
                {
                    MessageBox.Show("Успешная авторизация!");
                    Windows.ViewEmployees window = new Windows.ViewEmployees();
                    window.Show();
                    this.Close();
                    return;
                }
            }
            MessageBox.Show("Пользователь не найден");
        }