commit 957bebf18b6615677b70734cbf7add73f8a25e3e
Author: lbihannic <lucas.bihannic@inrae.fr>
Date:   Wed Apr 16 14:06:04 2025 +0200

    add export last day to json and csv

diff --git a/GES_PAC/AppShell.xaml b/GES_PAC/AppShell.xaml
index 7e0a215..0aba13f 100644
--- a/GES_PAC/AppShell.xaml
+++ b/GES_PAC/AppShell.xaml
@@ -10,10 +10,12 @@
     Title="GES_PAC">
 
 
+    <!-- 
     <ShellContent 
     Title="Accueil" 
     Route="Main"
     ContentTemplate="{DataTemplate local:MainView}" />
+    -->
 
     <ShellContent 
         Title="Remorque" 
diff --git a/GES_PAC/AppShell.xaml.cs b/GES_PAC/AppShell.xaml.cs
index 7ffab01..a4ba20e 100644
--- a/GES_PAC/AppShell.xaml.cs
+++ b/GES_PAC/AppShell.xaml.cs
@@ -23,6 +23,7 @@ namespace GES_PAC
             Routing.RegisterRoute(nameof(CreateBehaviourView), typeof(CreateBehaviourView));
             Routing.RegisterRoute(nameof(EndSetView), typeof(EndSetView));
             Routing.RegisterRoute(nameof(EndDayView), typeof(EndDayView));
+            Routing.RegisterRoute(nameof(ExportDataView), typeof(ExportDataView));
         }
     }
 }
diff --git a/GES_PAC/GES_PAC.csproj b/GES_PAC/GES_PAC.csproj
index d820698..bab2a21 100644
--- a/GES_PAC/GES_PAC.csproj
+++ b/GES_PAC/GES_PAC.csproj
@@ -25,7 +25,7 @@
 		<ApplicationTitle>GES_PAC</ApplicationTitle>
 
 		<!-- App Identifier -->
-		<ApplicationId>fr.inrae.sicpa.GES_PAC</ApplicationId>
+		<ApplicationId>fr.inrae.GES_PAC</ApplicationId>
 
 		<!-- Versions -->
 		<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
diff --git a/GES_PAC/GES_PAC.csproj.user b/GES_PAC/GES_PAC.csproj.user
index 119a1f3..06228c2 100644
--- a/GES_PAC/GES_PAC.csproj.user
+++ b/GES_PAC/GES_PAC.csproj.user
@@ -3,8 +3,8 @@
   <PropertyGroup>
     <IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
     <ActiveDebugFramework>net9.0-android</ActiveDebugFramework>
-    <ActiveDebugProfile>Android Emulator</ActiveDebugProfile>
-    <SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
+    <ActiveDebugProfile>Samsung SM-G556B (Android 14.0 - API 34)</ActiveDebugProfile>
+    <SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
     <DefaultDevice>pixel_7_-_api_35</DefaultDevice>
     <SelectedDevice>Xiaomi 23090RA98G</SelectedDevice>
   </PropertyGroup>
