Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / MainViewModel.cs @ e837cdf1

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

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