Révision 5d673ce0

Voir les différences:

GES_PAC/AppShell.xaml.cs
14 14
            Routing.RegisterRoute(nameof(CreateDayView), typeof(CreateDayView));
15 15
            Routing.RegisterRoute(nameof(CreatePersonView), typeof(CreatePersonView));
16 16
            Routing.RegisterRoute(nameof(CreatePlaceView), typeof(CreatePlaceView));
17
            Routing.RegisterRoute(nameof(CreateCalibrationView), typeof(CreateCalibrationView));
17 18
        }
18 19
    }
19 20

  
GES_PAC/GES_PAC.csproj
66 66
	</ItemGroup>
67 67

  
68 68
	<ItemGroup>
69
	  <Compile Update="View\CreateCalibrationView.xaml.cs">
70
	    <DependentUpon>CreateCalibrationView.xaml</DependentUpon>
71
	  </Compile>
69 72
	  <Compile Update="View\CreateDayView.xaml.cs">
70 73
	    <DependentUpon>CreateDayView.xaml</DependentUpon>
71 74
	  </Compile>
......
75 78
	</ItemGroup>
76 79

  
77 80
	<ItemGroup>
81
	  <MauiXaml Update="View\CreateCalibrationView.xaml">
82
	    <Generator>MSBuild:Compile</Generator>
83
	  </MauiXaml>
78 84
	  <MauiXaml Update="View\CreateDayView.xaml">
79 85
	    <Generator>MSBuild:Compile</Generator>
80 86
	  </MauiXaml>
GES_PAC/GES_PAC.csproj.user
6 6
    <ActiveDebugProfile>Xiaomi 23090RA98G (Android 14.0 - API 34)</ActiveDebugProfile>
7 7
    <SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
8 8
    <DefaultDevice>pixel_7_-_api_35</DefaultDevice>
9
    <SelectedDevice>Xiaomi 23090RA98G</SelectedDevice>
9 10
  </PropertyGroup>
10 11
  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-android|AnyCPU'">
11 12
    <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
GES_PAC/Model/Calibration.cs
5 5
    {
6 6
        public long Id { get; set; }
7 7
        public PhaseCalibration Phase { get; set; }
8
        public MesureCalibration Mesure { get; set; }
9
    }
8
        public List<MesureCalibration> Mesures { get; set; }
9
        
10
        public Calibration(PhaseCalibration Phase, MesureCalibration Mesure)
11
        {
12
            this.Phase = Phase;
13
            Mesures = [];
14
            Mesures.Add(Mesure);
15
        }
10 16

  
11
    public enum PhaseCalibration
12
    {
13
        DEBUT,
14
        FIN
17
        public void AddMesure(MesureCalibration mesure)
18
        {
19
            Mesures.Add(mesure);
20
        }
21

  
22
        public bool IsComplete()
23
        {
24
            return Mesures.Count == 3;
25
        }
26

  
27
        public List<TypeCalibration> GetTypesDone()
28
        {
29
            return Mesures.Select(m => m.Type).Distinct().ToList();
30
        }
15 31
    }
