namespace GBDD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox2.UseSystemPasswordChar = true;
            login.Click += login_Click;
        }

        private void label1_Click(object sender, EventArgs e)
        {
        }

        private void login_Click(object? sender, EventArgs e)
        {
            string sql = SqlQueries.AuthorizationUser(textBox1.Text, textBox2.Text);

            object? role = Db.Scalar(sql);

            if (role == null)
            {
                MessageBox.Show("Неверный логин или пароль");
                return;
            }

            int roleId = Convert.ToInt32(role);

            if (roleId == 1)
            {
                new Admin().Show();
            }
            else if (roleId == 2)
            {
                new Form2().Show();
            }
            else
            {
                object? driverId = Db.Scalar(SqlQueries.DriverIdByLogin(textBox1.Text));
                new UserFines(Convert.ToInt32(driverId)).Show();
            }

            Hide();
        }
    }
}
