private void buttonLogin_Click(object sender, EventArgs e) { String loginUser = loginField.Text; String passUser = pass.Text; DB db = new DB(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("SELECT * FROM `tourists` WHERE `login` = @uL AND `password` = @uP", db.getConnection()); command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginUser; command.Parameters.Add("@uP", MySqlDbType.VarChar).Value = passUser; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { var m = new MyCabinet(loginUser, passUser); m.Show(); this.Hide(); } else { MessageBox.Show("False login or password"); } }
private void buttonSignup_Click(object sender, EventArgs e) { String name = nameField.Text; String secondname = secnameField.Text; String surname = srnameField.Text; DateTime bday = bdayDate.Value; String loginUser = loginregField.Text; String passUser = passregField.Text; String Sex = sexField.Text; String category = categoryField.Text; int type = 0, access = 5; if (category == "Sportsman") { type = 2; } if (category == "Starter") { type = 3; } if (name == "") { MessageBox.Show("Input name"); access--; } if (loginUser == "") { MessageBox.Show("Input login"); access--; } if (passUser == "") { MessageBox.Show("Input password"); access--; } if (category == "") { MessageBox.Show("Choose category"); access--; } if (isUserExists()) { access--; } DB db = new DB(); MySqlCommand command = new MySqlCommand("INSERT INTO `tourists` (`Name`, `SecondName`, `Surname`, `Birthday`, `Type`, `Gender`, `login`, `password`) VALUES (@name, @secname, @surname, @bday, @type, @sex, @login, @pass)", db.getConnection()); command.Parameters.Add("@name", MySqlDbType.VarChar).Value = name; command.Parameters.Add("@secname", MySqlDbType.VarChar).Value = secondname; command.Parameters.Add("@surname", MySqlDbType.VarChar).Value = surname; command.Parameters.Add("@bday", MySqlDbType.Date).Value = bday; command.Parameters.Add("@type", MySqlDbType.Int32).Value = type; command.Parameters.Add("@sex", MySqlDbType.VarChar).Value = Sex; command.Parameters.Add("@login", MySqlDbType.VarChar).Value = loginUser; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = passUser; if (access == 5) { db.openConnection(); if (command.ExecuteNonQuery() == 1) { MessageBox.Show("Account created"); var m = new MyCabinet(loginUser, passUser); m.Show(); this.Hide(); } else { MessageBox.Show("Error. Account doesn't created"); } db.closeConnection(); } }