private void Button_Click(object sender, RoutedEventArgs e)
        {
            AdminPage main       = this.Owner as AdminPage;
            string    name       = empl_Name.Text;
            string    surname    = empl_Surname.Text;
            string    patronymic = empl_Patronymic.Text;

            if (name != "" && surname != "")
            {
                using (ADOmodel db = new ADOmodel(conString))
                {
                    bool EmployeeExists = false;
                    if (patronymic != "")
                    {
                        EmployeeExists = db.Employees.Any(p => p.Surname.Contains(surname) && p.Name.Contains(name) && p.Patronymic.Contains(patronymic));
                    }
                    else
                    {
                        EmployeeExists = db.Employees.Any(p => p.Surname.Contains(surname) && p.Name.Contains(name));
                    }

                    if (EmployeeExists)
                    {
                        main.EmployeeTable.ItemsSource = (from em in db.Employees
                                                          join p in db.Position_list on em.id_Position equals p.id_Position
                                                          join r in db.Role_list on em.id_Role equals r.id_Role
                                                          where em.Surname == surname && em.Name == name
                                                          select new
                        {
                            id = em.id_Employee,
                            Surname = em.Surname,
                            Name = em.Name,
                            Patronymic = em.Patronymic,
                            Position = p.Position_name,
                            Role = r.Role_name,
                            Login = em.Login,
                            Password = em.Password
                        }).ToList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Сотрудник не найден!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            else
            {
                MessageBox.Show("Заполните обязательные поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string login    = log.Text; // Считываем логин и пароль
            string password = pass.Password;

            if (login != "" && password != "")           // Проверка на непустоту полей
            {
                int userID = CheckUser(login, password); // Проверка на существование пользователя с таким логином и паролем и возврат его id
                if (userID > 0)                          // Если существует
                {
                    AdminPage adm = new AdminPage(conString, userID, returnRole(userID));
                    adm.Show();
                    this.Close();
                }
                else
                {
                    err.Content = "Неверный логин и/или пароль!";
                }
            }
            else
            {
                err.Content = "Введите логин и пароль!";
            }
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            AdminPage main       = this.Owner as AdminPage;
            string    phone      = Person_phone.Text;
            string    name       = Person_name.Text;
            string    surname    = Person_surname.Text;
            string    patronymic = Person_partonymic.Text;

            using (ADOmodel db = new ADOmodel(conString))
            {
                if (name == "" && surname == "" && patronymic == "" && phone == "")
                {
                    MessageBox.Show("Введите либо данные ФИО либо номер телефона!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else if (name != "" || surname != "" || patronymic != "")
                {
                    var ClientExists = db.Clients.Any(p => p.Surname.Contains(surname) && p.Name.Contains(name) && p.Patronymic.Contains(patronymic));

                    if (ClientExists)
                    {
                        main.ClientsTable.ItemsSource = (from c in db.Clients
                                                         join ca in db.Client_address on c.id_Address equals ca.id_Address
                                                         join lc in db.Loyality_card on c.id_Loyality_card equals lc.id_Loyality_card into grouping
                                                         from gr in grouping.DefaultIfEmpty()
                                                         where (c.Name.Contains(name)) && (c.Surname.Contains(surname)) && (c.Patronymic.Contains(patronymic))
                                                         select new
                        {
                            id = c.id_Client,
                            Surname = c.Surname,
                            Name = c.Name,
                            Patronymic = c.Patronymic,
                            Phone = c.Phone,
                            Country = ca.Country,
                            City = ca.City,
                            Street = ca.Street,
                            Building = ca.Building,
                            Flat = ca.Flat,
                            LoyalityDiscount = gr == null ? 0 : gr.Loyality_discount,
                            AmountPurshase = gr == null ? 0 : gr.Amount_purshases
                        }).ToList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Клиент не найден!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else if (phone != "")
                {
                    var ClientExists = db.Clients.Any(p => p.Phone == phone);
                    if (ClientExists)
                    {
                        main.ClientsTable.ItemsSource = (from c in db.Clients
                                                         join ca in db.Client_address on c.id_Address equals ca.id_Address
                                                         join lc in db.Loyality_card on c.id_Loyality_card equals lc.id_Loyality_card into grouping
                                                         from gr in grouping.DefaultIfEmpty()
                                                         where (c.Phone == phone)
                                                         select new
                        {
                            id = c.id_Client,
                            Surname = c.Surname,
                            Name = c.Name,
                            Patronymic = c.Patronymic,
                            Phone = c.Phone,
                            Country = ca.Country,
                            City = ca.City,
                            Street = ca.Street,
                            Building = ca.Building,
                            Flat = ca.Flat,
                            LoyalityDiscount = gr == null ? 0 : gr.Loyality_discount,
                            AmountPurshase = gr == null ? 0 : gr.Amount_purshases
                        }).ToList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Клиент не найден!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
        private void change_btn_Click(object sender, RoutedEventArgs e)
        {
            AdminPage main       = this.Owner as AdminPage;
            string    name       = empl_Name.Text;
            string    surname    = empl_Surname.Text;
            string    patronymic = empl_Patronymic.Text;
            var       pos        = empl_Position.SelectedIndex;
            var       role       = empl_Role.SelectedIndex;
            string    log        = empl_Log.Text;
            string    pas        = empl_Password.Text;

            using (ADOmodel db = new ADOmodel(conString))
            {
                try
                {
                    var employee = db.Employees.Where(em => em.id_Employee == id).FirstOrDefault();

                    if (name != "")
                    {
                        employee.Name = name;
                    }
                    if (surname != "")
                    {
                        employee.Surname = surname;
                    }
                    if (patronymic != "")
                    {
                        employee.Patronymic = patronymic;
                    }
                    if (pos != -1)
                    {
                        employee.id_Position = pos + 1;
                    }
                    if (role != -1)
                    {
                        employee.id_Role = role + 1;
                    }
                    if (log != "")
                    {
                        employee.Login = log;
                    }
                    if (pas != "")
                    {
                        employee.Password = pas;
                    }

                    db.SaveChanges();
                    MessageBox.Show("Данные успешно изменены!", "Изменение", MessageBoxButton.OK, MessageBoxImage.Information);
                    if (idCurrentEmpl == id && log != "" || idCurrentEmpl == id && pas != "")
                    {
                        MessageBox.Show("Необходимо произвести вход с помощью новых данных.", "Изменение", MessageBoxButton.OK, MessageBoxImage.Information);
                        this.Close();
                        MainWindow mw = new MainWindow();
                        mw.Show();
                        main.Close();
                    }
                    else
                    {
                        this.Close();
                    }
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException)
                {
                    MessageBox.Show("Ошибка. Попробуйте менять логин и пароль по очереди, а не одновременно.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Esempio n. 5
0
        private void AdminPageBtnClicked(object sender, RoutedEventArgs e)
        {
            AdminPage adminPage = new AdminPage();

            NavigationService.Navigate(adminPage);
        }