/
Economist.xaml.cs
117 lines (96 loc) · 3.59 KB
/
Economist.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace CurseWork
{
public partial class Economist : Window
{
private DiagramIncome pageIncome;
private ExpenseChart pageExpense;
private Dictionary<int, int> dictionary;
private bool isIncome;
public Economist()
{
dictionary = new Dictionary<int, int>()
{
{0, 0},
{1, 365},
{2, 182},
{3, 91},
{4, 30},
{5, 7},
{6, 3},
{7, 1}
};
InitializeComponent();
}
private void Foods_Click(object sender, RoutedEventArgs e)
{
isIncome = true;
LoadIncome(Date.SelectedIndex);
}
private void LoadIncome(int index )
{
Income.Visibility = Visibility.Visible;
LabelIncome.Visibility = Visibility.Visible;
Expenses.Visibility = Visibility.Hidden;
LabelExpenses.Visibility = Visibility.Hidden;
pageIncome = new DiagramIncome(dictionary[index]);
Frame.Navigate(pageIncome);
using (var context = new MSSQLContext())
{
var list = context.Orders
.Include(o => o.OrderList)
.ToList();
if(index != 0)
Income.Text = list.Where(l => DateTime.Now
.Subtract(l.OrderList.DateOrder.Date).TotalDays <= dictionary[index])
.Sum(l => l.PriceBoughtFor * l.Count).ToString();
else
Income.Text = list.Sum(l => l.PriceBoughtFor * l.Count).ToString();
}
}
private void Ingredients_Click(object sender, RoutedEventArgs e)
{
isIncome = false;
LoadExpense(Date.SelectedIndex);
}
private void LoadExpense(int index)
{
Income.Visibility = Visibility.Hidden;
LabelIncome.Visibility = Visibility.Hidden;
Expenses.Visibility = Visibility.Visible;
LabelExpenses.Visibility = Visibility.Visible;
pageExpense = new ExpenseChart(dictionary[index]);
Frame.Navigate(pageExpense);
using (var context = new MSSQLContext())
{
var list = context.PurchaseIngredients.ToList();
if (index != 0)
Expenses.Text = list.Where(l => DateTime.Now
.Subtract(l.DateOfPurchase.Date).TotalDays <= dictionary[index])
.Sum(l => l.Price * l.Count).ToString();
else
Expenses.Text = list.Sum(l => l.Price * l.Count).ToString();
}
}
private void Date_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (isIncome)
LoadIncome(Date.SelectedIndex);
else
LoadExpense(Date.SelectedIndex);
}
private void Report_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Report report = new Report();
if(Report.SelectedIndex == 0)
report.CommonPart(3, dictionary[Date.SelectedIndex]);
else if(Report.SelectedIndex == 1)
report.CommonPart(4, dictionary[Date.SelectedIndex]);
}
}
}