public InputCategoryWindow(MainWindow _mainWindow, ExpensePage _expensePage, DateTime _date)
        {
            InitializeComponent();
            dbContext   = new MonnyDbContext();
            controller  = _mainWindow;
            expensePage = _expensePage;
            date        = _date;

            // Set ComboBox list Item with user's custom categories
            ExpenseRepository repository = new ExpenseRepository();
            // List where used custom categories ids are being saved
            List <int> usedId = new List <int>();

            foreach (Expense e in repository.GetItems())
            {
                // Checks if e is current user expense
                // e.CategoryId > 7 because custom categories have id greater than 7
                if (e.UserId == controller.user.Id && e.CategoryId > 7)
                {
                    // Check if category hasn't been used already
                    if (!usedId.Exists(i => i == e.CategoryId))
                    {
                        CategoryRepository categories = new CategoryRepository();
                        // Add category to ComboBox Items
                        customCategories.Items.Add(categories.GetItem(e.CategoryId).Name);

                        usedId.Add(e.CategoryId);
                    }
                }
            }
        }
Пример #2
0
        public void SetProgressBar(DateTime date)
        {
            if (date <= DateTime.Now)
            {
                // Set progress bar width
                ExpenseRepository expenses    = new ExpenseRepository();
                double            sumExpenses = expenses.GetItems().Where(e => (e.UserId == controller.user.Id && e.Date.Day == date.Day && e.Date.Month == date.Month && e.Date.Year == date.Year)).Sum(e => e.AmountOfMoney);
                progressBar.Value = sumExpenses;

                // need to be done: setting max value of progress bar
                IncomeRepository incomes    = new IncomeRepository();
                double           sumIncomes = incomes.GetItems().Where(i => (i.UserId == controller.user.Id && i.Date.Month == date.Month)).Sum(i => i.MoneyCount);
                progressBar.Maximum = Math.Round(sumIncomes / 30.0);
                CheckProgressBarStatus(sumExpenses, progressBar.Maximum);
            }
            else
            {
                MessageBox.Show("Wrong date, can't set progress bar");
            }
        }