Пример #1
0
 private void logPurchasesBtn_Click(object sender, EventArgs e)
 {
     if (File.Exists(_selectedBudgetFilepath))
     {
         var manageBudget = new ManageBudget(YearTop.LoadFromFile(_selectedBudgetFilepath));
         manageBudget.Show();
     }
     else
     {
         MessageBox.Show("select a valid file to load from!");
     }
 }
Пример #2
0
        public void Init()
        {
            IAccountBase checking;
            IAccountBase credit;

            IIncome salary;
            IIncome bonus;

            //annuals
            IHardBill carRegistration;

            //monthlys
            IHardBill electricity;
            IHardBill cable;

            DateTime startingDate = new DateTime(2020, 1, 1);

            //create accounts
            checking = new CheckingAccount("checking", 5000, startingDate);
            credit   = new CreditCard("credit", 0, startingDate);

            //create income
            salary = new Income("salary", 2500, IncomeFrequencyEnum.BiWeekly, checking, new DateTime(2020, 1, 10));
            bonus  = new Income("bonus", 1500, IncomeFrequencyEnum.BiAnnualy, checking, new DateTime(2020, 1, 10));

            //annuals
            carRegistration = new HardBill("carRegistration", 1000, new DateTime(2020, 12, 31), HardBillFrequencyEnum.Annualy, credit, false);

            //monthlys
            electricity = new HardBill("electricity", 150, new DateTime(2020, 1, 15), HardBillFrequencyEnum.Monthly, checking, true);
            cable       = new HardBill("cable", 75, new DateTime(2020, 1, 20), HardBillFrequencyEnum.Monthly, credit, true);

            yearTop = new YearTop();
            yearTop.InitializeYear();

            //wire up top
            yearTop.AddAccount(checking);
            yearTop.AddAccount(credit);

            yearTop.AddIncomeSource(salary);
            yearTop.AddIncomeSource(bonus);

            yearTop.AddHardBill(carRegistration);
            yearTop.AddSoftBill("vacation", 7500, true);

            yearTop.AddHardBill(electricity);
            yearTop.AddHardBill(cable);
            yearTop.AddSoftBill("food", 500, false);
            yearTop.AddSoftBill("gas", 100, false);
        }
Пример #3
0
        public EditHardBillForm(IHardBill hardBill, YearTop year)
        {
            InitializeComponent();

            if (year == null)
            {
                throw new ArgumentException("Year has not been initialized yet.");
            }
            else
            {
                _year = year;
            }


            frequencyCb.Items.AddRange(Enum.GetNames(typeof(HardBillFrequencyEnum)));

            var accountList = _year.GetAccountsNames();

            foreach (var account in accountList)
            {
                accountCb.Items.Add(account);
            }

            if (hardBill != null)
            {
                _hardBill       = hardBill;
                nameTb.Text     = _hardBill.Name;
                nameTb.ReadOnly = true;

                firstBillDueDtp.Value   = _hardBill.FirstBillDue;
                firstBillDueDtp.Enabled = false;

                //editable
                amountTb.Text            = _hardBill.Amount.ToString();
                frequencyCb.SelectedItem = _hardBill.Frequency.ToString();
                accountCb.SelectedItem   = _hardBill.PaymentAccount.Name;
                autoPayCb.Checked        = _hardBill.AutoPay;
            }
            else
            {
                _hardBill = null;
            }
        }
