using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Digital_World_08 { public partial class Avtorization : Form { public Avtorization() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string username = LoginBox.Text; string password = PasswordBox.Text; // Подключение к базе данных SqlConnection conn = new SqlConnection("Data Source=class31000;Initial Catalog=digital_world_8;Integrated Security=True"); conn.Open(); // Поиск пользователя в базе данных SqlCommand cmd = new SqlCommand("SELECT Role FROM Users WHERE Username=@username AND Password=@password", conn); cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@password", password); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { // Авторизация прошла успешно reader.Read(); int role = reader.GetInt32(0); if (role == 1) { this.Hide(); Administrator administrator = new Administrator(); administrator.Show(); } else if (role == 2) { this.Hide(); Master master = new Master(); master.Show(); } else if (role == 3) { this.Hide(); Maneger maneger = new Maneger(); maneger.Show(); } } else { // Неверный логин или пароль } conn.Close(); } } }