Révision 957b1f34 GES_PAC/ViewModel/CreateCalibrationViewModel.cs

Voir les différences:

GES_PAC/ViewModel/CreateCalibrationViewModel.cs
1
using CommunityToolkit.Maui.Core.Extensions;
2 1
using GES_PAC.Model;
3 2
using GES_PAC.View;
4 3
using System.Collections.ObjectModel;
5
using System.Diagnostics;
6 4
using System.Windows.Input;
7 5

  
8 6
namespace GES_PAC.ViewModel
......
17 15
        private double? _conc_ch4;
18 16
        private string _refBouteille;
19 17
        private bool _isRefBouteilleVisible;
18
        private Calibration _lastCalibration;
19
        private bool _hasLastMeasure;
20
        private double? _lastO2;
21
        private double? _lastCO2;
22
        private double? _lastCH4;
20 23
        private bool _isFormValid;
21 24
        #endregion
22 25

  
......
34 37
                _selectedType = value;
35 38
                IsRefBouteilleVisible = _selectedType.Name != "Air";
36 39
                OnPropertyChanged();
40
                OnTypeChanged();
37 41
                ValidateForm();
38 42
            }
39 43
        }
......
89 93
                OnPropertyChanged();
90 94
            }
91 95
        }
96
        public Calibration LastCalibration
97
        {
98
            get => _lastCalibration;
99
            set
100
            {
101
                _lastCalibration = value;
102
                OnPropertyChanged();
103
            }
104
        }
105
        public bool HasLastMeasure
106
        {
107
            get => _hasLastMeasure;
108
            set
109
            {
110
                _hasLastMeasure = value;
111
                OnPropertyChanged();
112
            }
113
        }
114
        public double? LastO2
115
        {
116
            get => _lastO2;
117
            set
118
            {
119
                _lastO2 = value;
120
                OnPropertyChanged();
121
            }
122
        }
123
        public double? LastCO2
124
        {
125
            get => _lastCO2;
126
            set
127
            {
128
                _lastCO2 = value;
129
                OnPropertyChanged();
130
            }
131
        }
132
        public double? LastCH4
133
        {
134
            get => _lastCH4;
135
            set
136
            {
137
                _lastCH4 = value;
138
                OnPropertyChanged();
139
            }
140
        }
92 141

  
93 142
        public bool IsFormValid
94 143
        {
......
110 159
        #region Constructeurs
111 160
        public CreateCalibrationViewModel()
112 161
        {
162
            CreateCalibrationCommand = new Command(async () => await CreateCalibration());
113 163

  
114 164
            var journeeActuelle = JourneeViewModel.Instance.GetCurrentDay();
115 165
            var typesManquants = journeeActuelle.GetCurrentMissingCalibration();
116 166

  
117 167
            TypeCalibrations = new ObservableCollection<TypeCalibration>(typesManquants);
118

  
119 168
            SelectedType = TypeCalibrations[0];
120 169

  
121
            CreateCalibrationCommand = new Command(async () => await CreateCalibration());
170
            if (journeeActuelle.GetCurrentPhase() == PhaseCalibration.Fin)
171
            { 
172
                LastCalibration = journeeActuelle.GetDebutCalibration();
173
                HasLastMeasure = true;
174
            }
122 175
        }
123 176
        #endregion
124 177

  
......
133 186
            var phaseCalibration = JourneeViewModel.Instance.GetCurrentPhase();
134 187
            var isComplete = JourneeViewModel.Instance.GetCurrentDay().AddCalibration(newCalib, phaseCalibration);
135 188

  
136
            if (isComplete)
137
            {
138
                await Shell.Current.GoToAsync(nameof(SetListView));
139
            }
140
            else
141
            {
142
                await Shell.Current.GoToAsync(nameof(CreateCalibrationView));
189
            var targetView = nameof(CreateCalibrationView);
190
            if (isComplete) {
191
                targetView = phaseCalibration == PhaseCalibration.Debut ? nameof(SetListView) : nameof(MainView);
143 192
            }
193
            await Shell.Current.GoToAsync(targetView);
144 194

  
145 195
            IsBusy = false;
146 196
        }
......
163 213

  
164 214
            (CreateCalibrationCommand as Command)?.ChangeCanExecute();
165 215
        }
216

  
217
        private void OnTypeChanged()
218
        {
219
            if (!HasLastMeasure)
220
                return;
221
            var mesureCalibration = LastCalibration.getMesureCalibrationByType(SelectedType);
222
            LastCH4 = mesureCalibration.Conc_CH4;
223
            LastO2 = mesureCalibration.Conc_O2;
224
            LastCO2 = mesureCalibration.Conc_CO2;
225
        }
166 226
        #endregion
167 227
    }
168 228
}

Formats disponibles : Unified diff