Ejemplo n.º 1
0
 public void Add()
 {
     if (selectedLorry.passengers.Count != selectedLorry.maximumPassengers)
     {
         Passenger passengerToAdd = new Passenger();
         Console.WriteLine("Add passenger");
         Console.Write("First name: ");
         passengerToAdd.firstName = Console.ReadLine();
         Console.Write("Last name: ");
         passengerToAdd.lastName = Console.ReadLine();
         selectedLorry.passengers.Add(passengerToAdd);
         selectedLorry = lorryServiceObj.Update(selectedLorry);
     }
     else
     {
         Console.WriteLine("This vehicle is full");
     }
 }
Ejemplo n.º 2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            lorryToEdit.vehicleName           = vehicleNameTextBox.Text;
            lorryToEdit.numberPlate           = numberPlateTextBox.Text;
            lorryToEdit.weight.kilograms      = Convert.ToDecimal(weightTextBox.Text);
            lorryToEdit.hasLoad               = loadCheckBox.Checked;
            lorryToEdit.weight.kilograms      = Convert.ToDecimal(loadWeightTextBox.Text);
            lorryToEdit.maximumPassengers     = Convert.ToInt32(maxPassengersTextBox.Text);
            lorryToEdit.maximumFuel.litres    = Convert.ToDecimal(maxFuelTextBox.Text);
            lorryToEdit.milage.milesPerGallon = Convert.ToDecimal(milageTextBox.Text);

            lorryServiceObj.Update(lorryToEdit);
            Close();
            (Owner as LorryFormView).FillLorryList();
        }
 private void PassengerLorryFormView_FormClosed(object sender, FormClosedEventArgs e)
 {
     lorryServicesObj.Update(lorryToEdit);
     (Owner as LorryFormView).FillLorryList();
 }
        public void Select(Lorry selectedLorry)
        {
            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("\nSelected Lorry:");
                PrintInfo(selectedLorry, false);
                Console.WriteLine("Choose an option:");
                Console.WriteLine("\t1. Edit");
                Console.WriteLine("\t2. Delete");
                Console.WriteLine("\t3. Calculate fuel");
                Console.WriteLine("\t4. Refuel");
                Console.WriteLine("\t5. Passengers");
                Console.WriteLine("\t6. Back");

                switch (Console.ReadKey(true).KeyChar)
                {
                case '1':
                    LorryEditConsoleView lorryEditConsoleView = new LorryEditConsoleView(selectedLorry);
                    selectedLorry = lorryServicesObj.Update(lorryEditConsoleView.Load());
                    break;

                case '2':
                    Console.Write("Type vehicle name to confirm:");
                    if (Console.ReadLine() == selectedLorry.vehicleName)
                    {
                        lorryServicesObj.Delete(selectedLorry);
                        exit = true;
                    }
                    else
                    {
                        Console.WriteLine("Cancelled");
                    }
                    break;

                case '3':
                    Console.Write("Enter distance in miles: ");
                    Distance distance = new Distance();
                    distance.miles = Convert.ToDecimal(Console.ReadLine());
                    selectedLorry  = lorryServicesObj.CalculateFuel(selectedLorry, distance);
                    break;

                case '4':
                    selectedLorry = lorryServicesObj.Refuel(selectedLorry);
                    break;

                case '5':
                    LorryPassengerConsoleView lorryPassengers = new LorryPassengerConsoleView(selectedLorry);
                    lorryPassengers.Load();
                    break;

                case '6':
                    exit = true;
                    break;

                default:
                    Console.WriteLine("Invalid input");
                    break;
                }
            }
        }