Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / MainViewModel.cs @ 6f451cc1

Historique | Voir | Annoter | Télécharger (2,849 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 18f910c6 Lucas Bihannic
        #region Commandes
16 acb5dd8c lbihannic
        public ICommand GoToCreateDayCommand { get; }
17
        public ICommand ResumeDayCommand { get; }
18 957bebf1 lbihannic
        public ICommand ExportDataCommand { get; }
19 acb5dd8c lbihannic
        #endregion
20
21
        #region Propriétés
22
        public bool HasLastDay
23
        {
24
            get => _hasLastDay;
25
            set
26
            {
27
                SetProperty(ref _hasLastDay, value);
28
                OnPropertyChanged();
29
            }
30
        }
31
        public Journee CurrentDay
32
        {
33
            get => _currentDay;
34
            set
35
            {
36
                SetProperty(ref _currentDay, value);
37
                OnPropertyChanged();
38
            }
39
        }
40
        public string CurrentDayText
41
        {
42
            get => _currentDayText;
43
            set
44
            {
45
                SetProperty(ref _currentDayText, value);
46
                OnPropertyChanged();
47
            }
48
        }
49 18f910c6 Lucas Bihannic
        #endregion
50
51
        #region Constructeur
52 42456640 lbihannic
        public MainViewModel()
53 65ad7e66 Lucas Bihannic
        {
54 12ddf7ef lbihannic
55 65ad7e66 Lucas Bihannic
            GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage());
56 acb5dd8c lbihannic
            ResumeDayCommand = new Command(async () => await ResumeDay());
57 957bebf1 lbihannic
            ExportDataCommand = new Command(async () => await ExportData());
58 acb5dd8c lbihannic
59
            GetLastDay();
60 65ad7e66 Lucas Bihannic
        }
61 18f910c6 Lucas Bihannic
        #endregion
62 65ad7e66 Lucas Bihannic
63 18f910c6 Lucas Bihannic
        #region Méthodes
64 acb5dd8c lbihannic
        
65
        public void GetLastDay()
66
        {
67
            CurrentDay = JourneeViewModel.Instance.GetCurrentDay();
68
            HasLastDay = !CurrentDay?.IsComplete() ?? false;
69
            CurrentDayText = HasLastDay ? "Une journée en cours, la reprendre ?" : "Aucune journée trouvée, en créer une ?";
70
71
        }
72 65ad7e66 Lucas Bihannic
        private async Task GoToCreateDayPage()
73
        {
74 1019554c lbihannic
            if (IsBusy) return;
75 18f910c6 Lucas Bihannic
            IsBusy = true;
76 65ad7e66 Lucas Bihannic
            await Shell.Current.GoToAsync(nameof(CreateDayView));
77 18f910c6 Lucas Bihannic
            IsBusy = false;
78 65ad7e66 Lucas Bihannic
        }
79 acb5dd8c lbihannic
80
        private async Task ResumeDay()
81
        {
82
            if (IsBusy) return;
83
            IsBusy = true;
84
85
            CurrentDay = JourneeViewModel.Instance.GetCurrentDay();
86 9601eaf0 lbihannic
            var targetView = $"{nameof(CreateCalibrationView)}?phase={PhaseCalibration.DEBUT.Name}";
87
            if (CurrentDay.IsCalibrationComplete(PhaseCalibration.DEBUT))
88 acb5dd8c lbihannic
                targetView = nameof(SetListView);
89
90
            await Shell.Current.GoToAsync(targetView);
91
            IsBusy = false;
92 957bebf1 lbihannic
        }        
93
        private async Task ExportData()
94
        {
95
            if (IsBusy) return;
96
            IsBusy = true;
97
            await Shell.Current.GoToAsync(nameof(ExportDataView));
98
            IsBusy = false;
99 acb5dd8c lbihannic
        }
100 18f910c6 Lucas Bihannic
        #endregion
101 65ad7e66 Lucas Bihannic
    }
102
}