16 32
}
GES_PAC/Model/Journee.cs
1 1

  
2
using System.Diagnostics;
3
using System.Linq;
4

  
2 5
namespace GES_PAC.Model
3 6
{
4 7
    public class Journee
5 8
    {
9
        #region Propriétés
6 10
        public Personne Responsable { get; set; }
7 11
        public Lieu Lieu { get; set; }
8 12
        public long Id { get; set; }
9 13
        public DateTime Date { get; set; }
10
        public string Espece { get; set; }
11 14
        public string Regime { get; set; }
12 15
        public List<Serie> Series { get; set; }
13 16
        public List<Calibration> Calibrations { get; set; }
14
        
15
        public Journee(DateTime Date, Personne Responsable, Lieu Lieu, string Espece, string Regime)
17
        #endregion
18

  
19
        #region Constructeurs
20
        public Journee(DateTime Date, Personne Responsable, Lieu Lieu, string Regime)
16 21
        {
17 22
            this.Responsable = Responsable;
18 23
            this.Lieu = Lieu;
19 24
            this.Date = Date;
20
            this.Espece = Espece;
21 25
            this.Regime = Regime;
22
            this.Series = [];
23
            this.Calibrations = [];
26
            Series = [];
27
            Calibrations = [];
28
        }
29
        #endregion
30

  
31
        #region Méthodes
32

  
33
        public bool AddCalibration(MesureCalibration mesureCalibration)
34
        {
35
            if (Calibrations.Count == 0 || Calibrations.Last().IsComplete())
36
            {
37
                Calibrations.Add(new Calibration(Calibrations.Count == 0 ? PhaseCalibration.Debut : PhaseCalibration.Fin, mesureCalibration));
38
            }
39
            else
40
            {
41
                Calibrations.Last().Mesures.Add(mesureCalibration);
42
                return Calibrations.Last().IsComplete();
43
            }
44
            return false;
45
        }
46

  
47
        public PhaseCalibration GetCurrentPhase()
48
        {
49
            if (Calibrations.Count == 0 || !Calibrations.Last().IsComplete())
50
            {
51
                return PhaseCalibration.Debut;
52
            }
53
            return PhaseCalibration.Fin;
54
        }
55

  
56
        public Calibration GetCurrentCalibration()
57
        {
58
            return Calibrations.FirstOrDefault(c => c.Phase == GetCurrentPhase());
59
        }
60

  
61
        public List<TypeCalibration> GetCurrentMissingCalibration()
62
        {
63
            if (Calibrations.Count == 0 || Calibrations.Last().IsComplete())
64
            {
65
                return TypeCalibration.All;
66
            }
67
            return TypeCalibration.All.Except(Calibrations.Last().GetTypesDone()).ToList();
24 68
        }
69
        #endregion
25 70
    }
26 71
}
GES_PAC/Model/Mesure.cs
8 8
        public double Conc_O2 { get; set; }
9 9
        public double Conc_CO2 { get; set; }
10 10
        public double Conc_CH4 { get; set; }
11

  
12
        public Mesure(DateTime Time, double Conc_O2, double Conc_CO2, double Conc_CH4)
13
        {
14
            this.Time = Time;
15
            this.Conc_O2 = Conc_O2;
16
            this.Conc_CO2 = Conc_CO2;
17
            this.Conc_CH4 = Conc_CH4;
18
        }
11 19
    }
12 20
}
GES_PAC/Model/MesureCalibration.cs
4 4
    public class MesureCalibration : Mesure
5 5
    {
6 6
        public TypeCalibration Type { get; set; }
7
        public String? RefBouteille { get; set; }
7
        public string RefBouteille { get; set; }
8 8

  
9
    }
9
        public MesureCalibration(DateTime Time, double Conc_O2, double Conc_CO2, double Conc_CH4, TypeCalibration Type, string RefBouteille) : base(Time, Conc_O2, Conc_CO2, Conc_CH4)
10
        {
11
            this.Type = Type;
12
            this.RefBouteille = RefBouteille;
13
        }
10 14

  
11
    public enum TypeCalibration
12
    {
13
        AIR,
14
        METHANE,
15
        MELANGE
16 15
    }
