private void LoadListBoxCreatedVehicles()
        {
            Fahrzeugtyp aVehicleType = (Fahrzeugtyp)comboBoxVehicleType.SelectedItem;

            if (aVehicleType != null)
            {
                list.VehicleSortedByTypeList.Clear();
                listBoxVehicleInformation.Items.Clear();
                foreach (Fahrzeug vehicle in list.VehicleList)
                {
                    if (aVehicleType.Equals(vehicle.Fahrzeugtyp) && vehicle.Verfügbar)
                    {
                        list.addToVehicleSortedByTypeList(vehicle);
                    }
                }

                if (list.VehicleSortedByTypeList.Count != 0)
                {
                    foreach (Fahrzeug vehicle in list.VehicleSortedByTypeList)
                    {
                        listBoxVehicleInformation.Items.Add(vehicle);
                    }

                    EnableOrderComponents(true);
                    listBoxVehicleInformation.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("Für diesen Fahrzeugtyp sind momentan keine Fahrzeuge verfügbar.");
                    listBoxVehicleInformation.Items.Clear();
                    EnableOrderComponents(false);
                }
            }
        }
        private void LoadListBoxCreatedVehicles()
        {
            Fahrzeugtyp aVehicleType = (Fahrzeugtyp)comboBoxVehicleType.SelectedItem;

            if (aVehicleType != null)
            {
                list.VehicleSortedByTypeList.Clear();
                listBoxCreatedVehicles.Items.Clear();
                foreach (Fahrzeug vehicle in list.VehicleList)
                {
                    if (aVehicleType.Equals(vehicle.Fahrzeugtyp))
                    {
                        list.addToVehicleSortedByTypeList(vehicle);
                    }
                }

                foreach (Fahrzeug vehicle in list.VehicleSortedByTypeList)
                {
                    listBoxCreatedVehicles.Items.Add(vehicle);
                }

                if (!buttonCreateVehicle.IsEnabled)
                {
                    listBoxCreatedVehicles.SelectedIndex = 0;
                }
            }
        }
        private void CreateVehicle()
        {
            Fahrzeug newVehicle     = null;
            bool     textHasSpace   = false;
            bool     textWrongInput = false;

            if (!textBoxDescription.Text.Contains(" ") && !textBoxBrand.Text.Contains(" ") && !textBoxVintage.Text.Contains(" ") && !textBoxMileage.Text.Contains(" ") &&
                !textBoxGearChange.Text.Contains(" ") && !textBoxSeats.Text.Contains(" ") && !textBoxDoors.Text.Contains(" ") && !textBoxRentPerDay.Text.Contains(" "))
            {
                if (!textBoxDescription.Text.Equals("") && !textBoxBrand.Text.Equals("") && !textBoxVintage.Text.Equals("") && !textBoxMileage.Text.Equals("") && comboBoxVehicleType.SelectedItem != null &&
                    comboBoxInsurancePackage.SelectedItem != null && !textBoxGearChange.Text.Equals("") && !textBoxSeats.Text.Equals("") && !textBoxDoors.Text.Equals("") && !textBoxRentPerDay.Text.Equals("") && !HasTextInputOnlyCommas(textBoxRentPerDay.Text))
                {
                    Fahrzeugtyp        aVehicleType      = (Fahrzeugtyp)comboBoxVehicleType.SelectedItem;
                    Versicherungspaket aInsurancePackage = (Versicherungspaket)comboBoxInsurancePackage.SelectedItem;

                    newVehicle                      = new Fahrzeug();
                    newVehicle.FahrzeugID           = 0;
                    newVehicle.Fahrzeugtyp          = aVehicleType;
                    newVehicle.FahrzeugtypID        = aVehicleType.FahrzeugtypID;
                    newVehicle.Versicherungspaket   = aInsurancePackage;
                    newVehicle.VersicherungspaketID = aInsurancePackage.VersicherungspaketID;
                    newVehicle.Bezeichnung          = textBoxDescription.Text;
                    newVehicle.Marke                = textBoxBrand.Text;
                    newVehicle.Baujahr              = Convert.ToInt32(textBoxVintage.Text);
                    newVehicle.Kilometerstand       = Convert.ToDouble(textBoxMileage.Text);
                    newVehicle.Schaltung            = textBoxGearChange.Text;
                    newVehicle.Sitze                = Convert.ToInt32(textBoxSeats.Text);
                    newVehicle.Türe                 = Convert.ToInt32(textBoxDoors.Text);
                    newVehicle.Naviagationssystem   = Convert.ToBoolean(checkBoxNavigation.IsChecked);
                    newVehicle.Klimaanlage          = Convert.ToBoolean(checkBoxAirConditioning.IsChecked);
                    newVehicle.MietpreisProTag      = Convert.ToDouble(textBoxRentPerDay.Text);
                    newVehicle.Verfügbar            = Convert.ToBoolean(checkBoxAvailability.IsChecked);
                }
                else
                {
                    textWrongInput = true;
                    MessageBox.Show("Bitte füllen Sie die Fahrzeugdaten korrekt aus.");
                }
            }
            else
            {
                textHasSpace = true;
                MessageBox.Show("In Ihren Fahrzeugdaten dürfen keine Leerzeichen enthalten sein.");
            }

            if (!textWrongInput && !textHasSpace)
            {
                var result = MessageBox.Show("Möchten Sie ein neues Fahrzeug anlegen?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    ClearComponents();
                    list.addToVehicleList(newVehicle);
                    LoadListBoxCreatedVehicles();
                    comboBoxVehicleType.SelectedItem = newVehicle.Fahrzeugtyp;
                }
            }
        }