diff --git a/GES_PAC/Helpers/JourneeToCSV.cs b/GES_PAC/Helpers/JourneeToCSV.cs
new file mode 100644
index 0000000..6d5a619
--- /dev/null
+++ b/GES_PAC/Helpers/JourneeToCSV.cs
@@ -0,0 +1,41 @@
+﻿using GES_PAC.Model;
+using System.Text;
+
+namespace GES_PAC.Helpers
+{
+    public static class JourneeToCSV
+    {
+        public static string[] ConvertToCSV(Journee journee)
+        {
+            var sbMesure = new StringBuilder();
+            sbMesure.AppendLine("Elevage;Client;Responsable;Espece;Regime;MiseAJeun;Temperature;Humidite;Pression;NumBoite;Poids;DatePesee;RFID;Time;Conc_O2;Conc_CO2;Conc_CH4");
+            var sbComportement = new StringBuilder();
+            sbComportement.AppendLine("Elevage;Client;Responsable;Espece;Regime;MiseAJeun;Temperature;Humidite;Pression;NumBoite;Poids;DatePesee;RFID;Time;Comportement;Commentaire");
+            var sbCalibration = new StringBuilder();
+            sbCalibration.AppendLine("Elevage;Client;Responsable;PhaseCalibration;Time;Conc_O2;Conc_CO2;Conc_CH4");
+
+            foreach (var serie in journee.Series)
+            {
+                foreach (var serieAnimal in serie.SeriesAnimales)
+                {
+                    foreach (var mesure in serieAnimal.Mesures)
+                    {
+                        sbMesure.AppendLine($"{journee.Lieu.Nom};{journee.Lieu.Client};{journee.Responsable.Nom};{journee.Lieu.Espece};{journee.Regime};{serie.MiseAJeun.ToString("yyyy-MM-dd HH:mm")};{serie.Temperature};{serie.Humidite};{serie.Pression};{serieAnimal.NumeroBoite};{serieAnimal.Poids};{serieAnimal.DatePesee.ToString("yyyy-MM-dd")};{serieAnimal.RFID};{mesure.Time.ToString("HH:mm:ss")};{mesure.Conc_O2};{mesure.Conc_CO2};{mesure.Conc_CH4}");
+                    }
+                    foreach (var comportement in serieAnimal.Comportements)
+                    {
+                        sbComportement.AppendLine($"{journee.Lieu.Nom};{journee.Lieu.Client};{journee.Responsable.Nom};{journee.Lieu.Espece};{journee.Regime};{serie.MiseAJeun.ToString("yyyy-MM-dd HH:mm")};{serie.Temperature};{serie.Humidite};{serie.Pression};{serieAnimal.NumeroBoite};{serieAnimal.Poids};{serieAnimal.DatePesee.ToString("yyyy-MM-dd")};{serieAnimal.RFID};{comportement.Time.ToString("HH:mm:ss")};{comportement.Type.ToString()};{comportement.Commentaire}");
+                    }
+                }
+                foreach (var calibration in journee.Calibrations)
+                {
+                    foreach (var mesure in calibration.Mesures)
+                    {
+                        sbCalibration.AppendLine($"{journee.Lieu.Nom};{journee.Lieu.Client};{journee.Responsable.Nom};{calibration.Phase.ToString()};{mesure.Time.ToString("HH:mm:ss")};{mesure.Conc_O2};{mesure.Conc_CO2};{mesure.Conc_CH4}");
+                    }
+                }
+            }
+            return [sbMesure.ToString(), sbComportement.ToString(), sbCalibration.ToString()];
+        }
+    }
+}
diff --git a/GES_PAC/Model/Comportement.cs b/GES_PAC/Model/Comportement.cs
index ae30406..60b4178 100644
--- a/GES_PAC/Model/Comportement.cs
+++ b/GES_PAC/Model/Comportement.cs
@@ -3,20 +3,16 @@ namespace GES_PAC.Model
 {
     public class Comportement
     {
-        private DateTime date;
-        private TypeComportement selectedType;
-        private string description;
-
-        public Comportement(DateTime date, TypeComportement selectedType, string description)
-        {
-            this.date = date;
-            this.selectedType = selectedType;
-            this.description = description;
-        }
-
         public long Id { get; set; }
         public DateTime Time { get; set; }
-        public TypeComportement? Type { get; set; }
+        public TypeComportement Type { get; set; }
         public string? Commentaire { get; set; }
+
+        public Comportement(DateTime Time, TypeComportement Type, string Commentaire)
+        {
+            this.Time = Time;
+            this.Type = Type ?? TypeComportement.AUTRE;
+            this.Commentaire = Commentaire;
+        }
     }
 }
diff --git a/GES_PAC/Model/PhaseCalibration.cs b/GES_PAC/Model/PhaseCalibration.cs
index 0eb6737..27f46c9 100644
--- a/GES_PAC/Model/PhaseCalibration.cs
+++ b/GES_PAC/Model/PhaseCalibration.cs
@@ -11,8 +11,8 @@ namespace GES_PAC.Model
             Value = value;
         }
 