17 16
}
GES_PAC/Model/PhaseCalibration.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace GES_PAC.Model
8
{
9
    public class PhaseCalibration
10
    {
11
        public string Name { get; }
12
        public int Value { get; }
13

  
14
        private PhaseCalibration(string name, int value) // a passer en public quand integration webservice
15
        {
16
            Name = name;
17
            Value = value;
18
        }
19

  
20
        public static readonly PhaseCalibration Debut = new("Début", 1);
21
        public static readonly PhaseCalibration Fin = new("Fin", 2);
22

  
23
        public static readonly List<PhaseCalibration> All = new() { Debut, Fin };
24

  
25
        public override string ToString() => Name;
26

  
27
    }
28
}
GES_PAC/Model/TypeCalibration.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace GES_PAC.Model
8
{
9
    public class TypeCalibration
10
    {
11
        public string Name { get; }
12
        public int Value { get; }
13

  
14
        private TypeCalibration(string name, int value) // a passer en public quand integration webservice
15
        {
16
            Name = name;
17
            Value = value;
18
        }
19

  
20
        public static readonly TypeCalibration Air = new("Air", 1);
21
        public static readonly TypeCalibration Methane = new("Methane", 2);
22
        public static readonly TypeCalibration Melange = new("Mélange", 3);
23

  
24
        public static readonly List<TypeCalibration> All = new() { Air, Methane, Melange };
25

  
26
        public override string ToString() => Name;
27
    }
28

  
29
}
GES_PAC/View/CreateCalibrationView.xaml
1
<?xml version="1.0" encoding="utf-8" ?>
2
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4
             xmlns:vm="clr-namespace:GES_PAC.ViewModel"
5
             xmlns:tools="clr-namespace:GES_PAC.View.Tools"
6
             x:Class="GES_PAC.View.CreateCalibrationView"
7
             x:DataType="vm:CreateCalibrationViewModel">
8

  
9
    <Grid>
10
        <StackLayout BackgroundColor="White" Spacing="50">
11
            <tools:ConnectionIndicatorView />
12
            <ScrollView>
13

  
14
                <VerticalStackLayout Grid.Row="1" Spacing="30">
15

  
16
                    <Label Text="Mesure de calibration"
17
                       FontSize="20"
18
                       FontAttributes="Bold"
19
                       HorizontalOptions="Center" />
20
                    <VerticalStackLayout Spacing="15" WidthRequest="300">
21

  
22
                        <!-- Type de calibration -->
23
                        <VerticalStackLayout>
24

  
25
                            <Label Text="Type de calibration" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
26

  
27
                            <Picker Title="Sélectionnez un type de calibration"
28
                                ItemsSource="{Binding TypeCalibrations}"
29
                                ItemDisplayBinding="{Binding Name}"
30
                                SelectedItem="{Binding SelectedType}" />
31

  
32

  
33
                            <Label Text="Sélectionnez un type de calibration"
34
                                FontSize="12"
35
                                TextColor="Red"
36
                                IsVisible="{Binding TypeError}"/>
37
                        </VerticalStackLayout>
38

  
39
                        <!-- O2 -->
40
                        <VerticalStackLayout>
41
                            <Label Text="O2 (% vol.)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
42
                            <Entry Text="{Binding ConcO2 , Mode=TwoWay, TargetNullValue=''}" 
43
                                   FontSize="16" 
44
                                   TextColor="Black" 
45
                                   Placeholder="0,0" 
46
                                   Keyboard="Numeric"/>
47
                            <Label Text="Entrez une valeur"
48
                                FontSize="12"
49
                                TextColor="Red"
50
                                IsVisible="{Binding ConcO2Error}"/>
51
                        </VerticalStackLayout>
52

  
53
                        <!-- CO2 -->
54
                        <VerticalStackLayout>
55
                            <Label Text="CO2 (% vol.)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
56
                            <Entry Text="{Binding ConcCO2, Mode=TwoWay, TargetNullValue=''}" 
57
                                   FontSize="16" 
58
                                   TextColor="Black" 
59
                                   Placeholder="0,0" 
60
                                   Keyboard="Numeric"/>
61
                            <Label Text="Entrez une valeur"
62
                                FontSize="12"
63
                                TextColor="Red"
64
                                IsVisible="{Binding ConcCO2Error}"/>
65
                        </VerticalStackLayout>
66

  
67
                        <!-- CH4 -->
68
                        <VerticalStackLayout>
69
                            <Label Text="CH4 (ppm)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
70
                            <Entry Text="{Binding ConcCH4, Mode=TwoWay, TargetNullValue=''}" 
71
                                   FontSize="16" 
72
                                   TextColor="Black" 
73
                                   Placeholder="0,0" 
74
                                   Keyboard="Numeric"/>
75
                            <Label Text="Entrez une valeur"