Пример #4
0
        public ManageBudget(YearTop year)
        {
            _skipRefreshing = true;

            InitializeComponent();

            if (year == null)
            {
                throw new ArgumentException("Uninitialized year!");
            }

            _year                 = year;
            _dateSelected         = DateTime.Today;
            _showAnnual           = false;
            _allDatesTransactions = false;
            _selectedAccountName  = string.Empty;
            var accounts = _year.GetAccounts();

            if (accounts.Count <= 0)
            {
                throw new ArgumentException("Must instantiate at least one account.");
            }
            dateDtp.Value        = DateTime.Today;
            showAnnualCb.Checked = false;
            allDatesCb.Checked   = false;

            _year.FastForward(DateTime.Today);

            transactionsLv.MouseUp += new MouseEventHandler(purchasesLv_MouseUp);
            hardBillsLv.MouseUp    += new MouseEventHandler(hardBillsLv_MouseUp);
            softBillsLv.MouseUp    += new MouseEventHandler(softBillsLv_MouseUp);

            accountsLv.Items.Clear();
            foreach (var account in accounts)
            {
                ListViewItem lvi = new ListViewItem(account.Name);
                accountsLv.Items.Add(lvi);
            }
            accountsLv.Items[0].Checked = true;

            _skipRefreshing = false;
            RefreshPage();
        }
Пример #5
0
        public EditIncomeForm(IIncome income, YearTop year)
        {
            InitializeComponent();

            if (year == null)
            {
                throw new ArgumentException("Year has not been initialized yet.");
            }
            else
            {
                _year = year;
            }

            frequencyCb.Items.AddRange(Enum.GetNames(typeof(IncomeFrequencyEnum)));

            var accountList = _year.GetAccountsNames();

            foreach (var account in accountList)
            {
                accountCb.Items.Add(account);
            }

            if (income != null)
            {
                _income         = income;
                nameTb.Text     = _income.Name;
                nameTb.ReadOnly = true;

                firstDepositDtp.Value   = _income.FirstDeposit;
                firstDepositDtp.Enabled = false;

                //editable fields
                amountTb.Text            = _income.PaydayAmount.ToString();
                frequencyCb.SelectedItem = _income.PaydayFrequency.ToString();
                accountCb.SelectedItem   = _income.DepositAccount.Name;
            }
            else
            {
                _income = null;
                firstDepositDtp.Value = DateTime.Today;
            }
        }
Пример #6
0
        private void loadYearBtn_Click_1(object sender, EventArgs e)
        {
            var fileContent = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = @"C:\Users\Batman\budgets";
                openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    Properties.Settings.Default["BudgetFile"] = openFileDialog.FileName;
                    Properties.Settings.Default.Save();

                    _year = YearTop.LoadFromFile(openFileDialog.FileName);
                    RefreshPage();
                }
            }
        }
Пример #7
0
        public EditBudgetTop(YearTop year)
        {
            InitializeComponent();

            if (year != null)
            {
                _year = year;
            }
            else
            {
                _year = new YearTop();
            }

            accountsLv.MouseUp  += new MouseEventHandler(accountsLv_MouseUp);
            incomeLv.MouseUp    += new MouseEventHandler(incomeLv_MouseUp);
            hardBillsLv.MouseUp += new MouseEventHandler(annualHbLv_MouseUp);
            annualSbLv.MouseUp  += new MouseEventHandler(annualSbLv_MouseUp);
            monthlySbLv.MouseUp += new MouseEventHandler(monthlySbLv_MouseUp);

            RefreshPage();
        }
Пример #8
0
        public EditSbTransactionForm(YearTop year, DateTime currentDate)
        {
            InitializeComponent();

            if (year == null)
            {
                throw new ArgumentException("Year must be initialized.");
            }

            _year = year;

            var accounts = _year.GetAccounts();

            foreach (var keyValue in accounts)
            {
                accountCb.Items.Add(keyValue.Name);
            }
            _dateSelected  = currentDate;
            _monthSelected = _dateSelected.Month;
            dateDtp.Value  = _dateSelected;

            UpdateEntireTpl();
        }
Пример #9
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]);
                        }
                    }
                }
            }
        }
Пример #10
0
        private void editBudgetBtn_Click(object sender, EventArgs e)
        {
            var editBudgetTop = new EditBudgetTop(YearTop.LoadFromFile(_selectedBudgetFilepath));

            editBudgetTop.Show();
        }