-        public static readonly PhaseCalibration Debut = new("Début", 1);
-        public static readonly PhaseCalibration Fin = new("Fin", 2);
+        public static readonly PhaseCalibration Debut = new("DEBUT", 1);
+        public static readonly PhaseCalibration Fin = new("FIN", 2);
 
         public static readonly List<PhaseCalibration> All = new() { Debut, Fin };
 
diff --git a/GES_PAC/Model/TypeCalibration.cs b/GES_PAC/Model/TypeCalibration.cs
index 3bab5da..20142bc 100644
--- a/GES_PAC/Model/TypeCalibration.cs
+++ b/GES_PAC/Model/TypeCalibration.cs
@@ -11,9 +11,9 @@ namespace GES_PAC.Model
             Value = value;
         }
 
-        public static readonly TypeCalibration Air = new("Air", 0);
-        public static readonly TypeCalibration Methane = new("Methane", 1);
-        public static readonly TypeCalibration Melange = new("Mélange", 2);
+        public static readonly TypeCalibration Air = new("AIR", 0);
+        public static readonly TypeCalibration Methane = new("METHANE", 1);
+        public static readonly TypeCalibration Melange = new("MELANGE", 2);
 
         public static readonly List<TypeCalibration> All = new() { Air, Methane, Melange };
 
diff --git a/GES_PAC/Platforms/Android/AndroidFileHelper.cs b/GES_PAC/Platforms/Android/AndroidFileHelper.cs
new file mode 100644
index 0000000..d2aa10b
--- /dev/null
+++ b/GES_PAC/Platforms/Android/AndroidFileHelper.cs
@@ -0,0 +1,56 @@
+﻿using Android.Content;
+using Android.Provider;
+using System.Text;
+
+
+public static class AndroidFileHelper
+{
+    public static void SaveJsonToDownloads(string fileName, string content)
+    {
+        var context = Android.App.Application.Context;
+
+        ContentValues values = new ContentValues();
+        values.Put(MediaStore.IMediaColumns.DisplayName, fileName);
+        values.Put(MediaStore.IMediaColumns.MimeType, "text/json");
+
+        values.Put(MediaStore.IMediaColumns.RelativePath, $"{Android.OS.Environment.DirectoryDownloads}/GES_PAC");
+
+        var uri = context.ContentResolver.Insert(MediaStore.Downloads.ExternalContentUri, values);
+        if (uri == null) throw new IOException("Impossible de créer le fichier.");
+
+        using var stream = context.ContentResolver.OpenOutputStream(uri);
+        using var writer = new StreamWriter(stream, Encoding.UTF8);
+        writer.Write(content);
+        writer.Flush();
+    }
+    public static void SaveCSVToDownloads(string folderName, string[] contents)
+    {
+        if (contents.Length != 3)
+            throw new ArgumentException("Le tableau de contenu doit contenir exactement 3 éléments.");
+
+        var context = Android.App.Application.Context;
+
+        string[] fileNames = { "mesures.csv", "comportements.csv", "calibrations.csv" };
+        string folderPath = $"{Android.OS.Environment.DirectoryDownloads}/GES_PAC/{folderName.Replace("/","_")}";
+
+        for (int i = 0; i < fileNames.Length; i++)
+        {
+            ContentValues values = new ContentValues();
+            values.Put(MediaStore.IMediaColumns.DisplayName, fileNames[i]);
+            values.Put(MediaStore.IMediaColumns.MimeType, "text/csv");
+            values.Put(MediaStore.IMediaColumns.RelativePath, folderPath);
+
+            var uri = context.ContentResolver.Insert(MediaStore.Downloads.ExternalContentUri, values);
+            if (uri == null) throw new IOException($"Impossible de créer le fichier {fileNames[i]}.");
+
+            using var stream = context.ContentResolver.OpenOutputStream(uri);
+            using var writer = new StreamWriter(stream, Encoding.UTF8);
+            foreach (var line in contents[i])
+            {
+                writer.Write(line);
+            }
+            writer.Flush();
+        }
+    }
+}
+
diff --git a/GES_PAC/Platforms/Android/AndroidManifest.xml b/GES_PAC/Platforms/Android/AndroidManifest.xml
index e9937ad..377970e 100644
--- a/GES_PAC/Platforms/Android/AndroidManifest.xml
+++ b/GES_PAC/Platforms/Android/AndroidManifest.xml
@@ -1,6 +1,9 @@
 ﻿<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