76
                                FontSize="12"
77
                                TextColor="Red"
78
                                IsVisible="{Binding ConcCH4Error}"/>
79
                        </VerticalStackLayout>
80

  
81

  
82
                    </VerticalStackLayout>
83
                </VerticalStackLayout>
84
            </ScrollView>
85
            <StackLayout
86
                Margin="10"
87
                HorizontalOptions="CenterAndExpand"
88
                Orientation="Horizontal"
89
                VerticalOptions="FillAndExpand">
90

  
91
                <Button 
92
                    Text="Créer une journée"
93
                    Command="{Binding CreateCalibrationCommand}"
94
                    Style="{StaticResource btnNormal}"
95
                    IsEnabled="{Binding IsFormValid}"
96
                    VerticalOptions="End"/>
97
            </StackLayout>
98
        </StackLayout>
99
        <Grid Grid.RowSpan="1" IsVisible="{Binding IsBusy}">
100
            <Border StrokeThickness="0"
101
                            Background="Black"
102
                            Opacity="0.5"
103
                            Padding="20"
104
                            WidthRequest="160"
105
                            HeightRequest="160"
106
                            HorizontalOptions="Center"
107
                            VerticalOptions="Center"
108
                            StrokeShape="RoundRectangle 20">
109

  
110
                <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
111
                    <ActivityIndicator IsRunning="True" Color="White" />
112
                    <Label Text="Chargement..."
113
                            FontSize="14"
114
                            TextColor="white"
115
                            HorizontalOptions="Center"/>
116
                </VerticalStackLayout>
117
            </Border>
118
        </Grid>
119
    </Grid>
120

  
121
</ContentPage>
GES_PAC/View/CreateCalibrationView.xaml.cs
1
using GES_PAC.ViewModel;
2

  
3
namespace GES_PAC.View
4
{
5
    public partial class CreateCalibrationView
6
    {
7
        public CreateCalibrationView()
8
        {
9
            InitializeComponent();
10
            BindingContext = new CreateCalibrationViewModel();
11
        }
12
    }
13
}
GES_PAC/View/CreateDayView.xaml
52 52
                                IsVisible="{Binding PersonError}"/>
53 53
                        </VerticalStackLayout>
54 54

  
55
                        <!-- Espèce -->
56
                        <VerticalStackLayout>
57
                            <Label Text="Espèce" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
58
                            <Entry Text="{Binding Espece}" FontSize="16" TextColor="Black" Placeholder="Entrer l'espèce"/>
59
                            <Label Text="Min. 3 caractères"
60
                                FontSize="12"
61
                                TextColor="Red"
62
                                IsVisible="{Binding EspeceError}"/>
63
                        </VerticalStackLayout>
64

  
65 55
                        <!-- Régime alimentaire -->
66 56
                        <VerticalStackLayout>
67 57
                            <Label Text="Régime alimentaire" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
