// ====================================================================
        // Update the Data Grid View
        // ====================================================================
        private void UpdateDataGridView()
        {
            // don't do anything if budget is not yest defined
            if (budget == null)
            {
                return;
            }
            // filter options
            bool FilterFlag = cbFilterCategories.IsChecked == true;
            int  id         = -1;

            if (cmbCategories.SelectedItem != null)
            {
                id = ((Category)cmbCategories.SelectedItem).Id;
            }

            // ----------------------------------------------------------------
            // standard display
            // ----------------------------------------------------------------
            if (cbByCategory.IsChecked != true && cbByMonth.IsChecked != true)
            {
                // create columns for standard display
                CreateDataGridStandardDisplay();

                // set the ItemSource
                dataBudget.ItemsSource = null;
                dataBudget.ItemsSource = budget.GetExpenses(dpStartDate.SelectedDate, dpEndDate.SelectedDate, FilterFlag, id);
            }
            // ----------------------------------------------------------------
            // total by month
            // ----------------------------------------------------------------
            if (cbByMonth.IsChecked == true && cbByCategory.IsChecked != true)
            {
                MonthDisplayMode();

                dataBudget.ItemsSource = null;
                dataBudget.ItemsSource = budget.GetExpensesByMonth(dpStartDate.SelectedDate, dpEndDate.SelectedDate, FilterFlag, id);
            }

            // ----------------------------------------------------------------
            // total by category
            // ----------------------------------------------------------------
            if (cbByMonth.IsChecked != true && cbByCategory.IsChecked == true)
            {
                CategoryDisplayMode();

                dataBudget.ItemsSource = null;
                dataBudget.ItemsSource = budget.GetExpensesByCategory(dpStartDate.SelectedDate, dpEndDate.SelectedDate, FilterFlag, id);
            }
            // ----------------------------------------------------------------
            // total by category and month
            // ----------------------------------------------------------------
            if (cbByMonth.IsChecked == true && cbByCategory.IsChecked == true)
            {
                CategoryAndMonthDisplayMode();

                dataBudget.ItemsSource = null;
                dataBudget.ItemsSource = budget.GetExpensesByCategoryAndMonth(dpStartDate.SelectedDate, dpEndDate.SelectedDate, FilterFlag, id);
            }
        }
예제 #2
0
        // ====================================================================
        // Create the Columns for the DataGrid by Month Display mode
        // ====================================================================
        private void CreateDataGridMonthlyDisplayMode(DateTime?StartDate, DateTime?EndDate, bool Flag, int ID)
        {
            // create columns to display
            dataBudget.Columns.Clear();
            dataBudget.ItemsSource = null;
            dataBudget.ItemsSource = budget.GetExpensesByMonth(StartDate, EndDate, Flag, ID);
            var col = new DataGridTextColumn();

            col.Header  = "Month";
            col.Binding = new Binding("Month");
            dataBudget.Columns.Add(col);

            col         = new DataGridTextColumn();
            col.Header  = "Total";
            col.Binding = new Binding("Total");
            col.Binding.StringFormat = "F2";
            dataBudget.Columns.Add(col);
        }