Révision 1019554c GES_PAC/ViewModel/CreateMeasureViewModel.cs
GES_PAC/ViewModel/CreateMeasureViewModel.cs | ||
---|---|---|
1 | 1 |
using GES_PAC.Model; |
2 | 2 |
using GES_PAC.View; |
3 |
using System.Collections.ObjectModel; |
|
4 | 3 |
using System.Windows.Input; |
5 | 4 |
|
6 | 5 |
namespace GES_PAC.ViewModel |
... | ... | |
15 | 14 |
private double? _conc_co2; |
16 | 15 |
private double? _conc_ch4; |
17 | 16 |
private bool _isFormValid; |
17 |
private bool _hasLastMeasure; |
|
18 |
private double? _lastO2; |
|
19 |
private double? _lastCO2; |
|
20 |
private double? _lastCH4; |
|
18 | 21 |
#endregion |
19 | 22 |
|
20 | 23 |
#region Commandes |
... | ... | |
30 | 33 |
_chamberId = value; |
31 | 34 |
OnPropertyChanged(); |
32 | 35 |
OnPropertyChanged(nameof(Titre)); |
36 |
GetLastMeasure(); |
|
33 | 37 |
} |
34 | 38 |
} |
35 | 39 |
|
... | ... | |
65 | 69 |
ValidateForm(); |
66 | 70 |
} |
67 | 71 |
} |
68 |
|
|
72 |
public bool HasLastMeasure |
|
73 |
{ |
|
74 |
get => _hasLastMeasure; |
|
75 |
set |
|
76 |
{ |
|
77 |
_hasLastMeasure = value; |
|
78 |
OnPropertyChanged(); |
|
79 |
} |
|
80 |
} |
|
81 |
public double? LastO2 |
|
82 |
{ |
|
83 |
get => _lastO2; |
|
84 |
set |
|
85 |
{ |
|
86 |
_lastO2 = value; |
|
87 |
OnPropertyChanged(); |
|
88 |
} |
|
89 |
} |
|
90 |
public double? LastCO2 |
|
91 |
{ |
|
92 |
get => _lastCO2; |
|
93 |
set |
|
94 |
{ |
|
95 |
_lastCO2 = value; |
|
96 |
OnPropertyChanged(); |
|
97 |
} |
|
98 |
} |
|
99 |
public double? LastCH4 |
|
100 |
{ |
|
101 |
get => _lastCH4; |
|
102 |
set |
|
103 |
{ |
|
104 |
_lastCH4 = value; |
|
105 |
OnPropertyChanged(); |
|
106 |
} |
|
107 |
} |
|
69 | 108 |
public bool IsFormValid |
70 | 109 |
{ |
71 | 110 |
get => _isFormValid; |
... | ... | |
80 | 119 |
public bool ConcCO2Error { get; private set; } = true; |
81 | 120 |
public bool ConcCH4Error { get; private set; } = true; |
82 | 121 |
public string Titre => $"Mesures chambre {ChamberId}"; |
122 |
public Mesure? LastMeasure { get; set; } |
|
83 | 123 |
#endregion |
84 | 124 |
|
85 | 125 |
#region Constructeurs |
86 | 126 |
public CreateMeasureViewModel() |
87 | 127 |
{ |
88 | 128 |
CreateMeasureCommand = new Command(async () => await CreateMeasure()); |
129 |
|
|
130 |
HasLastMeasure = false; |
|
89 | 131 |
} |
90 | 132 |
#endregion |
91 | 133 |
|
92 | 134 |
#region Méthodes |
93 | 135 |
private async Task CreateMeasure() |
94 | 136 |
{ |
137 |
if (IsBusy) return; |
|
95 | 138 |
IsBusy = true; |
96 | 139 |
|
97 | 140 |
var date = DateTime.Now; |
98 | 141 |
var newMeasure = new Mesure(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0); |
99 |
var phaseCalibration = JourneeViewModel.Instance.GetCurrentPhase(); |
|
100 | 142 |
|
101 | 143 |
JourneeViewModel.Instance.AddMeasureToCurrentSet(newMeasure, ChamberId); |
102 | 144 |
|
... | ... | |
119 | 161 |
|
120 | 162 |
(CreateMeasureCommand as Command)?.ChangeCanExecute(); |
121 | 163 |
} |
164 |
|
|
165 |
private void GetLastMeasure() |
|
166 |
{ |
|
167 |
LastMeasure = JourneeViewModel.Instance.GetCurrentSet().GetLastMeasureByNumeroBoite(ChamberId); |
|
168 |
HasLastMeasure = LastMeasure != null; |
|
169 |
if (HasLastMeasure) |
|
170 |
{ |
|
171 |
LastO2 = LastMeasure.Conc_O2; |
|
172 |
LastCO2 = LastMeasure.Conc_CO2; |
|
173 |
LastCH4 = LastMeasure.Conc_CH4; |
|
174 |
} |
|
175 |
} |
|
122 | 176 |
#endregion |
123 | 177 |
} |
124 | 178 |
} |
Formats disponibles : Unified diff