Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string          connStr = "server=localhost;user=root;password=;database=mydb;port=3306;";
            MySqlConnection conn    = new MySqlConnection(connStr);

            try
            {
                conn.Open();
                string          sql = "SELECT role_idrole FROM users WHERE username=\"" + textBox1.Text + "\" AND password=\"" + textBox2.Text + "\";";
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    role = Convert.ToInt32(rdr[0].ToString());
                }
                rdr.Close();
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            conn.Close();
            switch (role)
            {
            case 0:

                MessageBox.Show("error");
                break;

            case 1:
                AdminForm frm = new AdminForm();
                frm.Show();

                break;

            case 2:
                AdminForm frm1 = new AdminForm();
                frm1.Show();

                break;

            default:
                break;
            }
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var username = textBox1.Text;
            var password = textBox4.Text;

            bool userExist = CheckIfUserExist(username, password);

            if (userExist == true)
            {
                this.Hide();
                AdminForm bookingForm = new AdminForm();
                bookingForm.Closed += (s, args) => this.Close();
                bookingForm.Show();
            }
            else
            {
                return;
            }
        }
Exemple #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string          query = "select * from admin where username='******' and password='******';";
            MySqlDataReader read;

            connect.Open();
            MySqlCommand cmd = new MySqlCommand(query, connect);

            read = cmd.ExecuteReader();
            if (read.Read())
            {
                AdminForm frmAdmin = new AdminForm();
                frmAdmin.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("login gagal");
            }
        }
Exemple #4
0
        private void enterButton_Click(object sender, EventArgs e) // при нажатии на кнопку ВОЙТИ
        {
            if (loginTextBox.Text == "" || passTextBox.Text == "") // заполнение строк логина и пароля обязательно
            {
                MessageBox.Show("Заполните пустые строки!", "Ошибка", MessageBoxButtons.OK);
            }
            else
            {
                SqlConnection conn          = DBUtils.GetDBConnection();
                string        sqlExpression = $"SELECT * FROM users WHERE login = '******' AND password = '******'";
                int           user_id       = 0;
                try
                {
                    conn.Open();
                    SqlCommand    command = new SqlCommand(sqlExpression, conn);
                    SqlDataReader reader  = command.ExecuteReader();
                    if (reader.HasRows)                                  // если пользователь найден
                    {
                        int userRole = getUserData(reader, ref user_id); // проверяем его роль и доступ

                        if (userRole == Constants.ACCESS_ERROR)
                        {
                            MessageBox.Show("Доступ запрещен.", "Ошибка", MessageBoxButtons.OK);
                        }
                        else if (userRole == Constants.ADMIN_ROLE)
                        {
                            clearInputs();
                            AdminForm adminForm = new AdminForm();
                            adminForm.Show();
                            this.Hide();
                        }
                        else if (userRole == Constants.USER_ROLE)
                        {
                            clearInputs();
                            CurrentUser.Id = user_id; //сохраняем id текущего пользователя
                            UserForm userForm = new UserForm();
                            userForm.Show();
                            this.Hide();
                        }
                        else
                        {
                            clearInputs();
                            CurrentUser.Id = user_id; //сохраняем id текущего пользователя
                            DocForm docForm = new DocForm();
                            docForm.Show();
                            this.Hide();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Такого пользователя не существует. Введите данные снова.", "Ошибка", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK);
                }
                finally
                {
                    // Гарантировать освобождение подключения
                    conn.Close();
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string          connStr = "server=localhost;user=root;password=;database=mydb;port=3306;";
            MySqlConnection conn    = new MySqlConnection(connStr);

            try
            {
                conn.Open();
                string          sql = "SELECT role_idrole FROM users WHERE username=\"" + Login.Text + "\" AND password=\"" + Password.Text + "\";";
                MySqlCommand    cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    role = Convert.ToInt32(rdr[0].ToString());
                }
                rdr.Close();
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            conn.Close();
            switch (role)
            {
            case 0:

                MessageBox.Show("\t Ошибка авторизации \n    Введен неверный логин или пароль");
                break;

            case 1:
                AdminForm Admin = new AdminForm();
                Admin.Show();
                role = 0;
                Close();
                break;

            case 2:
                Manager Manager = new Manager();
                Manager.Show();
                role = 0;
                Close();
                break;

            case 3:
                Storekeeper Storekeeper = new Storekeeper();
                Storekeeper.Show();
                role = 0;
                Close();
                break;

            case 4:
                Customer Customer = new Customer();
                Customer.Show();
                role = 0;
                Close();
                break;

            default:
                break;
            }
        }