예제 #1
0
 /// <summary>
 /// Park vehicle and turn on meter.
 /// </summary>
 public void AddVehicle(Vehicle v)
 {
     if (Settings.capacity > Parking.GetInstance().vehicles.Count)
     {
         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);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Withdraw money from vehicle account.
        /// </summary>
        /// /// <param name="vehicle">Represents object of vehicle.</param>
        private void GetPaid(object vehicle)
        {
            Vehicle v   = (Vehicle)vehicle;
            double  sum = Settings.price;

            if (v.IsParked)
            {
                switch (v.Type)
                {
                case Settings.VehicleType.Car: sum *= 2;
                    break;

                case Settings.VehicleType.Bus: sum *= 3.5;
                    break;

                case Settings.VehicleType.Truck: sum *= 5;
                    break;
                }
                if (v.Balance >= v.Rate)
                {
                    v.Balance -= sum;
                    Parking.GetInstance().Balance += sum;
                    Parking.GetInstance().transactions.Add(new Transaction()
                    {
                        Amount = sum, TimeOfTransaction = DateTime.Now, VehicleId = v.Id
                    });
                }
                else
                {
                    sum       *= Settings.penalty;
                    v.Balance -= sum;
                    Parking.GetInstance().Balance += sum;
                    Parking.GetInstance().transactions.Add(new Transaction()
                    {
                        Amount = sum, TimeOfTransaction = DateTime.Now, VehicleId = v.Id
                    });
                }
            }
            else
            {
                this.timer.Change(Timeout.Infinite, Timeout.Infinite);
            }
        }
예제 #3
0
        /// <summary>
        /// Print all hisrory of tranactions.
        /// </summary>
        public static List <string> ShowAllTranactions()
        {
            List <string> transactions = new List <string>();

            using (StreamReader sr = new StreamReader(TransactionsService.FilePath, Encoding.Default))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    transactions.Add(line);
                }
            }

            List <Transaction> trs = new List <Transaction>(Parking.GetInstance().transactions);

            foreach (Transaction t in trs.ToArray())
            {
                transactions.Add(t.ToString());
            }
            return(transactions);
        }