//Method used to get bloodgroup from radio buttons private Patient.BloodType GetBloodType() { //default type O as all patients can receive O (and all people with type O can only receive type O) Patient.BloodType type = Patient.BloodType.O; if (A.IsChecked == true) { type = Patient.BloodType.A; } else if (B.IsChecked == true) { type = Patient.BloodType.AB; } else if (AB.IsChecked == true) { type = Patient.BloodType.AB; } else if (O.IsChecked == true) { type = Patient.BloodType.O; } //message you must chose a bloodgroup else { MessageBox.Show("You must select a Bloodgroup"); } return(type); }
//method to create a new patient object private void btnAddPatient_Click(object sender, RoutedEventArgs e) { //get the ward details for the patient string wardname = (lbxWard.SelectedItem as Ward).WardName; int capacity = (lbxWard.SelectedItem as Ward).Capacity; //get the patients details (use the getbloodtype method here) string patientname = txbPatient.Text; Patient.BloodType type = GetBloodType(); DateTime dob; //make sure a DOB is chosen if (dpkDOB.SelectedDate.HasValue == false) { MessageBox.Show("You must select a Date of Birth"); return; } else { dob = dpkDOB.SelectedDate.Value; } //make sure there is place for the patient in the selected ward if (CountPatients(wardname) >= capacity) { MessageBox.Show("The number of patients for this Ward will be exceeded, please chose a different ward"); return; } //update list, set so as last patient added is selected and disable the add patient button ListPatients.Add(new Patient(wardname, capacity, patientname, type, dob)); lbxPatient.SelectedIndex = MatchingPatients.Count; btnAddPatient.IsEnabled = false; UpdatePatient(); }