Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Добавим подключение к БД
                using (SqlConnection connect = new SqlConnection(Program.conString))
                {
                    connect.Open();

                    if (textBoxLogin.Text == "" && textBoxPsw.Text == "")
                    {
                        MessageBox.Show("Вы не заполнили поле!");
                    }
                    login = textBoxLogin.Text;

                    string        sqlExp = string.Format("SELECT*FROM USERS WHERE login='******' ", login);
                    SqlCommand    cmd    = new SqlCommand(sqlExp, connect);
                    SqlDataReader reader = cmd.ExecuteReader();

                    //

                    if (reader.HasRows) // проверка есть ли данные
                    {
                        reader.Read();  // читаем строку
                        if ((string)reader["password"] == textBoxPsw.Text)
                        {
                            role = (string)reader["role"];
                            // сравниваем введенный пароль с паролем в бд и если он совпадает, то смотрим на значение
                            //поля роль и в зависимости от него открываем нужную форму
                            switch ((string)reader["role"])
                            {
                            case "Customer":
                                UserPanel usrP = new UserPanel(Login, Role);
                                usrP.Show(); break;

                            case "Manager":
                                ManagerPanel mngP = new ManagerPanel(Login, Role);
                                mngP.Show(); break;

                            case "Admin":
                                AdminPanel admP = new AdminPanel(Login, Role);
                                admP.Show(); break;

                            default: MessageBox.Show("Ошибка роли"); break;
                            }
                        }

                        else
                        {
                            MessageBox.Show("Неверный пароль");
                            textBoxLogin.Text = "";
                            textBoxPsw.Text   = "";
                        }
                    }
                    else
                    {
                        MessageBox.Show("Нет такого пользователя");
                        textBoxLogin.Text = "";
                        textBoxPsw.Text   = "";
                    }
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); return; }
        }
Ejemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            UserPanel cm = new UserPanel();

            cm.Close();
        }