コード例 #1
0
ファイル: Login.cs プロジェクト: ArtyomkaM/Marathon
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                Connection.connection.Open();

                string     sqlExp = "select [Email], [Password],[RoleId] from [dbo].[User] where [Email]=@login";
                SqlCommand cmd    = new SqlCommand(sqlExp, Connection.connection);
                cmd.Parameters.AddWithValue("@login", textBox_email.Text);
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();

                    if ((string)reader[1] == textBox_password.Text)
                    {
                        Connection.userLogin = textBox_email.Text;

                        switch ((string)reader[2])
                        {
                        case "R":
                            RunnerMenu mr = new RunnerMenu();
                            mr.Show();
                            this.Close();
                            break;

                        case "C":
                            CoordinatorMenu mc = new CoordinatorMenu();
                            mc.Show();
                            this.Close();
                            break;

                        case "A":
                            AdminMenu ma = new AdminMenu();
                            ma.Show();
                            this.Close();
                            break;

                        default:
                            MessageBox.Show("Нет такой роли");
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неверный пароль");
                    }
                }
                else
                {
                    MessageBox.Show("Неверный логин");
                }
                reader.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            Connection.connection.Close();
        }