Révision fff89fc5

Voir les différences:

GES_PAC/AppShell.xaml.cs
19 19
            Routing.RegisterRoute(nameof(CreateSetView), typeof(CreateSetView));
20 20
            Routing.RegisterRoute(nameof(ChambersView), typeof(ChambersView));
21 21
            Routing.RegisterRoute(nameof(EnterAnimalView), typeof(EnterAnimalView));
22
            Routing.RegisterRoute(nameof(CreateMeasureView), typeof(CreateMeasureView));
22 23
        }
23 24
    }
24

  
25 25
}
GES_PAC/GES_PAC.csproj
102 102
	  <MauiXaml Update="View\CreateDayView.xaml">
103 103
	    <Generator>MSBuild:Compile</Generator>
104 104
	  </MauiXaml>
105
	  <MauiXaml Update="View\CreateMeasureView.xaml">
106
	    <Generator>MSBuild:Compile</Generator>
107
	  </MauiXaml>
105 108
	  <MauiXaml Update="View\CreatePersonView.xaml">
106 109
	    <Generator>MSBuild:Compile</Generator>
107 110
	  </MauiXaml>
GES_PAC/Model/Serie.cs
30 30
        {
31 31
            SeriesAnimales.Add(serieAnimal);
32 32
        }
33

  
34
        public Dictionary<int, int> GetMeasureNumber()
35
        {
36
            return SeriesAnimales.ToDictionary(sa => sa.NumeroBoite, sa => sa.GetMeasureCount());
37
        }
38

  
39
        internal void AddMeasure(Mesure newMeasure, int numBoite)
40
        {
41
            SeriesAnimales.Select(sa => sa).Where(sa => sa.NumeroBoite == numBoite).First().AddMeasure(newMeasure);
42
        }
33 43
        #endregion
34 44
    }
35 45
}
GES_PAC/Model/SerieAnimal.cs
20 20
            Mesures = [];
21 21
            Comportements = [];
22 22
        }
23

  
24
        public int GetMeasureCount()
25
        {
26
            return Mesures.Count();
27
        }
28

  
29
        internal void AddMeasure(Mesure newMeasure)
30
        {
31
            Mesures.Add(newMeasure);
32
        }
23 33
    }
24 34
}
GES_PAC/View/ChambersView.xaml
47 47
                                </Grid.RowDefinitions>
48 48

  
49 49
                                <!-- Boutons Gauche -->
50
                                <Button Grid.Row="5" Grid.Column="0" Text="1" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="1"/>
51
                                <Button Grid.Row="4" Grid.Column="0" Text="3" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="3"/>
52
                                <Button Grid.Row="3" Grid.Column="0" Text="5" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="5"/>
53
                                <Button Grid.Row="2" Grid.Column="0" Text="7" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="7"/>
54
                                <Button Grid.Row="1" Grid.Column="0" Text="9" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="9"/>
55
                                <Button Grid.Row="0" Grid.Column="0" Text="11" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="11"/>
50
                                <Button Grid.Row="5" Grid.Column="0" Text="1" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="1" BackgroundColor="{Binding ChamberColors[0]}"/>
51
                                <Button Grid.Row="4" Grid.Column="0" Text="3" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="3" BackgroundColor="{Binding ChamberColors[2]}"/>
52
                                <Button Grid.Row="3" Grid.Column="0" Text="5" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="5" BackgroundColor="{Binding ChamberColors[4]}"/>
53
                                <Button Grid.Row="2" Grid.Column="0" Text="7" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="7" BackgroundColor="{Binding ChamberColors[6]}"/>
54
                                <Button Grid.Row="1" Grid.Column="0" Text="9" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="9" BackgroundColor="{Binding ChamberColors[8]}"/>
55
                                <Button Grid.Row="0" Grid.Column="0" Text="11" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="11" BackgroundColor="{Binding ChamberColors[10]}"/>
56 56

  
57 57
                                <!-- Boutons Droite -->
58
                                <Button Grid.Row="5" Grid.Column="2" Text="2" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="2"/>
59
                                <Button Grid.Row="4" Grid.Column="2" Text="4" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="4"/>
60
                                <Button Grid.Row="3" Grid.Column="2" Text="6" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="6"/>
