Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / MainViewModel.cs @ 9601eaf0

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

1
using GES_PAC.Model;
2
using GES_PAC.View;
3
using System.Windows.Input;
4

    
5
namespace GES_PAC.ViewModel
6
{
7
    public class MainViewModel : BaseViewModel 
8
    {
9
        #region Attributs
10
        private bool _hasLastDay = false;
11
        private Journee _currentDay;
12
        private string _currentDayText;
13
        #endregion
14

    
15
        #region Commandes
16
        public ICommand GoToCreateDayCommand { get; }
17
        public ICommand ResumeDayCommand { get; }
18
        public ICommand ExportDataCommand { get; }
19
        #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
        #endregion
50

    
51
        #region Constructeur
52
        public MainViewModel()
53
        {
54
            //ONLY FOR TESTS
55
            var date = DateTime.Now.AddHours(-2);
56
            var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
57
            newDay.AddSet(new Serie(date, date, 25, 25, 25));
58
            newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.DEBUT);
59
            newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.DEBUT);
60
            newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.DEBUT);
61
            newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
62
            newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
63
            JourneeViewModel.Instance.Journees.Add(newDay);
64
            //ONLY FOR TESTS
65

    
66
            GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage());
67
            ResumeDayCommand = new Command(async () => await ResumeDay());
68
            ExportDataCommand = new Command(async () => await ExportData());
69

    
70
            GetLastDay();
71
        }
72
        #endregion
73

    
74
        #region Méthodes
75
        
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
        private async Task GoToCreateDayPage()
84
        {
85
            if (IsBusy) return;
86
            IsBusy = true;
87
            await Shell.Current.GoToAsync(nameof(CreateDayView));
88
            IsBusy = false;
89
        }
90

    
91
        private async Task ResumeDay()
92
        {
93
            if (IsBusy) return;
94
            IsBusy = true;
95

    
96
            CurrentDay = JourneeViewModel.Instance.GetCurrentDay();
97
            var targetView = $"{nameof(CreateCalibrationView)}?phase={PhaseCalibration.DEBUT.Name}";
98
            if (CurrentDay.IsCalibrationComplete(PhaseCalibration.DEBUT))
99
                targetView = nameof(SetListView);
100

    
101
            await Shell.Current.GoToAsync(targetView);
102
            IsBusy = false;
103
        }        
104
        private async Task ExportData()
105
        {
106
            if (IsBusy) return;
107
            IsBusy = true;
108
            await Shell.Current.GoToAsync(nameof(ExportDataView));
109
            IsBusy = false;
110
        }
111
        #endregion
112
    }
113
}