GES_PAC/ViewModel/CreateCalibrationViewModel.cs
1
using CommunityToolkit.Maui.Core.Extensions;
2
using GES_PAC.Model;
3
using GES_PAC.View;
4
using System.Collections.ObjectModel;
5
using System.Diagnostics;
6
using System.Windows.Input;
7

  
8
namespace GES_PAC.ViewModel
9
{
10
    public class CreateCalibrationViewModel : BaseViewModel
11
    {
12

  
13
        #region Attributs
14
        private TypeCalibration _selectedType;
15
        private double? _conc_o2;
16
        private double? _conc_co2;
17
        private double? _conc_ch4;
18
        private string _ref_bouteille;
19
        private bool _isFormValid;
20
        #endregion
21

  
22
        #region Commandes
23
        public ICommand CreateCalibrationCommand { get; }
24
        #endregion
25

  
26
        #region Propriétés
27
        public ObservableCollection<TypeCalibration> TypeCalibrations { get; }
28
        public TypeCalibration SelectedType
29
        {
30
            get => _selectedType;
31
            set
32
            {
33
                _selectedType = value;
34
                OnPropertyChanged();
35
                ValidateForm();
36
            }
37
        }
38

  
39
        public double? ConcO2
40
        {
41
            get => _conc_o2;
42
            set
43
            {
44
                _conc_o2 = value;
45
                OnPropertyChanged();
46
                ValidateForm();
47
            }
48
        }
49

  
50
        public double? ConcCO2
51
        {
52
            get => _conc_co2;
53
            set
54
            {
55
                _conc_co2 = value;
56
                OnPropertyChanged();
57
                ValidateForm();
58
            }
59
        }
60

  
61
        public double? ConcCH4
62
        {
63
            get => _conc_ch4;
64
            set
65
            {
66
                _conc_ch4 = value;
67
                OnPropertyChanged();
68
                ValidateForm();
69
            }
70
        }
71
        public string RefBouteille
72
        {
73
            get => _ref_bouteille;
74
            set
75
            {
76
                _ref_bouteille = value;
77
                OnPropertyChanged();
78
                ValidateForm();
79
            }
80
        }
81
        public bool IsFormValid
82
        {
83
            get => _isFormValid;
84
            set
85
            {
86
                _isFormValid = value;
87
                OnPropertyChanged();
88
            }
89
        }
90

  
91
        public bool TypeError { get; private set; } = true;
92
        public bool ConcO2Error { get; private set; } = true;
93
        public bool ConcCO2Error { get; private set; } = true;
94
        public bool ConcCH4Error { get; private set; } = true;
95
        #endregion
96

  
97
        #region Constructeurs
98
        public CreateCalibrationViewModel()
99
        {
100

  
101
            var journeeActuelle = JourneeViewModel.Instance.GetCurrentDay();
102
            var typesManquants = journeeActuelle.GetCurrentMissingCalibration();
103

  
104
            TypeCalibrations = new ObservableCollection<TypeCalibration>(typesManquants);
105

  
106
            SelectedType = TypeCalibrations[0];
107

  
108
            CreateCalibrationCommand = new Command(async () => await CreateCalibration());
109
        }
110
        #endregion
111

  
112
        #region Méthodes
113
        private async Task CreateCalibration()
114
        {
115
            IsBusy = true;
116

  
117
            var date = DateTime.Now;
118
            var newCalib = new MesureCalibration(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0, SelectedType, RefBouteille);
119
            var isComplete = JourneeViewModel.Instance.GetCurrentDay().AddCalibration(newCalib);
120

  
121
            if (isComplete)
122
            {
123
                await Shell.Current.GoToAsync(nameof(MainView));
124
            }
125
            else
126
            {
127
                await Shell.Current.GoToAsync(nameof(CreateCalibrationView));
128
            }
129

  
130
            IsBusy = false;
131
        }
132

  
133
        private void ValidateForm()
134
        {
135
            TypeError = SelectedType == null;
136
            ConcO2Error = ConcO2 == null;
137
            ConcCO2Error = ConcCO2 == null;
138
            ConcCH4Error = ConcCH4 == null;
139

  
140
            OnPropertyChanged(nameof(TypeError));
141
            OnPropertyChanged(nameof(ConcO2Error));
142
            OnPropertyChanged(nameof(ConcCO2Error));
143
            OnPropertyChanged(nameof(ConcCH4Error));
144

  
145
            IsFormValid = !TypeError && !ConcO2Error && !ConcCO2Error && !ConcCH4Error;
146

  
147
            (CreateCalibrationCommand as Command)?.ChangeCanExecute();
148
        }
149
        #endregion
150
    }
151
}
GES_PAC/ViewModel/CreateDayViewModel.cs
10 10

  
11 11
        #region Attributs
12 12
        private Personne _selectedPerson;
13
        private string _espece;
14 13
        private string _regime;
15 14
        private bool _isFormValid;
16 15
        #endregion
......
46 45
                ValidateForm();
47 46
            }
48 47
        }
49

  
50
        
51
        public string Espece
52
        {
53
            get => _espece;
54
            set
55
            {
56
                _espece = value;
57
                OnPropertyChanged();
58
                ValidateForm();
59
            }
60
        }
