private void SelectDriver(object sender, RoutedEventArgs e) { Button b = sender as Button; TripDriver tripdr = b.CommandParameter as TripDriver; int id = tripdr.id; using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Driver dr = context.Drivers.First(c => c.Id == id); Car car = context.Cars.First(c => c.Id == dr.ActiveCar); Passenger ps = context.Passengers.First(c => c.Username == user); dr.Availability = false; context.Trips.Add(new Trip { StartX = int.Parse(xCordLoc.Text), StartY = int.Parse(yCordLoc.Text), EndX = int.Parse(xCordDest.Text), EndY = int.Parse(yCordDest.Text), StartTime = DateTime.Now, CarNr = car.Id, PassengerNr = ps.Id, Price = position.distance(int.Parse(xCordLoc.Text), int.Parse(yCordLoc.Text), int.Parse(xCordDest.Text), int.Parse(yCordDest.Text)) * dr.Price, Range = position.distance(int.Parse(xCordLoc.Text), int.Parse(yCordLoc.Text), int.Parse(xCordDest.Text), int.Parse(yCordDest.Text)), Status = false }); context.SaveChanges(); } MessageBox.Show("Your driver will arrive in: " + tripdr.time + "\n" + "Car: " + tripdr.car); LabelTripData.Content = "your driver will arrive in: " + tripdr.time; btnEndTrip.Visibility = Visibility.Visible; }
private string registerAcc() { using (TaxiDBEntities2 context = new TaxiDBEntities2()) { context.Passengers.Add(new Passenger { Username = regUser.Text, Password = regPass.Text }); context.SaveChanges(); } return(regUser.Text); }
private string registerAcc() { try { using (TaxiDBEntities2 context = new TaxiDBEntities2()) { context.Drivers.Add(new Driver { Username = regUser.Text, Password = regPass.Text, Price = double.Parse(regPrice.Text), Availability = true, Name = regName.Text, Lastname = regLastName.Text }); context.SaveChanges(); Driver driver = context.Drivers.FirstOrDefault(c => c.Username == regUser.Text); context.Cars.Add(new Car { Year = int.Parse(regCarYear.Text), Size = int.Parse(regCarSize.Text), Model = regCarModel.Text, DriverNr = driver.Id }); context.SaveChanges(); Car car = context.Cars.FirstOrDefault(c => c.DriverNr == driver.Id); driver.ActiveCar = car.Id; context.SaveChanges(); } } catch (FormatException) { MessageBox.Show("Invalid input"); } return(regUser.Text); }
private void AddCar_Click(object sender, RoutedEventArgs e) { using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Driver dr = context.Drivers.First(c => c.Username == user); context.Cars.Add(new Car { Model = AddModel.Text, Year = int.Parse(AddYear.Text), Size = int.Parse(AddSize.Text), DriverNr = dr.Id }); context.SaveChanges(); } LabelSuccesfulCar.Content = "Car added"; listDriversCars(); }
private void addLoc_Click(object sender, RoutedEventArgs e) { try { using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Driver dr = context.Drivers.First(c => c.Username == user); dr.CoordX = int.Parse(xCordLoc.Text); dr.CordY = int.Parse(yCordLoc.Text); context.SaveChanges(); LabelSuccesfulLoc.Content = "Location updated"; } } catch (FormatException) { MessageBox.Show("Incorrect input"); } }
private void btnEndTrip_Click(object sender, RoutedEventArgs e) { LabelTripData.Content = ""; btnEndTrip.Visibility = Visibility.Hidden; using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Passenger ps = context.Passengers.First(c => c.Username == user); Trip tr = context.Trips.First(c => c.PassengerNr == ps.Id && c.Status == false); Driver dr = context.Drivers.First(c => c.ActiveCar == tr.CarNr); tr.EndTime = DateTime.Now; tr.Status = true; tr.EndX = int.Parse(xCordDest.Text); tr.EndY = int.Parse(yCordDest.Text); dr.CoordX = int.Parse(xCordDest.Text); dr.CordY = int.Parse(yCordDest.Text); dr.Availability = true; context.SaveChanges(); } }
private void RemoveCar(object sender, RoutedEventArgs e) { Button b = sender as Button; DriversCar drCar = b.CommandParameter as DriversCar; int idToRemove = drCar.id; using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Driver dr = context.Drivers.First(c => c.Username == user); if (dr.ActiveCar == idToRemove) { MessageBox.Show("Cannot remove active car"); } else { var carToRemove = context.Cars.First(x => x.Id == idToRemove); context.Cars.Remove(carToRemove); context.SaveChanges(); } } listDriversCars(); }
private void SelectCar(object sender, RoutedEventArgs e) { Button b = sender as Button; DriversCar drCar = b.CommandParameter as DriversCar; int idToSelect = drCar.id; using (TaxiDBEntities2 context = new TaxiDBEntities2()) { Driver dr = context.Drivers.First(c => c.Username == user); if (dr.ActiveCar == idToSelect) { MessageBox.Show("The car is already selected"); } else { dr.ActiveCar = idToSelect; context.SaveChanges(); Car activeCar = context.Cars.First(c => c.Id == dr.ActiveCar); LabelActiveCar.Content = "Active car: " + activeCar.Model + " " + activeCar.Year; } } }