Exemplo n.º 1
0
        public MoneyEditor(MoneyItem moneyItem)
        {
            if (moneyItem == null)
              {
            throw new ArgumentNullException("moneyItem");
              }

              if (moneyItem.EntryType == EntryType.None)
              {
            throw new ArgumentException("moneyItem.EntryType");
              }

              InitializeComponent();

              this.MoneyItem = moneyItem;

              this.Accounts.ValueMember = "Id";
              this.Accounts.DisplayMember = "Name";

              this.Categories.ValueMember = "Id";
              this.Categories.DisplayMember = "Name";

              this.Subcategories.ValueMember = "Id";
              this.Subcategories.DisplayMember = "Name";
        }
Exemplo n.º 2
0
        private DataGridViewRow CreateRow(MoneyItem item)
        {
            var row = new DataGridViewRow();

              int iconId = 0;
              Account account = this.User.Accounts[item.AccountId];
              Category category = this.User.Categories[item.CategoryId];
              Category parentCategory = null;

              if (category.ParentId > 0)
              {
            parentCategory = this.User.Categories[category.ParentId];
              }

              if (item.IconId > 0)
              {
            // иконка записи
            iconId = item.IconId;
              }
              else
              {
            if (category.IconId > 0)
            {
              // иконка категории
              iconId = category.IconId;
            }
            else
            {
              // иконка статьи
              if (parentCategory != null)
              {
            iconId = parentCategory.IconId;
              }
            }
              }

              var iconCell = new DataGridViewImageCell();

              if (iconId > 0)
              {
            iconCell.Value = this.User.GetIcon(iconId);
              }
              else
              {
            if (item.EntryType == EntryType.Expense)
            {
              iconCell.Value = Properties.Resources.item_еxpense;
            }
            else if (item.EntryType == EntryType.Income)
            {
              iconCell.Value = Properties.Resources.item_income;
            }
            else
            {
              iconCell.Value = Properties.Resources.item;
            }
              }

              row.Cells.Add(iconCell);
              row.Cells.Add(new DataGridViewTextBoxCell { Value = (parentCategory != null ? parentCategory.Name : category.Name) });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = (parentCategory != null ? category.Name : "") });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = item.Title });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = account.Name });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = item.DateEntry });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = item.Amount });
              row.Cells.Add(new DataGridViewTextBoxCell { Value = account.CurrencyCode, Tag = account.CurrencyCode }); //u.Currencies[account.CurrencyCode].ShortName

              row.Tag = item;

              // стили
              row.DefaultCellStyle.BackColor = category.BackColor;
              row.DefaultCellStyle.ForeColor = category.ForeColor;
              row.DefaultCellStyle.Font = new Font(this.DataGridView1.Font, category.FontStyle);

              return row;
        }
Exemplo n.º 3
0
        public void ItemsTest()
        {
            User.Kill(App.CurrentPath, "entries");

              var u = User.Create(ApplicationType.Web, App.CurrentPath, "entries", "123");

              var currency = new Currency();
              currency.LongName = "Российский рубль";
              currency.ShortName = "₽";
              currency.Code = "RUB";
              u.Save(currency);

              var accountType = new AccountType();
              accountType.Name = "Сундук";
              u.Save(accountType);

              var account = new Account();
              account.Name = "Денежный счет items";
              account.AccountTypeId = accountType.Id;
              account.CurrencyCode = currency.Code;
              u.Save(account);

              var cat = new Category();
              cat.Name = "Главная статья доходов";
              cat.CategoryType = EntryType.Income;
              cat.FontStyle = FontStyle.Bold;
              u.Save(cat);

              var items = new List<MoneyItem>();
              var rnd = new Random(DateTime.Now.Millisecond);
              var date = DateTime.Now;
              for (int i = 1; i <= 100; i++)
              {
            var item = new MoneyItem();
            item.AccountId = account.Id;
            item.Amount = rnd.Next(1000, Int32.MaxValue);
            item.EntryType = EntryType.Income;
            item.CategoryId = cat.Id;
            item.DateEntry = date;
            item.DateCreated = date;
            item.Description = "Вот такой вот доход!";
            item.Title = String.Format("Запись #{0}", i);
            items.Add(item);
              }

              u.Save(items);

              for (int i = 1; i < 10; i++)
              {
            var list = u.GetMoneyItems(page: i, maxDataPerPage: 10);
            Assert.AreEqual(list[0].Id, 100 - ((i - 1) * 10));
            Assert.AreEqual(list[0].Title, String.Format("Запись #{0}", 100 - ((i - 1) * 10)));
              }

              var list2 = u.GetMoneyItems(search: "Запись #50");
              Assert.IsTrue(list2.Count == 1);

              u.Delete(items);

              // выборка по датам
              items = new List<MoneyItem>();
              for (int i = -5; i <= 5; i++)
              {
            var entry = new MoneyItem();
            entry.AccountId = account.Id;
            entry.Amount = rnd.Next(1000, Int32.MaxValue);
            entry.EntryType = EntryType.Income;
            entry.CategoryId = cat.Id;
            entry.DateEntry = DateTime.Now.AddDays(i);
            entry.Description = "Вот такой вот доход!";
            entry.Title = String.Format("Запись #{0}", i);
            items.Add(entry);
              }
              u.Save(items);

              // выше от текущей даты
              list2 = u.GetMoneyItems(dateFrom: DateTime.Now);
              for (int i = 0; i <= 5; i++)
              {
            Assert.IsTrue(System.DateTime.Now.AddDays(i).Date.Subtract(list2[5 - i].DateEntry.Date).TotalSeconds == 0);
              }

              // до текущей даты
              list2 = u.GetMoneyItems(dateTo: DateTime.Now);
              for (int i = 0; i <= 5; i++)
              {
            Assert.IsTrue(System.DateTime.Now.AddDays(-i).Date.Subtract(list2[i].DateEntry.Date).TotalSeconds == 0);
              }

              // между двух дат
              list2 = u.GetMoneyItems(dateFrom: DateTime.Now.AddDays(-2), dateTo: DateTime.Now.AddDays(2));
              Assert.IsTrue(System.DateTime.Now.Date.Subtract(list2[2].DateEntry.Date).TotalSeconds == 0);
        }