private void Window_Loaded(object sender, RoutedEventArgs e) { //get link to main window MainWindow main = this.Owner as MainWindow; if (main.lbxCars.SelectedItem != null) { tempVan = main.lbxCars.SelectedItem as Van; } txMake.Text = tempVan.Make; txModel.Text = tempVan.Model; txPrice.Text = tempVan.Price.ToString(); txYear.Text = tempVan.Year.ToString(); txMileage.Text = tempVan.Mileage.ToString(); txColour.Text = tempVan.Colour.ToString(); txDescription.Text = tempVan.Description; txImgPath.Text = tempVan.imagePath; cbxVanType.SelectedItem = tempVan.VanType; cbxWheelbase.SelectedItem = tempVan.Wheelbase; }
private void btnDelete_Click(object sender, RoutedEventArgs e) { if(lbxCars.SelectedItem != null) { txCarDetails.Text = ""; if (lbxCars.SelectedItem.GetType().Name == "Car") { Car selectedCar = lbxCars.SelectedItem as Car; if (selectedCar != null) { AllList.Remove(selectedCar); CarList.Remove(selectedCar); } } else if (lbxCars.SelectedItem.GetType().Name == "Bike") { Bike selectedBike = lbxCars.SelectedItem as Bike; if (selectedBike != null) { AllList.Remove(selectedBike); BikeList.Remove(selectedBike); } } else if (lbxCars.SelectedItem.GetType().Name == "Van") { Van selectedVan = lbxCars.SelectedItem as Van; if (selectedVan != null) { AllList.Remove(selectedVan); VanList.Remove(selectedVan); } } UpdateListbox(); } }
private void lbxCars_SelectionChanged(object sender, SelectionChangedEventArgs e) { if(lbxCars.SelectedItem != null) { if (lbxCars.SelectedItem.GetType().Name == "Car") { Car selectedCar = lbxCars.SelectedItem as Car; txCarDetails.Text = selectedCar.VehDisplayDetails(); imgCar.Source = new BitmapImage(new Uri(selectedCar.imagePath, UriKind.Relative)); } else if (lbxCars.SelectedItem.GetType().Name == "Bike") { Bike selectedBike = lbxCars.SelectedItem as Bike; txCarDetails.Text = selectedBike.VehDisplayDetails(); imgCar.Source = new BitmapImage(new Uri(selectedBike.imagePath, UriKind.Relative)); } else if (lbxCars.SelectedItem.GetType().Name == "Van") { Van selectedVan = lbxCars.SelectedItem as Van; txCarDetails.Text = selectedVan.VehDisplayDetails(); imgCar.Source = new BitmapImage(new Uri(selectedVan.imagePath, UriKind.Relative)); } } }
private void btnAddVan_Click(object sender, RoutedEventArgs e) { if (txImgPath.Text != null && txMake.Text != null && txModel.Text != null && txPrice.Text != null && txYear.Text != null && txMileage.Text != null && txColour.Text != null && txDescription.Text != null && txImgPath != null) { try { Van tempVan = new Van(); tempVan.Make = txMake.Text; tempVan.Model = txModel.Text; tempVan.Price = Convert.ToInt32(txPrice.Text); tempVan.Year = Convert.ToInt32(txYear.Text); tempVan.Mileage = Convert.ToInt32(txMileage.Text); tempVan.Colour = txColour.Text; string selectionType = cbxVanType.SelectedItem.ToString(); string selectionWheels = cbxWheelbase.SelectedItem.ToString(); tempVan.imagePath = txImgPath.Text; foreach (var type in tempVan.possibleVanTypes) { if (selectionType == type) { tempVan.VanType = selectionType; break; } else { tempVan.VanType = tempVan.possibleVanTypes[5]; } } foreach (var wheel in tempVan.possibleWheelbase) { if (selectionWheels == wheel) { tempVan.Wheelbase = selectionWheels; break; } else { tempVan.Wheelbase = tempVan.possibleWheelbase[3]; } } tempVan.Description = txDescription.Text; tempVan.imagePath = txImgPath.Text; //get link to main window MainWindow main = this.Owner as MainWindow; //add Car main.VanList.AddLast(tempVan); main.AllList.AddLast(tempVan); //close window this.Close(); main.UpdateListbox(); } catch (FormatException formatEx) { MessageBox.Show("Error in input, Probably a string in a number field (Price, Year or Mileage) -->" + formatEx.Message); } } }