Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / MainViewModel.cs @ 42456640

Historique | Voir | Annoter | Télécharger (3,387 ko)

1 12ddf7ef lbihannic
using GES_PAC.Model;
2 65ad7e66 Lucas Bihannic
using GES_PAC.View;
3 acb5dd8c lbihannic
using System.Windows.Input;
4 65ad7e66 Lucas Bihannic
5
namespace GES_PAC.ViewModel
6
{
7 acb5dd8c lbihannic
    public class MainViewModel : BaseViewModel 
8 65ad7e66 Lucas Bihannic
    {
9 acb5dd8c lbihannic
        #region Attributs
10
        private bool _hasLastDay = false;
11
        private Journee _currentDay;
12
        private string _currentDayText;
13
        #endregion
14
15 42456640 lbihannic
        
16 18f910c6 Lucas Bihannic
17
        #region Commandes
18 acb5dd8c lbihannic
        public ICommand GoToCreateDayCommand { get; }
19
        public ICommand ResumeDayCommand { get; }
20
        #endregion
21
22
        #region Propriétés
23
        public bool HasLastDay
24
        {
25
            get => _hasLastDay;
26
            set
27
            {
28
                SetProperty(ref _hasLastDay, value);
29
                OnPropertyChanged();
30
            }
31
        }
32
        public Journee CurrentDay
33
        {
34
            get => _currentDay;
35
            set
36
            {
37
                SetProperty(ref _currentDay, value);
38
                OnPropertyChanged();
39
            }
40
        }
41
        public string CurrentDayText
42
        {
43
            get => _currentDayText;
44
            set
45
            {
46
                SetProperty(ref _currentDayText, value);
47
                OnPropertyChanged();
48
            }
49
        }
50 18f910c6 Lucas Bihannic
        #endregion
51
52
        #region Constructeur
53 42456640 lbihannic
        public MainViewModel()
54 65ad7e66 Lucas Bihannic
        {
55 12ddf7ef lbihannic
            //ONLY FOR TESTS
56 42456640 lbihannic
            //var date = DateTime.Now;
57
            //var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
58
            //newDay.AddSet(new Serie(date, date, 25, 25, 25));
59
            //newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut);
60
            //newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut);
61
            //newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut);
62
            //newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
63
            //newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
64
            //JourneeViewModel.Instance.Journees.Add(newDay);
65 12ddf7ef lbihannic
            //ONLY FOR TESTS
66
67 65ad7e66 Lucas Bihannic
            GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage());
68 acb5dd8c lbihannic
            ResumeDayCommand = new Command(async () => await ResumeDay());
69
70
            GetLastDay();
71 65ad7e66 Lucas Bihannic
        }
72 18f910c6 Lucas Bihannic
        #endregion
73 65ad7e66 Lucas Bihannic
74 18f910c6 Lucas Bihannic
        #region Méthodes
75 acb5dd8c lbihannic
        
76
        public void GetLastDay()
77
        {
78
            CurrentDay = JourneeViewModel.Instance.GetCurrentDay();
79
            HasLastDay = !CurrentDay?.IsComplete() ?? false;
80
            CurrentDayText = HasLastDay ? "Une journée en cours, la reprendre ?" : "Aucune journée trouvée, en créer une ?";
81
82
        }
83 65ad7e66 Lucas Bihannic
        private async Task GoToCreateDayPage()
84
        {
85 1019554c lbihannic
            if (IsBusy) return;
86 18f910c6 Lucas Bihannic
            IsBusy = true;
87 65ad7e66 Lucas Bihannic
            await Shell.Current.GoToAsync(nameof(CreateDayView));
88 18f910c6 Lucas Bihannic
            IsBusy = false;
89 65ad7e66 Lucas Bihannic
        }
90 acb5dd8c lbihannic
91
        private async Task ResumeDay()
92
        {
93
            if (IsBusy) return;
94
            IsBusy = true;
95
96
            CurrentDay = JourneeViewModel.Instance.GetCurrentDay();
97
            var targetView = nameof(CreateCalibrationView);
98
            if (CurrentDay.IsCalibrationComplete(PhaseCalibration.Debut))
99
                targetView = nameof(SetListView);
100
101
            await Shell.Current.GoToAsync(targetView);
102
            IsBusy = false;
103
        }
104 18f910c6 Lucas Bihannic
        #endregion
105 65ad7e66 Lucas Bihannic
    }
106
}