root / GES_PAC / ViewModel / ChambersViewModel.cs @ 4afea73d
Historique | Voir | Annoter | Télécharger (1,81 ko)
1 | 09d4a0de | lbihannic | using GES_PAC.Model; |
---|---|---|---|
2 | using GES_PAC.View; |
||
3 | fff89fc5 | lbihannic | using System.Collections.ObjectModel; |
4 | 09d4a0de | lbihannic | using System.Windows.Input; |
5 | |||
6 | namespace GES_PAC.ViewModel |
||
7 | { |
||
8 | public class ChambersViewModel : BaseViewModel |
||
9 | { |
||
10 | |||
11 | #region Attributs |
||
12 | fff89fc5 | lbihannic | |
13 | 09d4a0de | lbihannic | #endregion |
14 | |||
15 | #region Commandes |
||
16 | public ICommand OnClickChamberCommand { get; } |
||
17 | #endregion |
||
18 | |||
19 | #region Propriétés |
||
20 | |||
21 | fff89fc5 | lbihannic | public Dictionary<int, int> NumberMeasure { get; set; } |
22 | |||
23 | public ObservableCollection<Color> ChamberColors { get; } = []; |
||
24 | 4afea73d | lbihannic | public ObservableCollection<int> ChamberNumbers { get; } = []; |
25 | fff89fc5 | lbihannic | |
26 | 09d4a0de | lbihannic | #endregion |
27 | |||
28 | #region Constructeurs |
||
29 | public ChambersViewModel() |
||
30 | { |
||
31 | fff89fc5 | lbihannic | NumberMeasure = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet().GetMeasureNumber(); |
32 | 4afea73d | lbihannic | UpdateChamberDatas(); |
33 | fff89fc5 | lbihannic | |
34 | ba296a27 | lbihannic | OnClickChamberCommand = new Command<string>(async (idStr) => |
35 | { |
||
36 | int id = int.Parse(idStr); |
||
37 | await GoToEnterAnimal(id); |
||
38 | }); |
||
39 | 09d4a0de | lbihannic | } |
40 | #endregion |
||
41 | |||
42 | #region Méthodes |
||
43 | private async Task GoToEnterAnimal(int id) |
||
44 | { |
||
45 | IsBusy = true; |
||
46 | 4afea73d | lbihannic | |
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 | 09d4a0de | lbihannic | IsBusy = false; |
53 | } |
||
54 | fff89fc5 | lbihannic | |
55 | 4afea73d | lbihannic | private void UpdateChamberDatas() |
56 | fff89fc5 | lbihannic | { |
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 | 4afea73d | lbihannic | ChamberNumbers.Add(count); |
63 | fff89fc5 | lbihannic | } |
64 | } |
||
65 | 09d4a0de | lbihannic | #endregion |
66 | } |
||
67 | } |