private void CreatAccountTile_Click(object sender, EventArgs e) { CreateAccountForm createAccountForm = new CreateAccountForm(this); this.Hide(); createAccountForm.Show(); }
/// <summary> /// Inserts an new user into an online database. /// </summary> /// <param name="username">The username the query has to insert.</param> /// <param name="name">The name the query has to insert.</param> /// <param name="dateofbirth">The date of birth the query has to insert.</param> /// <param name="passcode">The passcode the query has to insert hashed.</param> /// <param name="email">The email the query has to insert.</param> /// <param name="currentForm">The current Form to to open show an error code, if one occures.</param> public static void InsertAccount(string username, string name, DateTime dateofbirth, string passcode, string email, CreateAccountForm currentForm) { using (MySqlConnection con = new MySqlConnection(@"host=mysql8.db4free.net;user=schoolproject;password=carsharing;database=carsharing4;port=3307")) { try { // open connection to database con.Open(); // INTERACTION WITH DATABASE using (MySqlCommand cmd = new MySqlCommand("INSERT INTO `Person` (`Username`, `Name`, `DateOfBirth`, `Passcode`, `email`, `is_Admin`) VALUES (@username, @name, @date, @passcode, @email, '1')", con)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@date", dateofbirth); cmd.Parameters.AddWithValue("@passcode", Cryptography.sha256_hash(passcode)); cmd.Parameters.AddWithValue("@email", email); cmd.ExecuteNonQuery(); } } catch (Exception) { MetroMessageBox.Show(currentForm, "An error occured."); } finally { // close connection to database con.Close(); } } }