示例#1
0
        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;
        }
示例#2
0
        private void DisplayInfo(object sender, RoutedEventArgs e)
        {
            Button     b      = sender as Button;
            TripDriver tripdr = b.CommandParameter as TripDriver;

            Panel.SetZIndex(DriversListView, -1);
            Panel.SetZIndex(DriverDetails, 1);
            Panel.SetZIndex(btnBack, 1);
            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.DriverNr == id);
                DriverDetails.Items.Add("Name: " + dr.Name);
                DriverDetails.Items.Add("LastName: " + dr.Lastname);
                DriverDetails.Items.Add("Car model: " + car.Model);
                DriverDetails.Items.Add("Car year: " + car.Year);
                DriverDetails.Items.Add("Seats: " + car.Size);
            }
        }
示例#3
0
 private void btnSearch_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(xCordDest.Text) && !string.IsNullOrEmpty(yCordDest.Text))
     {
         try
         {
             List <TripDriver> tripDr = new List <TripDriver>();
             using (TaxiDBEntities2 context = new TaxiDBEntities2())
             {
                 var drivers = context.Drivers.ToList();
                 foreach (Driver driver in drivers)
                 {
                     if (driver.Availability)
                     {
                         Car        car = context.Cars.First(c => c.DriverNr == driver.Id);
                         TripDriver td  = new TripDriver();
                         td.id    = driver.Id;
                         td.car   = (car.Model + " " + car.Year + " seats: " + car.Size);
                         td.time  = driver.time(int.Parse(xCordLoc.Text), int.Parse(yCordLoc.Text), durationKm).ToString();
                         td.price = driver.price(int.Parse(xCordLoc.Text), int.Parse(yCordLoc.Text), Convert.ToDouble(driver.Price), pricePKM);
                         tripDr.Add(td);
                     }
                 }
                 List <TripDriver> SortedList = tripDr.OrderBy(o => o.time).ToList();
                 DriversListView.ItemsSource = SortedList;
             }
         }
         catch (FormatException)
         {
             LabelErrLoc.Content = "Location input incorrect";
         }
     }
     else
     {
         MessageBox.Show("Enter your destination!");
     }
 }