private void buttonFind_Click(object sender, EventArgs e) { SWIMMER swimmer = new SWIMMER(); //Search coaches by id try { int id = Convert.ToInt32(textBoxId.Text); MySqlCommand command = new MySqlCommand("SELECT `ID`, `First Name`, `Last Name`, `Age`, `Swim Team/s`, `Swim Group` FROM `swimmers` WHERE `ID`=" + id); DataTable table = studProg.getStudentsProgress(command); if (table.Rows.Count > 0) { textBoxFname.Text = table.Rows[0]["First Name"].ToString(); textBoxLname.Text = table.Rows[0]["Last Name"].ToString(); textBoxAge.Text = table.Rows[0]["Age"].ToString(); textBoxSwmT.Text = table.Rows[0]["Swim Team/s"].ToString(); textBoxSwimG.Text = table.Rows[0]["Swim Group"].ToString(); } } catch { MessageBox.Show("Enter a Valid Swimmer's ID", "Invalid ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { //Add Prebeginner SWIMMER swimmer = new SWIMMER(); string fname = textBoxFname.Text; string lname = textBoxLname.Text; string gender = "Male"; if (radioButtonFemale.Checked) { gender = "Female"; } DateTime bdate = dateTimePicker1.Value; string age = textBoxAge.Text; string school = textBoxSchool.Text; string medical = textBoxMedical.Text; string swimt = textBoxSwmT.Text; string swiml = textBoxGroup.Text; string pname = textBoxPname.Text; string paddress = textBoxPaddress.Text; string pnum = textBoxPnum.Text; string pemail = textBoxPemail.Text; //checking the age of the coach //the swimmer must be between 2 - 4 int born_year = dateTimePicker1.Value.Year; int this_year = DateTime.Now.Year; if (((this_year - born_year) < 2) || ((this_year - born_year) > 19)) { MessageBox.Show("The Swimmer's Age Must be Between 2 and 19 Years", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (verif()) { if (swimmer.insertSwimmer(fname, lname, gender, bdate, age, school, medical, swimt, swiml, pname, paddress, pnum, pemail)) { MessageBox.Show("New Swimmer Added", "Add Swimmer", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error", "Add Swimmer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Please Check The Information Again. There Are Empty Fields", "Add Swimmer", MessageBoxButtons.OK, MessageBoxIcon.Error); } }