-	<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="fr.inrae.GES_PAC">
+	<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="GES_PAC"></application>
 	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 	<uses-permission android:name="android.permission.INTERNET" />
+	<uses-permission android:name="android.permission.BLUETOOTH" />
+	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 </manifest>
\ No newline at end of file
diff --git a/GES_PAC/View/ChambersView.xaml b/GES_PAC/View/ChambersView.xaml
index 749243f..e1d2779 100644
--- a/GES_PAC/View/ChambersView.xaml
+++ b/GES_PAC/View/ChambersView.xaml
@@ -48,20 +48,20 @@
                                 </Grid.RowDefinitions>
 
                                 <!-- Boutons Gauche -->
-                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="0" ChamberId="1" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="0" ChamberId="3" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="0" ChamberId="5" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="0" ChamberId="7" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="0" ChamberId="9" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="0" ChamberId="11" Timer="{Binding Timer}"/>
+                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="0" ChamberId="1" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="0" ChamberId="3" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="0" ChamberId="5" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="0" ChamberId="7" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="0" ChamberId="9" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="0" ChamberId="11" ParentViewModel="{Binding .}"/>
 
                                 <!-- Boutons Droite -->
-                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="2" ChamberId="2" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="2" ChamberId="4" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="2" ChamberId="6" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="2" ChamberId="8" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="2" ChamberId="10" Timer="{Binding Timer}"/>
-                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="2" ChamberId="12" Timer="{Binding Timer}"/>
+                                <controls:ChamberButtonView Grid.Row="5" Grid.Column="2" ChamberId="2" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="4" Grid.Column="2" ChamberId="4" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="3" Grid.Column="2" ChamberId="6" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="2" Grid.Column="2" ChamberId="8" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="1" Grid.Column="2" ChamberId="10" ParentViewModel="{Binding .}"/>
+                                <controls:ChamberButtonView Grid.Row="0" Grid.Column="2" ChamberId="12" ParentViewModel="{Binding .}"/>
 
                                 <!-- Couloir central -->
                                 <BoxView Grid.Column="1" Grid.RowSpan="6" HeightRequest="500" WidthRequest="75" Color="Gray"/>
diff --git a/GES_PAC/View/Controls/ChamberButtonView.xaml.cs b/GES_PAC/View/Controls/ChamberButtonView.xaml.cs
index 47a3c21..685cc8c 100644
--- a/GES_PAC/View/Controls/ChamberButtonView.xaml.cs
+++ b/GES_PAC/View/Controls/ChamberButtonView.xaml.cs
@@ -8,13 +8,13 @@ public partial class ChamberButtonView : ContentView
     public static readonly BindableProperty ChamberIdProperty =
         BindableProperty.Create(nameof(ChamberId), typeof(int), typeof(ChamberButtonView), default(int), propertyChanged: OnChamberIdChanged);
 
-    public static readonly BindableProperty TimerProperty =
-        BindableProperty.Create(nameof(Timer), typeof(TimerPublisher), typeof(ChamberButtonView), propertyChanged: OnTimerChanged);
+    public static readonly BindableProperty ParentViewModelProperty =
+        BindableProperty.Create(nameof(ParentViewModel), typeof(ChambersViewModel), typeof(ChamberButtonView), propertyChanged: OnParentChanged);
 
-    public TimerPublisher? Timer
+    public ChambersViewModel? ParentViewModel
     {
-        get => (TimerPublisher?)GetValue(TimerProperty);
-        set => SetValue(TimerProperty, value);
+        get => (ChambersViewModel?)GetValue(ParentViewModelProperty);
+        set => SetValue(ParentViewModelProperty, value);
     }
 
     public int ChamberId
