//creates a number of instructors public static void CreateInstructors(int count) { List <Town> towns = Towns.GetTowns(); Random rnd = new Random(); for (int i = 0; i < count; i++) { Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-Pilot.RetirementAge), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town); Dictionary <PilotRating, int> rankings = new Dictionary <PilotRating, int>(); rankings.Add(PilotRatings.GetRating("A"), 10); rankings.Add(PilotRatings.GetRating("B"), 20); rankings.Add(PilotRatings.GetRating("C"), 40); rankings.Add(PilotRatings.GetRating("D"), 20); rankings.Add(PilotRatings.GetRating("E"), 10); PilotRating ranking = AIHelpers.GetRandomItem <PilotRating>(rankings); Instructor instructor = new Instructor(profile, ranking); Instructors.AddInstructor(instructor); } }
private async void btn_addInstructor_Click(object sender, RoutedEventArgs e) { string errorList = ""; if (cmb_gender.SelectedIndex == -1) { errorList += "Select a gender.\n"; } if (lblBlock_CV.Text != "...." && !System.IO.File.Exists(lblBlock_CV.Text)) { errorList += "The selected CV does not exist.\n"; } if (num_age.Value == null) { errorList += "Numeric values cannot be null.\n"; } if (txt_address.Text == "") { errorList += "Address cannot be empty.\n"; } if (txt_instructorName.Text == "") { errorList += "Instructor name cannot be empty.\n"; } if (txt_qualifier.Text == "") { errorList += "Qualifier cannot be empty.\n"; } if (txt_phone.Text == "") { errorList += "Phone field cannot be empty.\n"; } foreach (char letter in txt_phone.Text) { if (!char.IsDigit(letter)) { errorList += "Phone can only consist of numbers!\n"; break; } } if (errorList != "") { await this.ShowMessageAsync("Check the following!", errorList); return; } if (Globals.Instructors.ToList().Exists(x => x.Value.Name == txt_instructorName.Text || x.Value.Phone == txt_phone.Text)) { if (EditedInstructor == null || (EditedInstructor != null && EditedInstructor.Name != txt_instructorName.Text)) { if (await this.ShowMessageAsync("Are you sure", "There exist an instructor with the same name/phone, are you sure you want to continue", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative) { return; } } } try { var newIns = new Instructor() { Name = txt_instructorName.Text, Address = txt_address.Text, Phone = txt_phone.Text, Gender = cmb_gender.SelectedIndex, Qualifier = txt_qualifier.Text, Age = Convert.ToInt32(num_age.Value), }; if (System.IO.File.Exists(lblBlock_CV.Text)) { newIns.CV = System.IO.File.ReadAllBytes(lblBlock_CV.Text); } //foreach (CheckedObject item in courses_listView.Items) //{ // if (item.Checked) // { // newIns.TeachingCourses.Add(item.Class); // } //} if (EditedInstructor == null) { Instructors.AddInstructor(newIns); } else { newIns.Id = EditedInstructor.Id; Instructors.EditInstructor(newIns); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Globals.RefreshReferenceInformation(); }