Gestion de l'erreur de connexion a la BDD, ajout de composants + ajouts de vues

GestionBanques
Hugo LIVET 2 years ago
parent 45b220c477
commit 77a0f3c7c0

@ -1,7 +1,7 @@
# Cons'Eco # Cons'Eco
[![Build Status](https://codefirst.iut.uca.fr/api/badges/hugo.livet/ConsEco/status.svg)](https://codefirst.iut.uca.fr/hugo.livet/ConsEco) [![Build Status](https://codefirst.iut.uca.fr/api/badges/hugo.livet/ConsEco/status.svg)](https://codefirst.iut.uca.fr/hugo.livet/ConsEco)
[![Csharp](https://img.shields.io/badge/-CSharp-50C878?style=for-the-badge&logo=csharp)](https://learn.microsoft.com/fr-fr/dotnet/csharp/) [![Xaml](https://img.shields.io/badge/-XAML-6495ED?style=for-the-badge&logo=xaml)](https://learn.microsoft.com/fr-fr/dotnet/desktop/wpf/xaml/?view=netdesktop-6.0) [![.NET/MAUI](https://img.shields.io/badge/-.NET/WPF-B87333?style=for-the-badge&logo=dotnet)](https://learn.microsoft.com/fr-fr/dotnet/maui/what-is-maui?view=net-maui-7.0) [![Csharp](https://img.shields.io/badge/-CSharp-50C878?style=for-the-badge&logo=csharp)](https://learn.microsoft.com/fr-fr/dotnet/csharp/) [![Xaml](https://img.shields.io/badge/-XAML-6495ED?style=for-the-badge&logo=xaml)](https://learn.microsoft.com/fr-fr/dotnet/desktop/wpf/xaml/?view=netdesktop-6.0) [![.NET/WPF](https://img.shields.io/badge/-.NET/WPF-B87333?style=for-the-badge&logo=dotnet)](https://learn.microsoft.com/fr-fr/dotnet/desktop/wpf/?view=netdesktop-6.0)
<br /> <br />
<div align="center"> <div align="center">

@ -13,14 +13,34 @@ using System.Threading;
using Model; using Model;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Data.Common; using System.Data.Common;
using System.Reflection.PortableExecutable;
namespace LinqToPgSQL namespace LinqToPgSQL
{ {
public class PersLinqToPgSQL : IPersistanceManager public class PersLinqToPgSQL : IPersistanceManager
{ {
private Hash hash = new Hash(); private Hash hash = new Hash();
string connexionBDD = String.Format("Server=90.114.135.116; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); private static string connexionBDD = String.Format("Server=2.3.8.130; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer");
private static NpgsqlConnection dbAccess = new NpgsqlConnection(connexionBDD);
public bool TestConnexionAsDatabase()
{
bool isOk = true;
try
{
dbAccess.Open();
}
catch(NpgsqlException ex)
{
isOk = false;
Debug.WriteLine("Problème de connection à la base de données. - " + ex.Message);
}
finally
{
dbAccess.Close();
}
return isOk;
}
public string LoadInscrit(string id, string mdp) public string LoadInscrit(string id, string mdp)
{ {
int resultat=0; int resultat=0;
@ -53,7 +73,11 @@ namespace LinqToPgSQL
{ {
var conn = new NpgsqlConnection(connexionBDD); var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection"); Console.Out.WriteLine("Ouverture de la connection");
try
conn.Open();
/*try
{ {
conn.Open(); conn.Open();
} }
@ -62,7 +86,7 @@ namespace LinqToPgSQL
conn.Close(); conn.Close();
Debug.WriteLine("Problème de connection à la base de données. Aprés fermeture, l'application se fermera automatiquement."); Debug.WriteLine("Problème de connection à la base de données. Aprés fermeture, l'application se fermera automatiquement.");
Environment.Exit(-1); Environment.Exit(-1);
} }*/
NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT mail FROM Inscrit", conn).ExecuteReader(); NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT mail FROM Inscrit", conn).ExecuteReader();
@ -335,5 +359,22 @@ namespace LinqToPgSQL
// attente des autres supression // attente des autres supression
} }
public IList<Banque> ImportBanques()
{
IList<Banque> bquesDispo = new List<Banque>();
dbAccess.Open();
NpgsqlCommand cmd = new NpgsqlCommand($"SELECT * FROM Banque", dbAccess);
NpgsqlDataReader dbReader = cmd.ExecuteReader();
while (dbReader.Read())
{
bquesDispo.Add(new Banque(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2)));
}
dbAccess.Close();
return bquesDispo;
}
} }
} }

@ -7,11 +7,6 @@
Shell.FlyoutBehavior="Disabled" Shell.FlyoutBehavior="Disabled"
Shell.NavBarIsVisible="False"> Shell.NavBarIsVisible="False">
<!--<ShellContent
ContentTemplate="{DataTemplate local:Dashboard}"
Route="MainPage" />-->
<TabBar> <TabBar>
<ShellContent Title="Tableau de Bord" <ShellContent Title="Tableau de Bord"
Icon="home_black.png" Icon="home_black.png"
@ -41,4 +36,16 @@
ContentTemplate="{DataTemplate local:ChangePassword}" ContentTemplate="{DataTemplate local:ChangePassword}"
Route="ChangePassword"/> Route="ChangePassword"/>
<ShellContent
ContentTemplate="{DataTemplate local:GestionBanques}"
Route="GestionBanques"/>
<ShellContent
ContentTemplate="{DataTemplate local:AjoutBanques}"
Route="AjoutBanques"/>
<ShellContent
ContentTemplate="{DataTemplate local:ErrorPage}"
Route="ErrorPage"/>
</Shell> </Shell>

@ -14,12 +14,16 @@ namespace IHM
Routing.RegisterRoute("Inscription", typeof(Inscription)); Routing.RegisterRoute("Inscription", typeof(Inscription));
Routing.RegisterRoute("ForgetPassword", typeof(ForgetPassword)); Routing.RegisterRoute("ForgetPassword", typeof(ForgetPassword));
Routing.RegisterRoute("ChangePassword", typeof(ChangePassword)); Routing.RegisterRoute("ChangePassword", typeof(ChangePassword));
Routing.RegisterRoute("GestionBanques", typeof(GestionBanques));
Routing.RegisterRoute("AjoutBanques", typeof(AjoutBanques));
Routing.RegisterRoute("ErrorPage", typeof(ErrorPage));
} }
} }
} }

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="IHM.Composant.BanqueDispo">
<Border StrokeShape="RoundRectangle 20" BackgroundColor="{StaticResource Tertiary}" Padding="20">
<VerticalStackLayout>
<Image Source="{Binding ImageBanque}"/>
<Button Text="CHOISIR" Clicked="Banque_Clicked"/>
</VerticalStackLayout>
</Border>
</ViewCell>