@@ -31,9 +31,9 @@ public partial class ChamberButtonView : ContentView
     {
         base.OnBindingContextChanged();
 
-        if (BindingContext is not ChamberButtonViewModel && ChamberId != 0 && Timer != null)
+        if (BindingContext is not ChamberButtonViewModel && ChamberId != 0 && ParentViewModel != null)
         {
-            var vm = new ChamberButtonViewModel(ChamberId, Timer);
+            var vm = new ChamberButtonViewModel(ChamberId, ParentViewModel);
             BindingContext = vm;
             vm.UpdateProperties();
         }
@@ -48,7 +48,7 @@ public partial class ChamberButtonView : ContentView
             vm.UpdateChamberId(id);
         }
     }
-    private static void OnTimerChanged(BindableObject bindable, object oldValue, object newValue)
+    private static void OnParentChanged(BindableObject bindable, object oldValue, object newValue)
     {
         if (bindable is ChamberButtonView view)
         {
diff --git a/GES_PAC/View/ExportDataView.xaml b/GES_PAC/View/ExportDataView.xaml
new file mode 100644
index 0000000..6e32dd3
--- /dev/null
+++ b/GES_PAC/View/ExportDataView.xaml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"  
+            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
+            xmlns:vm="clr-namespace:GES_PAC.ViewModel"  
+            xmlns:tools="clr-namespace:GES_PAC.View.Tools"  
+            x:Class="GES_PAC.View.ExportDataView"  
+            x:DataType="vm:ExportDataViewModel">
+
+    <Grid>
+        <StackLayout BackgroundColor="White" Spacing="50">
+
+            <tools:ConnectionIndicatorView />
+            <ScrollView>
+                <StackLayout Spacing="100">
+
+                    <Label Text="Exporter les données"   
+                        FontSize="22"
+                        FontAttributes="Bold"
+                        HorizontalOptions="Center"/>
+
+                    <Label Text="{Binding DataFoundText}"  
+                       FontSize="18"  
+                       HorizontalOptions="Center"/>
+
+                </StackLayout>
+            </ScrollView>
+            <StackLayout HorizontalOptions="Center" VerticalOptions="EndAndExpand" Spacing="75" Margin="0, 0, 0, 50">
+
+                <Button  
+                   Text="Exporter en JSON"  
+                   Command="{Binding ExportJSONCommand}"  
+                   Style="{StaticResource btnNormal}"  
+                   VerticalOptions="End"  
+                   HorizontalOptions="Center"
+                   IsVisible="{Binding HasData}"/>
+
+                <Button  
+                   Text="Exporter en CSV"  
+                   Command="{Binding ExportCSVCommand}"  
+                   Style="{StaticResource btnNormal}"  
+                   VerticalOptions="End"  
+                   HorizontalOptions="Center"  
+                   IsVisible="{Binding HasData}"/>
+
+            </StackLayout>
+
+        </StackLayout>
+        <Grid Grid.RowSpan="1" IsVisible="{Binding IsBusy}">
+            <Border StrokeThickness="0"  
+               Background="Black"  
+               Opacity="0.5"  
+               Padding="20"  
+               WidthRequest="160"  
+               HeightRequest="160"  
+               HorizontalOptions="Center"  
+               VerticalOptions="Center"  
+               StrokeShape="RoundRectangle 20">
+
+                <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">
+                    <ActivityIndicator IsRunning="True" Color="White" />
+                    <Label Text="Chargement..."  
+                       FontSize="14"  
+                       TextColor="white"  
+                       HorizontalOptions="Center"/>
+                </VerticalStackLayout>
+            </Border>
+        </Grid>
+
+    </Grid>
+</ContentPage>
diff --git a/GES_PAC/View/ExportDataView.xaml.cs b/GES_PAC/View/ExportDataView.xaml.cs
new file mode 100644
index 0000000..5c576eb
--- /dev/null
+++ b/GES_PAC/View/ExportDataView.xaml.cs
@@ -0,0 +1,12 @@
+﻿using GES_PAC.ViewModel;
+
+namespace GES_PAC.View;
+
+public partial class ExportDataView
+{
+    public ExportDataView()
+    {
+        InitializeComponent();
+        BindingContext = new ExportDataViewModel();
+    }
+}
diff --git a/GES_PAC/View/MainView.xaml b/GES_PAC/View/MainView.xaml
index 93967a9..778c17d 100644
--- a/GES_PAC/View/MainView.xaml
+++ b/GES_PAC/View/MainView.xaml
@@ -13,10 +13,22 @@
             <ScrollView>
                 <StackLayout Spacing="100">
 
-                    <Label Text="Bonjour"
-                        FontSize="22"
-                        FontAttributes="Bold"
-                        HorizontalOptions="Center"/>
+                    <Grid ColumnDefinitions="*,Auto,*" Padding="10">
+
+                        <Button Text="Exporter"
+                            Command="{Binding ExportDataCommand}"  
+                            Grid.Column="0"
+                            HorizontalOptions="Start"
+                            VerticalOptions="Center" />
+
+                        <Label Text="Bonjour"
+                           Grid.Column="1"
+                           FontSize="22"
+                           FontAttributes="Bold"
+                           HorizontalOptions="Center"
+                           VerticalOptions="Center" />
+
+                    </Grid>
 
                     <Label Text="{Binding CurrentDayText}"
                         FontSize="18"
diff --git a/GES_PAC/ViewModel/ChambersViewModel.cs b/GES_PAC/ViewModel/ChambersViewModel.cs
index 86441ff..722fe9c 100644
--- a/GES_PAC/ViewModel/ChambersViewModel.cs
+++ b/GES_PAC/ViewModel/ChambersViewModel.cs
@@ -19,6 +19,8 @@ namespace GES_PAC.ViewModel
 
         #region Propriétés
         public TimerPublisher Timer { get; }
+        public List<ChamberButtonViewModel> Buttons { get; } = new();
+
         #endregion
 
         #region Constructeurs
@@ -45,6 +47,8 @@ namespace GES_PAC.ViewModel
         internal async void OnAppearing()
         {
             CurrentSet = JourneeViewModel.Instance.GetCurrentSet();
+            RefreshAll();
+
             if (CurrentSet == null)
             {
                 IsBusy = true;
@@ -52,6 +56,17 @@ namespace GES_PAC.ViewModel
                 IsBusy = false;
             }
         }
+        public void RegisterButton(ChamberButtonViewModel vm)
+        {
+            if (!Buttons.Contains(vm))
+                Buttons.Add(vm);
+        }
+        public void RefreshAll()
+        {
+            foreach (var btn in Buttons)
+                btn.UpdateProperties();
+        }
+
         #endregion
     }
 }
