コード例 #1
0
        private void saveYearBtn_Click_1(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 2;
            saveFileDialog1.RestoreDirectory = true;

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

                _year.SaveToFile(saveFileDialog1.FileName);
            }
        }
コード例 #2
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]);
                        }
                    }
                }
            }
        }