示例#1
0
 public void CategoryViewModelTest()
 {
     CategoryViewModel expense = Application.Categories.First(cwm => cwm.Type == CategoryType.Expense);
     Assert.IsNotNull(expense);
     CategoryViewModel newExpense = new CategoryViewModel(Database, expense, new Category("Test", -1, CategoryType.Expense, 1.0));
     Assert.IsNotNull(newExpense);
     Assert.AreEqual(newExpense.Name, "Test");
 }
示例#2
0
        public CategoryViewModel(ICategoriesManager categoriesManager, CategoryViewModel parent, Category category)
            : this(category)
        {
            m_categoriesManager = categoriesManager;
            m_parent = parent;

            WatchChildren();
        }
示例#3
0
 public void UpdateUnderlyingDataTest()
 {
     CategoryViewModel newExpense = new CategoryViewModel(Database, new Category("Test 1", -1, CategoryType.Expense, 1.0));
     Assert.IsNotNull(newExpense);
     Assert.AreEqual(newExpense.Name, "Test 1");
     Assert.AreEqual(newExpense.UnderlyingData.name, "Test 1");
     newExpense.Name = "Test 2";
     Assert.AreEqual(newExpense.Name, "Test 2");
     Assert.AreEqual(newExpense.UnderlyingData.name, "Test 1");
     newExpense.UpdateUnderlyingData();
     Assert.AreEqual(newExpense.Name, "Test 2");
     Assert.AreEqual(newExpense.UnderlyingData.name, "Test 2");
 }
示例#4
0
 private void CheckCanDrop(CategoryViewModel currentCategory, DragEventArgs e)
 {
     e.Effects = DragDropEffects.None;
     if (null == currentCategory)
         return;
     if (!e.Data.GetDataPresent("Category"))
         return;
     e.Handled = true;
     CategoryViewModel category = (CategoryViewModel)e.Data.GetData("Category");
     if (null == category)
         return;
     if (category.IsCovers(currentCategory))
         return;
     e.Effects = DragDropEffects.Move;
 }
示例#5
0
 internal void AdjustParent(AccountancyApplication app)
 {
     m_parent = app.GetCategory(m_underlyingData.categoryId);
 }
示例#6
0
 public bool IsCovers(CategoryViewModel category)
 {
     CategoryViewModel c = category;
     while (null != c)
     {
         if (c.CategoryId == CategoryId)
             return true;
         c = c.Parent;
     }
     return false;
 }
示例#7
0
 private void BuildObjectCollections()
 {
     Users = new ObservableCollection<PersonViewModel>(m_database.EnumAllUsers().Select(p => GetPerson(p)));
     Accounts = new ObservableCollection<AccountViewModel>(m_database.EnumAllAccounts().Select(a => GetAccount(a)));
     Categories = new ObservableCollection<CategoryViewModel>(m_database.EnumAllCategories().Select(c => new CategoryViewModel(m_database, c)));
     Categories.ForEach(c => c.AdjustParent(this));
     Expenses = new ObservableCollection<ExpenseViewModel>(m_database.EnumAllExpenses().Select(e => new ExpenseViewModel(e, this)));
     VirtualRoot = new CategoryViewModel(m_database, null, new Category("Virtual", 0, CategoryType.Expense, 0.0));
     Reports = new ObservableCollection<OlapView>(m_database.Reports);
 }
示例#8
0
 public void RemoveCategory(CategoryViewModel category)
 {
     m_database.Delete(category.UnderlyingData);
     category.Parent.Children.Remove(category);
     Categories.Remove(GetCategory(category.CategoryId));
 }
示例#9
0
 public void ChangeCategoryParent(CategoryViewModel category, CategoryViewModel newParent)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public void ChangeCategoryOrder(CategoryViewModel category, CategoryViewModel categoryBefore)
 {
     throw new NotImplementedException();
 }
示例#11
0
 public void ChangeCategory(CategoryViewModel category, string newName, CategoryType type)
 {
     Category cat = category.UnderlyingData;
     cat.name = newName;
     cat.type = type;
     m_database.Update(cat);
     category.Name = newName;
     category.Type = type;
     category.UpdateUnderlyingData();
 }
示例#12
0
 public CategoryViewModel AddChildCategory(CategoryViewModel category, string name, CategoryType type)
 {
     long catId = m_database.Add(name, category.CategoryId, type);
     Category c = new Category(name, catId, category.CategoryId, type, double.NaN);
     CategoryViewModel newCategory = new CategoryViewModel(m_database, category, c);
     category.Children.Add(newCategory);
     Categories.Add(newCategory);
     return newCategory;
 }
示例#13
0
 public ExpenseViewModel(long amount, CategoryViewModel category, AccountViewModel account, string description, AccountancyApplication app)
     : this(new Expense(0, account.AccountId, amount, category.CategoryId, app.SelectedDate, description), app)
 {
 }
示例#14
0
 public void CategoryViewModelTest1()
 {
     CategoryViewModel newExpense = new CategoryViewModel(Database, new Category("Test 1", -1, CategoryType.Expense, 1.0));
     Assert.IsNotNull(newExpense);
     Assert.AreEqual(newExpense.Name, "Test 1");
 }