private void WantAdmin() { this.Hide(); AdminForm adminForm = new AdminForm(); adminForm.Show(); }
private void button2_Click(object sender, EventArgs e) { String login = loginField.Text; String pass = passwordField.Text; DB db = new DB(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("SELECT * FROM `agents` WHERE `login` = @login AND `password` = @password", db.getConnection()); command.Parameters.Add("@login", MySqlDbType.VarChar).Value = login; command.Parameters.Add("@password", MySqlDbType.VarChar).Value = pass; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { if (table.Rows[0][4].ToString() == "False") { Form2 form2 = new Form2(table.Rows[0][0].ToString()); this.Hide(); form2.Show(); } else { AdminForm admForm = new AdminForm(); this.Hide(); admForm.Show(); } } else { MessageBox.Show("Введите правильный логин или пароль"); } }
private void btnSignIn_Click(object sender, EventArgs e) { if (UserName.Text == "admin" && Password.Text == "admin") { con.Open(); this.Hide(); admin = new AdminForm(); admin.Show(); } else { MessageBox.Show("Wrong Username or Password!", "Try again!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } }
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; } }
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"); } }
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; } }