Exemple #1
0
        public static void GenerateVehicleGridBody(List <Vehicle> vehicles)
        {
            foreach (var item in vehicles)
            {
                Console.Write(item.Id);
                Console.Write("\t\t" + item.EnginePower);
                Console.Write("\t\t" + (!(item.EngineType > 0) ? "-" : item.EngineType.ToString()));
                Console.Write("\t" + item.ModelNumber);
                Console.Write("\t\t" + item.TireSize);

                if (item.GetType() == typeof(NormalVehicle))
                {
                    Console.Write("\t\t" + "-");
                    Console.Write("\t" + "-");
                }
                else if (item.GetType() == typeof(SportsVehicle))
                {
                    var items = (SportsVehicle)item;
                    Console.Write("\t\t" + items.Turbo);
                    Console.Write("\t" + "-");
                }
                else if (item.GetType() == typeof(HeavyVehicle))
                {
                    HeavyVehicle items = (HeavyVehicle)item;
                    Console.Write("\t\t" + "-");
                    Console.Write("\t" + items.Weight);
                }
                Console.WriteLine();
            }
        }
        public static void Main()
        {
            while (true)
            {
                Display         Display         = new Display();
                Functions       functions       = new Functions();
                List <Ticket>   tickets         = new List <Ticket>();
                IParkingService ParkingServices = new ParkingSevice();
                ITicketService  ticketService   = new TicketService();
                int             option;
                string          regionalCode;
                Display.Print("WELCOME TO ABCD PARKING LOT");
                Display.Print("******************************************");
                Display.Print("please enter number of slots for 2 wheeler");
                int twoWheeler = functions.Input();
                Display.Print("please enter number of slots for 4 wheeler");
                int fourWheeler = functions.Input();
                Display.Print("please enter number of slots for heavy vehicle");
                int heavyVehicle = functions.Input();
                Display.Print("do you want to enter the Regional Code\n\t1.yes\n\t2.no");
                option = functions.Input();
                switch (option)
                {
                case 1:
                    Display.Print("please enter a Regional Code:");
                    regionalCode = Display.Scan();
                    functions.Regionalcode(regionalCode);
                    break;

                default:
                    regionalCode = null;
                    break;
                }
                ParkingServices.InitializeParkingLot(twoWheeler, fourWheeler, heavyVehicle);
                bool Exit = false;
                do
                {
                    Display.Print("select a option\n\t1.park\n\t2.Un-park\n\t3.Display status of all slots\n\t4.Exit(Re-Initialize)");
                    option = functions.Input();
                    switch (option)
                    {
                    case 1:
                        Display.Print("please enter the valid details of the vehicle");
                        Vehicle vehicle = new Vehicle();
                        Display.Print("Choose the type of vehicle\n\t1.2 wheeler\n\t2.4 wheeler\n\t3.heavy vehicle\n\t");
                        int         choice         = functions.Input();
                        var         Type           = (VehicleModel)choice;
                        List <Slot> AvailableSlots = ParkingServices.GetAvailableSlots(Type);
                        if (AvailableSlots != null)
                        {
                            bool validSlot = false;    //FOR EXITING THE LOOP
                            do
                            {
                                foreach (Slot thisSlot in AvailableSlots)
                                {
                                    Console.WriteLine($"slot-{ thisSlot.Id }");
                                }
                                Display.Print("Please choose a slot number");
                                int  slotNumber   = functions.Input();
                                Slot SelectedSlot = AvailableSlots.Find(slot => slot.Id == slotNumber);
                                bool validity     = false;
                                if (SelectedSlot != null)
                                {
                                    do
                                    {
                                        Display.Print("Please enter the vehicle number");
                                        string number        = Display.Scan();
                                        var    VehicleNumber = functions.vehicleNumber(number, regionalCode);
                                        switch (choice)
                                        {
                                        case 1:
                                            vehicle = new TwoWheeler(VehicleNumber);
                                            break;

                                        case 2:
                                            vehicle = new FourWheeler(VehicleNumber);
                                            break;

                                        case 3:
                                            vehicle = new HeavyVehicle(VehicleNumber);
                                            break;

                                        default:
                                            break;
                                        }
                                        Validations validation = new Validations();
                                        if (validation.IsValidVehicleNumber(vehicle.VehicleNumber) == true)
                                        {
                                            bool isSame = ParkingServices.CheckSimialarVehicleNo(vehicle.VehicleNumber);
                                            if (isSame == false)
                                            {
                                                validity = true;
                                            }
                                            else
                                            {
                                                Display.Print("The Vehicle numberis already parked in another slot");
                                                Display.Print("******************************************");
                                            }
                                            //*********there is still a chance that two vehicles can be parked with same number
                                        }
                                        else
                                        {
                                            Display.Print("Please check the format of the vehicle number");
                                            Display.Print("******************************************");
                                            validity = false;
                                        }
                                    }while (validity == false);
                                    SelectedSlot.ParkedVehicle = vehicle;
                                    Ticket ticket = ticketService.GenerateTicket(slotNumber, vehicle.VehicleNumber);
                                    ParkingServices.Park(slotNumber, vehicle.VehicleNumber);
                                    ticketService.UpdateTicketList(ticket);
                                    functions.Parked(SelectedSlot.Id);
                                    Display.Print("******************************************");
                                    Console.WriteLine($"Ticket Id:{ticket.Id}\nVehicle Number:{SelectedSlot.ParkedVehicle.VehicleNumber}\nSlot Number:{SelectedSlot.Id}\nIn-Time:{ticket.InTime}");
                                    Display.Print("******************************************");
                                    validSlot = true;
                                }
                                else
                                {
                                    functions.Invalid();
                                }
                            }while (validSlot == false);
                        }
                        else
                        {
                            functions.NoSlot();
                        }

                        break;

                    case 2:
                        while (true)
                        {
                            int ticketCount = ticketService.GetTicketCount();
                            if (ticketCount != 0)
                            {
                                bool validSlot = false;
                                do
                                {
                                    Display.Print("Please enter the slot Id");
                                    int    Id             = functions.Input();
                                    Ticket SelectedTicket = ticketService.GetTicket(Id);
                                    if (SelectedTicket != null)
                                    {
                                        Slot slot = ParkingServices.GetSlot(SelectedTicket.SlotNumber);
                                        if (slot.Availability == Status.OCCUPIED)
                                        {
                                            SelectedTicket.OutTime = DateTime.Now;
                                            ParkingServices.UnPark(SelectedTicket.SlotNumber);
                                            Display.Print("******************************************");
                                            Display.Print("The vehicle is unparked");
                                            Console.WriteLine($"Ticket Id:{SelectedTicket.Id}\nVehicle Number:{SelectedTicket.VehicleNumber}\nSlot Number:{SelectedTicket.SlotNumber}\nIn-Time:{SelectedTicket.InTime}\nOut-Time:{SelectedTicket.OutTime}");
                                            Display.Print("******************************************");
                                        }
                                        else
                                        {
                                            Display.Print("the vehicle is already unparked from the slot");
                                            Display.Print("******************************************");
                                        }
                                        validSlot = true;
                                    }
                                    else
                                    {
                                        Display.Print("enter a valid slot id");
                                    }
                                }while (validSlot == false);
                                break;
                            }
                            else
                            {
                                Display.Print("no tickets are generated yet");
                                break;
                            }
                        }
                        break;

                    case 3:
                        List <Slot> Slots = ParkingServices.GetSlots();
                        foreach (Slot slot in Slots)
                        {
                            string vehicleNumber = ((slot.ParkedVehicle == null) ? "-----" : slot.ParkedVehicle.VehicleNumber);
                            Console.WriteLine($"slot:{slot.Id}  type:{slot.Type}  status:{Convert.ToString(slot.Availability)} vehiclePArked:{vehicleNumber}");
                        }
                        Display.Print("******************************************");
                        break;

                    case 4:
                        Exit = true;

                        break;

                    default:
                        Display.Print("please select a valid option");
                        Display.Print("******************************************");
                        break;
                    }
                }while (Exit == false);
            }
        }