private void button1_Click(object sender, EventArgs e) { //Initialize variables int newTaggerID; Person newPerson = new Person(); PersonQuery query = new PersonQuery(connection); //Parse and validate input if (!ParseInput(ref newPerson)) { //Show error message MessageBox.Show("Could not add person to the repository!\nPlease check all fields for errors.", "Error Message:", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (ParseInput(ref newPerson)) { //Add entry to repository query.addPerson(newPerson); //Get the system assigned tagger ID, and display this to the user newTaggerID = query.getPerson(newPerson.name).id; //Show success message MessageBox.Show("Person successfully added to the repository!\nTheir tagger ID is " + newTaggerID + ".\nPlease write this down!", "Person Added", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//Validates length of tagger ID and uses database to check if tagger ID is in the system public static string validateTaggerID(int taggerID, MySqlConnection connection) { string validID = Convert.ToString(taggerID); if (validID.Length > 8) //Check over Length return ""; //Check if taggerID is in system PersonQuery getID = new PersonQuery(connection); Person user = new Person(); user = getID.getPerson(taggerID); if (user == null) return ""; return user.name; }