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; } }
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; } }
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]); } } } } }