private void addBtn_Click(object sender, EventArgs e) { //Add Coach COACHES coach = new COACHES(); 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 address = textBoxAddress.Text; string phone = textBoxPhone.Text; string email = textBoxEmail.Text; string steam = textBoxSwm.Text; //checking the age of the coach //the swimmer must be between 16 - 45 int born_year = dateTimePicker1.Value.Year; int this_year = DateTime.Now.Year; if (((this_year - born_year) < 16) || ((this_year - born_year) > 45)) { MessageBox.Show("The Coach's Age Must be Between 16 and 45 Years", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (verif()) { if (coach.insertCoach(fname, lname, gender, bdate, age, address, phone, email, steam)) { MessageBox.Show("New Coach Added", "Add Coach", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error", "Add Coach", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Please Check The Information Again. There Are Empty Fields", "Add Coach", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonFind_Click(object sender, EventArgs e) { COACHES coach = new COACHES(); //Search coaches by id try { int id = Convert.ToInt32(textBoxId.Text); MySqlCommand command = new MySqlCommand("SELECT `ID`, `First Name`, `Last Name`, `Swim Team/s` FROM `coaches` WHERE `ID`=" + id); DataTable table = coach.getCoaches(command); if (table.Rows.Count > 0) { textBoxFname.Text = table.Rows[0]["First Name"].ToString(); textBoxLname.Text = table.Rows[0]["Last Name"].ToString(); textBoxSwmT.Text = table.Rows[0]["Swim Team/s"].ToString(); } } catch { MessageBox.Show("Enter a Valid Swimmer's ID", "Invalid ID", MessageBoxButtons.OK, MessageBoxIcon.Error); } }