root / GES_PAC / ViewModel / CreateMeasureViewModel.cs @ 4afea73d
Historique | Voir | Annoter | Télécharger (3,146 ko)
1 |
using GES_PAC.Model; |
---|---|
2 |
using GES_PAC.View; |
3 |
using System.Collections.ObjectModel; |
4 |
using System.Windows.Input; |
5 |
|
6 |
namespace GES_PAC.ViewModel |
7 |
{ |
8 |
[QueryProperty(nameof(ChamberId), "chamberId")] |
9 |
public class CreateMeasureViewModel : BaseViewModel |
10 |
{ |
11 |
|
12 |
#region Attributs |
13 |
private int _chamberId; |
14 |
private double? _conc_o2; |
15 |
private double? _conc_co2; |
16 |
private double? _conc_ch4; |
17 |
private bool _isFormValid; |
18 |
#endregion |
19 |
|
20 |
#region Commandes |
21 |
public ICommand CreateMeasureCommand { get; } |
22 |
#endregion |
23 |
|
24 |
#region Propriétés |
25 |
public int ChamberId |
26 |
{ |
27 |
get => _chamberId; |
28 |
set |
29 |
{ |
30 |
_chamberId = value; |
31 |
OnPropertyChanged(); |
32 |
OnPropertyChanged(nameof(Titre)); |
33 |
} |
34 |
} |
35 |
|
36 |
public double? ConcO2 |
37 |
{ |
38 |
get => _conc_o2; |
39 |
set |
40 |
{ |
41 |
_conc_o2 = value; |
42 |
OnPropertyChanged(); |
43 |
ValidateForm(); |
44 |
} |
45 |
} |
46 |
|
47 |
public double? ConcCO2 |
48 |
{ |
49 |
get => _conc_co2; |
50 |
set |
51 |
{ |
52 |
_conc_co2 = value; |
53 |
OnPropertyChanged(); |
54 |
ValidateForm(); |
55 |
} |
56 |
} |
57 |
|
58 |
public double? ConcCH4 |
59 |
{ |
60 |
get => _conc_ch4; |
61 |
set |
62 |
{ |
63 |
_conc_ch4 = value; |
64 |
OnPropertyChanged(); |
65 |
ValidateForm(); |
66 |
} |
67 |
} |
68 |
|
69 |
public bool IsFormValid |
70 |
{ |
71 |
get => _isFormValid; |
72 |
set |
73 |
{ |
74 |
_isFormValid = value; |
75 |
OnPropertyChanged(); |
76 |
} |
77 |
} |
78 |
|
79 |
public bool ConcO2Error { get; private set; } = true; |
80 |
public bool ConcCO2Error { get; private set; } = true; |
81 |
public bool ConcCH4Error { get; private set; } = true; |
82 |
public string Titre => $"Mesures chambre {ChamberId}"; |
83 |
#endregion |
84 |
|
85 |
#region Constructeurs |
86 |
public CreateMeasureViewModel() |
87 |
{ |
88 |
CreateMeasureCommand = new Command(async () => await CreateMeasure()); |
89 |
} |
90 |
#endregion |
91 |
|
92 |
#region Méthodes |
93 |
private async Task CreateMeasure() |
94 |
{ |
95 |
IsBusy = true; |
96 |
|
97 |
var date = DateTime.Now; |
98 |
var newMeasure = new Mesure(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0); |
99 |
var phaseCalibration = JourneeViewModel.Instance.GetCurrentPhase(); |
100 |
|
101 |
JourneeViewModel.Instance.AddMeasureToCurrentSet(newMeasure, ChamberId); |
102 |
|
103 |
await Shell.Current.GoToAsync(nameof(ChambersView)); |
104 |
|
105 |
IsBusy = false; |
106 |
} |
107 |
|
108 |
private void ValidateForm() |
109 |
{ |
110 |
ConcO2Error = ConcO2 == null; |
111 |
ConcCO2Error = ConcCO2 == null; |
112 |
ConcCH4Error = ConcCH4 == null; |
113 |
|
114 |
OnPropertyChanged(nameof(ConcO2Error)); |
115 |
OnPropertyChanged(nameof(ConcCO2Error)); |
116 |
OnPropertyChanged(nameof(ConcCH4Error)); |
117 |
|
118 |
IsFormValid = !ConcO2Error && !ConcCO2Error && !ConcCH4Error; |
119 |
|
120 |
(CreateMeasureCommand as Command)?.ChangeCanExecute(); |
121 |
} |
122 |
#endregion |
123 |
} |
124 |
} |