Esempio n. 1
0
        private int AddNewVehicleToSlot(Vehicle newVehicle)
        {
            foreach (var s in boxes)
            {
                result = s.Add(newVehicle);//if result is true, vehicle was successfully added, if not true a new box instance will be created
                if (!result)
                {
                    slotPosition++;

                    if (IsSlotNullOrEmpty())
                    {
                        boxes[slotPosition] = new ParkingBox(slotPosition);
                    }
                }
                else
                {
                    vehicleCount++;
                    Visualize.TextColor(Visualize.ColorType.Green, "\nAdding ");
                    Visualize.TextColor(Visualize.ColorType.Black, "Vehicle Regnr: ");
                    Visualize.TextColor(Visualize.ColorType.Magenta, $"{newVehicle.Regnr} ");
                    Visualize.TextColor(Visualize.ColorType.Black, "");
                    Console.ReadKey();
                    return(slotPosition);
                }
            }
            return(-1);
        }
        //borked
        public void MoveVehicle()
        {
            Console.Write("Enter Regnr for the vehicle you want to search for");
            Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
            Visualize.TextColor(Visualize.ColorType.Black, "");

            string regnr = SendToUserInput(Want_To_SetRegnr);

            if (!string.IsNullOrEmpty(regnr))
            {
                if (parkingLot.Contains(regnr) != -1)
                {
                    Console.Write("Enter a new box number between");
                    Visualize.TextColor(Visualize.ColorType.Red, " 1-100");
                    Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
                    Visualize.TextColor(Visualize.ColorType.Black, "");

                    string input = SendToUserInput(Want_To_MoveVehicle);
                    if (!string.IsNullOrEmpty(input))
                    {
                        int toInt = int.Parse(input);
                        Console.Write(parkingLot.CreateNewBox(regnr, toInt - 1));
                        BackUp.SaveDataToBin(parkingLot);
                        Console.ReadKey();
                    }
                }
                else
                {
                    Visualize.TextColor(Visualize.ColorType.Red, $"\nVehicle { regnr} not found!");
                    Visualize.TextColor(Visualize.ColorType.Black, "");
                    Console.ReadKey();
                }
            }
        }
Esempio n. 3
0
 private bool IsSlotNullOrEmpty()//checks if a vehicle object excist in any element of the array boxes and if the parkinglot is full
 {
     for (int i = slotPosition; i < boxes.Length; i++)
     {
         try
         {
             if (boxes[i] == null)
             {
                 return(true);
             }
             if (boxes[i].Vehicles.Count > 0)
             {
                 return(false);
             }
         }catch (IndexOutOfRangeException)
         {
             Console.Clear();
             Visualize.TextColor(Visualize.ColorType.Red, "The parkinglot is full, remove a vehicle to make space!");
             Visualize.TextColor(Visualize.ColorType.Black, "");
             Console.ReadKey();
         }
         finally
         {
         }
     }
     return(false);
 }
        public void SearchForVehicle()
        {
            Console.Write("Enter Regnr for the vehicle you want to search for");
            Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
            Visualize.TextColor(Visualize.ColorType.Black, "");
            string regnr = SendToUserInput(Want_To_SetRegnr);

            if (!string.IsNullOrEmpty(regnr))
            {
                Console.WriteLine(parkingLot.SearchForVehicle(regnr));
                Console.ReadKey();
            }
        }
        public void RemoveVehicle()
        {
            Console.Write("Enter Regnr for the vehicle you want to remove");
            Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
            Visualize.TextColor(Visualize.ColorType.Black, "");

            string regnr = SendToUserInput(Want_To_SetRegnr);

            if (!string.IsNullOrEmpty(regnr))
            {
                Console.Write(parkingLot.Remove(regnr));
                BackUp.SaveDataToBin(parkingLot);
                Console.ReadKey();
            }
        }
        Program()
        {
            Console.Title           = "Prauge Parking <3";
            Console.BackgroundColor = ConsoleColor.Yellow;
            orgenize.Parking        = BackUp.LoadDataFromBin();
            while (isRunning)
            {
                Console.Clear();
                Visualize.VisualizeMenu();
                switch (UserInput.HandleInput(Handle_Menu))
                {
                case "1":
                    orgenize.AddNewVehicle();
                    break;

                case "2":
                    orgenize.RemoveVehicle();
                    break;

                case "3":
                    orgenize.ShowAllVehicles();
                    break;

                case "4":
                    orgenize.SearchForVehicle();
                    break;

                case "5":
                    orgenize.MoveVehicle();
                    break;

                case "0":
                    Console.Clear();
                    Visualize.TextColor(Visualize.ColorType.Magenta, "\nClosing....\n\n");
                    Visualize.TextColor(Visualize.ColorType.Black, "");
                    isRunning = false;
                    break;

                default:
                    Visualize.TextColor(Visualize.ColorType.Red, "Error! Wrong input!");
                    Console.ReadKey();
                    Visualize.TextColor(Visualize.ColorType.Black, "");
                    break;
                }
            }
        }
        public void AddNewVehicle()
        {
            Console.Write("Enter Regnr for the vehicle you want to add");
            Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
            Visualize.TextColor(Visualize.ColorType.Black, "");

            string regnr = SendToUserInput(Want_To_SetRegnr);

            if (!string.IsNullOrEmpty(regnr))
            {
                if (parkingLot.Contains(regnr) == Not_Same_RegNr)
                {
                    Console.Write("Is it a Car ");
                    Visualize.TextColor(Visualize.ColorType.Red, "Y");
                    Visualize.TextColor(Visualize.ColorType.Black, "/");
                    Visualize.TextColor(Visualize.ColorType.Red, "N ");
                    Visualize.TextColor(Visualize.ColorType.Green, ":>_ ");
                    Visualize.TextColor(Visualize.ColorType.Black, "");

                    string type = SendToUserInput(Want_To_setVehicleType);

                    if (!string.IsNullOrEmpty(type))
                    {
                        if (type == "Y")
                        {
                            parkingLot.CreateNewVehicle(regnr, VehicleType.Car);
                        }
                        if (type == "N")
                        {
                            parkingLot.CreateNewVehicle(regnr, VehicleType.Bike);
                        }


                        BackUp.SaveDataToBin(parkingLot);
                    }
                }
                else
                {
                    Visualize.TextColor(Visualize.ColorType.Red, $"\nVehicle {regnr} already excist");
                    Visualize.TextColor(Visualize.ColorType.Black, "");
                    Console.ReadKey();
                }
            }
        }
        public static string SendToUserInput(uint n)
        {
            string input = null;

            try
            {
                return(input = UserInput.HandleInput(n));
            }
            catch (ArgumentException e)
            {
                Visualize.TextColor(Visualize.ColorType.Red, e.Message);
                Visualize.TextColor(Visualize.ColorType.Black, "");
                Console.ReadKey();
            }
            finally
            {
            }
            return(null);
        }