Compare commits
1 Commits
master
...
feature/Ro
Author | SHA1 | Date | |
---|---|---|---|
f9a764e550 |
26
Database.cs
Normal file
26
Database.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using HegreHotel.Models;
|
||||
using SQLite;
|
||||
|
||||
namespace HegreHotel;
|
||||
|
||||
public class Database
|
||||
{
|
||||
private static SQLiteAsyncConnection _database;
|
||||
|
||||
public static async Task<SQLiteAsyncConnection> GetConnection()
|
||||
{
|
||||
if (_database == null)
|
||||
{
|
||||
var databasePath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db");
|
||||
_database = new SQLiteAsyncConnection(databasePath);
|
||||
|
||||
// Créer les tables
|
||||
await _database.CreateTableAsync<Client>();
|
||||
await _database.CreateTableAsync<Chambre>();
|
||||
await _database.CreateTableAsync<Reservation>();
|
||||
await _database.CreateTableAsync<Status>();
|
||||
}
|
||||
|
||||
return _database;
|
||||
}
|
||||
}
|
@ -57,9 +57,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EntityFramework" Version="6.5.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
|
||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
18
Models/Chambre.cs
Normal file
18
Models/Chambre.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace HegreHotel.Models;
|
||||
|
||||
using SQLite;
|
||||
|
||||
public class Chambre
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string? Nom { get; set; }
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public decimal Tarif { get; set; }
|
||||
|
||||
public int NombrePersonnes { get; set; }
|
||||
}
|
21
Models/Client.cs
Normal file
21
Models/Client.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace HegreHotel.Models;
|
||||
|
||||
using SQLite;
|
||||
|
||||
public class Client
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? Nom { get; set; }
|
||||
|
||||
[MaxLength(100)]
|
||||
public string? Prenom { get; set; }
|
||||
|
||||
[MaxLength(150), Unique]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[MaxLength(15), Unique]
|
||||
public string? Telephone { get; set; }
|
||||
}
|
29
Models/Reservation.cs
Normal file
29
Models/Reservation.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace HegreHotel.Models;
|
||||
|
||||
using SQLite;
|
||||
|
||||
public class Reservation
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime DateDebut { get; set; }
|
||||
|
||||
public DateTime DateFin { get; set; }
|
||||
|
||||
public string? Demandes { get; set; }
|
||||
|
||||
// Navigation properties (ignorées dans SQLite)
|
||||
|
||||
[Indexed]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[Indexed]
|
||||
public int ChambreId { get; set; }
|
||||
|
||||
[Ignore]
|
||||
public Client Client { get; set; }
|
||||
|
||||
[Ignore]
|
||||
public Chambre Chambre { get; set; }
|
||||
}
|
12
Models/Status.cs
Normal file
12
Models/Status.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace HegreHotel.Models;
|
||||
|
||||
using SQLite;
|
||||
|
||||
public class Status
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
[MaxLength(50), Unique]
|
||||
public string? Libelle { get; set; }
|
||||
}
|
36
Services/ClientService.cs
Normal file
36
Services/ClientService.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using SQLite;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using HegreHotel;
|
||||
using HegreHotel.Models;
|
||||
|
||||
public class ClientService
|
||||
{
|
||||
// Ajouter un client
|
||||
public static async Task AjouterClient(Client client)
|
||||
{
|
||||
var db = await Database.GetConnection();
|
||||
await db.InsertAsync(client);
|
||||
}
|
||||
|
||||
// Récupérer tous les clients
|
||||
public static async Task<List<Client>> GetClientsAsync()
|
||||
{
|
||||
var db = await Database.GetConnection();
|
||||
return await db.Table<Client>().ToListAsync();
|
||||
}
|
||||
|
||||
// Modifier un client
|
||||
public static async Task ModifierClient(Client client)
|
||||
{
|
||||
var db = await Database.GetConnection();
|
||||
await db.UpdateAsync(client);
|
||||
}
|
||||
|
||||
// Supprimer un client
|
||||
public static async Task SupprimerClient(Client client)
|
||||
{
|
||||
var db = await Database.GetConnection();
|
||||
await db.DeleteAsync(client);
|
||||
}
|
||||
}
|
18
Views/ClientsPage.xaml
Normal file
18
Views/ClientsPage.xaml
Normal file
@ -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"
|
||||
x:Class="HegreHotel.Views.ClientsPage"
|
||||
Title="Clients">
|
||||
|
||||
<StackLayout>
|
||||
<Button Text="Ajouter un Client" Clicked="OnAjouterClientClicked" />
|
||||
<CollectionView x:Name="ClientsList">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Label Text="{Binding Nom}" />
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</StackLayout>
|
||||
</ContentPage>
|
37
Views/ClientsPage.xaml.cs
Normal file
37
Views/ClientsPage.xaml.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HegreHotel.Models;
|
||||
|
||||
namespace HegreHotel.Views;
|
||||
|
||||
public partial class ClientsPage : ContentPage
|
||||
{
|
||||
public ClientsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
ChargerClients();
|
||||
}
|
||||
|
||||
private async void ChargerClients()
|
||||
{
|
||||
var clients = await ClientService.GetClientsAsync();
|
||||
ClientsList.ItemsSource = clients;
|
||||
}
|
||||
|
||||
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||
{
|
||||
var nouveauClient = new Client
|
||||
{
|
||||
Nom = "Dupont",
|
||||
Prenom = "Jean",
|
||||
Email = "jean.dupont@example.com",
|
||||
Telephone = "0123456789"
|
||||
};
|
||||
|
||||
await ClientService.AjouterClient(nouveauClient);
|
||||
ChargerClients();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user