Esempio n. 1
0
        /// <summary>
        /// Park vehicle and turn on meter.
        /// </summary>
        public void AddVehicle()
        {
            if (Settings.capacity > Parking.GetInstance().vehicles.Count)
            {
                this.ReadInfo(out int type, out double balance, out string licenseNumber);
                Vehicle v = this.CreateVehicle(type, balance, licenseNumber);
                v.IsParked = true;

                if (!VehicleViewer.IsParked(v.Id))
                {
                    Parking.GetInstance().vehicles.Add(v);
                    this.tm    = new TimerCallback(this.GetPaid);
                    this.timer = new Timer(this.tm, v, 0, Settings.period);
                    Console.WriteLine("Your vehicle is parked.");
                }
                else
                {
                    Console.WriteLine("Your vehicle has already parked.");
                }
            }
            else
            {
                Console.WriteLine("Sorry, the ParkingLot is full.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Check whether the vehicle is parked.
        /// </summary>
        public static void TakeVehicle()
        {
            var id = VehicleViewer.ReadLicenseNumber();

            if (VehicleViewer.IsParked(id))
            {
                var v = VehicleViewer.FindVehicle(id);
                check : if (v.Balance < 0)
                {
                    Console.WriteLine($"You have a debt for parking in amount of {v.Balance}. Please fund your account.");
                    VehicleAccount.FundAccount(v);
                    goto check;
                }

                v.IsParked = false;
                Parking.GetInstance().vehicles.Remove(v);
                Console.WriteLine("Taking vehicle is successful.");
            }
            else
            {
                Console.WriteLine($"There is no vehicle with license number {id}");
            }
        }