Skip to content

Commit

Permalink
Added a search bar for products page
Browse files Browse the repository at this point in the history
  • Loading branch information
lextrack committed Oct 29, 2023
1 parent da0378f commit 6db9bc1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions InventarioDB/InventarioDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.0.1</AssemblyVersion>
<FileVersion>1.0.1</FileVersion>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<Copyright>Lextrack</Copyright>
<ApplicationIcon>icono.ico</ApplicationIcon>
<Authors>Lextrack</Authors>
Expand Down
6 changes: 2 additions & 4 deletions InventarioDB/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<Grid Background="#FF282727">
<Frame x:Name="frame" NavigationUIVisibility="Hidden" />
<ComboBox x:Name="comboBoxPaginas" SelectionChanged="ComboBoxPaginas_SelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" SelectedIndex="0">
<ComboBox x:Name="comboBoxPaginas" SelectionChanged="ComboBoxPaginas_SelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,16,0,0" SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
Expand All @@ -25,12 +25,10 @@
</ComboBox.ItemTemplate>
</ComboBox>

<Button Width="30" Height="30" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,10" BorderThickness="0,0,0,0" Click="Button_Click">
<Button Width="30" Height="30" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,18" BorderThickness="0,0,0,0" Click="Button_Click">
<Button.Background>
<ImageBrush ImageSource="/Resources/info.png" Stretch="Uniform"/>
</Button.Background>
</Button>

</Grid>

</Window>
5 changes: 5 additions & 0 deletions InventarioDB/UI/Pages/Productos.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<!-- Definición de columna para el contenido principal (DataGrid y título) -->
</Grid.ColumnDefinitions>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,21,55,0">
<TextBox x:Name="SearchBox" Width="140" ToolTip="Introducce el nombre del producto a buscar" BorderBrush="ForestGreen"/>
<Button Content="Buscar" Click="SearchButton_Click" Width="45"/>
</StackPanel>

<TextBlock Text="Stock de productos" Foreground="ForestGreen" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0" Margin="0,10,0,0"/>

<DataGrid x:Name="DataGridView" AutoGenerateColumns="False" IsReadOnly="True" VerticalAlignment="Stretch" Grid.Row="1" Margin="0,30,0,35">
Expand Down
8 changes: 7 additions & 1 deletion InventarioDB/UI/Pages/Productos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ public Productos()
}

// Mostrar el contenido de la db en el DataGrid con paginación
private void ShowProducts()
private void ShowProducts(string searchQuery = "")
{
// Establece una conexión a la base de datos utilizando el contexto de la base de datos InventarioDbContext.
using var db = new InventarioDbContext();

// Realiza una consulta a través de Entity Framework Core para recuperar datos de la tabla "Productos".
var productoData = db.Productos
.Where(p => p.Nombre.Contains(searchQuery)) // Se indica que la busqueda se hará por el nombre del producto
.OrderByDescending(p => p.Fecha) // Ordena los resultados por el campo "Fecha", aunque se puede usar el ID también.
.Skip((pageNumber - 1) * pageSize) // Salta registros para llegar a la página deseada.
.Take(pageSize) // Toma una cantidad específica de registros (tamaño de página).
Expand Down Expand Up @@ -55,6 +56,11 @@ private void ShowProducts()
PageInfoTextBlock.Text = $"Página {pageNumber} de {totalPages}";
}

private void SearchButton_Click(object sender, RoutedEventArgs e)
{
ShowProducts(SearchBox.Text);
}

private void PreviousPage_Click(object sender, RoutedEventArgs e)
{
if (pageNumber > 1)
Expand Down
4 changes: 2 additions & 2 deletions InventarioDB/UI/Windows/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<Label Content="InventarioDB" Foreground="#FFA104E4" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,20,0,0" FontSize="25"/>

<Image Source="/Resources/icon.ico" Width="60" Height="60" Margin="32,0,0,25" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1"/>
<Label Content="InventarioDB v1.0.1" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="1" />
<Label Content="Copyright © Lextrack 2023" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" />
<Label Content="InventarioDB v1.0.2" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="1" />
<Label Content="Copyright © Lextrack 2024" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" />

<TextBlock Text="Gracias a Flaticon por los iconos presentes en esta app." TextWrapping="Wrap" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2" Width="271" />

Expand Down
4 changes: 2 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Copyright (c) 2023 Lextrack (Ariel Alejandro)
Copyright (c) 2024 Lextrack (Ariel Alejandro)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

For software named "InventarioDB" version 1.0.1:
For software named "InventarioDB" version 1.0.2:

InventarioDB is licensed under the MIT License. You may not use this software except in compliance with the MIT License.

Expand Down

0 comments on commit 6db9bc1

Please sign in to comment.