Révision acb5dd8c GES_PAC/ViewModel/MainViewModel.cs
GES_PAC/ViewModel/MainViewModel.cs | ||
---|---|---|
1 | 1 |
using GES_PAC.Model; |
2 | 2 |
using GES_PAC.Services; |
3 | 3 |
using GES_PAC.View; |
4 |
using System.Windows.Input; |
|
4 | 5 |
|
5 | 6 |
namespace GES_PAC.ViewModel |
6 | 7 |
{ |
7 |
public class MainViewModel : BaseViewModel |
|
8 |
public class MainViewModel : BaseViewModel
|
|
8 | 9 |
{ |
10 |
#region Attributs |
|
11 |
private bool _hasLastDay = false; |
|
12 |
private Journee _currentDay; |
|
13 |
private string _currentDayText; |
|
14 |
#endregion |
|
15 |
|
|
9 | 16 |
#region Services |
10 | 17 |
private readonly ConnexionService connService; |
11 | 18 |
#endregion |
12 | 19 |
|
13 | 20 |
#region Commandes |
14 |
public Command GoToCreateDayCommand { get; } |
|
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 |
} |
|
15 | 53 |
#endregion |
16 | 54 |
|
17 | 55 |
#region Constructeur |
18 | 56 |
public MainViewModel(ConnexionService connService) |
19 | 57 |
{ |
20 | 58 |
//ONLY FOR TESTS |
21 |
var date = DateTime.Now; |
|
22 |
var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], ""); |
|
23 |
newDay.AddSet(new Serie(date, date, 25, 25, 25)); |
|
24 |
newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut); |
|
25 |
newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut); |
|
26 |
newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut); |
|
27 |
newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, "")); |
|
28 |
newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false); |
|
29 |
JourneeViewModel.Instance.Journees.Add(newDay); |
|
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);
|
|
30 | 68 |
//ONLY FOR TESTS |
31 | 69 |
|
32 |
this.connService = connService; |
|
33 | 70 |
GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage()); |
71 |
ResumeDayCommand = new Command(async () => await ResumeDay()); |
|
72 |
|
|
73 |
this.connService = connService; |
|
74 |
|
|
75 |
GetLastDay(); |
|
34 | 76 |
} |
35 | 77 |
#endregion |
36 | 78 |
|
37 | 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 |
} |
|
38 | 88 |
private async Task GoToCreateDayPage() |
39 | 89 |
{ |
40 | 90 |
if (IsBusy) return; |
... | ... | |
42 | 92 |
await Shell.Current.GoToAsync(nameof(CreateDayView)); |
43 | 93 |
IsBusy = false; |
44 | 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 |
} |
|
45 | 109 |
#endregion |
46 | 110 |
} |
47 | 111 |
} |
Formats disponibles : Unified diff