private void button_update_gps_Click(object sender, EventArgs e) { if (button_update_gps.Text == "Edit") { textBox_Latitude.Enabled = true; textBox_Longitude.Enabled = true; button_show_on_map.Enabled = false; button_update_gps.Text = "Update"; } else { textBox_Latitude.Enabled = false; textBox_Longitude.Enabled = false; button_show_on_map.Enabled = true; button_update_gps.Text = "Edit"; if (_car.GpsID != null) { //update GPSCoordinate CurrentGPS = Program.db.GPSCoordinates.Find(_car.GpsID); // _car.GPSCoordinate = CurrentGPS; CurrentGPS.Latitude = Double.Parse(textBox_Latitude.Text); CurrentGPS.Longitude = Double.Parse(textBox_Longitude.Text); Program.db.SaveChanges(); } } }
private void SaveCloseClick(object sender, EventArgs e) { _car.Color = textBox_color.Text; _car.Wheels = Int32.Parse(NM_Wheels.Text); _car.Seats = Int32.Parse(textBox_seats.Text); _car.Drivetrain = textBox_drivetrain.Text; _car.BHP = Int32.Parse(textBox_BHP.Text); _car.ApkDate = textBox_ApkDate.Value.Date; _car.LicensePlate = textBox_license.Text; _car.ManufacturingDate = textBox_manufacturingDate.Value.Date; _car.Brand = textBox_brand.Text; _car.Model = textBox_model.Text; _car.Catagory = textBox_catagory.Text; _car.FuelType = textBox_fuel.Text; _car.Mileage = Int32.Parse(textBox_mileage.Text); _car.LeftOrRightHand = CheckSteeringwheel(); if (listViewPerson.SelectedItems.Count > 0) { int PersonID = Int32.Parse(listViewPerson.SelectedItems[0].Name); Person selectedPerson = Program.db.Persons.Find(PersonID); _car.Person = selectedPerson; } if (_car.GpsID == null) { GPSCoordinate _gps = new GPSCoordinate(); Program.db.GPSCoordinates.Add(_gps); GPSCoordinate selectedGPS = Program.db.GPSCoordinates.Find(_gps.ID); _car.GPSCoordinate = selectedGPS; } _car.GPSCoordinate.Latitude = double.Parse(textBox_Latitude.Text); _car.GPSCoordinate.Longitude = double.Parse(textBox_Longitude.Text); // add fleetID to car _car.FleetID = Fleet.selectedID; //save car changes' Program.db.Cars.AddOrUpdate(_car); Program.db.SaveChanges(); //close the form(); Close(); }
private void button_delete_Click(object sender, EventArgs e) { // check if there is something selected if (listViewCar.SelectedItems.Count > 0) { var CarID = listViewCar.SelectedItems[0].Tag; Car selectedCar = Program.db.Cars.Find(CarID); GPSCoordinate gpsFromSelectedCar = Program.db.GPSCoordinates.Find(selectedCar.GpsID); Program.db.GPSCoordinates.Remove(gpsFromSelectedCar); Program.db.Cars.Remove(selectedCar); Program.db.SaveChanges(); ListOfFilteredCars = null; ShowList(); } }