Exemplo n.º 4
0
        // Funktion zum hinzufügen weiterer Fahrzeuge
        // Erst wird die Angabe des Typs gefordert und dann darauf hin ein entsprechendes neues Fahrzeug Objekt vom angegebenen Typ erstellt
        // Danach wird man aufgefordert die benötigten Daten anzugeben
        public static void addNewFahrzeug(List <Fahrzeug> alleFahrzeuge, Parkplatz[] Parkplätze)
        {
            bool fahrzeugAngelegt = false;

            do
            {
                try
                {
                    //Initialisierung des Enums mit einem Defaultwert
                    Fahrzeugtyp einFahrzeugtyp = Fahrzeugtyp.Default;

                    Console.WriteLine("Geben Sie bitte den gewünschten Fahrzeugtyp ein: \nPKW \nLKW\nMotorrad\n");
                    string fahrzeugtyp = Convert.ToString(Console.ReadLine());
                    fahrzeugtyp = fahrzeugtyp.ToLower();
                    // Prüfung des gewünschten Fahrzeugtyps und anlegen eines neuen Objektes des gewünschten Typs
                    if (fahrzeugtyp != "pkw" && fahrzeugtyp != "lkw" && fahrzeugtyp != "motorrad")
                    {
                        throw new Exception();
                    }
                    if (fahrzeugtyp == "pkw")
                    {
                        einFahrzeugtyp = Fahrzeugtyp.PKW;
                    }
                    if (fahrzeugtyp == "lkw")
                    {
                        einFahrzeugtyp = Fahrzeugtyp.LKW;
                    }
                    if (fahrzeugtyp == "motorrad")
                    {
                        einFahrzeugtyp = Fahrzeugtyp.Motorrad;
                    }
                    // Frage nach den Daten die für alle Fahrzeugtypen gebraucht werden
                    Console.WriteLine("Geben Sie bitte den Hersteller an:");
                    string hersteller = Convert.ToString(Console.ReadLine());

                    Console.WriteLine("Geben Sie bitte das Modell an:");
                    string modell = Convert.ToString(Console.ReadLine());

                    Console.WriteLine("Geben Sie bitte das Kennzeichen an:");
                    string kennzeichen = Convert.ToString(Console.ReadLine());

                    Console.WriteLine("Geben Sie bitte das Anschaffungsjahr an:");
                    string anschaffungsjahrString = (Console.ReadLine());
                    if (!Int32.TryParse(anschaffungsjahrString, out int anschaffungsjahr))
                    {
                        throw new Exception();
                    }

                    Console.WriteLine("Geben Sie bitte den Anschaffungspreis an:");
                    string anschaffungspreisString = (Console.ReadLine());
                    if (!Int32.TryParse(anschaffungspreisString, out int anschaffungspreis))
                    {
                        throw new Exception();
                    }

                    //Parkplatzabfrage
                    // Hier wird sowohl geprüft, ob der Parkplatz für das Fahrzeug kompatibel ist, sowie ob der Parkplatz frei ist
                    bool ParkplatzFrei     = false;
                    bool ParkplatztypPasst = false;
                    int  ParkplatzGewünscht;
                    do
                    {
                        Console.WriteLine("Geben Sie bitte den gewünschten Parkplatz ein. \nDas Parkhaus hat 300 Stellplätze.\nPKW Parkplätze: 1-100\nLKW Parkplätze: 101-200 \nMotorradstellplätze: 201- 300 ");
                        string parkplatzStringGewünscht = (Console.ReadLine());
                        if (!Int32.TryParse(parkplatzStringGewünscht, out ParkplatzGewünscht))
                        {
                            throw new Exception();
                        }
                        ParkplatzFrei     = false;
                        ParkplatztypPasst = false;

                        if (Parkplätze[ParkplatzGewünscht - 1].Parkplatztyp.ToString() != einFahrzeugtyp.ToString())
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nDer Parkplatz ist leider nicht für diesen Fahrzeugtyp kompatibel!\n");
                            Console.ForegroundColor = ConsoleColor.White;
                        }

                        else if (Parkplätze[ParkplatzGewünscht - 1].Parkplatztyp.ToString() == einFahrzeugtyp.ToString())
                        {
                            ParkplatztypPasst = true;
                        }

                        if (Parkplätze[ParkplatzGewünscht - 1].Frei == false)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nDer Parkplatz ist leider bereits belegt! Bitte wählen Sie einen anderen Parkplatz aus.\n");
                            Console.ForegroundColor = ConsoleColor.White;
                        }

                        else if (Parkplätze[ParkplatzGewünscht - 1].Frei != false)
                        {
                            ParkplatzFrei = true;
                        }
                    }while(ParkplatzFrei != true || ParkplatztypPasst != true);

                    //Hier wird nach den Fahrzeugtyp spezifischen Daten gefragt
                    switch (fahrzeugtyp)
                    {
                    case "pkw":
                        Console.WriteLine("Geben Sie bitte den bitte geben Sie den Hubraum an:");
                        string pkwhubraumString = (Console.ReadLine());
                        if (!Int32.TryParse(pkwhubraumString, out int pkwhubraum))
                        {
                            throw new Exception();
                        }

                        Console.WriteLine("Geben Sie bitte den bitte geben Sie die Leistung an:");
                        string leistungString = (Console.ReadLine());
                        if (!Int32.TryParse(leistungString, out int leistung))
                        {
                            throw new Exception();
                        }

                        Console.WriteLine("Geben Sie bitte die Schadstoffklasse ein: (Schadstoffarm, Diesel, Normal)");
                        string schadstoffklasse = Convert.ToString(Console.ReadLine());
                        schadstoffklasse = schadstoffklasse.ToLower();

                        Schadstoffklasse EnumSchadstoffklasse;
                        if (schadstoffklasse == "schadstoffarm")
                        {
                            EnumSchadstoffklasse = Schadstoffklasse.Schadstoffarm;
                        }
                        else if (schadstoffklasse == "diesel")
                        {
                            EnumSchadstoffklasse = Schadstoffklasse.Diesel;
                        }
                        else if (schadstoffklasse == "normal")
                        {
                            EnumSchadstoffklasse = Schadstoffklasse.Normal;
                        }
                        else
                        {
                            throw new Exception();
                        }

                        alleFahrzeuge.Add(new PKW(hersteller, modell, kennzeichen, new DateTime(anschaffungsjahr, 1, 1), anschaffungspreis, ParkplatzGewünscht, pkwhubraum, leistung, EnumSchadstoffklasse));
                        fahrzeugAngelegt = true;


                        break;

                    case "lkw":

                        Console.WriteLine("Geben Sie bitte den bitte geben Sie die Anzahl der Achsen an:");
                        string anzahlAchsenString = (Console.ReadLine());
                        if (!Int32.TryParse(anzahlAchsenString, out int anzahlAchsen))
                        {
                            throw new Exception();
                        }

                        Console.WriteLine("Geben Sie bitte den bitte geben Sie die maximale Zuladung in Tonnen an:");
                        string zuladungInTonnenString = (Console.ReadLine());
                        if (!Int32.TryParse(zuladungInTonnenString, out int zuladungInTonnen))
                        {
                            throw new Exception();
                        }

                        alleFahrzeuge.Add(new LKW(hersteller, modell, kennzeichen, new DateTime(anschaffungsjahr, 1, 1), anschaffungspreis, ParkplatzGewünscht, anzahlAchsen, zuladungInTonnen));
                        fahrzeugAngelegt = true;
                        break;

                    case "motorrad":
                        Console.WriteLine("Geben Sie bitte den bitte geben Sie den Hubraum an:");
                        string motorradhubraumString = (Console.ReadLine());
                        if (!Int32.TryParse(motorradhubraumString, out int motorradhubraum))
                        {
                            throw new Exception();
                        }

                        alleFahrzeuge.Add(new Motorräder(hersteller, modell, kennzeichen, new DateTime(anschaffungsjahr, 1, 1), anschaffungspreis, ParkplatzGewünscht, motorradhubraum));
                        fahrzeugAngelegt = true;
                        break;
                    }

                    //Bei erfolgreichem erstellen des Fahrzeugs den Parkplatz belegen
                    Parkplätze[ParkplatzGewünscht - 1].Frei = false;
                    Console.WriteLine("Das Fahrzeug wurde erfolgreich angelegt");
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\nDie angegebenen Daten sind ungültig! Bitte geben Sie gültige Werte ein\n");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            } while (fahrzeugAngelegt == false);
        }