61

  
62 48
        
63 49
        public string Regime
64 50
        {
......
83 69

  
84 70
        public bool PlaceError { get; private set; } = true;
85 71
        public bool PersonError { get; private set; } = true;
86
        public bool EspeceError { get; private set; } = true;
87 72
        public bool RegimeError { get; private set; } = true;
88 73
        #endregion
89 74

  
......
103 88
        {
104 89
            IsBusy = true;
105 90
            var date = DateTime.Now;
106
            var newDay = new Journee(date, SelectedPerson, SelectedPlace, Espece, Regime);
91
            var newDay = new Journee(date, SelectedPerson, SelectedPlace, Regime);
107 92
            JourneeViewModel.Instance.Journees.Add(newDay);
108
            await Shell.Current.GoToAsync("//Main"); // A changer plus tard
93
            await Shell.Current.GoToAsync(nameof(CreateCalibrationView));
109 94
            IsBusy = false;
110 95
        }
111 96

  
......
113 98
        {
114 99
            PersonError = SelectedPerson == null;
115 100
            PlaceError = SelectedPlace == null;
116
            EspeceError = string.IsNullOrWhiteSpace(Espece) || Espece.Length < 3;
117 101
            RegimeError = string.IsNullOrWhiteSpace(Regime) || Regime.Length < 3;
118 102

  
119 103
            OnPropertyChanged(nameof(PlaceError));
120 104
            OnPropertyChanged(nameof(PersonError));
121
            OnPropertyChanged(nameof(EspeceError));
122 105
            OnPropertyChanged(nameof(RegimeError));
123 106

  
124
            IsFormValid = !PlaceError && !PersonError && !EspeceError && !RegimeError;
107
            IsFormValid = !PlaceError && !PersonError && !RegimeError;
125 108

  
126 109
            (CreateDayCommand as Command)?.ChangeCanExecute();
127 110
        }
GES_PAC/ViewModel/JourneeViewModel.cs
19 19
        public static JourneeViewModel Instance => _instance ??= new JourneeViewModel();
20 20
        #endregion
21 21

  
22
        #region Constructeur
22
        #region Constructeurs
23 23
        private JourneeViewModel() { }
24 24
        #endregion
25

  
26
        #region Méthodes
27
        public Journee GetCurrentDay()
28
        {
29
            DateTime today = DateTime.Today;
30
            return Journees.FirstOrDefault(j => j.Date.Date == today);
31
        }
32
        #endregion
25 33
    }
26 34
}
GES_PAC/ViewModel/PersonViewModel.cs
15 15
        #endregion
16 16

  
17 17
        #region Constructeur
18
        private PersonViewModel() { }
18
        private PersonViewModel() {
19
            Persons.Add(new Personne("Bond", "James", "jamesbond@inrae.fr")); // Ajout d'une personne par défaut pour les tests
20
        }
19 21
        #endregion
20 22
    }
21 23
}
GES_PAC/ViewModel/PlaceViewModel.cs
16 16
        #endregion
17 17
        
18 18
        #region Constructeur
19
        private PlaceViewModel() { }
19
        private PlaceViewModel() {
20
            Places.Add(new Lieu("Ferme du soleil", "Dupont", "Chèvres")); // Ajout d'un lieu par défaut pour les tests
21
        }
20 22
        #endregion
21 23
    }
22 24
}
GES_PAC/ViewModel/TypeCalibrationViewModel.cs
1
using GES_PAC.Model;
2
using System;
3
using System.Collections.Generic;
4
using System.Collections.ObjectModel;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8

  
9
namespace GES_PAC.ViewModel
10
{
11
    public class TypeCalibrationViewModel
12
    {
13
        public ObservableCollection<TypeCalibration> Calibrations { get; }
14

  
15
        public TypeCalibrationViewModel()
16
        {
17
            Calibrations = new ObservableCollection<TypeCalibration>(TypeCalibration.All);
18
        }
19
    }
20
}

Formats disponibles : Unified diff