Révision 6f451cc1 GES_PAC/ViewModel/CreateCalibrationViewModel.cs
GES_PAC/ViewModel/CreateCalibrationViewModel.cs | ||
---|---|---|
1 | 1 |
using GES_PAC.Model; |
2 | 2 |
using GES_PAC.View; |
3 |
using Microsoft.EntityFrameworkCore; |
|
3 | 4 |
using System.Collections.ObjectModel; |
4 | 5 |
using System.Windows.Input; |
5 | 6 |
|
... | ... | |
11 | 12 |
|
12 | 13 |
#region Attributs |
13 | 14 |
public string _phaseName; |
15 |
private ObservableCollection<TypeCalibration> _typeCalibrations; |
|
14 | 16 |
private TypeCalibration _selectedType; |
15 | 17 |
private double? _conc_o2; |
16 | 18 |
private double? _conc_co2; |
... | ... | |
36 | 38 |
get => _phaseName; |
37 | 39 |
set |
38 | 40 |
{ |
41 |
if (_phaseName == value) return; |
|
39 | 42 |
_phaseName = value; |
40 | 43 |
Phase = PhaseCalibration.All.FirstOrDefault(p => p.Name == value) ?? PhaseCalibration.DEBUT; |
41 | 44 |
OnPropertyChanged(); |
45 |
OnPhaseChanged(); |
|
42 | 46 |
} |
43 | 47 |
} |
44 |
public ObservableCollection<TypeCalibration> TypeCalibrations { get; } |
|
48 |
public ObservableCollection<TypeCalibration> TypeCalibrations |
|
49 |
{ |
|
50 |
get => _typeCalibrations; |
|
51 |
set |
|
52 |
{ |
|
53 |
_typeCalibrations = value; |
|
54 |
OnPropertyChanged(); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
45 | 58 |
public TypeCalibration SelectedType |
46 | 59 |
{ |
47 | 60 |
get => _selectedType; |
48 | 61 |
set |
49 | 62 |
{ |
50 | 63 |
_selectedType = value; |
51 |
IsRefBouteilleVisible = _selectedType != TypeCalibration.Air;
|
|
64 |
IsRefBouteilleVisible = _selectedType != TypeCalibration.AIR;
|
|
52 | 65 |
OnPropertyChanged(); |
53 | 66 |
OnTypeChanged(); |
54 | 67 |
ValidateForm(); |
... | ... | |
173 | 186 |
public CreateCalibrationViewModel() |
174 | 187 |
{ |
175 | 188 |
CreateCalibrationCommand = new Command(async () => await CreateCalibration()); |
189 |
} |
|
190 |
#endregion |
|
176 | 191 |
|
192 |
#region Méthodes |
|
193 |
|
|
194 |
public void OnPhaseChanged() |
|
195 |
{ |
|
177 | 196 |
var journeeActuelle = JourneeViewModel.Instance.GetCurrentDay(); |
178 |
var typesManquants = journeeActuelle.GetCurrentMissingCalibration(); |
|
179 |
var phaseCalibration = journeeActuelle.GetCurrentPhase(); |
|
197 |
var typesManquants = journeeActuelle.GetMissingCalibrationByPhase(Phase); |
|
180 | 198 |
|
181 | 199 |
TypeCalibrations = new ObservableCollection<TypeCalibration>(typesManquants); |
182 | 200 |
SelectedType = TypeCalibrations[0]; |
183 | 201 |
|
184 |
if (journeeActuelle.GetCurrentPhase() == PhaseCalibration.FIN)
|
|
185 |
{
|
|
202 |
if (Phase == PhaseCalibration.FIN)
|
|
203 |
{ |
|
186 | 204 |
LastCalibration = journeeActuelle.GetDebutCalibration(); |
187 | 205 |
HasLastMeasure = true; |
206 |
OnTypeChanged(); |
|
188 | 207 |
} |
189 | 208 |
} |
190 |
#endregion |
|
191 |
|
|
192 |
#region Méthodes |
|
193 | 209 |
private async Task CreateCalibration() |
194 | 210 |
{ |
195 | 211 |
if (IsBusy) return; |
196 | 212 |
IsBusy = true; |
197 | 213 |
|
214 |
var journee = JourneeViewModel.Instance.GetCurrentDay(); |
|
198 | 215 |
var date = DateTime.Now; |
199 | 216 |
var newCalib = new MesureCalibration(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0, SelectedType, RefBouteille); |
200 |
var isComplete = JourneeViewModel.Instance.GetCurrentDay().AddCalibration(newCalib, Phase); |
|
201 | 217 |
|
218 |
var calibration = journee.Calibrations.FirstOrDefault(c => c.Phase == Phase); |
|
219 |
if (calibration == null) |
|
220 |
{ |
|
221 |
calibration = new Calibration(Phase, newCalib); |
|
222 |
journee.AddCalibration(calibration); |
|
223 |
App.Db.Calibration.Add(calibration); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
calibration.AddMesure(newCalib); |
|
228 |
} |
|
229 |
|
|
230 |
App.Db.MesureCalibration.Add(newCalib); |
|
231 |
await App.Db.SaveChangesAsync(); |
|
232 |
|
|
233 |
var isComplete = calibration.IsComplete(); |
|
202 | 234 |
var targetView = $"{nameof(CreateCalibrationView)}?phase={PhaseName}"; |
203 | 235 |
if (isComplete) { |
204 | 236 |
targetView = Phase == PhaseCalibration.DEBUT ? nameof(SetListView) : nameof(MainView); |
Formats disponibles : Unified diff