Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / ChambersViewModel.cs @ 1019554c

Historique | Voir | Annoter | Télécharger (2,334 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
21 fff89fc5 lbihannic
        public Dictionary<int, int> NumberMeasure { get; set; }
22
        public ObservableCollection<Color> ChamberColors { get; } = [];
23 4afea73d lbihannic
        public ObservableCollection<int> ChamberNumbers { get; } = [];
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 fff89fc5 lbihannic
            NumberMeasure = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet().GetMeasureNumber();
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
            if (!NumberMeasure.ContainsValue(id))
57
                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
            ChamberColors.Clear();
67
            for (int i = 1; i <= 12; i++)
68
            {
69
                int count = NumberMeasure.TryGetValue(i, out var val) ? val : 0;
70
                ChamberColors.Add(count > 0 ? Colors.LightGreen : Colors.White);
71 4afea73d lbihannic
                ChamberNumbers.Add(count);
72 fff89fc5 lbihannic
            }
73
        }
74 09d4a0de lbihannic
        #endregion
75
    }
76
}