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 muskafidi_de
{
    public partial class auth : Form
    {

        public object Username { get; private set; }
        public auth()
        {
            InitializeComponent();
            CenterToParent();
        }

        private void auth_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox2.Text;
            string password = textBox1.Text;
            SqlConnection conn = new SqlConnection(@"Data Source=Class31000;Initial Catalog=06_muskafidi_de;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT Роль, Статус 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);
                int status = reader.GetInt32(1);
                if (status == 1)
                {
                    if (role == 1)
                    {
                        Admin administrator = new Admin();
                        administrator.Show();
                        this.Hide();
                    }
                    else if (role == 2)
                    {
                        manager form3 = new manager();
                        form3.Show();
                        this.Hide();
                    }
                    else if (role == 3)
                    {
                        Master form3 = new Master();
                        form3.Show();
                        this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("Отказано в доступе");
                }
            }


        }
    }
}
