Пример #1
0
        public bool UserMoveVehicle()
        {
            string regNum = userInput.AskForReg();
            // todo: Need to tell user why it failed.
            int place = SearchForVehicle(regNum).ParkingNum;

            if (SearchForReg(regNum) == -1)
            {
                return(false);
            }
            int moveToIndex = userInput.AskForNumber(1, 100);

            moveToIndex--;
            // todo: Need to tell user why it failed.
            bool success = MoveTo(regNum, moveToIndex);

            if (success)
            {
                userInput.MoveOrder(SearchForVehicle(regNum), place);
                DbHandler.Save(vehicles);

                return(true);
            }
            else
            {
                Console.WriteLine("Couldn't move to there.");
                userInput.BackToMenu();
                DbHandler.Save(vehicles);

                return(false);
            }
        }
Пример #2
0
        public bool UserRemovesVehicle()
        {
            string regNum = userInput.AskForReg();

            Vehicle vehicle = SearchForVehicle(regNum);

            if (vehicle.IsCar)
            {
                userInput.CheckOutVehicle(vehicle);
                vehicles.Remove(vehicle);
                DbHandler.Save(vehicles);

                return(true);
            }
            else
            {
                foreach (Vehicle vehicle1 in vehicles)
                {
                    if (vehicle1.ParkingNum == vehicle.ParkingNum)
                    {
                        userInput.CheckOutVehicle(vehicle);
                        vehicle1.FillsWholeSpace = false;
                        vehicles.Remove(vehicle);
                        DbHandler.Save(vehicles);

                        return(true);
                    }
                }
            }


            DbHandler.Save(vehicles);

            return(false);
        }
Пример #3
0
        public bool UserOptimizeMcSpace()
        {
            // find all optimize opertunities and present in an array.
            List <int> optimizeChoises = FindOptimizeMcChoises();
            int        numChoises;

            if (optimizeChoises.Count % 2 == 1)
            {
                numChoises = (optimizeChoises.Count - 1) / 2;
            }
            else
            {
                numChoises = optimizeChoises.Count / 2;
            }

            int[,] choices = new int[numChoises, 2];

            for (int i = 0; i < numChoises; i += 2)
            {
                choices[i, 0] = optimizeChoises[0];
                choices[i, 1] = optimizeChoises[i * 2 + 1];
            }

            if (choices.GetLength(0) == 0)
            {
                userInput.PrintNothingtoSeeHere();
                return(false);
            }
            //lets user make a choice of alternetives.
            int userChoice = userInput.AskForOptimizationChoice(choices, vehicles);

            int fromNum = vehicles[choices[userChoice, 1]].ParkingNum;
            int toNum   = vehicles[choices[userChoice, 0]].ParkingNum;

            Console.WriteLine("Move vehicle {0} from {1} to {2}", vehicles[choices[userChoice, 0]].RegNum, fromNum, toNum);
            //Console.WriteLine("Press enter to continue.");
            //Console.ReadLine();
            userInput.BackToMenu();

            vehicles[choices[userChoice, 1]].ParkingNum      = toNum;
            vehicles[choices[userChoice, 0]].FillsWholeSpace = true;
            vehicles[choices[userChoice, 1]].FillsWholeSpace = true;

            // todo: Let user know where to drive cars.
            DbHandler.Save(vehicles);
            return(true);
        }
Пример #4
0
        public bool UserAddVehicle()
        {
            string regNum = userInput.AskForReg();

            if (SearchForReg(regNum) != -1)
            {
                // Go to menu.
                Console.WriteLine("That vehicle has already checked in.");
                userInput.BackToMenu();
                return(false);
            }
            bool    isCar   = userInput.AskForType();
            Vehicle vehicle = new Vehicle(regNum, isCar);

            vehicle = InsertVehicle(vehicle);
            // Om fordonet ej blivit tilldelad en ruta.
            userInput.DriveOrder(vehicle);
            DbHandler.Save(vehicles);
            return(vehicle.ParkingNum != -1);
        }
Пример #5
0
        public bool UserOptimizeSpace()
        {
            List <int> optimizeChoises = FindOptimizeChoice();

            if (optimizeChoises.Count == 0)
            {
                userInput.PrintNothingtoSeeHere();
                return(false);
            }


            int    optimizeChoise = optimizeChoises[2];
            string regPlate       = vehicles[optimizeChoise].RegNum;

            //Låter först användaren godkänna ändringen.
            if (userInput.OrderUserToMoveCars(optimizeChoises, regPlate))
            {
                DbHandler.Save(vehicles);
                return(MoveTo(regPlate, optimizeChoises[0]));
            }
            return(false);
        }
Пример #6
0
 public bool SaveToFile()
 {
     return(DbHandler.Save(vehicles));
 }