diff --git a/GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs b/GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs
index 8041909..e10c432 100644
--- a/GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs
+++ b/GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs
@@ -101,16 +101,14 @@ namespace GES_PAC.ViewModel.Controls
 
         #region Constructeurs
 
-        public ChamberButtonViewModel(int chamberId, TimerPublisher timerPublisher)
+        public ChamberButtonViewModel(int chamberId, ChambersViewModel parentViewModel)
         {
             ChamberId = chamberId;
-            _timer = timerPublisher;
+            _timer = parentViewModel.Timer;
+            parentViewModel.RegisterButton(this);
 
             OnClickChamberCommand = new Command(async () => await GoToChamber());
-            ButtonBackgroundColor = Colors.White;
-            ButtonIsEnabled = true;
-            ButtonLabel = "0";
-            TimeIn = "";
+            InitButtonProperties();
             CurrentSet = JourneeViewModel.Instance?.GetCurrentSet();
 
             UpdateChamberId(chamberId);
@@ -124,11 +122,19 @@ namespace GES_PAC.ViewModel.Controls
             ChamberId = chamberId;
             UpdateProperties();
         }
+        public void InitButtonProperties()
+        {
+            ButtonBackgroundColor = Colors.White;
+            ButtonIsEnabled = true;
+            ButtonLabel = "0";
+            TimeIn = "";
+        }
         public void UpdateProperties()
         {
             CurrentSet = JourneeViewModel.Instance?.GetCurrentSet();
             AnimalSet = CurrentSet?.GetSerieAnimalByNumBoite(ChamberId);
             ButtonText = ChamberId.ToString();
+            InitButtonProperties();
 
             int measureCount = AnimalSet?.GetMeasureCount() ?? 0;
 
diff --git a/GES_PAC/ViewModel/CreateBehaviourViewModel.cs b/GES_PAC/ViewModel/CreateBehaviourViewModel.cs
index 725de76..7ed3255 100644
--- a/GES_PAC/ViewModel/CreateBehaviourViewModel.cs
+++ b/GES_PAC/ViewModel/CreateBehaviourViewModel.cs
@@ -89,9 +89,9 @@ namespace GES_PAC.ViewModel
             IsBusy = true;
 
             var date = DateTime.Now;
-            var set = JourneeViewModel.Instance.GetCurrentSet();
             var newBehaviour = new Comportement(date, SelectedType, Description);
-            set.AddBehaviour(newBehaviour, ChamberId, IsAnimalOut);
+            var currentSet = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet();
+            currentSet.AddBehaviour(newBehaviour, ChamberId, IsAnimalOut);
 
             await Shell.Current.Navigation.PopToRootAsync();
             IsBusy = false;
diff --git a/GES_PAC/ViewModel/CreateCalibrationViewModel.cs b/GES_PAC/ViewModel/CreateCalibrationViewModel.cs
index 6d01b21..f76f133 100644
--- a/GES_PAC/ViewModel/CreateCalibrationViewModel.cs
+++ b/GES_PAC/ViewModel/CreateCalibrationViewModel.cs
@@ -35,7 +35,7 @@ namespace GES_PAC.ViewModel
             set
             {
                 _selectedType = value;
-                IsRefBouteilleVisible = _selectedType.Name != "Air";
+                IsRefBouteilleVisible = _selectedType != TypeCalibration.Air;
                 OnPropertyChanged();
                 OnTypeChanged();
                 ValidateForm();
diff --git a/GES_PAC/ViewModel/CreateMeasureViewModel.cs b/GES_PAC/ViewModel/CreateMeasureViewModel.cs
index ec46c58..1851719 100644
--- a/GES_PAC/ViewModel/CreateMeasureViewModel.cs
+++ b/GES_PAC/ViewModel/CreateMeasureViewModel.cs
@@ -196,11 +196,9 @@ namespace GES_PAC.ViewModel
             var date = DateTime.Now;
             var newMeasure = new Mesure(date, ConcO2 ?? 0, ConcCO2 ?? 0, ConcCH4 ?? 0);
             var currentSet = JourneeViewModel.Instance.GetCurrentDay().GetCurrentSet();
-
             currentSet.AddMeasure(newMeasure, ChamberId, IsAnimalOut);
 
             await Shell.Current.Navigation.PopToRootAsync();
-
             IsBusy = false;
         }
         private async Task GoToBehaviour()
diff --git a/GES_PAC/ViewModel/ExportDataViewModel.cs b/GES_PAC/ViewModel/ExportDataViewModel.cs
new file mode 100644
index 0000000..d874b0a
--- /dev/null
+++ b/GES_PAC/ViewModel/ExportDataViewModel.cs
@@ -0,0 +1,87 @@
+﻿using System.Windows.Input;
+using GES_PAC.Model;
+using GES_PAC.Helpers;
+using System.Text.Json;
+using System.Collections.ObjectModel;
+
+
+namespace GES_PAC.ViewModel
+{
+    public class ExportDataViewModel : BaseViewModel
+    {
+        #region Attributs
+        private bool _hasData = false;
+        public string _dataFoundText;
+        #endregion
+
+        #region Propriétés
+        public bool HasData
+        {
+            get => _hasData;
+            set
+            {
+                SetProperty(ref _hasData, value);
+                OnPropertyChanged();
+            }
+        }
+        public string DataFoundText
+        {
+            get => _dataFoundText;
+            set
+            {
+                SetProperty(ref _dataFoundText, value);
+                OnPropertyChanged();
+            }
+        }
+        public ObservableCollection<Journee>? DayList { get; set; }
+        #endregion
+
+        #region Commandes
+        public ICommand ExportJSONCommand { get; }
+        public ICommand ExportCSVCommand { get; }
+        #endregion
+
+        #region Constructeur
+        public ExportDataViewModel()
+        {
+            ExportJSONCommand = new Command(ExportJSON);
+            ExportCSVCommand = new Command(ExportCSV);
+
+            DayList = JourneeViewModel.Instance?.Journees ?? null;
+            HasData = DayList != null && DayList.Count > 0;
+            DataFoundText = HasData ? "Données trouvées" : "Aucune donnée trouvée";
+        }
+        #endregion
+
+        #region Méthodes
+        private void ExportJSON()
+        {
+#if ANDROID
+            if(IsBusy) return;
+            IsBusy = true;
+            var lastDay = DayList.Last();
+            string fileName = lastDay.Date.ToString();
+            string json = JsonSerializer.Serialize(lastDay);
+            AndroidFileHelper.SaveJsonToDownloads(fileName, json);
+            IsBusy = false;
+#endif
+        }
+
+        private void ExportCSV()
+        {
+#if ANDROID
+            if(IsBusy) return;
+            IsBusy = true;
+            var lastDay = DayList.Last();
+            string folderName = lastDay.Date.ToString();
+            string[] csv = JourneeToCSV.ConvertToCSV(lastDay);
+            Console.WriteLine(csv[0]);
+            AndroidFileHelper.SaveCSVToDownloads(folderName, csv);
+            IsBusy = false;
+#endif
+        }
+
+        #endregion
+    }
+}
+
diff --git a/GES_PAC/ViewModel/MainViewModel.cs b/GES_PAC/ViewModel/MainViewModel.cs
index 58a571e..0f4e659 100644
--- a/GES_PAC/ViewModel/MainViewModel.cs
+++ b/GES_PAC/ViewModel/MainViewModel.cs
@@ -12,11 +12,10 @@ namespace GES_PAC.ViewModel
         private string _currentDayText;
         #endregion
 
-        
-
         #region Commandes
         public ICommand GoToCreateDayCommand { get; }
         public ICommand ResumeDayCommand { get; }
+        public ICommand ExportDataCommand { get; }
         #endregion
 
         #region Propriétés
@@ -53,19 +52,20 @@ namespace GES_PAC.ViewModel
         public MainViewModel()
         {
             //ONLY FOR TESTS
-            //var date = DateTime.Now;
-            //var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
-            //newDay.AddSet(new Serie(date, date, 25, 25, 25));
-            //newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut);
-            //newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut);
-            //newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut);
-            //newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
-            //newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
-            //JourneeViewModel.Instance.Journees.Add(newDay);
+            var date = DateTime.Now;
+            var newDay = new Journee(date, PersonViewModel.Instance.Persons[0], PlaceViewModel.Instance.Places[0], "");
+            newDay.AddSet(new Serie(date, date, 25, 25, 25));
+            newDay.AddCalibration(new MesureCalibration(date, 50, 40, 500, TypeCalibration.Air, ""), PhaseCalibration.Debut);
+            newDay.AddCalibration(new MesureCalibration(date, 0, 0, 1000000, TypeCalibration.Methane, "dazdazd"), PhaseCalibration.Debut);
+            newDay.AddCalibration(new MesureCalibration(date, 30, 30, 3000, TypeCalibration.Melange, "deqsfsdf"), PhaseCalibration.Debut);
+            newDay.GetCurrentSet().AddSerieAnimal(new SerieAnimal(1, 500, date, ""));
+            newDay.GetCurrentSet().AddMeasure(new Mesure(date, 50, 50, 50), 1, false);
+            JourneeViewModel.Instance.Journees.Add(newDay);
             //ONLY FOR TESTS
 
             GoToCreateDayCommand = new Command(async () => await GoToCreateDayPage());
             ResumeDayCommand = new Command(async () => await ResumeDay());
+            ExportDataCommand = new Command(async () => await ExportData());
 
             GetLastDay();
         }
@@ -100,6 +100,13 @@ namespace GES_PAC.ViewModel
 
             await Shell.Current.GoToAsync(targetView);
             IsBusy = false;
+        }        
+        private async Task ExportData()
+        {
+            if (IsBusy) return;
+            IsBusy = true;
+            await Shell.Current.GoToAsync(nameof(ExportDataView));
+            IsBusy = false;
         }
         #endregion
     }
