root / GES_PAC / ViewModel / Controls / ChamberButtonViewModel.cs @ 12ddf7ef
Historique | Voir | Annoter | Télécharger (3,271 ko)
1 |
using GES_PAC.Model; |
---|---|
2 |
using GES_PAC.View; |
3 |
using System.Windows.Input; |
4 |
|
5 |
namespace GES_PAC.ViewModel.Controls |
6 |
{ |
7 |
public class ChamberButtonViewModel : BaseViewModel |
8 |
{ |
9 |
#region Attributs |
10 |
private string _buttonText; |
11 |
private int _buttonCommandParameter; |
12 |
private Color _buttonBackgroundColor; |
13 |
private bool _buttonIsEnabled; |
14 |
private string _buttonLabel; |
15 |
private ICommand _onClickChamberCommand; |
16 |
#endregion |
17 |
|
18 |
#region Propriétés |
19 |
|
20 |
public string ButtonText { |
21 |
get => _buttonText; |
22 |
set |
23 |
{ |
24 |
_buttonText = value; |
25 |
OnPropertyChanged(); |
26 |
} |
27 |
} |
28 |
public int ButtonCommandParameter |
29 |
{ |
30 |
get => _buttonCommandParameter; |
31 |
set |
32 |
{ |
33 |
_buttonCommandParameter = value; |
34 |
OnPropertyChanged(); |
35 |
} |
36 |
} |
37 |
public Color ButtonBackgroundColor |
38 |
{ |
39 |
get => _buttonBackgroundColor; |
40 |
set |
41 |
{ |
42 |
_buttonBackgroundColor = value; |
43 |
OnPropertyChanged(); |
44 |
} |
45 |
} |
46 |
public bool ButtonIsEnabled |
47 |
{ |
48 |
get => _buttonIsEnabled; |
49 |
set |
50 |
{ |
51 |
_buttonIsEnabled = value; |
52 |
OnPropertyChanged(); |
53 |
} |
54 |
} |
55 |
public string ButtonLabel |
56 |
{ |
57 |
get => _buttonLabel; |
58 |
set |
59 |
{ |
60 |
_buttonLabel = value; |
61 |
OnPropertyChanged(); |
62 |
} |
63 |
} |
64 |
public Serie CurrentSet { get; set; } |
65 |
#endregion |
66 |
|
67 |
#region Commandes |
68 |
public ICommand OnClickChamberCommand |
69 |
{ |
70 |
get => _onClickChamberCommand; |
71 |
set |
72 |
{ |
73 |
_onClickChamberCommand = value; |
74 |
OnPropertyChanged(); |
75 |
} |
76 |
} |
77 |
#endregion |
78 |
|
79 |
#region Constructeurs |
80 |
#endregion |
81 |
|
82 |
#region Méthodes |
83 |
public void UpdateProperties(int chamberId) |
84 |
{ |
85 |
OnClickChamberCommand = new Command(async () => await GoToEnterAnimal()); |
86 |
|
87 |
CurrentSet = JourneeViewModel.Instance.GetCurrentSet(); |
88 |
|
89 |
ButtonText = chamberId.ToString(); |
90 |
ButtonCommandParameter = chamberId; |
91 |
|
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(); |
100 |
} |
101 |
private async Task GoToEnterAnimal() |
102 |
{ |
103 |
if (IsBusy) return; |
104 |
IsBusy = true; |
105 |
|
106 |
if (CurrentSet.GetMeasureNumberByNumeroBoite(ButtonCommandParameter) == 0) |
107 |
await Shell.Current.GoToAsync($"{nameof(EnterAnimalView)}?chamberId={ButtonCommandParameter}"); |
108 |
else |
109 |
await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={ButtonCommandParameter}"); |
110 |
|
111 |
IsBusy = false; |
112 |
} |
113 |
#endregion |
114 |
} |
115 |
} |