Example #1
0
        private void button_enter_Click(object sender, RoutedEventArgs e)
        {
            string mail = textbox_mail.Text.ToLower();
            string pass = passwordbox_password.Password;

            if (mail != "" && pass != "")
            {
                string user_count = Shortcuts.get_one_string_data_from($@"select count(*) from `users`
																 where `mail` = '{mail}'
																 and `password` = '{pass}';"                                                                ,
                                                                       connection);

                if (user_count == "1")
                {
                    try_count    = 3;
                    current_user = Shortcuts.get_user(mail, pass, connection);
                    //Запоминание пользователя
                    if (Checkbox_remember.IsChecked.Value)
                    {
                        if (File.Exists(remember_file_path))
                        {
                            File.Delete(remember_file_path);
                        }
                        using (StreamWriter sw = new StreamWriter(remember_file_path))
                        {
                            sw.WriteLine(textbox_mail.Text);
                            sw.WriteLine(passwordbox_password.Password);
                            sw.Close();
                        }
                    }
                    int    hours = DateTime.Now.Hour;
                    string greeting;
                    if (hours >= 6 && hours <= 11)
                    {
                        greeting = "Доброе утро, ";
                    }
                    else if (hours >= 12 && hours <= 17)
                    {
                        greeting = "Добрый день, ";
                    }
                    else if (hours >= 18 && hours <= 21)
                    {
                        greeting = "Добрый вечер, ";
                    }
                    else
                    {
                        greeting = "Доброй ночи, ";
                    }
                    greeting += current_user.first_name + " " + current_user.second_name + "!";
                    MessageBox.Show(greeting);
                    switch (current_user.role)
                    {
                    case "администратор":
                        MainWindow window = new MainWindow(current_user, this);
                        window.Show();
                        Hide();
                        break;

                    case "менеджер по заявкам":
                        RequestManagerWindow rmw = new RequestManagerWindow(current_user, this);
                        rmw.Show();
                        Hide();
                        break;

                    case "менеджер по поставкам":
                        SupplyManagerWindow smw = new SupplyManagerWindow(current_user, this);
                        smw.Show();
                        Hide();
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Неверный логин или пароль.");
                    try_count--;
                    if (try_count <= 0)
                    {
                        MessageBox.Show("Количество попыток превышено, введите проверочный текст!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        textbox_mail.Text             = "";
                        passwordbox_password.Password = "";
                        change_login_ability(false);
                        generate_captcha();
                        change_captcha_visibility(Visibility.Visible);
                    }
                }
            }
            else
            {
                MessageBox.Show("Введите логин и пароль.");
            }
        }