61
                                <Button Grid.Row="2" Grid.Column="2" Text="8" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="8"/>
62
                                <Button Grid.Row="1" Grid.Column="2" Text="10" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="10"/>
63
                                <Button Grid.Row="0" Grid.Column="2" Text="12" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="12"/>
58
                                <Button Grid.Row="5" Grid.Column="2" Text="2" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="2" BackgroundColor="{Binding ChamberColors[1]}"/>
59
                                <Button Grid.Row="4" Grid.Column="2" Text="4" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="4" BackgroundColor="{Binding ChamberColors[3]}"/>
60
                                <Button Grid.Row="3" Grid.Column="2" Text="6" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="6" BackgroundColor="{Binding ChamberColors[5]}"/>
61
                                <Button Grid.Row="2" Grid.Column="2" Text="8" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="8" BackgroundColor="{Binding ChamberColors[7]}"/>
62
                                <Button Grid.Row="1" Grid.Column="2" Text="10" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="10" BackgroundColor="{Binding ChamberColors[9]}"/>
63
                                <Button Grid.Row="0" Grid.Column="2" Text="12" Style="{StaticResource ChambreButtonStyle}" Command="{Binding OnClickChamberCommand}" CommandParameter="12" BackgroundColor="{Binding ChamberColors[11]}"/>
64 64

  
65 65
                                <!-- Couloir central -->
66 66
                                <BoxView Grid.Column="1" Grid.RowSpan="6" HeightRequest="500" WidthRequest="75" Color="Gray"/>
GES_PAC/View/CreateMeasureView.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.CreateMeasureView"
7
             x:DataType="vm:CreateMeasureViewModel">
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="{Binding Titre}"
17
                       FontSize="20"
18
                       FontAttributes="Bold"
19
                       HorizontalOptions="Center" />
20
                    <VerticalStackLayout Spacing="15" WidthRequest="300">
21

  
22
                        <!-- CH4 -->
23
                        <VerticalStackLayout>
24
                            <Label Text="CH4 (ppm)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
25
                            <Entry Text="{Binding ConcCH4, Mode=TwoWay, TargetNullValue=''}" 
26
                                   FontSize="16" 
27
                                   TextColor="Black" 
28
                                   Placeholder="0,0" 
29
                                   Keyboard="Numeric"/>
30
                            <Label Text="Entrez une valeur"
31
                                FontSize="12"
32
                                TextColor="Red"
33
                                IsVisible="{Binding ConcCH4Error}"/>
34
                        </VerticalStackLayout>
35

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

  
50
                        <!-- CO2 -->
51
                        <VerticalStackLayout>
52
                            <Label Text="CO2 (% vol.)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
53
                            <Entry Text="{Binding ConcCO2, Mode=TwoWay, TargetNullValue=''}" 
54
                                   FontSize="16" 
55
                                   TextColor="Black" 
56
                                   Placeholder="0,0" 
57
                                   Keyboard="Numeric"/>
58
                            <Label Text="Entrez une valeur"
59
                                FontSize="12"
60
                                TextColor="Red"
61
                                IsVisible="{Binding ConcCO2Error}"/>
62
                        </VerticalStackLayout>
63
                    </VerticalStackLayout>
64
                </VerticalStackLayout>
65
            </ScrollView>
66
            <StackLayout
67
                Margin="10"
68
                HorizontalOptions="CenterAndExpand"
69
                Orientation="Horizontal"
70
                VerticalOptions="FillAndExpand">
71

  
72
                <Button 
73
                    Text="Enregistrer les mesures"
74
                    Command="{Binding CreateMeasureCommand}"
75
                    Style="{StaticResource btnNormal}"
76
                    IsEnabled="{Binding IsFormValid}"
77
                    VerticalOptions="End"/>
78
            </StackLayout>
79
        </StackLayout>
80
        <Grid Grid.RowSpan="1" IsVisible="{Binding IsBusy}">
81
            <Border StrokeThickness="0"
82
                            Background="Black"
83
                            Opacity="0.5"
84
                            Padding="20"
85
                            WidthRequest="160"
86
                            HeightRequest="160"
87
                            HorizontalOptions="Center"
88
                            VerticalOptions="Center"
