Révision e837cdf1 GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs
GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs | ||
---|---|---|
7 | 7 |
public class ChamberButtonViewModel : BaseViewModel |
8 | 8 |
{ |
9 | 9 |
#region Attributs |
10 |
private Serie _currentSet; |
|
10 | 11 |
private string _buttonText; |
11 | 12 |
private int _chamberId; |
12 | 13 |
private Color _buttonBackgroundColor; |
13 | 14 |
private bool _buttonIsEnabled; |
14 | 15 |
private string _buttonLabel; |
16 |
private string _timeIn; |
|
15 | 17 |
private ICommand _onClickChamberCommand; |
18 |
private readonly TimerPublisher _timer; |
|
19 |
|
|
16 | 20 |
#endregion |
17 | 21 |
|
18 | 22 |
#region Propriétés |
19 |
|
|
23 |
public Serie CurrentSet |
|
24 |
{ |
|
25 |
get => _currentSet; |
|
26 |
set |
|
27 |
{ |
|
28 |
_currentSet = value; |
|
29 |
OnPropertyChanged(); |
|
30 |
} |
|
31 |
} |
|
20 | 32 |
public string ButtonText { |
21 | 33 |
get => _buttonText; |
22 | 34 |
set |
... | ... | |
61 | 73 |
OnPropertyChanged(); |
62 | 74 |
} |
63 | 75 |
} |
64 |
public Serie CurrentSet { get; set; } |
|
76 |
public string TimeIn |
|
77 |
{ |
|
78 |
get => _timeIn; |
|
79 |
set |
|
80 |
{ |
|
81 |
_timeIn = value; |
|
82 |
OnPropertyChanged(); |
|
83 |
} |
|
84 |
} |
|
85 |
public SerieAnimal AnimalSet; |
|
86 |
private bool _isSubscribed = false; |
|
87 |
|
|
65 | 88 |
#endregion |
66 | 89 |
|
67 | 90 |
#region Commandes |
... | ... | |
77 | 100 |
#endregion |
78 | 101 |
|
79 | 102 |
#region Constructeurs |
80 |
#endregion |
|
81 | 103 |
|
82 |
#region Méthodes |
|
83 |
public void UpdateProperties(int chamberId) |
|
104 |
public ChamberButtonViewModel(int chamberId, TimerPublisher timerPublisher) |
|
84 | 105 |
{ |
85 |
OnClickChamberCommand = new Command(async () => await GoToEnterAnimal()); |
|
106 |
ChamberId = chamberId; |
|
107 |
_timer = timerPublisher; |
|
86 | 108 |
|
109 |
OnClickChamberCommand = new Command(async () => await GoToChamber()); |
|
110 |
ButtonBackgroundColor = Colors.White; |
|
111 |
ButtonIsEnabled = true; |
|
112 |
ButtonLabel = "0"; |
|
113 |
TimeIn = ""; |
|
87 | 114 |
CurrentSet = JourneeViewModel.Instance.GetCurrentSet(); |
88 | 115 |
|
89 |
ButtonText = chamberId.ToString(); |
|
116 |
UpdateChamberId(chamberId); |
|
117 |
} |
|
118 |
|
|
119 |
#endregion |
|
120 |
|
|
121 |
#region Méthodes |
|
122 |
public void UpdateChamberId(int chamberId) |
|
123 |
{ |
|
90 | 124 |
ChamberId = chamberId; |
125 |
UpdateProperties(); |
|
126 |
} |
|
127 |
public void UpdateProperties() |
|
128 |
{ |
|
129 |
AnimalSet = CurrentSet.GetSerieAnimalByNumBoite(ChamberId); |
|
130 |
ButtonText = ChamberId.ToString(); |
|
131 |
|
|
132 |
int measureCount = AnimalSet?.GetMeasureCount() ?? 0; |
|
91 | 133 |
|
92 |
ButtonIsEnabled = JourneeViewModel.Instance.GetCurrentSet().GetIsInByNumeroBoite(chamberId); |
|
93 |
bool hasBehaviour = CurrentSet.GetHasBehaviourByNumeroBoite(chamberId); |
|
94 |
int count = CurrentSet.GetMeasureNumberByNumeroBoite(chamberId); |
|
95 |
if (hasBehaviour) |
|
96 |
ButtonBackgroundColor = Colors.Yellow; |
|
97 |
else |
|
98 |
ButtonBackgroundColor = count > 0 ? Colors.LightGreen : Colors.White; |
|
99 |
ButtonLabel = count.ToString(); |
|
134 |
if (measureCount == 0) |
|
135 |
return; |
|
136 |
|
|
137 |
if (!_isSubscribed && !AnimalSet.IsOut) |
|
138 |
{ |
|
139 |
_timer.Register(OnTimerTick); |
|
140 |
_isSubscribed = true; |
|
141 |
} |
|
142 |
|
|
143 |
if (_isSubscribed && AnimalSet.IsOut) |
|
144 |
{ |
|
145 |
_timer.Unregister(OnTimerTick); |
|
146 |
_isSubscribed = false; |
|
147 |
} |
|
148 |
|
|
149 |
ButtonIsEnabled = !AnimalSet.IsOut; |
|
150 |
ButtonBackgroundColor = AnimalSet.HasBehaviour() ? Colors.Yellow : Colors.LightGreen; |
|
151 |
ButtonLabel = measureCount.ToString(); |
|
152 |
TimeIn = AnimalSet.GetTimeInChamber(); |
|
100 | 153 |
} |
101 |
private async Task GoToEnterAnimal() |
|
154 |
|
|
155 |
private async Task GoToChamber() |
|
102 | 156 |
{ |
103 | 157 |
if (IsBusy) return; |
104 | 158 |
IsBusy = true; |
105 | 159 |
|
106 |
var targetView = (CurrentSet.GetMeasureNumberByNumeroBoite(ChamberId) == 0) ? nameof(EnterAnimalView) : nameof(CreateMeasureView);
|
|
160 |
var targetView = (CurrentSet.GetSerieAnimalByNumBoite(ChamberId) == null) ? nameof(EnterAnimalView) : nameof(CreateMeasureView);
|
|
107 | 161 |
|
108 | 162 |
await Shell.Current.GoToAsync($"{targetView}?chamberId={ChamberId}"); |
109 | 163 |
|
110 | 164 |
IsBusy = false; |
111 | 165 |
} |
166 |
public void OnTimerTick(object? sender, EventArgs e) |
|
167 |
{ |
|
168 |
TimeIn = AnimalSet?.GetTimeInChamber() ?? ""; |
|
169 |
} |
|
170 |
|
|
112 | 171 |
#endregion |
113 | 172 |
} |
114 | 173 |
} |
Formats disponibles : Unified diff