예제 #1
0
        private void EditCategory()
        {
            CategoryModel newCategory = new CategoryModel {
                DataIndexes = new List <int>(SelectedCategory?.DataIndexes), Name = SelectedCategory.Name
            };
            CategoryValidateViewModel validateVM = new CategoryValidateViewModel(ref newCategory);

            Views.CategoryValidateView validateView = new Views.CategoryValidateView();
            validateView.DataContext = validateVM;
            validateView.ShowDialog();

            if (!SelectedCategory.Equals(newCategory))
            {
                try
                {
                    storageHandler.ReplaceCategory(SelectedCategory, newCategory);
                }
                catch (FileNotFoundException ex)
                { MessageBox.Show($"File not found {ex.Message}."); }
                catch (InvalidOperationException ex)
                { MessageBox.Show($"Can't save data to file {ex.Message}."); }
                catch (Exception ex)
                { MessageBox.Show($"Something is wrong {ex.Message}."); }
                GetCategories();
            }
        }
예제 #2
0
        private void ShowData(object obj)
        {
            lines.Children.Clear();

            if (SelectedType.Equals(Constants.PROFIT))
            {
                if (!SelectedCategory.Equals(Constants.ALL_DATA))
                {
                    List <Activity> profits = profitActivities.Where(p => p.category.Equals(SelectedCategory)).ToList();
                    profits = filterPeriod(profits);
                    chartData(profits, null);
                }
                else
                {
                    chartData(filterPeriod(profitActivities), null);
                }
            }
            else if (SelectedType.Equals(Constants.EXPENSE))
            {
                if (!SelectedCategory.Equals(Constants.ALL_DATA))
                {
                    List <Activity> expenses = expenseActivities.Where(p => p.category.Equals(SelectedCategory)).ToList();
                    expenses = filterPeriod(expenses);
                    chartData(null, expenses);
                }
                else
                {
                    chartData(null, filterPeriod(expenseActivities));
                }
            }
            else
            {
                List <Activity> filteredProfitExpenses = filterPeriod(profitExpenses);
                chartData(filteredProfitExpenses, filteredProfitExpenses);
            }
        }
예제 #3
-1
        public PdfSharp.Charting.Chart LineChart()
        {
            List <Activity> filteredProfitExpenses;

            if (SelectedType.Equals(Constants.PROFIT))
            {
                if (!SelectedCategory.Equals(Constants.ALL_DATA))
                {
                    List <Activity> profits = profitActivities.Where(p => p.category.Equals(SelectedCategory)).ToList();
                    filteredProfitExpenses = filterPeriod(profits);
                }
                else
                {
                    filteredProfitExpenses = filterPeriod(profitActivities);
                }
            }
            else if (SelectedType.Equals(Constants.EXPENSE))
            {
                if (!SelectedCategory.Equals(Constants.ALL_DATA))
                {
                    List <Activity> expenses = expenseActivities.Where(p => p.category.Equals(SelectedCategory)).ToList();
                    filteredProfitExpenses = filterPeriod(expenses);
                }
                else
                {
                    filteredProfitExpenses = filterPeriod(expenseActivities);
                }
            }
            else
            {
                filteredProfitExpenses = filterPeriod(profitExpenses);
            }

            PdfSharp.Charting.Chart chart = new PdfSharp.Charting.Chart(ChartType.Line);
            Series series;

            if (filteredProfitExpenses.Find(o => o.type.Equals(Constants.PROFIT)) != null)
            {
                series      = chart.SeriesCollection.AddSeries();
                series.Name = "Profit";
                series.Add(filteredProfitExpenses
                           .Where(o => o.type.Equals(Constants.PROFIT)).ToList()
                           .ConvertAll(o => o.amount).ToArray());
            }

            if (filteredProfitExpenses.Find(o => o.type.Equals(Constants.EXPENSE)) != null)
            {
                series      = chart.SeriesCollection.AddSeries();
                series.Name = "Expense";
                series.Add(filteredProfitExpenses
                           .Where(o => o.type.Equals(Constants.EXPENSE)).ToList()
                           .ConvertAll(o => o.amount).ToArray());
            }

            chart.XAxis.MajorTickMark = TickMarkType.Outside;
            chart.XAxis.Title.Caption = "Date";

            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.Title.Caption     = "Amount";
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color   = XColors.DarkGray;
            chart.PlotArea.LineFormat.Width   = 1;
            chart.PlotArea.LineFormat.Visible = true;

            chart.Legend.Docking            = DockingType.Bottom;
            chart.Legend.LineFormat.Visible = true;

            XSeries xseries = chart.XValues.AddXSeries();

            xseries.Add(filteredProfitExpenses.ConvertAll(o => o.dateTime.ToShortDateString()).ToArray());

            return(chart);
        }