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