89
                            StrokeShape="RoundRectangle 20">
90

  
91
                <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
92
                    <ActivityIndicator IsRunning="True" Color="White" />
93
                    <Label Text="Chargement..."
94
                            FontSize="14"
95
                            TextColor="white"
96
                            HorizontalOptions="Center"/>
97
                </VerticalStackLayout>
98
            </Border>
99
        </Grid>
100
    </Grid>
101

  
102
</ContentPage>
GES_PAC/View/CreateMeasureView.xaml.cs
1
using GES_PAC.ViewModel;
2

  
3
namespace GES_PAC.View
4
{
5
    public partial class CreateMeasureView
6
    {
7
        public CreateMeasureView()
8
        {
9
            InitializeComponent();
10
            BindingContext = new CreateMeasureViewModel();
11
        }
12
    }
13
}
GES_PAC/View/EnterAnimalView.xaml
23 23
                        <VerticalStackLayout>
24 24

  
25 25
                            <Label Text="Numéro RFID" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
26
                            <Entry Text="{Binding NumRFID}" FontSize="16" TextColor="Black" Placeholder="25"/>
26
                            <Entry Text="{Binding NumRFID}" FontSize="16" TextColor="Black" Placeholder="04 9C 64 D2 45 2B 80"/>
27 27
                            <Label Text="Min. 5 caractères"
28 28
                                FontSize="12"
29 29
                                TextColor="Red"
......
34 34
                        <!-- Poids -->
35 35
                        <VerticalStackLayout>
36 36
                            <Label Text="Poids (kg)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/>
37
                            <Entry Text="{Binding Poids}" FontSize="16" TextColor="Black" Placeholder="25" Keyboard="Numeric"/>
37
                            <Entry Text="{Binding Poids}" FontSize="16" TextColor="Black" Placeholder="75" Keyboard="Numeric"/>
38 38
                            <Label Text="Entrez une valeur"
39 39
                                FontSize="12"
40 40
                                TextColor="Red"
GES_PAC/ViewModel/ChambersViewModel.cs
1 1
using GES_PAC.Model;
2 2
using GES_PAC.View;
3
using System.Collections.ObjectModel;
3 4
using System.Windows.Input;
4 5

  
5 6
namespace GES_PAC.ViewModel
......
8 9
    {
9 10

  
10 11
        #region Attributs
12
        
11 13
        #endregion
12 14

  
13 15
        #region Commandes
......
16 18

  
17 19
        #region Propriétés
18 20

  
21
        public Dictionary<int, int> NumberMeasure { get; set; }
22

  
23
        public ObservableCollection<Color> ChamberColors { get; } = [];
24

  
19 25
        #endregion
20 26

  
21 27
        #region Constructeurs
22 28
        public ChambersViewModel()
23 29
        {
30
            NumberMeasure = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet().GetMeasureNumber();
31
            UpdateChamberColors();
32

  
24 33
            OnClickChamberCommand = new Command<string>(async (idStr) =>
25 34
            {
26 35
                int id = int.Parse(idStr);
27 36
                await GoToEnterAnimal(id);
28 37
            });
29

  
30 38
        }
31 39
        #endregion
32 40

  
......
37 45
            await Shell.Current.GoToAsync($"{nameof(EnterAnimalView)}?chamberId={id}");
38 46
            IsBusy = false;
39 47
        }
48

  
49
        private void UpdateChamberColors()
50
        {
51
            ChamberColors.Clear();
52
            for (int i = 1; i <= 12; i++)
53
            {
54
                int count = NumberMeasure.TryGetValue(i, out var val) ? val : 0;
55
                ChamberColors.Add(count > 0 ? Colors.LightGreen : Colors.White);
56
            }
57
        }
40 58
        #endregion
41 59
    }
