/// <summary> /// this is a click event to open service window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonService_Clicked(object sender, RoutedEventArgs e) { Button button = sender as Button; Vehicle vehicleService = button.DataContext as Vehicle; vehicleHistory = new VehicleHistory(); AddService addService = new AddService(vehicleService.Id, vehicleService.VehicleOdometer); addService.ShowDialog(); }
/// <summary> /// this is a click event to open history button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ViewButton_Clicked(object sender, RoutedEventArgs e) { Button selectedButton = (Button)sender; Vehicle v = selectedButton.CommandParameter as Vehicle; vehicleHistory = new VehicleHistory(v.RegistrationID, v.CarManufacture, v.CarModel, v.CarYear, v.FuelType, v.TankCapacity, v.VehicleOdometer, v.serviceCount); vehicleHistory.Owner = this; vehicleHistory.journeys = journeys.Where(journey => journey.vehicleID == v.Id).ToList(); vehicleHistory.JourneysListViewForHistory.ItemsSource = vehicleHistory.journeys; vehicleHistory.bookings = bookings.Where(booking => booking.Vehicleid == v.Id).ToList(); vehicleHistory.BookingsListViewForHistory.ItemsSource = vehicleHistory.bookings; vehicleHistory.fuelPurchases = fuelPurchases.Where(fuelP => fuelP.VId == v.Id).ToList(); vehicleHistory.FuelPurchasesViewForHistory.ItemsSource = vehicleHistory.fuelPurchases; vehicleHistory.services = services.Where(service => service.vehicleID == v.Id).ToList(); vehicleHistory.servicesListView.ItemsSource = vehicleHistory.services; vehicleHistory.ShowDialog(); }
/// <summary> /// this is click event to add service/service now! /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ServiceNowButton_Clicked(object sender, RoutedEventArgs e) { Service service = new Service(); service.vehicleID = id; service.ServiceOdometer = int.Parse(TextBoxLastOdometerForService.Text); service.ServiceDate = DateTime.Parse(DatePickerForLastServiceDate.Text); CarList.services.Add(service); // save new service to list of services Service.SaveServices(CarList.services); Vehicle relatedVehicle = CarList.vehicles.Find(v => v.Id == service.vehicleID); List <Service> relatedServicesWithVehicle = CarList.services.FindAll(s => s.vehicleID == relatedVehicle.Id); relatedVehicle.updateServicesCount(relatedServicesWithVehicle); vehicleHistory = new VehicleHistory(); vehicleHistory.servicesListView.ItemsSource = CarList.services; vehicleHistory.servicesListView.Items.Refresh(); Close(); }