root / GES_PAC / ViewModel / MainViewModel.cs @ 9601eaf0
Historique | Voir | Annoter | Télécharger (3,754 ko)
1 | 12ddf7ef | lbihannic | using GES_PAC.Model; |
---|---|---|---|
2 | 65ad7e66 | Lucas Bihannic | using GES_PAC.View; |
3 | acb5dd8c | lbihannic | using System.Windows.Input; |
4 | 65ad7e66 | Lucas Bihannic | |
5 | namespace GES_PAC.ViewModel |
||
6 | { |
||
7 | acb5dd8c | lbihannic | public class MainViewModel : BaseViewModel |
8 | 65ad7e66 | Lucas Bihannic | { |
9 | acb5dd8c | lbihannic | #region Attributs |
10 | private bool _hasLastDay = false; |
||
11 | private Journee _currentDay; |
||
12 | private string _currentDayText; |
||
13 | #endregion |
||
14 | |||
15 | 18f910c6 | Lucas Bihannic | #region Commandes |
16 | acb5dd8c | lbihannic | public ICommand GoToCreateDayCommand { get; } |
17 | public ICommand ResumeDayCommand { get; } |
||
18 | 957bebf1 | lbihannic | public ICommand ExportDataCommand { get; } |
19 | acb5dd8c | lbihannic | #endregion |
20 | |||
21 | #region Propriétés |
||
22 | public bool HasLastDay |
||
23 | { |
||
24 | get => _hasLastDay; |
||
25 | set |
||
26 | { |
||
27 | SetProperty(ref _hasLastDay, value); |
||
28 | OnPropertyChanged(); |
||
29 | } |
||
30 | } |
||
31 | public Journee CurrentDay |
||
32 | { |
||
33 | get => _currentDay; |
||
34 | set |
||
35 | { |
||
36 | SetProperty(ref _currentDay, value); |
||
37 | OnPropertyChanged(); |
||
38 | } |
||
39 | } |
||
40 | public string CurrentDayText |
||
41 | { |
||
42 | get => _currentDayText; |
||
43 | set |
||
44 | { |
||
45 | SetProperty(ref _currentDayText, value); |
||
46 | OnPropertyChanged(); |
||
47 | } |
||
48 | } |
||
49 | 18f910c6 | Lucas Bihannic | #endregion |
50 | |||
51 | #region Constructeur |
||
52 | 42456640 | lbihannic | public MainViewModel() |
53 | 65ad7e66 | Lucas Bihannic | { |
54 | 12ddf7ef | lbihannic | //ONLY FOR TESTS |
55 | 9601eaf0 | lbihannic | var date = DateTime.Now.AddHours(-2); |
56 | 957bebf1 | lbihannic | var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], ""); |
57 | newDay.AddSet(new Serie(date, date, 25, 25, 25)); |
||
58 | 9601eaf0 | lbihannic | newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.DEBUT); |
59 | newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.DEBUT); |
||
60 | newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.DEBUT); |
||
61 | 957bebf1 | lbihannic | newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, "")); |
62 | newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false); |
||
63 | JourneeViewModel.Instance.Journees.Add(newDay); |
||
64 | 12ddf7ef | lbihannic | //ONLY FOR TESTS |
65 | |||
66 | 65ad7e66 | Lucas Bihannic | GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage()); |
67 | acb5dd8c | lbihannic | ResumeDayCommand = new Command(async () => await ResumeDay()); |
68 | 957bebf1 | lbihannic | ExportDataCommand = new Command(async () => await ExportData()); |
69 | acb5dd8c | lbihannic | |
70 | GetLastDay(); |
||
71 | 65ad7e66 | Lucas Bihannic | } |
72 | 18f910c6 | Lucas Bihannic | #endregion |
73 | 65ad7e66 | Lucas Bihannic | |
74 | 18f910c6 | Lucas Bihannic | #region Méthodes |
75 | acb5dd8c | lbihannic | |
76 | public void GetLastDay() |
||
77 | { |
||
78 | CurrentDay = JourneeViewModel.Instance.GetCurrentDay(); |
||
79 | HasLastDay = !CurrentDay?.IsComplete() ?? false; |
||
80 | CurrentDayText = HasLastDay ? "Une journée en cours, la reprendre ?" : "Aucune journée trouvée, en créer une ?"; |
||
81 | |||
82 | } |
||
83 | 65ad7e66 | Lucas Bihannic | private async Task GoToCreateDayPage() |
84 | { |
||
85 | 1019554c | lbihannic | if (IsBusy) return; |
86 | 18f910c6 | Lucas Bihannic | IsBusy = true; |
87 | 65ad7e66 | Lucas Bihannic | await Shell.Current.GoToAsync(nameof(CreateDayView)); |
88 | 18f910c6 | Lucas Bihannic | IsBusy = false; |
89 | 65ad7e66 | Lucas Bihannic | } |
90 | acb5dd8c | lbihannic | |
91 | private async Task ResumeDay() |
||
92 | { |
||
93 | if (IsBusy) return; |
||
94 | IsBusy = true; |
||
95 | |||
96 | CurrentDay = JourneeViewModel.Instance.GetCurrentDay(); |
||
97 | 9601eaf0 | lbihannic | var targetView = $"{nameof(CreateCalibrationView)}?phase={PhaseCalibration.DEBUT.Name}"; |
98 | if (CurrentDay.IsCalibrationComplete(PhaseCalibration.DEBUT)) |
||
99 | acb5dd8c | lbihannic | targetView = nameof(SetListView); |
100 | |||
101 | await Shell.Current.GoToAsync(targetView); |
||
102 | IsBusy = false; |
||
103 | 957bebf1 | lbihannic | } |
104 | private async Task ExportData() |
||
105 | { |
||
106 | if (IsBusy) return; |
||
107 | IsBusy = true; |
||
108 | await Shell.Current.GoToAsync(nameof(ExportDataView)); |
||
109 | IsBusy = false; |
||
110 | acb5dd8c | lbihannic | } |
111 | 18f910c6 | Lucas Bihannic | #endregion |
112 | 65ad7e66 | Lucas Bihannic | } |
113 | } |