Пример #1
0
 /// <summary>
 /// Check whether the vehicle is parked.
 /// </summary>
 public static void TakeVehicle(Vehicle v)
 {
     if (VehicleViewer.IsParked(v.Id))
     {
         v.IsParked = false;
         Parking.GetInstance().vehicles.Remove(v);
     }
 }
Пример #2
0
 /// <summary>
 /// Set timers for automatic writing logs.
 /// </summary>
 public static void LogTransactions()
 {
     File.Create(FilePath).Close();
     TimerCallback tmc1   = new TimerCallback(WriteTransactions);
     TimerCallback tmc2   = new TimerCallback(CheckTransactions);
     Timer         timer1 = new Timer(tmc1, Parking.GetInstance().transactions, 60000, 60000);
     Timer         timer2 = new Timer(tmc2, Parking.GetInstance().transactions, 60500, 1000);
 }
Пример #3
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);
         }
     }
 }
Пример #4
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);
            }
        }
Пример #5
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);
        }