root / GES_PAC / ViewModel / MainViewModel.cs @ 42456640
Historique | Voir | Annoter | Télécharger (3,387 ko)
1 |
using GES_PAC.Model; |
---|---|
2 |
using GES_PAC.View; |
3 |
using System.Windows.Input; |
4 | |
5 |
namespace GES_PAC.ViewModel |
6 |
{ |
7 |
public class MainViewModel : BaseViewModel |
8 |
{ |
9 |
#region Attributs |
10 |
private bool _hasLastDay = false; |
11 |
private Journee _currentDay; |
12 |
private string _currentDayText; |
13 |
#endregion |
14 | |
15 |
|
16 | |
17 |
#region Commandes |
18 |
public ICommand GoToCreateDayCommand { get; } |
19 |
public ICommand ResumeDayCommand { get; } |
20 |
#endregion |
21 | |
22 |
#region Propriétés |
23 |
public bool HasLastDay |
24 |
{ |
25 |
get => _hasLastDay; |
26 |
set |
27 |
{ |
28 |
SetProperty(ref _hasLastDay, value); |
29 |
OnPropertyChanged(); |
30 |
} |
31 |
} |
32 |
public Journee CurrentDay |
33 |
{ |
34 |
get => _currentDay; |
35 |
set |
36 |
{ |
37 |
SetProperty(ref _currentDay, value); |
38 |
OnPropertyChanged(); |
39 |
} |
40 |
} |
41 |
public string CurrentDayText |
42 |
{ |
43 |
get => _currentDayText; |
44 |
set |
45 |
{ |
46 |
SetProperty(ref _currentDayText, value); |
47 |
OnPropertyChanged(); |
48 |
} |
49 |
} |
50 |
#endregion |
51 | |
52 |
#region Constructeur |
53 |
public MainViewModel() |
54 |
{ |
55 |
//ONLY FOR TESTS |
56 |
//var date = DateTime.Now; |
57 |
//var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], ""); |
58 |
//newDay.AddSet(new Serie(date, date, 25, 25, 25)); |
59 |
//newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut); |
60 |
//newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut); |
61 |
//newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut); |
62 |
//newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, "")); |
63 |
//newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false); |
64 |
//JourneeViewModel.Instance.Journees.Add(newDay); |
65 |
//ONLY FOR TESTS |
66 | |
67 |
GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage()); |
68 |
ResumeDayCommand = new Command(async () => await ResumeDay()); |
69 | |
70 |
GetLastDay(); |
71 |
} |
72 |
#endregion |
73 | |
74 |
#region Méthodes |
75 |
|
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 |
private async Task GoToCreateDayPage() |
84 |
{ |
85 |
if (IsBusy) return; |
86 |
IsBusy = true; |
87 |
await Shell.Current.GoToAsync(nameof(CreateDayView)); |
88 |
IsBusy = false; |
89 |
} |
90 | |
91 |
private async Task ResumeDay() |
92 |
{ |
93 |
if (IsBusy) return; |
94 |
IsBusy = true; |
95 | |
96 |
CurrentDay = JourneeViewModel.Instance.GetCurrentDay(); |
97 |
var targetView = nameof(CreateCalibrationView); |
98 |
if (CurrentDay.IsCalibrationComplete(PhaseCalibration.Debut)) |
99 |
targetView = nameof(SetListView); |
100 | |
101 |
await Shell.Current.GoToAsync(targetView); |
102 |
IsBusy = false; |
103 |
} |
104 |
#endregion |
105 |
} |
106 |
} |