Esempio n. 1
0
        private void purchasesDelete_Click(object sender, EventArgs e)
        {
            Transaction t           = transactionsLv.SelectedItems[0].Tag as Transaction;
            string      accountName = transactionsLv.SelectedItems[0].SubItems[2].Text;

            if (!_year.GetAccount(accountName).RemoveTransaction(t.TransactionId))
            {
                throw new ArgumentException("Could not find transaction!");
            }
            RefreshPage();
        }
Esempio n. 2
0
        private void saveBtn_Click_1(object sender, EventArgs e)
        {
            NewIncomeAddedEventArgs args = new NewIncomeAddedEventArgs();

            decimal amount;

            if (!decimal.TryParse(amountTb.Text, out amount))
            {
                amountTb.Text = 0.ToString();
                MessageBox.Show("Invalid amount!");
                return;
            }

            string   name         = nameTb.Text;
            DateTime firstDeposit = firstDepositDtp.Value.Date;

            IncomeFrequencyEnum frequency;

            Enum.TryParse(frequencyCb.SelectedItem.ToString(), out frequency);

            string accountName = accountCb.Text;

            if (_income == null)
            {
                _income        = new Income(name, amount, frequency, _year.GetAccount(accountName), firstDeposit);
                args.NewIncome = _income;
            }
            else
            {
                _income.DepositAccount  = _year.GetAccount(accountName);
                _income.PaydayAmount    = amount;
                _income.PaydayFrequency = frequency;

                args.NewIncome = null;
            }

            OnNewIncomeAdded(args);

            this.Close();
        }
Esempio n. 3
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            NewHardBillAddedEventArgs args = new NewHardBillAddedEventArgs();

            string   name         = nameTb.Text;
            DateTime firstBillDue = firstBillDueDtp.Value.Date;

            decimal amount;

            if (!decimal.TryParse(amountTb.Text, out amount))
            {
                amountTb.Text = _hardBill.Amount.ToString();
                MessageBox.Show("Invalid amount!");
                return;
            }

            HardBillFrequencyEnum frequency;

            Enum.TryParse(frequencyCb.SelectedItem.ToString(), out frequency);

            string accountName = accountCb.Text;
            bool   autoPay     = autoPayCb.Checked;

            if (_hardBill == null)
            {
                args.NewHardBill = new HardBill(name, amount, firstBillDue, frequency, _year.GetAccount(accountName), autoPay);
            }
            else
            {
                _hardBill.Amount         = amount;
                _hardBill.Frequency      = frequency;
                _hardBill.PaymentAccount = _year.GetAccount(accountName);
                _hardBill.AutoPay        = autoPay;
                args.NewHardBill         = null;
            }
            OnNewHardBillAdded(args);

            this.Close();
        }
Esempio n. 4
0
        public void SimplePurchaseTest()
        {
            decimal creditExpected   = yearTop.GetAccount("credit").CurrentBalance;
            decimal checkingExpected = yearTop.GetAccount("checking").CurrentBalance;

            //transaction details
            decimal             amount;
            string              description;
            DateTime            date;
            SoftBillTransaction sbt;

            /* Credit checks */
            amount      = 100;
            description = "grocery store";
            date        = new DateTime(2020, 1, 15);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.Date    = date;
            sbt.SoftGroupSplit["food"] = amount;
            yearTop.GetAccount("credit").NewDebitTransaction(sbt);

            creditExpected += amount;
            Assert.AreEqual(creditExpected, yearTop.GetAccount("credit").CurrentBalance);

            /* Credit checks */
            amount      = 150;
            description = "grocery store";
            date        = new DateTime(2020, 1, 16);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.Date    = date;
            sbt.SoftGroupSplit["food"] = amount;
            yearTop.GetAccount("credit").NewDebitTransaction(sbt);

            creditExpected += amount;
            Assert.AreEqual(creditExpected, yearTop.GetAccount("credit").CurrentBalance);

            /* Checking checks */
            amount      = 150;
            description = "gas station";
            date        = new DateTime(2020, 1, 16);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.Date    = date;
            sbt.SoftGroupSplit["gas"] = amount;
            yearTop.GetAccount("checking").NewDebitTransaction(sbt);

            checkingExpected -= amount;
            Assert.AreEqual(checkingExpected, yearTop.GetAccount("checking").CurrentBalance);

            amount      = 50;
            description = "gas station";
            date        = new DateTime(2020, 1, 20);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.Date    = date;
            sbt.SoftGroupSplit["gas"] = amount;
            yearTop.GetAccount("checking").NewDebitTransaction(sbt);

            checkingExpected -= amount;
            Assert.AreEqual(checkingExpected, yearTop.GetAccount("checking").CurrentBalance);
        }
Esempio n. 5
0
        public void SerializeTest()
        {
            string filepath = @"C:\Users\Batman\budgets\BudgetTest.bin";

            yearTop.FastForward(new DateTime(2020, 12, 31));

            //transaction details
            decimal             amount;
            string              description;
            DateTime            date;
            SoftBillTransaction sbt;

            /* Credit checks */
            amount      = 100;
            description = "grocery store";
            date        = new DateTime(2020, 1, 15);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.SoftGroupSplit["food"] = amount;
            yearTop.GetAccount("credit").NewDebitTransaction(sbt);

            /* Checking checks */
            amount      = 150;
            description = "gas station";
            date        = new DateTime(2020, 1, 16);
            sbt         = yearTop.GetSoftBillTransaction(description, amount, date.Month);
            sbt.SoftGroupSplit["gas"] = amount;
            yearTop.GetAccount("checking").NewDebitTransaction(sbt);

            yearTop.SaveToFile(filepath);

            YearTop desYearTop = YearTop.LoadFromFile(filepath);

            var accountNames = yearTop.GetAccountsNames();

            foreach (var name in accountNames)
            {
                IAccountBase origAccount = yearTop.GetAccount(name);
                IAccountBase copyAccount = desYearTop.GetAccount(name);

                Assert.AreEqual(origAccount.CurrentBalance, copyAccount.CurrentBalance);
                IReadOnlyList <Transaction> origTs = origAccount.GetTransactions();
                IReadOnlyList <Transaction> copyTs = copyAccount.GetTransactions();
                for (int i = 0; i < origTs.Count; i++)
                {
                    Transaction origT = origTs[i];
                    Transaction copyT = copyTs[i];

                    Assert.AreEqual(origT.Amount, copyT.Amount);
                    Assert.AreEqual(origT.Date, copyT.Date);
                    Assert.AreEqual(origT.Description, copyT.Description);

                    if (origT.GetType().Name.Contains("SoftBill"))
                    {
                        SoftBillTransaction origSbt = origT as SoftBillTransaction;
                        SoftBillTransaction copySbt = copyT as SoftBillTransaction;

                        foreach (var item in origSbt.SoftGroupSplit)
                        {
                            Assert.AreEqual(item.Value, copySbt.SoftGroupSplit[item.Key]);
                        }
                    }
                }
            }
        }