コード例 #1
0
ファイル: Login.cs プロジェクト: UchihaDanShal/Marathon
        private void metroButton1_Click(object sender, EventArgs e)
        {
            MySqlConnection connection = new MySqlConnection("server=localhost;database=marathon;user=root;password=lox123");

            connection.Open();
            MySqlCommand command = new MySqlCommand("SELECT * FROM user WHERE Email = @login AND Password = @password", connection);

            command.Parameters.AddWithValue("@login", metroTextBox1.Text);
            command.Parameters.AddWithValue("@password", metroTextBox2.Text);
            command.Prepare();
            MySqlDataReader reader = command.ExecuteReader();
            int             result = 0;

            while (reader.Read())
            {
                result = result + 1;
            }
            if (result == 1)
            {
                connection.Close();
                MySqlCommand roleCommand = new MySqlCommand("SELECT RoleId FROM user WHERE Email = @login", connection);
                connection.Open();
                roleCommand.Parameters.AddWithValue("@login", metroTextBox1.Text);
                roleCommand.Prepare();
                var value = roleCommand.ExecuteScalar();
                if (value.ToString() == "R")
                {
                    Runner.RunnerAuthMenu ram = new Runner.RunnerAuthMenu(this.metroTextBox1.Text);
                    ram.Show();
                    this.Close();
                    connection.Close();
                }
                if (value.ToString() == "A")
                {
                    Admin.AdminMenu am = new Admin.AdminMenu();
                    am.Show();
                    this.Close();
                    connection.Close();
                }
                if (value.ToString() == "C")
                {
                    Coordinator.Menu cm = new Coordinator.Menu();
                    cm.Show();
                    this.Close();
                    connection.Close();
                }
            }
            else
            {
                MetroMessageBox.Show(this, "Неверный логин или пароль");
            }
        }
コード例 #2
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            if (metroTextBox1.Text != "" && metroTextBox2.Text != "")
            {
                try
                {
                    Program.connection.Open();
                    string       sql        = String.Format("SELECT * FROM Usеr WHERE Email='{0}' AND Password='******'", metroTextBox1.Text, metroTextBox2.Text);
                    MySqlCommand sqlCommand = new MySqlCommand(sql, Program.connection);
                    Program.sqlDataReader = sqlCommand.ExecuteReader();
                    Program.sqlDataReader.Read();
                    Program.userInfo.Email     = Program.sqlDataReader.GetString("Email");
                    Program.userInfo.Password  = Program.sqlDataReader.GetString("Password");
                    Program.userInfo.FirstName = Program.sqlDataReader.GetString("FirstName");
                    Program.userInfo.LastName  = Program.sqlDataReader.GetString("LastName");
                    Program.userInfo.RoleId    = Program.sqlDataReader.GetString("RoleId");
                    Program.sqlDataReader.Close();

                    if (Program.userInfo.RoleId == "R")
                    {
                        sqlCommand            = new MySqlCommand($"SELECT RunnerId, Gender, CountryCode, DateOfBirth, IsCheckROM FROM Runnеr WHERE Email='{metroTextBox1.Text}'", Program.connection);
                        Program.sqlDataReader = sqlCommand.ExecuteReader();
                        Program.sqlDataReader.Read();
                        Program.userInfo.Gender      = Program.sqlDataReader.GetString("Gender");
                        Program.userInfo.CountryCode = Program.sqlDataReader.GetString("CountryCode");
                        Program.userInfo.DateOfBirth = Program.sqlDataReader.GetDateTime("DateOfBirth");
                        Program.userInfo.RunnerId    = Program.sqlDataReader.GetInt32("RunnerId");
                        Program.userInfo.checkIsRegisterOnMarafon = Program.sqlDataReader.GetBoolean("IsCheckROM");
                        Program.sqlDataReader.Close();
                        DateTime Age = Program.userInfo.DateOfBirth;
                        Program.userInfo.AgeGroup = Age.Year > 2003 ? 1 : Age.Year > 1991 ? 2 : Age.Year > 1981 ? 3 : Age.Year > 1964 ? 4 : Age.Year > 1950 ? 5 : 6;
                        sqlCommand            = new MySqlCommand($"SELECT CountryName FROM Cоuntry WHERE CountryCode='{Program.userInfo.CountryCode}'", Program.connection);
                        Program.sqlDataReader = sqlCommand.ExecuteReader();
                        Program.sqlDataReader.Read();
                        Program.userInfo.CountryName = Program.sqlDataReader.GetString("CountryName");
                        Program.connection.Close();
                        Runner.RunnerAuthMenu ram = new Runner.RunnerAuthMenu(this.metroTextBox1.Text);
                        ram.Show();
                        this.Close();
                        Program.connection.Close();
                    }
                    if (Program.userInfo.RoleId == "A")
                    {
                        Admin.AdminMenu am = new Admin.AdminMenu();
                        am.Show();
                        this.Close();
                        Program.connection.Close();
                    }
                    if (Program.userInfo.RoleId == "C")
                    {
                        Coordinator.runed cm = new Coordinator.runed();
                        cm.Show();
                        this.Close();
                        Program.connection.Close();
                    }
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Не верные Email или пароль", "Закрыть", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    Program.connection.Close();
                }
            }
            else
            {
                MessageBox.Show("Не все поля заполнены!", "Закрыть", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }