Exemple #1
0
        public static Document CreateTestDocument(string xmlString)
        {
            XElement root = XDocument.Parse(xmlString).Root;
            Document document = new Document();

            //Initialize Reserves
            foreach (var t in root.Elements("Type"))
            {
                ReserveType type = new ReserveType();
                type.Name = t.Attribute("name").Value;
                document.AddModelObject<ReserveType>(type);
                foreach (var c in t.Elements())
                {
                    Reserve reserve = new Reserve(1000);
                    reserve.Name = c.Attribute("name").Value;
                    reserve.Type = type;
                    document.AddModelObject<Reserve>(reserve);
                }
            }

            //Initialize Categories
            foreach (var e in root.Element("Expenses").Elements("Item"))
            {
                createCategory(document, null, e, CategoryType.Expense);
            }

            foreach (var i in root.Element("Incomes").Elements("Source"))
            {
                createCategory(document, null, i, CategoryType.Income);
            }

            createTransactions(document);

            Budget budget = new Budget(Period.CurrentWeek);
            budget.Name = "Week Budget";
            document.AddBudget(budget);

            budget = new Budget(Period.CurrentMonth);
            budget.Name = "Month Budget";
            document.AddBudget(budget);

            budget = new Budget(Period.CurrentQuarter);
            budget.Name = "Quarter Budget";
            document.AddBudget(budget);

            budget = new Budget(Period.CurrentYear);
            budget.Name = "Year Budget";
            document.AddBudget(budget);

            return document;
        }
Exemple #2
0
        private static void createTransactions(Document document)
        {
            Transaction t = null;
            TransactionType type = (TransactionType)rnd.Next(3);
            DateTime date = DateTime.Now.AddDays(-rnd.Next(100));

            for (int i = 0; i < 100; i++)
            {
                type = (TransactionType)rnd.Next(0, 3);
                t = new Transaction(type);
                switch (type)
                {
                    case TransactionType.Deposit:
                        t.Source = document.IncomeCategories[rnd.Next(0, document.IncomeCategories.Count)];
                        t.Target = document.Reserves[rnd.Next(0, document.Reserves.Count)];
                        break;
                    case TransactionType.Withdrawal:
                        t.Source = document.Reserves[rnd.Next(0, document.Reserves.Count)];
                        t.Target = document.ExpenseCategories[rnd.Next(0, document.ExpenseCategories.Count)];
                        break;
                    case TransactionType.Transfer:
                        t.Source = document.Reserves[rnd.Next(0, document.Reserves.Count)];
                        t.Target = document.Reserves[rnd.Next(0, document.Reserves.Count)];
                        break;
                    default:
                        break;
                }
                t.Amount = Math.Round(rnd.NextDouble() * rnd.Next(10, 100), 2);
                t.Date = date.AddDays(rnd.NextDouble() * rnd.Next(10, 100));
                document.AddModelObject<Transaction>(t);
            }
        }
Exemple #3
0
 private static void createCategory(Document document, Category parent, XElement element, CategoryType type)
 {
     Category category = new Category(type);
     string name = element.Attribute("name").Value;
     category.Name = name;
     category.Parent = parent;
     category.BudgetPeriodType = (PeriodType)rnd.Next((int)PeriodType.Weekly, (int)PeriodType.Yearly + 1);
     document.AddModelObject<Category>(category);
     foreach (var c in element.Elements())
     {
         createCategory(document, category, c, type);
     }
 }