Ejemplo n.º 1
0
        private void SumOfTransactions(object obj)
        {
            double sum  = 0;
            var    time = DateTime.Now;

            time = time.AddMinutes(-1);
            foreach (var item in ListOfTransactions)
            {
                if (item.Date >= time)
                {
                    sum += item.Tax;
                }
                else
                {
                    ListOfTransactions.Remove(item);
                }
            }

            if (File.Exists(TransactionFileName))
            {
                using (var sw = new StreamWriter(TransactionFileName, true))
                {
                    sw.WriteLine("Sum: " + sum + ", time: " + time);
                }
            }
        }
Ejemplo n.º 2
0
        public void TopUpBalance()
        {
            Console.WriteLine("Write id of your car: ");
            var id    = Convert.ToInt32(Console.ReadLine());
            int index = Instance.ListOfCars.FindIndex(car => car.Id == Convert.ToInt32(Console.ReadLine()));

            Console.WriteLine("Write count of money for adding to balance of your car: ");
            double money = Convert.ToDouble(Console.ReadLine());

            if (Instance.ListOfCars[index].Fine == 0)
            {
                Instance.ListOfCars[index].Balance += money;
            }
            else
            {
                if (money <= Instance.ListOfCars[index].Fine)
                {
                    Instance.ListOfCars[index].Fine -= money;
                    Income += money;
                    ListOfTransactions.Add(new Transaction(id, money));
                }
                else
                {
                    Income += Instance.ListOfCars[index].Fine;
                    ListOfTransactions.Add(new Transaction(id, Instance.ListOfCars[index].Fine));
                    Instance.ListOfCars[index].Balance += money - Instance.ListOfCars[index].Fine;
                    Instance.ListOfCars[index].Fine     = 0;
                }
            }
            Console.WriteLine("Balance of your car was changed successfully!");
        }
Ejemplo n.º 3
0
        public void TestIfRightAmountOfLines()
        {
            List <Product> products = new List <Product>()
            {
                new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack")
            };
            ListOfProducts     listOfProducts = new ListOfProducts(products, null);
            ListOfTransactions transactions   = new ListOfTransactions(ReadFromFiles.ReadFromTransactionFileToListOfTransactions(validTransactionFileWithTwoTransactions, listOfProducts, null), null);

            Assert.AreEqual(transactions.NumberOfTransactions, 2);
        }
Ejemplo n.º 4
0
        public void TestIfRightTransactionsIsMade()
        {
            List <Product> products = new List <Product>()
            {
                new Product(1, "Mælk", "l", "Food"), new Product(2, "Kage", "kg", "Snack")
            };
            ListOfProducts listOfProducts = new ListOfProducts(products, null);

            ListOfTransactions transactions = new ListOfTransactions(ReadFromFiles.ReadFromTransactionFileToListOfTransactions(validTransactionFileWithTwoTransactions, listOfProducts, null), null);

            Assert.AreEqual(transactions.FindTransactionByID(1).AmountOfMoney, 10);
        }
Ejemplo n.º 5
0
        private void Transaction(object obj)
        {
            var    id           = (int)obj;
            var    indexOfCar   = ListOfCars.FindIndex(car => car.Id == id);
            double priceOfTrans = _settings.Prices[ListOfCars[indexOfCar].Type];

            if (priceOfTrans > ListOfCars[indexOfCar].Balance)
            {
                priceOfTrans *= _settings.Fine;
                ListOfCars[indexOfCar].Fine += priceOfTrans;
            }
            else
            {
                ListOfCars[indexOfCar].Balance -= priceOfTrans;
                Income += priceOfTrans;
                ListOfTransactions.Add(new Transaction(id, priceOfTrans));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Write off funds
        /// </summary>
        public void WriteOffFunds()
        {
            DateTime dateTimeNow = DateTime.Now;

            foreach (Car item in ListOfCars)
            {
                double writtenOffFunds;

                if (item.Balance >= 0)
                {
                    writtenOffFunds = Settings.ParkingPrices[item.CarType];
                }
                else
                {
                    writtenOffFunds = Settings.Fine * Settings.ParkingPrices[item.CarType];
                }

                item.Balance -= writtenOffFunds;
                ListOfTransactions.Add(new Transaction(dateTimeNow, item.Id, writtenOffFunds));

                Balance += writtenOffFunds;
            }
        }