root / GES_PAC / ViewModel / EnterAnimalViewModel.cs @ 4e39035b
Historique | Voir | Annoter | Télécharger (2,736 ko)
1 |
using GES_PAC.Model; |
---|---|
2 |
using GES_PAC.View; |
3 |
using System.Windows.Input; |
4 |
|
5 |
namespace GES_PAC.ViewModel |
6 |
{ |
7 |
[QueryProperty(nameof(ChamberId), "chamberId")] |
8 |
public class EnterAnimalViewModel : BaseViewModel |
9 |
{ |
10 |
|
11 |
#region Attributs |
12 |
private int _chamberId; |
13 |
|
14 |
private string _numrfid; |
15 |
private double? _poids; |
16 |
private bool _isFormValid; |
17 |
#endregion |
18 |
|
19 |
#region Commandes |
20 |
public ICommand EnterAnimalCommand { get; } |
21 |
#endregion |
22 |
|
23 |
#region Propriétés |
24 |
|
25 |
|
26 |
public int ChamberId |
27 |
{ |
28 |
get => _chamberId; |
29 |
set |
30 |
{ |
31 |
_chamberId = value; |
32 |
OnPropertyChanged(); |
33 |
OnPropertyChanged(nameof(Titre)); |
34 |
} |
35 |
} |
36 |
|
37 |
public string NumRFID |
38 |
{ |
39 |
get => _numrfid; |
40 |
set |
41 |
{ |
42 |
_numrfid = value; |
43 |
OnPropertyChanged(); |
44 |
ValidateForm(); |
45 |
} |
46 |
} |
47 |
|
48 |
public double? Poids |
49 |
{ |
50 |
get => _poids; |
51 |
set |
52 |
{ |
53 |
_poids = value; |
54 |
OnPropertyChanged(); |
55 |
ValidateForm(); |
56 |
} |
57 |
} |
58 |
|
59 |
public bool IsFormValid |
60 |
{ |
61 |
get => _isFormValid; |
62 |
set |
63 |
{ |
64 |
_isFormValid = value; |
65 |
OnPropertyChanged(); |
66 |
} |
67 |
} |
68 |
|
69 |
public bool NumRFIDError { get; private set; } = true; |
70 |
public bool PoidsError { get; private set; } = true; |
71 |
public string Titre => $"Informations animal chambre {ChamberId}"; |
72 |
|
73 |
#endregion |
74 |
|
75 |
#region Constructeurs |
76 |
public EnterAnimalViewModel() |
77 |
{ |
78 |
EnterAnimalCommand = new Command(async () => await EnterAnimal()); |
79 |
} |
80 |
#endregion |
81 |
|
82 |
#region Méthodes |
83 |
private async Task EnterAnimal() |
84 |
{ |
85 |
if (IsBusy) return; |
86 |
IsBusy = true; |
87 |
var date = DateTime.Now; |
88 |
var journeeActuelle = JourneeViewModel.Instance.GetCurrentDay(); |
89 |
var newAnimalSet = new SerieAnimal(ChamberId, Poids ?? 0, date, NumRFID); |
90 |
journeeActuelle.GetCurrentSet().AddSerieAnimal(newAnimalSet); |
91 |
|
92 |
await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={ChamberId}"); |
93 |
IsBusy = false; |
94 |
} |
95 |
|
96 |
private void ValidateForm() |
97 |
{ |
98 |
NumRFIDError = NumRFID == null || NumRFID.Length < 5; |
99 |
PoidsError = Poids == null; |
100 |
|
101 |
OnPropertyChanged(nameof(NumRFIDError)); |
102 |
OnPropertyChanged(nameof(PoidsError)); |
103 |
|
104 |
IsFormValid = !NumRFIDError && !PoidsError; |
105 |
|
106 |
(EnterAnimalCommand as Command)?.ChangeCanExecute(); |
107 |
} |
108 |
#endregion |
109 |
} |
110 |
} |