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!"); } }
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(); } } }
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]); } } } } }
private void editBudgetBtn_Click(object sender, EventArgs e) { var editBudgetTop = new EditBudgetTop(YearTop.LoadFromFile(_selectedBudgetFilepath)); editBudgetTop.Show(); }