@ -0,0 +1,23 @@
namespace IHM.Composant;
public partial class BanqueDispo : ViewCell
{
public BanqueDispo()
{
InitializeComponent();
}
public static readonly BindableProperty ImageBanqueProperty =
BindableProperty.Create("ImageBanque", typeof(string), typeof(BanqueDispo), "");
public string ImageBanque
{
get { return (string)GetValue(ImageBanqueProperty); }
set { SetValue(ImageBanqueProperty, value); }
}
private void Banque_Clicked(object sender, EventArgs e)
{
}
}

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="IHM.Composant.BanqueVC"
x:Name="root">
<FlexLayout Direction="Row" AlignItems="Center" JustifyContent="SpaceAround">
<Label Text="{Binding NomBanque}" FontAttributes="Bold" FontSize="Body"/>
<Label Text="{Binding DateLastReload}" FontAttributes="Italic" FontSize="Body"/>
<ImageButton Source="reload_banks.png"
Padding="10" Margin="10"
CornerRadius="10" HeightRequest="65"
BackgroundColor="{StaticResource Primary}"
Clicked="MaBanque_Clicked"/>
</FlexLayout>
</ViewCell>

@ -0,0 +1,32 @@
namespace IHM.Composant;
public partial class BanqueVC : ViewCell
{
public BanqueVC()
{
InitializeComponent();
}
public static readonly BindableProperty NomBanqueProperty =
BindableProperty.Create("NomBanque", typeof(string), typeof(BanqueVC), "");
public string NomBanque
{
get { return (string)GetValue(NomBanqueProperty); }
set { SetValue(NomBanqueProperty, value); }
}
public static readonly BindableProperty DateLastReloadProperty =
BindableProperty.Create("DateLastReload", typeof(string), typeof(BanqueVC), "");
public string DateLastReload
{
get { return (string)GetValue(DateLastReloadProperty); }
set { SetValue(DateLastReloadProperty, value); }
}
private void MaBanque_Clicked(object sender, EventArgs e)
{
}
}

