Compare commits
1 Commits
main
...
feature/ya
Author | SHA1 | Date | |
---|---|---|---|
8d8578a059 |
@ -20,6 +20,7 @@ namespace MauiAppStock.Data
|
|||||||
await db.CreateTableAsync<Appareil>();
|
await db.CreateTableAsync<Appareil>();
|
||||||
await db.CreateTableAsync<Piece>();
|
await db.CreateTableAsync<Piece>();
|
||||||
await db.CreateTableAsync<AppareilPiece>(); // Table de liaison
|
await db.CreateTableAsync<AppareilPiece>(); // Table de liaison
|
||||||
|
await db.CreateTableAsync<MouvementStock>(); // Table des mouvements de stock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,5 +140,34 @@ namespace MauiAppStock.Data
|
|||||||
.Where(ap => ap.AppareilId == appareilId && ap.PieceId == pieceId)
|
.Where(ap => ap.AppareilId == appareilId && ap.PieceId == pieceId)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CRUD pour MouvementStock
|
||||||
|
public static Task<int> AddMouvementStockAsync(MouvementStock mouvement)
|
||||||
|
{
|
||||||
|
return db.InsertAsync(mouvement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<List<MouvementStock>> GetMouvementsStockAsync()
|
||||||
|
{
|
||||||
|
return db.Table<MouvementStock>().OrderByDescending(m => m.DateMouvement).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<List<MouvementStock>> GetMouvementsStockForPieceAsync(int pieceId)
|
||||||
|
{
|
||||||
|
return await db.Table<MouvementStock>()
|
||||||
|
.Where(m => m.PieceId == pieceId)
|
||||||
|
.OrderByDescending(m => m.DateMouvement)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<int> UpdateMouvementStockAsync(MouvementStock mouvement)
|
||||||
|
{
|
||||||
|
return db.UpdateAsync(mouvement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<int> DeleteMouvementStockAsync(MouvementStock mouvement)
|
||||||
|
{
|
||||||
|
return db.DeleteAsync(mouvement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,12 @@ namespace MauiAppStock.Models
|
|||||||
public string Nom { get; set; }
|
public string Nom { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
// Vous pouvez ajouter d'autres propriétés (stock, historique, etc.)
|
// Vous pouvez ajouter d'autres propriétés (stock, historique, etc.)
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Nom}";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
32
MauiAppStock/Models/MouvementStock.cs
Normal file
32
MauiAppStock/Models/MouvementStock.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using SQLite;
|
||||||
|
|
||||||
|
namespace MauiAppStock.Models
|
||||||
|
{
|
||||||
|
public class MouvementStock
|
||||||
|
{
|
||||||
|
[PrimaryKey, AutoIncrement]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int PieceId { get; set; }
|
||||||
|
|
||||||
|
public DateTime DateMouvement { get; set; }
|
||||||
|
|
||||||
|
public TypeMouvement Type { get; set; }
|
||||||
|
|
||||||
|
public int Quantite { get; set; } // Number of parts moved
|
||||||
|
|
||||||
|
public string? Commentaire { get; set; }
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
|
public string NomPiece { get; set; }
|
||||||
|
|
||||||
|
[Ignore]
|
||||||
|
public bool HasComment => !string.IsNullOrWhiteSpace(Commentaire);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TypeMouvement
|
||||||
|
{
|
||||||
|
EntreeStock, // Parts entering stock (purchase)
|
||||||
|
SortieReparation // Parts used for repair
|
||||||
|
}
|
||||||
|
}
|
@ -6,13 +6,17 @@ namespace MauiAppStock.Models
|
|||||||
{
|
{
|
||||||
[PrimaryKey, AutoIncrement]
|
[PrimaryKey, AutoIncrement]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Nom { get; set; }
|
public string? Nom { get; set; }
|
||||||
public string Description { get; set; }
|
public string? Description { get; set; }
|
||||||
public double Prix { get; set; }
|
public double Prix { get; set; }
|
||||||
public int Stock { get; set; }
|
public int Stock { get; set; }
|
||||||
public string Fournisseur { get; set; }
|
public string? Fournisseur { get; set; }
|
||||||
|
|
||||||
|
// public int Appareil { get; set; }
|
||||||
|
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public bool EstRecommandee { get; set; }
|
public bool EstRecommandee { get; set; }
|
||||||
|
|
||||||
|
public string DetailView { get { return " ID : " + Id + @" - " + Description; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,9 @@
|
|||||||
<Editor x:Name="DescriptionEditor" Placeholder="Description" HeightRequest="100"/>
|
<Editor x:Name="DescriptionEditor" Placeholder="Description" HeightRequest="100"/>
|
||||||
<Entry x:Name="PrixEntry" Placeholder="Prix" Keyboard="Numeric"/>
|
<Entry x:Name="PrixEntry" Placeholder="Prix" Keyboard="Numeric"/>
|
||||||
<Entry x:Name="StockEntry" Placeholder="Stock" Keyboard="Numeric"/>
|
<Entry x:Name="StockEntry" Placeholder="Stock" Keyboard="Numeric"/>
|
||||||
|
<!-- <Picker x:Name="FournisseurPicker"
|
||||||
|
Title="Choisissez un Fournisseur">
|
||||||
|
</Picker> !-->
|
||||||
<Entry x:Name="FournisseurEntry" Placeholder="Fournisseur"/>
|
<Entry x:Name="FournisseurEntry" Placeholder="Fournisseur"/>
|
||||||
<Button Text="Enregistrer" Clicked="OnSaveClicked"/>
|
<Button Text="Enregistrer" Clicked="OnSaveClicked"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using MauiAppStock.Models;
|
using MauiAppStock.Models;
|
||||||
using MauiAppStock.Data;
|
using MauiAppStock.Data;
|
||||||
|
using Microsoft.Maui.Controls.Internals;
|
||||||
|
|
||||||
namespace MauiAppStock.Views
|
namespace MauiAppStock.Views
|
||||||
{
|
{
|
||||||
@ -8,18 +9,34 @@ namespace MauiAppStock.Views
|
|||||||
public AddPiecePage()
|
public AddPiecePage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
LoadAppareils();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadAppareils()
|
||||||
|
{
|
||||||
|
// FournisseurPicker.ItemsSource = await Database.GetAppareilsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnSaveClicked(object sender, EventArgs e)
|
private async void OnSaveClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (double.TryParse(PrixEntry.Text, out double prix) && int.TryParse(StockEntry.Text, out int stock))
|
if (double.TryParse(PrixEntry.Text, out double prix) && int.TryParse(StockEntry.Text, out int stock))
|
||||||
{
|
{
|
||||||
|
// Appareil appareilPicked = AppareilPicker.SelectedItem as Appareil;
|
||||||
|
|
||||||
|
// if (appareilPicked == null)
|
||||||
|
//{
|
||||||
|
// await DisplayAlert("ERREUR", "L'appareil n'est pas un valide", "OK");
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
var piece = new Piece
|
var piece = new Piece
|
||||||
{
|
{
|
||||||
Nom = NomEntry.Text,
|
Nom = NomEntry.Text,
|
||||||
Description = DescriptionEditor.Text,
|
Description = DescriptionEditor.Text,
|
||||||
Prix = prix,
|
Prix = prix,
|
||||||
Stock = stock,
|
Stock = stock,
|
||||||
|
// Appareil = appareilPicked.Id, Exemple pour fournisseur
|
||||||
Fournisseur = FournisseurEntry.Text
|
Fournisseur = FournisseurEntry.Text
|
||||||
};
|
};
|
||||||
await Database.AddPieceAsync(piece);
|
await Database.AddPieceAsync(piece);
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
<Editor x:Name="DescriptionEditor" Placeholder="Description" HeightRequest="100"/>
|
<Editor x:Name="DescriptionEditor" Placeholder="Description" HeightRequest="100"/>
|
||||||
<Entry x:Name="PrixEntry" Placeholder="Prix" Keyboard="Numeric"/>
|
<Entry x:Name="PrixEntry" Placeholder="Prix" Keyboard="Numeric"/>
|
||||||
<Entry x:Name="StockEntry" Placeholder="Stock" Keyboard="Numeric"/>
|
<Entry x:Name="StockEntry" Placeholder="Stock" Keyboard="Numeric"/>
|
||||||
|
<Picker x:Name="AppareilPicker"
|
||||||
|
Title="Choisissez un appareil">
|
||||||
|
</Picker>
|
||||||
<Entry x:Name="FournisseurEntry" Placeholder="Fournisseur"/>
|
<Entry x:Name="FournisseurEntry" Placeholder="Fournisseur"/>
|
||||||
<Button Text="Enregistrer" Clicked="OnSaveClicked"/>
|
<Button Text="Enregistrer" Clicked="OnSaveClicked"/>
|
||||||
<Button Text="Supprimer" Clicked="OnDeleteClicked" TextColor="Red"/>
|
<Button Text="Supprimer" Clicked="OnDeleteClicked" TextColor="Red"/>
|
||||||
|
@ -6,19 +6,34 @@ namespace MauiAppStock.Views
|
|||||||
public partial class EditPiecePage : ContentPage
|
public partial class EditPiecePage : ContentPage
|
||||||
{
|
{
|
||||||
private Piece _piece;
|
private Piece _piece;
|
||||||
|
|
||||||
public EditPiecePage(Piece piece)
|
public EditPiecePage(Piece piece)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
// LoadAppareils();
|
||||||
_piece = piece;
|
_piece = piece;
|
||||||
NomEntry.Text = piece.Nom;
|
NomEntry.Text = piece.Nom;
|
||||||
DescriptionEditor.Text = piece.Description;
|
DescriptionEditor.Text = piece.Description;
|
||||||
PrixEntry.Text = piece.Prix.ToString();
|
PrixEntry.Text = piece.Prix.ToString();
|
||||||
StockEntry.Text = piece.Stock.ToString();
|
StockEntry.Text = piece.Stock.ToString();
|
||||||
FournisseurEntry.Text = piece.Fournisseur;
|
FournisseurEntry.Text = piece.Fournisseur; // TODO : Prochainement picker pour fournisseur
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private async void LoadAppareils()
|
||||||
|
//{
|
||||||
|
// AppareilPicker.ItemsSource = await Database.GetAppareilsAsync();
|
||||||
|
//}
|
||||||
|
|
||||||
private async void OnSaveClicked(object sender, EventArgs e)
|
private async void OnSaveClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
// Appareil appareilPicked = AppareilPicker.SelectedItem as Appareil;
|
||||||
|
|
||||||
|
//if (appareilPicked == null)
|
||||||
|
//{
|
||||||
|
// await DisplayAlert("ERREUR", "L'appareil n'est pas un valide", "OK");
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
if (double.TryParse(PrixEntry.Text, out double prix) && int.TryParse(StockEntry.Text, out int stock))
|
if (double.TryParse(PrixEntry.Text, out double prix) && int.TryParse(StockEntry.Text, out int stock))
|
||||||
{
|
{
|
||||||
_piece.Nom = NomEntry.Text;
|
_piece.Nom = NomEntry.Text;
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
<Button Text="Gestion des Appareils" Clicked="OnAppareilsClicked" />
|
<Button Text="Gestion des Appareils" Clicked="OnAppareilsClicked" />
|
||||||
<Button Text="Gestion des Pièces" Clicked="OnPiecesClicked" />
|
<Button Text="Gestion des Pièces" Clicked="OnPiecesClicked" />
|
||||||
<Button Text="Associer une Pièce à un Appareil" Clicked="OnAssocierPieceClicked" />
|
<Button Text="Associer une Pièce à un Appareil" Clicked="OnAssocierPieceClicked" />
|
||||||
|
<Button Text="Mouvement de Stock" Clicked="OnMouvementStockClicked" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
@ -25,5 +25,10 @@ namespace MauiAppStock.Views
|
|||||||
// On navigue vers une page qui permet de sélectionner un appareil pour ensuite associer une pièce.
|
// On navigue vers une page qui permet de sélectionner un appareil pour ensuite associer une pièce.
|
||||||
await Navigation.PushAsync(new SelectAppareilForAssociationPage());
|
await Navigation.PushAsync(new SelectAppareilForAssociationPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void OnMouvementStockClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new MouvementStockPage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
60
MauiAppStock/Views/MouvementStockHistoryPage.xaml
Normal file
60
MauiAppStock/Views/MouvementStockHistoryPage.xaml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?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="MauiAppStock.Views.MouvementStockHistoryPage"
|
||||||
|
Title="Historique des Mouvements">
|
||||||
|
<Grid RowDefinitions="Auto,*">
|
||||||
|
<VerticalStackLayout Grid.Row="0" Spacing="10" Padding="20">
|
||||||
|
<Label Text="Historique des Mouvements de Stock"
|
||||||
|
SemanticProperties.HeadingLevel="Level1"
|
||||||
|
FontSize="24"
|
||||||
|
HorizontalOptions="Center" />
|
||||||
|
|
||||||
|
<Picker x:Name="FilterPicker"
|
||||||
|
Title="Filtrer par type"
|
||||||
|
SelectedIndexChanged="OnFilterChanged">
|
||||||
|
<Picker.Items>
|
||||||
|
<x:String>Tous</x:String>
|
||||||
|
<x:String>Entrée Stock</x:String>
|
||||||
|
<x:String>Sortie Réparation</x:String>
|
||||||
|
</Picker.Items>
|
||||||
|
</Picker>
|
||||||
|
</VerticalStackLayout>
|
||||||
|
|
||||||
|
<CollectionView Grid.Row="1"
|
||||||
|
x:Name="MouvementsCollection"
|
||||||
|
SelectionMode="None">
|
||||||
|
<CollectionView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Frame Margin="10" Padding="10">
|
||||||
|
<Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,Auto,Auto">
|
||||||
|
<Label Text="{Binding NomPiece}"
|
||||||
|
FontSize="16"
|
||||||
|
FontAttributes="Bold"
|
||||||
|
Grid.Column="0"
|
||||||
|
Grid.Row="0"/>
|
||||||
|
|
||||||
|
<Label Text="{Binding DateMouvement, StringFormat='{0:dd/MM/yyyy HH:mm}'}"
|
||||||
|
Grid.Column="1"
|
||||||
|
Grid.Row="0"/>
|
||||||
|
|
||||||
|
<Label Text="{Binding Type, StringFormat='Type: {0}'}"
|
||||||
|
Grid.Column="0"
|
||||||
|
Grid.Row="1"/>
|
||||||
|
|
||||||
|
<Label Text="{Binding Quantite, StringFormat='Quantité: {0}'}"
|
||||||
|
Grid.Column="1"
|
||||||
|
Grid.Row="1"/>
|
||||||
|
|
||||||
|
<Label Text="{Binding Commentaire}"
|
||||||
|
Grid.Column="0"
|
||||||
|
Grid.ColumnSpan="2"
|
||||||
|
Grid.Row="2"
|
||||||
|
IsVisible="{Binding HasComment}"/>
|
||||||
|
</Grid>
|
||||||
|
</Frame>
|
||||||
|
</DataTemplate>
|
||||||
|
</CollectionView.ItemTemplate>
|
||||||
|
</CollectionView>
|
||||||
|
</Grid>
|
||||||
|
</ContentPage>
|
60
MauiAppStock/Views/MouvementStockHistoryPage.xaml.cs
Normal file
60
MauiAppStock/Views/MouvementStockHistoryPage.xaml.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using MauiAppStock.Models;
|
||||||
|
using MauiAppStock.Data;
|
||||||
|
|
||||||
|
namespace MauiAppStock.Views;
|
||||||
|
|
||||||
|
public partial class MouvementStockHistoryPage : ContentPage
|
||||||
|
{
|
||||||
|
private List<MouvementStock> allMouvements;
|
||||||
|
private List<Piece> pieces;
|
||||||
|
|
||||||
|
public MouvementStockHistoryPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Load all pieces to get their names
|
||||||
|
pieces = await Database.GetPiecesAsync();
|
||||||
|
|
||||||
|
// Load all movements
|
||||||
|
allMouvements = await Database.GetMouvementsStockAsync();
|
||||||
|
|
||||||
|
// Add piece names to movements
|
||||||
|
foreach (var mouvement in allMouvements)
|
||||||
|
{
|
||||||
|
var piece = pieces.FirstOrDefault(p => p.Id == mouvement.PieceId);
|
||||||
|
if (piece != null)
|
||||||
|
{
|
||||||
|
mouvement.NomPiece = piece.Nom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display all movements initially
|
||||||
|
MouvementsCollection.ItemsSource = allMouvements;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Impossible de charger l'historique: " + ex.Message, "OK");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFilterChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (allMouvements == null) return;
|
||||||
|
|
||||||
|
var selectedIndex = FilterPicker.SelectedIndex;
|
||||||
|
var filteredMouvements = selectedIndex switch
|
||||||
|
{
|
||||||
|
1 => allMouvements.Where(m => m.Type == TypeMouvement.EntreeStock).ToList(),
|
||||||
|
2 => allMouvements.Where(m => m.Type == TypeMouvement.SortieReparation).ToList(),
|
||||||
|
_ => allMouvements
|
||||||
|
};
|
||||||
|
|
||||||
|
MouvementsCollection.ItemsSource = filteredMouvements;
|
||||||
|
}
|
||||||
|
}
|
55
MauiAppStock/Views/MouvementStockPage.xaml
Normal file
55
MauiAppStock/Views/MouvementStockPage.xaml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?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="MauiAppStock.Views.MouvementStockPage"
|
||||||
|
Title="Mouvement de Stock">
|
||||||
|
<ScrollView>
|
||||||
|
<VerticalStackLayout Spacing="10" Padding="20">
|
||||||
|
<Label Text="Mouvement de Stock"
|
||||||
|
SemanticProperties.HeadingLevel="Level1"
|
||||||
|
FontSize="24"
|
||||||
|
HorizontalOptions="Center" />
|
||||||
|
|
||||||
|
<Button Text="Voir l'historique"
|
||||||
|
Clicked="OnViewHistoryClicked"
|
||||||
|
HorizontalOptions="End" />
|
||||||
|
|
||||||
|
<Picker x:Name="TypeMouvementPicker"
|
||||||
|
Title="Type de Mouvement">
|
||||||
|
<Picker.Items>
|
||||||
|
<x:String>Entrée Stock</x:String>
|
||||||
|
<x:String>Sortie Réparation</x:String>
|
||||||
|
</Picker.Items>
|
||||||
|
</Picker>
|
||||||
|
|
||||||
|
<Picker x:Name="PiecePicker"
|
||||||
|
Title="Sélectionner une pièce"
|
||||||
|
ItemDisplayBinding="{Binding Nom}"
|
||||||
|
SelectedIndexChanged="OnPieceSelected"/>
|
||||||
|
|
||||||
|
<Label Text="Quantité:"
|
||||||
|
SemanticProperties.HeadingLevel="Level2"/>
|
||||||
|
<Entry x:Name="QuantiteEntry"
|
||||||
|
Keyboard="Numeric"
|
||||||
|
Placeholder="Entrez la quantité"/>
|
||||||
|
|
||||||
|
<Label Text="Commentaire:"
|
||||||
|
SemanticProperties.HeadingLevel="Level2"/>
|
||||||
|
<Editor x:Name="CommentaireEditor"
|
||||||
|
Placeholder="Ajouter un commentaire"
|
||||||
|
HeightRequest="100"/>
|
||||||
|
|
||||||
|
<Button x:Name="SaveButton"
|
||||||
|
Text="Enregistrer"
|
||||||
|
SemanticProperties.Hint="Enregistre le mouvement de stock"
|
||||||
|
Clicked="OnSaveClicked"
|
||||||
|
HorizontalOptions="Center" />
|
||||||
|
|
||||||
|
<Button x:Name="CancelButton"
|
||||||
|
Text="Annuler"
|
||||||
|
SemanticProperties.Hint="Annule l'opération"
|
||||||
|
Clicked="OnCancelClicked"
|
||||||
|
HorizontalOptions="Center" />
|
||||||
|
</VerticalStackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</ContentPage>
|
101
MauiAppStock/Views/MouvementStockPage.xaml.cs
Normal file
101
MauiAppStock/Views/MouvementStockPage.xaml.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using MauiAppStock.Models;
|
||||||
|
using MauiAppStock.Data;
|
||||||
|
|
||||||
|
namespace MauiAppStock.Views;
|
||||||
|
|
||||||
|
public partial class MouvementStockPage : ContentPage
|
||||||
|
{
|
||||||
|
private List<Piece> pieces;
|
||||||
|
private Piece selectedPiece;
|
||||||
|
|
||||||
|
public MouvementStockPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pieces = await Database.GetPiecesAsync();
|
||||||
|
PiecePicker.ItemsSource = pieces;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Impossible de charger les données: " + ex.Message, "OK");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPieceSelected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (PiecePicker.SelectedItem != null)
|
||||||
|
{
|
||||||
|
selectedPiece = (Piece)PiecePicker.SelectedItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnViewHistoryClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new MouvementStockHistoryPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnSaveClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (selectedPiece == null)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Veuillez sélectionner une pièce", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!int.TryParse(QuantiteEntry.Text, out int quantite) || quantite <= 0)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Veuillez entrer une quantité valide", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Create new stock movement
|
||||||
|
var mouvement = new MouvementStock
|
||||||
|
{
|
||||||
|
PieceId = selectedPiece.Id,
|
||||||
|
DateMouvement = DateTime.Now,
|
||||||
|
Type = TypeMouvementPicker.SelectedIndex == 0 ? TypeMouvement.EntreeStock : TypeMouvement.SortieReparation,
|
||||||
|
Quantite = quantite,
|
||||||
|
Commentaire = CommentaireEditor.Text
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update piece stock
|
||||||
|
if (TypeMouvementPicker.SelectedIndex == 0)
|
||||||
|
{
|
||||||
|
selectedPiece.Stock += quantite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (selectedPiece.Stock < quantite)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Stock insuffisant", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedPiece.Stock -= quantite;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save changes using Database class
|
||||||
|
await Database.AddMouvementStockAsync(mouvement);
|
||||||
|
await Database.UpdatePieceAsync(selectedPiece);
|
||||||
|
|
||||||
|
await DisplayAlert("Succès", "Mouvement de stock enregistré", "OK");
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Impossible d'enregistrer le mouvement: " + ex.Message, "OK");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnCancelClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<ContentPage x:Class="MauiAppStock.Views.PiecesPage"
|
<ContentPage x:Class="MauiAppStock.Views.PiecesPage"
|
||||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
@ -7,17 +8,17 @@
|
|||||||
<vm:PiecesViewModel />
|
<vm:PiecesViewModel />
|
||||||
</ContentPage.BindingContext>
|
</ContentPage.BindingContext>
|
||||||
<ContentPage.ToolbarItems>
|
<ContentPage.ToolbarItems>
|
||||||
<ToolbarItem Text="+" Clicked="OnAddPieceClicked"/>
|
<ToolbarItem Text="+" Clicked="OnAddPieceClicked" />
|
||||||
</ContentPage.ToolbarItems>
|
</ContentPage.ToolbarItems>
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<Label Text="Liste des Pièces" FontSize="24" HorizontalOptions="Center"/>
|
<Label Text="Liste des Pièces" FontSize="24" HorizontalOptions="Center" />
|
||||||
<ListView x:Name="PiecesListView" ItemsSource="{Binding Pieces}"
|
<ListView x:Name="PiecesListView" ItemsSource="{Binding Pieces}"
|
||||||
IsPullToRefreshEnabled="True"
|
IsPullToRefreshEnabled="True"
|
||||||
RefreshCommand="{Binding LoadPiecesCommand}"
|
RefreshCommand="{Binding LoadPiecesCommand}"
|
||||||
ItemTapped="OnPieceTapped">
|
ItemTapped="OnPieceTapped">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextCell Text="{Binding Nom}" Detail="{Binding Description}"/>
|
<TextCell Text="{Binding Nom}" Detail="{Binding DetailView}" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
</ListView>
|
</ListView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user