//removes a student from the object public void removeStudent(PilotStudent student) { this.Students.Remove(student); this.FlightSchool.removeStudent(student); }
//adds a student to the object public void addStudent(PilotStudent student) { this.Students.Add(student); this.FlightSchool.addStudent(student); }
//adds a student to the instructor public void addStudent(PilotStudent student) { this.Students.Add(student); }
//removes a students from the instructor public void removeStudent(PilotStudent student) { this.Students.Remove(student); }
//adds a student to the flight school public void addStudent(PilotStudent student) { this.Students.Add(student); }
//removes a student from the flight school public void removeStudent(PilotStudent student) { this.Students.Remove(student); }
//returns the aircraft for a student private TrainingAircraft getStudentAircraft(PilotStudent student) { Dictionary<TrainingAircraftType, int> types = this.FlightSchool.Aircrafts.GroupBy(a => a.Type). Select(group => new { Type = group.Key, Count = group.Sum(g => g.Type.MaxNumberOfStudents) }).ToDictionary(g => g.Type, g => g.Count); ; foreach (PilotStudent ps in this.FlightSchool.Students) { types[ps.Aircraft.Type]--; } var freeTypes = types.Where(t => t.Value > 0).Select(t => t.Key).OrderBy(t=>t.TypeLevel); return this.FlightSchool.Aircrafts.First(a=>a.Type == freeTypes.First()); }
private void btnHire_Click(object sender, RoutedEventArgs e) { var aircraftsTypesFree = this.FlightSchool.Aircrafts.Select(a => a.Type); Dictionary<TrainingAircraftType,int> types = this.FlightSchool.Aircrafts.GroupBy(a=>a.Type). Select(group => new { Type = group.Key, Count = group.Sum(g=>g.Type.MaxNumberOfStudents) }).ToDictionary(g => g.Type, g => g.Count); ; foreach (PilotStudent student in this.FlightSchool.Students) { var firstAircraft = student.Rating.Aircrafts.OrderBy(a=>a.TypeLevel).FirstOrDefault(a=>types.ContainsKey(a) && types[a] > 0); if (firstAircraft != null && types.ContainsKey(firstAircraft)) types[firstAircraft]--; } List<PilotRating> possibleRatings = new List<PilotRating>(); foreach (PilotRating rating in PilotRatings.GetRatings()) { if (rating.Aircrafts.Exists(a => types.ContainsKey(a) && types[a] > 0)) possibleRatings.Add(rating); } WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2811"), string.Format(Translator.GetInstance().GetString("MessageBox", "2811", "message")), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { List<Town> towns = Towns.GetTowns(this.FlightSchool.FlightSchool.Airport.Profile.Country); Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-35), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town); Instructor instructor = (Instructor)cbInstructor.SelectedItem; string airlinerFamily = cbTrainAircraft.SelectedItem.ToString(); PilotStudent student = new PilotStudent(profile, GameObject.GetInstance().GameTime,instructor ,GeneralHelpers.GetPilotStudentRating(instructor,possibleRatings),airlinerFamily); TrainingAircraft aircraft = getStudentAircraft(student); student.Aircraft = aircraft; this.FlightSchool.addStudent(student); instructor.addStudent(student); setHireStudentsStatus(); double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -studentPrice); } }
private void btnHire_Click(object sender, RoutedEventArgs e) { Random rnd = new Random(); ComboBox cbInstructor = new ComboBox(); cbInstructor.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbInstructor.Width = 200; cbInstructor.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbInstructor.DisplayMemberPath = "Profile.Name"; cbInstructor.SelectedValuePath = "Profile.Name"; foreach (Instructor instructor in this.FlightSchool.Instructors.Where(i => i.Students.Count < Model.PilotModel.FlightSchool.MaxNumberOfStudentsPerInstructor)) cbInstructor.Items.Add(instructor); cbInstructor.SelectedIndex = 0; if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PanelFlightSchool", "1005"), cbInstructor) == PopUpSingleElement.ButtonSelected.OK && cbInstructor.SelectedItem != null) { List<Town> towns = Towns.GetTowns(this.FlightSchool.FlightSchool.Airport.Profile.Country); Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-55), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(), Names.GetInstance().getRandomLastName(), birthdate, town); PilotStudent student = new PilotStudent(profile, GameObject.GetInstance().GameTime, (Instructor)cbInstructor.SelectedItem); this.FlightSchool.addStudent(student); ((Instructor)cbInstructor.SelectedItem).addStudent(student); setHireStudentsStatus(); double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -studentPrice); } }
//removes a student from the object public void removeStudent(PilotStudent student) { this.Students.Remove(student); this.FlightSchool.removeStudent(student); this.NumberOfStudents = this.Students.Count; }
//adds a student to the object public void addStudent(PilotStudent student) { this.Students.Add(student); this.FlightSchool.addStudent(student); this.NumberOfStudents = this.Students.Count; }