42 60
}
GES_PAC/ViewModel/CreateMeasureViewModel.cs
1
using GES_PAC.Model;
2
using GES_PAC.View;
3
using System.Collections.ObjectModel;
4
using System.Windows.Input;
5

  
6
namespace GES_PAC.ViewModel
7
{
8
    [QueryProperty(nameof(ChamberId), "chamberId")]
9
    public class CreateMeasureViewModel : BaseViewModel
10
    {
11

  
12
        #region Attributs
13
        private int _chamberId;
14
        private double? _conc_o2;
15
        private double? _conc_co2;
16
        private double? _conc_ch4;
17
        private bool _isFormValid;
18
        #endregion
19

  
20
        #region Commandes
21
        public ICommand CreateMeasureCommand { get; }
22
        #endregion
23

  
24
        #region Propriétés
25
        public int ChamberId
26
        {
27
            get => _chamberId;
28
            set
29
            {
30
                _chamberId = value;
31
                OnPropertyChanged();
32
                OnPropertyChanged(nameof(Titre));
33
            }
34
        }
35

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

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

  
58
        public double? ConcCH4
59
        {
60
            get => _conc_ch4;
61
            set
62
            {
63
                _conc_ch4 = value;
64
                OnPropertyChanged();
65
                ValidateForm();
66
            }
67
        }
68

  
69
        public bool IsFormValid
70
        {
71
            get => _isFormValid;
72
            set
73
            {
74
                _isFormValid = value;
75
                OnPropertyChanged();
76
            }
77
        }
78

  
79
        public bool ConcO2Error { get; private set; } = true;
80
        public bool ConcCO2Error { get; private set; } = true;
81
        public bool ConcCH4Error { get; private set; } = true;
82
        public string Titre => $"Mesures chambre {ChamberId}";
83
        #endregion
84

  
85
        #region Constructeurs
86
        public CreateMeasureViewModel()
87
        {
88
            CreateMeasureCommand = new Command(async () => await CreateMeasure());
89
        }
90
        #endregion
91

  
92
        #region Méthodes
93
        private async Task CreateMeasure()
94
        {
95
            IsBusy = true;
96

  
97
            var date = DateTime.Now;
98
            var newMeasure = new Mesure(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0);
99
            var phaseCalibration = JourneeViewModel.Instance.GetCurrentPhase();
100

  
101
            JourneeViewModel.Instance.AddMeasureToCurrentSet(newMeasure, ChamberId);
102

  
103
            await Shell.Current.GoToAsync(nameof(ChambersView));
104

  
105
            IsBusy = false;
106
        }
107

  
108
        private void ValidateForm()
109
        {
110
            ConcO2Error = ConcO2 == null;
111
            ConcCO2Error = ConcCO2 == null;
112
            ConcCH4Error = ConcCH4 == null;
113

  
114
            OnPropertyChanged(nameof(ConcO2Error));
115
            OnPropertyChanged(nameof(ConcCO2Error));
116
            OnPropertyChanged(nameof(ConcCH4Error));
117

  
118
            IsFormValid = !ConcO2Error && !ConcCO2Error && !ConcCH4Error;
119

  
120
            (CreateMeasureCommand as Command)?.ChangeCanExecute();
121
        }
122
        #endregion
123
    }
124
}
GES_PAC/ViewModel/EnterAnimalViewModel.cs
68 68

  
69 69
        public bool NumRFIDError { get; private set; } = true;
70 70
        public bool PoidsError { get; private set; } = true;
71
        public string Titre => $"Information animal chambre {ChamberId}";
71
        public string Titre => $"Informations animal chambre {ChamberId}";
72 72

  
73 73
        #endregion
74 74

  
......
88 88
            var newAnimalSet = new SerieAnimal(ChamberId, Poids ?? 0, date, NumRFID);
89 89
            journeeActuelle.GetCurrentSet().AddSerieAnimal(newAnimalSet);
90 90

  
91
            await Shell.Current.GoToAsync(nameof(ChambersView));
91
            await Shell.Current.GoToAsync($"{nameof(CreateMeasureView)}?chamberId={ChamberId}");
92 92
            IsBusy = false;
93 93
        }
94 94

  
GES_PAC/ViewModel/JourneeViewModel.cs
34 34
            var journeeActuelle = GetCurrentDay();
35 35
            return journeeActuelle.GetCurrentPhase();
36 36
        }
37

  
38
        public void AddMeasureToCurrentSet(Mesure newMeasure, int numBoite)
39
        {
40
            GetCurrentDay().GetCurrentSet().AddMeasure(newMeasure, numBoite);
41
        }
37 42
        #endregion
38 43
    }
39 44
}

Formats disponibles : Unified diff