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