root / GES_PAC / ViewModel / ChambersViewModel.cs @ 4afea73d
Historique | Voir | Annoter | Télécharger (1,81 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 |
public class ChambersViewModel : BaseViewModel |
9 |
{ |
10 |
|
11 |
#region Attributs |
12 |
|
13 |
#endregion |
14 |
|
15 |
#region Commandes |
16 |
public ICommand OnClickChamberCommand { get; } |
17 |
#endregion |
18 |
|
19 |
#region Propriétés |
20 |
|
21 |
public Dictionary<int, int> NumberMeasure { get; set; } |
22 |
|
23 |
public ObservableCollection<Color> ChamberColors { get; } = []; |
24 |
public ObservableCollection<int> ChamberNumbers { get; } = []; |
25 |
|
26 |
#endregion |
27 |
|
28 |
#region Constructeurs |
29 |
public ChambersViewModel() |
30 |
{ |
31 |
NumberMeasure = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet().GetMeasureNumber(); |
32 |
UpdateChamberDatas(); |
33 |
|
34 |
OnClickChamberCommand = new Command<string>(async (idStr) => |
35 |
{ |
36 |
int id = int.Parse(idStr); |
37 |
await GoToEnterAnimal(id); |
38 |
}); |
39 |
} |
40 |
#endregion |
41 |
|
42 |
#region Méthodes |
43 |
private async Task GoToEnterAnimal(int id) |
44 |
{ |
45 |
IsBusy = true; |
46 |
|
47 |
if (!NumberMeasure.ContainsValue(id)) |
48 |
await Shell.Current.GoToAsync($"{nameof(EnterAnimalView)}?chamberId={id}"); |
49 |
else |
50 |
await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={id}"); |
51 |
|
52 |
IsBusy = false; |
53 |
} |
54 |
|
55 |
private void UpdateChamberDatas() |
56 |
{ |
57 |
ChamberColors.Clear(); |
58 |
for (int i = 1; i <= 12; i++) |
59 |
{ |
60 |
int count = NumberMeasure.TryGetValue(i, out var val) ? val : 0; |
61 |
ChamberColors.Add(count > 0 ? Colors.LightGreen : Colors.White); |
62 |
ChamberNumbers.Add(count); |
63 |
} |
64 |
} |
65 |
#endregion |
66 |
} |
67 |
} |