private void btnSaveRace_Click(object sender, EventArgs e) { List <Race> races = mainForm.allRaces.getRacesList(); int raceIndex = races.FindIndex(i => i.ID == race.ID); try { race.ID = Convert.ToInt32(txtRaceid.Text); if (race.GetType() == typeof(Race)) { races[raceIndex] = race; race.ID = Convert.ToInt32(txtRaceid.Text); race.Date = Convert.ToDateTime(timeDatePicker.Text); race.StartTime = Convert.ToDateTime(txtTime.Text); race.Location = Convert.ToString(txtCapacity.Text); race.Capacity = Convert.ToInt32(txtCapacity.Text); race.Cost = Convert.ToDouble(txtCosttt.Text); } else if (race.GetType() == typeof(MotorRace)) { MotorRace motorRace = (MotorRace)race; motorRace.IsSponsored = Convert.ToBoolean(txtBoxBoolEdit.Text); motorRace.SponsorName = Convert.ToString(txtSponsorNAme.Text); motorRace.EngineType = Convert.ToInt32(txtenginetype.Text); motorRace.ID = Convert.ToInt32(txtRaceid.Text); motorRace.Date = Convert.ToDateTime(timeDatePicker.Text); motorRace.StartTime = Convert.ToDateTime(txtTime.Text); motorRace.Location = Convert.ToString(txtLocation.Text); motorRace.Capacity = Convert.ToInt32(txtCapacity.Text); motorRace.Cost = Convert.ToDouble(txtCosttt.Text); races[raceIndex] = motorRace; } else if (race.GetType() == typeof(PedalRace)) { PedalRace pedalRace = (PedalRace)race; pedalRace.RollerCategory = Convert.ToDouble(txtRollerCategoryEdit.Text); pedalRace.ID = Convert.ToInt32(txtRaceid.Text); pedalRace.Date = Convert.ToDateTime(timeDatePicker.Text); pedalRace.StartTime = Convert.ToDateTime(txtTime.Text); pedalRace.Location = Convert.ToString(txtLocation.Text); pedalRace.Capacity = Convert.ToInt32(txtCapacity.Text); pedalRace.Cost = Convert.ToDouble(txtCosttt.Text); races[raceIndex] = pedalRace; } mainForm.allRaces.setRacesList(races); mainForm.refreshRaceList(); MessageBox.Show("Race seccessfully edited.", "Success"); } catch (FormatException) { //if the user does not introduce correct data then this exeption will pop up. MessageBox.Show("Invalid format.", "Error"); } }
private void EditRace_load(object sender, EventArgs e) { txtRaceid.Text = race.ID.ToString(); if (race.GetType() == typeof(Race)) { txtRaceid.Text = race.ID.ToString(); timeDatePicker.Text = race.Date.ToString(); txtTime.Text = race.StartTime.ToString(); txtLocation.Text = race.Location.ToString(); txtCapacity.Text = race.Capacity.ToString(); txtCosttt.Text = race.Cost.ToString(); } else if (race.GetType() == typeof(MotorRace)) { MotorRace motorRace = (MotorRace)race; txtBoxBoolEdit.Text = motorRace.IsSponsored.ToString(); txtSponsorNAme.Text = motorRace.SponsorName.ToString(); txtenginetype.Text = motorRace.EngineType.ToString(); txtRaceid.Text = motorRace.ID.ToString(); timeDatePicker.Text = motorRace.Date.ToString(); txtTime.Text = motorRace.StartTime.ToString(); txtLocation.Text = motorRace.Location.ToString(); txtCapacity.Text = motorRace.Capacity.ToString(); txtCosttt.Text = motorRace.Cost.ToString(); txtRollerCategoryEdit.Visible = false; lblRollerCategoryEdit.Visible = false; } else if (race.GetType() == typeof(PedalRace)) { PedalRace pedalRace = (PedalRace)race; txtRollerCategoryEdit.Text = pedalRace.RollerCategory.ToString(); txtRaceid.Text = pedalRace.ID.ToString(); timeDatePicker.Text = pedalRace.Date.ToString(); txtTime.Text = pedalRace.StartTime.ToString(); txtLocation.Text = pedalRace.Location.ToString(); txtCapacity.Text = pedalRace.Capacity.ToString(); txtCosttt.Text = pedalRace.Cost.ToString(); lblEngineType.Visible = false; lblSponsorName.Visible = false; lblsponsoredit.Visible = false; txtBoxBoolEdit.Visible = false; txtSponsorNAme.Visible = false; cbBoolean.Visible = false; txtenginetype.Visible = false; } }
private void btnPadelRace_Click(object sender, EventArgs e) { try { PedalRace race = new PedalRace(Convert.ToDouble(textBoxRollerCategory.Text), Convert.ToInt32(textBoxRaceIdPedal.Text), Convert.ToDateTime(dateTimePickerPedalRace.Text), Convert.ToDateTime(textBoxTimePedal.Text), Convert.ToString(textBoxLocationPedal.Text), Convert.ToInt32(textBoxCapacityPedal.Text), Convert.ToDouble(textboxCostPedal.Text)); if (form1.allRaces.getRacesList().FindIndex(i => i.ID == race.ID) != -1) { throw new ArgumentException(); } if (race.Capacity > 50) { throw new MaxCapacityExceeded(); } form1.allRaces.AddRace(race); form1.refreshRacesTypesList(); form1.refreshRaceList(); MessageBox.Show("Pedal Race has been added Successfully!", "Success"); this.Close(); } catch (FormatException) { MessageBox.Show("Please check the data you have introduced.", "Invalid Input.", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (MaxCapacityExceeded) { MessageBox.Show("The Max Capacity was reached at 50 people, please remember that races only supports until 50 people.", "Invalid input.", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentException) { MessageBox.Show("An entry with this ID already exists.", "Invalid input.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// Method for filling data for proof of concept // Not needed when data persistence is added private void AddSomeHardCodedData() { //set up some DateTime objects DateTime startDate1 = new DateTime(2017, 12, 21); DateTime startDate2 = new DateTime(2011, 10, 19); DateTime startDate3 = new DateTime(2017, 12, 22); DateTime startDate4 = new DateTime(2019, 09, 23); //set up some DateTime objects DateTime time1 = new DateTime(2019, 12, 12); time1.Date.Add(new TimeSpan(10, 20, 00)); DateTime time2 = new DateTime(2020, 10, 19); time2.Date.Add(new TimeSpan(12, 00, 00)); DateTime time3 = new DateTime(2019, 12, 22); time3.Date.Add(new TimeSpan(12, 00, 00)); DateTime time4 = new DateTime(2020, 09, 23); time4.Date.Add(new TimeSpan(18, 00, 00)); // objects PedalRace race1 = new PedalRace(12, 1, startDate1, time1, "Stadium of Light", 15, 25.00); PedalRace race2 = new PedalRace(18, 2, startDate2, time2, "Durham Services", 25, 30.00); MotorRace race3 = new MotorRace(true, "University of Sunderland", 2, 3, startDate3, time3, "St Peters", 25, 5.00); MotorRace race4 = new MotorRace(true, "SAFC", 2, 4, startDate4, time4, "The Bridges", 25, 5.00); //Add races to list. allRaces.AddRace(race1); allRaces.AddRace(race2); allRaces.AddRace(race3); allRaces.AddRace(race4); }