Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / EnterAnimalViewModel.cs @ 4afea73d

Historique | Voir | Annoter | Télécharger (2,688 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
            IsBusy = true;
86
            var date = DateTime.Now;
87
            var journeeActuelle = JourneeViewModel.Instance.GetCurrentDay();
88
            var newAnimalSet = new SerieAnimal(ChamberId, Poids ?? 0, date, NumRFID);
89
            journeeActuelle.GetCurrentSet().AddSerieAnimal(newAnimalSet);
90

    
91
            await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={ChamberId}");
92
            IsBusy = false;
93
        }
94

    
95
        private void ValidateForm()
96
        {
97
            NumRFIDError = NumRFID.Length < 5 ;
98
            PoidsError = Poids == null;
99

    
100
            OnPropertyChanged(nameof(NumRFIDError));
101
            OnPropertyChanged(nameof(PoidsError));
102

    
103
            IsFormValid = !NumRFIDError && !PoidsError;
104

    
105
            (EnterAnimalCommand as Command)?.ChangeCanExecute();
106
        }
107
        #endregion
108
    }
109
}