private void btnCreateNewInPersonEventOK_Click(object sender, EventArgs e) { Location selectedLocation = null; string locationKey; DateTime dateTime = dateTimePicker1.Value; double avgSpeed; string eventTitle; if (dateTime.CompareTo(DateTime.Now) <= 0) { MessageBox.Show("You can only create events that take place in the future."); return; } if (string.IsNullOrWhiteSpace(txtAvgSpeedTab1.Text) || !double.TryParse(txtAvgSpeedTab1.Text, out avgSpeed)) { MessageBox.Show("Please enter a value for the event average speed consisting of digits and one comma."); return; } if (string.IsNullOrWhiteSpace(txtEventTitleTab1.Text)) { MessageBox.Show("Please enter a title for the event."); return; } if (db.Events.ContainsKey(txtEventTitleTab1.Text)) { MessageBox.Show("An event with this title already exists. Please provide a different title."); return; } else { eventTitle = txtEventTitleTab1.Text; } if (listLocations.SelectedItems.Count == 0) { MessageBox.Show("Please select a location from the list or create a new one."); return; } foreach (ListViewItem item in listLocations.SelectedItems) { locationKey = item.SubItems[0].Text; selectedLocation = db.RunningLocations[locationKey]; } Event newEvent = new InPersonEvent(dateTime, avgSpeed, eventTitle, selectedLocation); db.Events.Add(newEvent.EventTitle, newEvent); Close(); }
protected Database() { User user1 = new User("Tom", "password"); User user2 = new User("Alex", "password"); User user3 = new User("Lisa", "password"); User user4 = new User("Mario", "password"); User user5 = new User("Lucia", "password"); Users.Add(user1.UserName, user1); Users.Add(user2.UserName, user2); Users.Add(user3.UserName, user3); Users.Add(user4.UserName, user4); Users.Add(user5.UserName, user5); Location route1 = new Location("Ostpark, Munich", 48.112242, 11.630701, 5); Location route2 = new Location("Parco di Villa Borghese, Rome", 41.914614, 12.481987, 6); Location route3 = new Location("Parco degli Acquedotti, Rome", 41.853406, 12.557115, 10); Location route4 = new Location("Englischer Garten, Munich", 48.164334, 11.605598, 8); Location route5 = new Location("Parco Sempione, Milan", 45.474371, 9.171659, 4); RunningLocations.Add(route1.RouteName, route1); RunningLocations.Add(route2.RouteName, route2); RunningLocations.Add(route3.RouteName, route3); RunningLocations.Add(route4.RouteName, route4); RunningLocations.Add(route5.RouteName, route5); Event jogging1 = new InPersonEvent(new DateTime(2020, 08, 01, 08, 30, 00), 11.0, "Jogging in the park", route3); Event jogging2 = new InPersonEvent(new DateTime(2020, 08, 09, 19, 00, 00), 11.5, "After work jogging", route5); Event jogging3 = new VirtualEvent(new DateTime(2020, 8, 21, 09, 00, 00), 10.0, "Jogging as a virtual group", 7.0); Event jogging4 = new InPersonEvent(new DateTime(2020, 06, 01, 10, 00, 00), 12.0, "Morning jogging on 1st June", route1); Event jogging5 = new VirtualEvent(new DateTime(2020, 7, 28, 19, 00, 00), 11.5, "Jogging in different locations", 5.0); Event jogging6 = new InPersonEvent(new DateTime(2020, 5, 15, 11, 00, 00), 10.0, "Speed challenge", route5); Event jogging7 = new VirtualEvent(new DateTime(2020, 7, 31, 18, 30, 00), 13.0, "Evening jogging", 5.0); Events.Add(jogging1.EventTitle, jogging1); Events.Add(jogging2.EventTitle, jogging2); Events.Add(jogging3.EventTitle, jogging3); Events.Add(jogging4.EventTitle, jogging4); Events.Add(jogging5.EventTitle, jogging5); Events.Add(jogging6.EventTitle, jogging6); Events.Add(jogging7.EventTitle, jogging7); Participant part1 = new Participant(user1, jogging1); Participant part2 = new Participant(user1, jogging3); Participant part3 = new Participant(user1, jogging4); Participant part4 = new Participant(user2, jogging4); Participant part5 = new Participant(user3, jogging4); Participant part6 = new Participant(user4, jogging4); Participant part7 = new Participant(user1, jogging5); Participant part8 = new Participant(user1, jogging6); Participant part9 = new Participant(user2, jogging6); Participant part10 = new Participant(user4, jogging6); part7.SetRunningLocation(route4); part8.SetRunningLocation(route2); part3.CheckInAtEvent(); part4.CheckInAtEvent(); part5.CheckInAtEvent(); part6.CheckInAtEvent(); part8.CheckInAtEvent(); part9.CheckInAtEvent(); part10.CheckInAtEvent(); EventResults results1 = part3.UploadEventResults(TimeSpan.Parse("00:32:15", CultureInfo.InvariantCulture), 10.5, 166); EventResults results2 = part4.UploadEventResults(TimeSpan.Parse("00:31:09", CultureInfo.InvariantCulture), null, 170); EventResults results3 = part5.UploadEventResults(TimeSpan.Parse("00:34:38", CultureInfo.InvariantCulture), 9.8, null); EventResults results4 = part6.UploadEventResults(TimeSpan.Parse("00:35:00", CultureInfo.InvariantCulture), null, null); UserGroup group1 = new UserGroup(user1, "Munich Joggers"); UserGroup group2 = new UserGroup(user2, "Milan Joggers"); UserGroup group3 = new UserGroup(user3, "City joggers"); UserGroups.Add(group1.GroupName, group1); UserGroups.Add(group2.GroupName, group2); UserGroups.Add(group3.GroupName, group3); group1.AddMember(user3); group1.AddMember(user4); group2.AddMember(user4); group2.AddMember(user5); group3.AddMember(user1); }