private void btnSearchByName_Click(object sender, RoutedEventArgs e)
        {
            Panel.SetZIndex(DriversSearch, 1);
            Panel.SetZIndex(TripHistoryDatagrid, -1);
            Panel.SetZIndex(StatisticsBox, -1);
            List <DriverDetails> DrDet = new List <DriverDetails>();

            using (TaxiDBEntities2 context = new TaxiDBEntities2())
            {
                var drivers = context.Drivers.ToList();
                foreach (Driver driver in drivers)
                {
                    if (Regex.IsMatch(driver.Lastname, SearchByName.Text, RegexOptions.IgnoreCase))
                    {
                        Car           car = context.Cars.First(c => c.Id == driver.ActiveCar);
                        DriverDetails dd  = new DriverDetails();
                        dd.carModel     = car.Model;
                        dd.carYear      = Convert.ToInt32(car.Year);
                        dd.carSize      = Convert.ToInt32(car.Size);
                        dd.availability = driver.Availability;
                        dd.name         = driver.Name;
                        dd.lastName     = driver.Lastname;
                        dd.price        = driver.Price.ToString();
                        DrDet.Add(dd);
                    }
                }
                DriversSearch.ItemsSource = DrDet;
            }
        }
        private void register_Click(object sender, RoutedEventArgs e)
        {
            bool done = false;

            using (TaxiDBEntities2 context = new TaxiDBEntities2())
            {
                Passenger passenger = context.Passengers.FirstOrDefault(c => c.Username == regUser.Text);
                if (passenger != null)
                {
                    labelErrReg.Content = "The username is already taken";
                    done = true;
                }
            }
            if (string.IsNullOrWhiteSpace(regUser.Text) || string.IsNullOrWhiteSpace(regPass.Text))
            {
                labelErrReg.Content = "You must enter all required fields";
                done = true;
            }
            else if (regPass.Text != regPassRep.Text)
            {
                labelErrReg.Content = "Passwords entered do not match";
                done = true;
            }
            if (!done)
            {
                systemWindow win = new systemWindow(registerAcc());
                win.Show();
                this.Close();
            }
        }
        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;
        }
 public systemWindow(string LoggedUser)
 {
     InitializeComponent();
     user = LoggedUser;
     LabelHelloUser.Content = "Hello " + user;
     using (TaxiDBEntities2 context = new TaxiDBEntities2())
     {
         loggedPass = context.Passengers.First(c => c.Username == user);
     }
 }
 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 void login_Click(object sender, RoutedEventArgs e)
 {
     using (TaxiDBEntities2 context = new TaxiDBEntities2())
     {
         Passenger passenger = context.Passengers.FirstOrDefault(c => c.Username == loginUser.Text && c.Password == loginPass.Text);
         if (passenger != null)
         {
             systemWindow win = new systemWindow(passenger.Username);
             win.Show();
             this.Close();
         }
     }
 }
 private void btnCheckStatistics_Click(object sender, RoutedEventArgs e)
 {
     StatisticsBox.Items.Clear();
     Panel.SetZIndex(DriversSearch, -1);
     Panel.SetZIndex(TripHistoryDatagrid, -1);
     Panel.SetZIndex(StatisticsBox, 1);
     using (TaxiDBEntities2 context = new TaxiDBEntities2())
     {
         Passenger ps = context.Passengers.First(c => c.Username == user);
         StatisticsBox.Items.Add("Total range traveled: " + context.Trips.Where(o => o.PassengerNr == ps.Id).Sum(p => p.Range));
         StatisticsBox.Items.Add("Total Price paid: " + context.Trips.Where(o => o.PassengerNr == ps.Id).Sum(p => p.Price));
         StatisticsBox.Items.Add("Average range per trip: " + context.Trips.Where(o => o.PassengerNr == ps.Id).Average(p => p.Range));
         StatisticsBox.Items.Add("Average price per trip: " + context.Trips.Where(o => o.PassengerNr == ps.Id).Average(p => p.Price));
     }
 }
 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();
 }
Exemple #9
0
 private void login_Click(object sender, RoutedEventArgs e)
 {
     using (TaxiDBEntities2 context = new TaxiDBEntities2())
     {
         Driver driver = context.Drivers.FirstOrDefault(c => c.Username == loginUser.Text && c.Password == loginPass.Password);
         if (driver != null)
         {
             DriversMainWindow win = new DriversMainWindow(loginUser.Text);
             win.Show();
             this.Close();
         }
         else
         {
             labelErrLogin.Content = "Incorrect usename or password";
         }
     }
 }
 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 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);
            }
        }
        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;
                }
            }
        }
        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 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!");
     }
 }
        private void listDriversCars()
        {
            List <DriversCar> drCar = new List <DriversCar>();

            using (TaxiDBEntities2 context = new TaxiDBEntities2())
            {
                Driver dr   = context.Drivers.First(c => c.Username == user);
                var    cars = context.Cars.ToList();
                foreach (Car car in cars)
                {
                    if (car.DriverNr == dr.Id)
                    {
                        DriversCar dc = new DriversCar();
                        dc.id  = car.Id;
                        dc.car = car.Model + " " + car.Year + " Seats: " + car.Size;
                        drCar.Add(dc);
                    }
                }
                List <DriversCar> SortedList = drCar.OrderBy(o => o.id).ToList();
                CarListView.ItemsSource = SortedList;
                Car activeCar = context.Cars.First(c => c.Id == dr.ActiveCar);
                LabelActiveCar.Content = "Active car: " + activeCar.Model + " " + activeCar.Year;
            }
        }
Exemple #17
0
 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);
 }