@ -35,6 +35,12 @@
<MauiIcon Include="Resources\AppIcon\logo.svg" ForegroundFile="Resources\AppIcon\logo.svg" Color="#512BD4" BaseSize="100,100"> <MauiIcon Include="Resources\AppIcon\logo.svg" ForegroundFile="Resources\AppIcon\logo.svg" Color="#512BD4" BaseSize="100,100">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</MauiIcon> </MauiIcon>
<MauiImage Include="Resources\Images\DashBoard\account_banks.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</MauiImage>
<MauiImage Include="Resources\Images\GestionBanques\reload_banks.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</MauiImage>
<MauiImage Include="Resources\Images\NavBar\dollar_black.png" /> <MauiImage Include="Resources\Images\NavBar\dollar_black.png" />
<MauiImage Include="Resources\Images\NavBar\settings_black.png" /> <MauiImage Include="Resources\Images\NavBar\settings_black.png" />
<Resource Include="Resources\Images\NavBar\home_black.png" /> <Resource Include="Resources\Images\NavBar\home_black.png" />
@ -61,6 +67,7 @@
<ItemGroup> <ItemGroup>
<None Remove="Resources\Images\DashBoard\account_banks.png" /> <None Remove="Resources\Images\DashBoard\account_banks.png" />
<None Remove="Resources\Images\GestionBanques\reload_banks.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -85,6 +92,9 @@
<Compile Update="Desktop\MainPage.xaml.cs"> <Compile Update="Desktop\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon> <DependentUpon>MainPage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Mobile\ErrorPage.xaml.cs">
<DependentUpon>ErrorPage.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -94,9 +104,24 @@
<MauiXaml Update="ChangePassword.xaml"> <MauiXaml Update="ChangePassword.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Composant\BanqueDispo.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Composant\BanqueVC.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="ForgetPassword.xaml"> <MauiXaml Update="ForgetPassword.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Mobile\AjoutBanques.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Mobile\ErrorPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Mobile\GestionBanques.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Operations.xaml"> <MauiXaml Update="Operations.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -0,0 +1,18 @@
<?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:composant="clr-namespace:IHM.Composant"
x:Class="IHM.Mobile.AjoutBanques"
Title="AjoutBanques">
<VerticalStackLayout>
<Label Text="Liste des Banques" FontAttributes="Bold" FontSize="Body" HorizontalOptions="Center"/>
<CollectionView>
<CollectionView.ItemTemplate>
<DataTemplate>
<composant:BanqueDispo ImageBanque="bla.png" />
<!-- il faut le namespace !!!! -->
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,9 @@
namespace IHM.Mobile;
public partial class AjoutBanques : ContentPage
{
public AjoutBanques()
{
InitializeComponent();
}
}

@ -21,10 +21,11 @@
<Label Text="Cons'Eco" FontSize="20" VerticalOptions="Center" FontAttributes="Bold"/> <Label Text="Cons'Eco" FontSize="20" VerticalOptions="Center" FontAttributes="Bold"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<ImageButton Grid.Row="0" Grid.Column="1" Source="Resources/Images/Dashboard/account_banks.png" <ImageButton Grid.Row="0" Grid.Column="1" Source="account_banks.png"
HorizontalOptions="End" Padding="10" Margin="10" HorizontalOptions="End" Padding="10" Margin="10"
CornerRadius="10" HeightRequest="65" CornerRadius="10" HeightRequest="65"
BackgroundColor="{StaticResource Primary}"/> BackgroundColor="{StaticResource Primary}"
Clicked="Banques_Clicked"/>
<Label Grid.Row="1" Grid.ColumnSpan="2" Text="Liste des Dernières Opérations : " FontAttributes="Bold" FontSize="Body" Padding="20,5,0,0"/> <Label Grid.Row="1" Grid.ColumnSpan="2" Text="Liste des Dernières Opérations : " FontAttributes="Bold" FontSize="Body" Padding="20,5,0,0"/>

@ -13,15 +13,25 @@ public partial class DashBoard : ContentPage
if (Mgr.SelectedInscrit == null) if (Mgr.SelectedInscrit == null)
{ {
loadInscription(); loadPage(new MainPage());
} }
if (!Mgr.testConnexionAsDatabase())
{
loadPage(new ErrorPage());
}
} }
public async void loadInscription() public async void loadPage(Page p)
{
await Navigation.PushModalAsync(p);
}
private void Banques_Clicked(object sender, EventArgs e)
{ {
await Navigation.PushModalAsync(new MainPage()); loadPage(new GestionBanques());
} }
} }

@ -0,0 +1,16 @@
<?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"
x:Class="IHM.Mobile.ErrorPage"
Title="Error">
<FlexLayout Direction="Column" JustifyContent="Center" AlignItems="Center">
<Image Source="{AppThemeBinding Light=logo_sans_fond_black.png, Dark=logo_sans_fond.png}"
HorizontalOptions="Center" HeightRequest="200"/>
<ActivityIndicator IsRunning="true" Margin="0,120,0,0" />
<Label Text="Tentative de connexion" Margin="0,20,0,0" FontSize="Body" FontAttributes="Bold"/>
</FlexLayout>
</ContentPage>

