Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / ChambersViewModel.cs @ 9fd69a0e

Historique | Voir | Annoter | Télécharger (2,606 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 9fd69a0e lbihannic
        public ObservableCollection<Color> ChamberColors { get; set; } = [];
21
        public ObservableCollection<int> ChamberNumbers { get; set; } = [];
22
        public ObservableCollection<bool> ChamberIsIn { get; set; } = [];
23
        public Serie CurrentSet { get; set; }
24 fff89fc5 lbihannic
25 09d4a0de lbihannic
        #endregion
26
27
        #region Constructeurs
28
        public ChambersViewModel()
29
        {
30 1019554c lbihannic
            //ONLY FOR TESTS
31
            var date = DateTime.Now;
32
            var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
33
            newDay.AddSerie(new Serie(date, date, 25, 25, 25));
34
            newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
35
            newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1);
36
            JourneeViewModel.Instance.Journees.Add(newDay);
37
            //ONLY FOR TESTS
38
39 9fd69a0e lbihannic
            CurrentSet = JourneeViewModel.Instance.GetCurrentSet();
40 4afea73d lbihannic
            UpdateChamberDatas();
41 fff89fc5 lbihannic
42 ba296a27 lbihannic
            OnClickChamberCommand = new Command<string>(async (idStr) =>
43
            {
44
                int id = int.Parse(idStr);
45
                await GoToEnterAnimal(id);
46
            });
47 09d4a0de lbihannic
        }
48
        #endregion
49
50
        #region Méthodes
51
        private async Task GoToEnterAnimal(int id)
52
        {
53 1019554c lbihannic
            if (IsBusy) return;
54 09d4a0de lbihannic
            IsBusy = true;
55 4afea73d lbihannic
56 9fd69a0e lbihannic
            if (CurrentSet.GetMeasureNumberByNumeroBoite(id) == 0)
57 4afea73d lbihannic
                await Shell.Current.GoToAsync($"{nameof(EnterAnimalView)}?chamberId={id}");
58
            else
59
                await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={id}");
60
61 09d4a0de lbihannic
            IsBusy = false;
62
        }
63 fff89fc5 lbihannic
64 4afea73d lbihannic
        private void UpdateChamberDatas()
65 fff89fc5 lbihannic
        {
66 9fd69a0e lbihannic
            ChamberIsIn = JourneeViewModel.Instance.GetCurrentSet().GetIsOutDatas();
67 fff89fc5 lbihannic
            for (int i = 1; i <= 12; i++)
68
            {
69 9fd69a0e lbihannic
                bool hasBehaviour = CurrentSet.GetHasBehaviourByNumeroBoite(i);
70
                int count = CurrentSet.GetMeasureNumberByNumeroBoite(i);
71
                if (hasBehaviour)
72
                    ChamberColors.Add(Colors.Yellow);
73
                else
74
                    ChamberColors.Add(count > 0 ? Colors.LightGreen : Colors.White);
75 4afea73d lbihannic
                ChamberNumbers.Add(count);
76 fff89fc5 lbihannic
            }
77
        }
78 09d4a0de lbihannic
        #endregion
79
    }
80
}