@ -0,0 +1,46 @@
using Model;
using System.Diagnostics;
namespace IHM.Mobile;
public partial class ErrorPage : ContentPage
{
public Manager Mgr => (App.Current as App).Manager;
public const int TIME_TEST_DB = 15000;
public ErrorPage()
{
InitializeComponent();
startTestConnexion();
}
protected override bool OnBackButtonPressed()
{
return true;
}
public void conIsActive()
{
while (!Mgr.testConnexionAsDatabase())
{
Thread.Sleep(TIME_TEST_DB);
}
ConnexionValide();
return;
}
public void startTestConnexion()
{
Task testConnexion = new Task(() => conIsActive());
testConnexion.Start();
}
private async void ConnexionValide()
{
await Navigation.PopModalAsync();
}
}

@ -0,0 +1,49 @@
<?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:composant="clr-namespace:IHM.Composant"
x:Class="IHM.Mobile.GestionBanques"
Title="GestionBanques">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.10*"/>
<RowDefinition Height="0.05*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<HorizontalStackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="Center">
<Image Source="Resources/Images/logo_sans_fond.png" HeightRequest="50" Margin="20"/>
<Label Text="Cons'Eco" FontSize="20" VerticalOptions="Center" FontAttributes="Bold"/>
</HorizontalStackLayout>
<ImageButton Grid.Row="0" Grid.Column="1" Source="reload_banks.png"
HorizontalOptions="End" Padding="10" Margin="10"
CornerRadius="10" HeightRequest="65"
BackgroundColor="{StaticResource Primary}"/>
<ImageButton Grid.Row="0" Grid.Column="2" Source="reload_banks.png"
HorizontalOptions="End" Padding="10" Margin="10"
CornerRadius="10" HeightRequest="65"
BackgroundColor="{StaticResource Primary}"/>
<Label Grid.Row="1" Grid.ColumnSpan="3" Text="Liste des Banques disponibles : " FontAttributes="Bold" FontSize="Body" Padding="20,5,0,0"/>
<CollectionView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" ItemsSource="{Binding BanquesDisponibleInApp}">
<CollectionView.ItemTemplate>
<DataTemplate>
<composant:BanqueVC NomBanque="{Binding Nom}" DateLastReload="12/12/2003" /><!-- il faut le namespace !!!! -->
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</ContentPage>

@ -0,0 +1,16 @@
using Model;
namespace IHM.Mobile;
public partial class GestionBanques : ContentPage
{
public Manager Mgr => (App.Current as App).Manager;
public GestionBanques()
{
InitializeComponent();
BindingContext= Mgr;
//Mgr.BanquesDisponibleInApp=Mgr.importBanques();
}
}

@ -12,9 +12,11 @@ namespace IHM.Mobile
BindingContext = this; BindingContext = this;
} }
public void ConnectionOnClicked(object sender, EventArgs e) public void ConnectionOnClicked(object sender, EventArgs e)
{ {
if(EntryMail.Text == null || EntryPassworld.Text == null) if (EntryMail.Text == null || EntryPassworld.Text == null)
{ {
AffichError("Champ invalide", "Veuillez compléter tout les champs", "OK"); AffichError("Champ invalide", "Veuillez compléter tout les champs", "OK");
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

@ -17,5 +17,7 @@ namespace Model
bool ExistEmail(string mail); bool ExistEmail(string mail);
void ChangePasswordBdd(string mail, string newMdp); void ChangePasswordBdd(string mail, string newMdp);
string RecupMdpBdd(string mail); string RecupMdpBdd(string mail);
bool TestConnexionAsDatabase();
public IList<Banque> ImportBanques();
} }
} }

@ -1,4 +1,5 @@
using System.ComponentModel; using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Model namespace Model
{ {
@ -25,6 +26,8 @@ namespace Model
} }
private Banque selectedBanque; private Banque selectedBanque;
public ObservableCollection<Banque> BanquesDisponibleInApp { get; set; } = new ObservableCollection<Banque>();
void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public Manager(IPersistanceManager persistance) public Manager(IPersistanceManager persistance)
@ -76,6 +79,16 @@ namespace Model
{ {
return hash.IsEqualHash(mdpBdd, mdpSent); return hash.IsEqualHash(mdpBdd, mdpSent);
} }
public bool testConnexionAsDatabase()
{
return Pers.TestConnexionAsDatabase();
}
public IList<Banque> importBanques()
{
return Pers.ImportBanques();
}
} }
} }

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Stub public class Stub //la classe n'implémante pas IPersistanceManager
{ {
public List<Banque> Banques = new(); public List<Banque> Banques = new();
public List<Inscrit> Inscrits = new(); public List<Inscrit> Inscrits = new();

Loading…
Cancel
Save