Skip to content

Commit

Permalink
Correciones y mejoras finales del sistema
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorel254 committed Jan 13, 2021
1 parent 09abc23 commit 0cffcc6
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 160 deletions.
63 changes: 17 additions & 46 deletions Producto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Kit.Enums;
using SQLHelper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -44,6 +45,15 @@ public Producto(int Id, string Codigo, string Nombre, string Descripcion, string
this.Precio = Precio;
}

public static List<string> ListarProvedores()
{
return Conexion.Sqlite.Lista<string>("SELECT DISTINCT PROVEDOR FROM PRODUCTOS WHERE OCULTO=0");
}
public static List<string> ListarCategorias()
{
return Conexion.Sqlite.Lista<string>("SELECT DISTINCT CLASIFICACION FROM PRODUCTOS WHERE OCULTO=0");
}

/// <summary>
/// Se lee en la base de datos la información de un producto
/// </summary>
Expand Down Expand Up @@ -128,60 +138,21 @@ public bool Validar()

public static List<Producto> Listar()
{
List<Producto> productos = new List<Producto>();
Producto producto = null;
using (IReader leector = Conexion.Sqlite.Leector("SELECT *FROM PRODUCTOS WHERE OCULTO=0 ORDER BY NOMBRE"))
{
if (leector.Read())
{
int Id = Convert.ToInt32(leector["ID"]);
string codigo = Convert.ToString(leector["CODIGO"]);
string nombre = Convert.ToString(leector["NOMBRE"]);
string descripcion = Convert.ToString(leector["DESCRIPCION"]);
string clasificacion = Convert.ToString(leector["CLASIFICACION"]);
string unidad = Convert.ToString(leector["UNIDAD"]);
ImageSource imagen = ((byte[])leector["IMAGEN"]).ByteToImage();
string proveedor = Convert.ToString(leector["PROVEDOR"]);
float existencia = Convert.ToSingle(leector["EXISTENCIA"]);
float minimo = Convert.ToSingle(leector["MINIMO"]);
float maximo = Convert.ToSingle(leector["MAXIMO"]);
float precio = Convert.ToSingle(leector["PRECIO"]);
producto = new Producto(Id, codigo, nombre, descripcion, clasificacion, unidad, imagen, proveedor, existencia, minimo, maximo, precio);
productos.Add(producto);
}
}
return productos;
return Conexion.Sqlite.Lista<string>("SELECT CODIGO FROM PRODUCTOS WHERE OCULTO=0 ORDER BY NOMBRE")
.Select(x => Obtener(x)).ToList();
}

public static List<Producto> Buscar(string Categoria, string Busqueda)
{
List<Producto> productos = new List<Producto>();
if (SQLH.IsInjection(Categoria,Busqueda))
if (SQLH.IsInjection(Categoria, Busqueda))
{
return productos;
}
Producto producto = null;
using (IReader leector = Conexion.Sqlite.Leector("SELECT *FROM PRODUCTOS WHERE (CLASIFICACION = '" + Categoria + "' OR '" + Categoria + "'='') AND OCULTO=0 AND NOMBRE LIKE '%" + Busqueda + "%' ORDER BY NOMBRE"))
{
while (leector.Read())
{
int Id = Convert.ToInt32(leector["ID"]);
string codigo = Convert.ToString(leector["CODIGO"]);
string nombre = Convert.ToString(leector["NOMBRE"]);
string descripcion = Convert.ToString(leector["DESCRIPCION"]);
string clasificacion = Convert.ToString(leector["CLASIFICACION"]);
string unidad = Convert.ToString(leector["UNIDAD"]);
ImageSource imagen = ((byte[])leector["IMAGEN"]).ByteToImage();
string proveedor = Convert.ToString(leector["PROVEDOR"]);
float existencia = Convert.ToSingle(leector["EXISTENCIA"]);
float minimo = Convert.ToSingle(leector["MINIMO"]);
float maximo = Convert.ToSingle(leector["MAXIMO"]);
float precio = Convert.ToSingle(leector["PRECIO"]);
producto = new Producto(Id, codigo, nombre, descripcion, clasificacion, unidad, imagen, proveedor, existencia, minimo, maximo, precio);
productos.Add(producto);
}
}
return productos;

return Conexion.Sqlite.Lista<string
>("SELECT CODIGO FROM PRODUCTOS WHERE (CLASIFICACION = '" + Categoria + "' OR '" + Categoria + "'='') AND OCULTO=0 AND NOMBRE LIKE '%" + Busqueda + "%' ORDER BY NOMBRE")
.Select(x => Obtener(x)).ToList();
}

public static float ObtenerExistencia(string CodigoProducto)
Expand Down
24 changes: 7 additions & 17 deletions Reporte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ private static Rango Fechas()
}
public static void Existencia()
{
Rango rango = Fechas();
if (rango.Cancelado) { return; }
DataTable consulta = Conexion.Sqlite.DataTable(
$@"SELECT
PRODUCTOS.CODIGO,
PRODUCTOS.NOMBRE,
PRODUCTOS.CLASIFICACION,
printf('%.2f',PRODUCTOS.EXISTENCIA) AS EXISTENCIA,
strftime('%d/%m/%Y',MOVIMIENTOS.FECHA) as 'FECHA'
FROM PRODUCTOS
JOIN MOVIMIENTOS ON PRODUCTOS.ID = MOVIMIENTOS.ID_PRODUCTO {(rango.TodasLasFechas ? "" :
@"WHERE JulianDay(MOVIMIENTOS.FECHA) >=JulianDay('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Inicio) +
"') AND JulianDay(MOVIMIENTOS.FECHA) <=JulianDay('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Fin) + "')")}", "CONSULTA");
IFNULL(strftime('%d/%m/%Y',(SELECT MAX(JULIANDAY(M.FECHA)) FROM MOVIMIENTOS M WHERE PRODUCTOS.ID = M.ID_PRODUCTO )),'S/M') as 'FECHA'
FROM PRODUCTOS WHERE PRODUCTOS.OCULTO=0", "CONSULTA");
if (consulta.Rows.Count <= 0)
{
SinMovimientos();
Expand All @@ -62,10 +55,7 @@ FROM PRODUCTOS
// , new Variable("FECHA_FINAL", rango.Fin));

////función para abrir el diseñador del reporte - COMPAÑEROS
reporteador.MostrarReporte("ReporteExistencia.mrt"
, new Variable(consulta)
, new Variable("FECHA_INICIAL", rango.Inicio)
, new Variable("FECHA_FINAL", rango.Fin));
reporteador.MostrarReporte("ReporteExistencia.mrt", new Variable(consulta));
}
public static void Movimiento(DataTable movimientos, string Observaciones, string Concepto)
{
Expand Down Expand Up @@ -93,9 +83,9 @@ public static void Movimientos()
printf('%.2f',MOVIMIENTOS.EXISTENCIA_ACTUAL) AS EXISTENCIA_ACTUAL,
printf('%.2f',MOVIMIENTOS.EXISTENCIA_POSTERIOR) AS EXISTENCIA_POSTERIOR
FROM PRODUCTOS
JOIN MOVIMIENTOS ON PRODUCTOS.ID = MOVIMIENTOS.ID_PRODUCTO
JOIN MOVIMIENTOS ON PRODUCTOS.ID = MOVIMIENTOS.ID_PRODUCTO WHERE PRODUCTOS.OCULTO=0
{(rango.TodasLasFechas ?
"" : @" WHERE JulianDay(MOVIMIENTOS.FECHA) >= JulianDay('" +
"" : @" AND JulianDay(MOVIMIENTOS.FECHA) >= JulianDay('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Inicio) +
"') AND JulianDay(MOVIMIENTOS.FECHA) <=JulianDay('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Fin) + "')")}", "CONSULTA");
Expand All @@ -113,7 +103,7 @@ FROM PRODUCTOS

private static void SinMovimientos()
{
Kit.Services.CustomMessageBox.Current.Show("No se encontrarón movimiento en el rango de fechas seleccionado", "Alerta", CustomMessageBoxButton.OK, CustomMessageBoxImage.Warning);
Kit.Services.CustomMessageBox.Current.Show("No se encontrarón movimientos en el rango de fechas seleccionado", "Alerta", CustomMessageBoxButton.OK, CustomMessageBoxImage.Warning);
}

public static void EntradasSalidas(Tipo Tipo)
Expand All @@ -133,7 +123,7 @@ public static void EntradasSalidas(Tipo Tipo)
USUARIOS.NOMBRE AS USUARIO
FROM PRODUCTOS
JOIN MOVIMIENTOS ON PRODUCTOS.ID = MOVIMIENTOS.ID_PRODUCTO
JOIN USUARIOS ON USUARIOS.ID=MOVIMIENTOS.ID_USUARIO {(rango.TodasLasFechas ? "" : @"WHERE TIPO='{(Tipo == Tipo.Entrada ? 'E' : 'S')}' AND JULIANDAY(MOVIMIENTOS.FECHA) >=JULIANDAY('" +
JOIN USUARIOS ON USUARIOS.ID=MOVIMIENTOS.ID_USUARIO WHERE PRODUCTOS.OCULTO=0 {(rango.TodasLasFechas ? "" : @" AND TIPO='{(Tipo == Tipo.Entrada ? 'E' : 'S')}' AND JULIANDAY(MOVIMIENTOS.FECHA) >=JULIANDAY('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Inicio) +
"') AND JULIANDAY(MOVIMIENTOS.FECHA) <=JULIANDAY('" +
SQLHelper.SQLHelper.FormatTime((DateTime)rango.Fin) + "')")}", "CONSULTA");
Expand Down
17 changes: 17 additions & 0 deletions Usuario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ public Usuario(int Id, string NickName, string Nombre, string Password, bool PEn
this.Imagen = Imagen;
this.PUsuarios = EDUSUARIO;
}
public static Usuario ObtenerPorNombreNick(string NickName)
{
Usuario usu = Obtener(NickName);
if (usu is null)
{
if (SQLH.IsInjection(NickName))
{
return null;
}
string nick = Conexion.Sqlite.Single<string>($"SELECT NICKNAME FROM USUARIOS WHERE NOMBRE='{NickName}'");
if (!string.IsNullOrEmpty(nick))
{
return Obtener(nick);
}
}
return usu;
}
public static Usuario Obtener(string NickName)
{
Usuario usuario = null;
Expand Down
6 changes: 3 additions & 3 deletions ViewModels/InventarioFisico/Invis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public string Categoria
public ObservableCollection<ProductoInvis> Productos { get; set; }
public Invis()
{
this.Categorias = Conexion.Sqlite.Lista<string>("SELECT CLASIFICACION FROM PRODUCTOS WHERE OCULTO=0"); ;
this.Categorias = Producto.ListarCategorias();
this.Productos = new ObservableCollection<ProductoInvis>();
}

Expand All @@ -52,9 +52,9 @@ private async void CambioCategoria(string nueva)
private void CargarCategoria()
{
this.Productos.Clear();
using (IReader leector = Conexion.Sqlite.Leector("SELECT * FROM PRODUCTOS WHERE OCULTO=0"))
using (IReader leector = Conexion.Sqlite.Leector($"SELECT * FROM PRODUCTOS WHERE OCULTO=0 AND CLASIFICACION='{Categoria}'"))
{
if (leector.Read())
while (leector.Read())
{
int Id = Convert.ToInt32(leector["ID"]);
string codigo = Convert.ToString(leector["CODIGO"]);
Expand Down
4 changes: 4 additions & 0 deletions Views/Alertas.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public partial class Alertas
public Alertas()
{
InitializeComponent();
RecargarAlertas();
}
public void RecargarAlertas()
{
if (Kit.WPF.Tools.IsInited)
ResAlertas.ItemsSource = Alerta.ListarProductosConAlerta();
}
Expand Down
2 changes: 1 addition & 1 deletion Views/AltaProductos.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<TextBlock Margin="5" Grid.Row="0" Grid.Column="0" TextWrapping="Wrap" FontSize="18" FontWeight="Bold" Text="Existencia inicial:"/>
<TextBlock Margin="5" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap" FontSize="18" FontWeight="Bold" Text="Mínimo*:"/>
<TextBlock Margin="5" Grid.Row="0" Grid.Column="2" TextWrapping="Wrap" FontSize="18" FontWeight="Bold" Text="Máximo*:"/>
<TextBox VerticalContentAlignment="Center" IsEnabled="False" BorderBrush="Black" Margin="5" Grid.Row="1" Grid.Column="0" Text="{Binding Existencia}" TextWrapping="Wrap" FontSize="18" x:Name="TxtExistencia"/>
<TextBox VerticalContentAlignment="Center" IsEnabled="True" BorderBrush="Black" Margin="5" Grid.Row="1" Grid.Column="0" Text="{Binding Existencia}" TextWrapping="Wrap" FontSize="18" x:Name="TxtExistencia"/>

<TextBox Margin="5" Grid.Row="1" Grid.Column="1" Text="{Binding Minimo}" TextWrapping="Wrap" FontSize="18"/>
<TextBox Margin="5" Grid.Row="1" Grid.Column="2" Text="{Binding Maximo}" TextWrapping="Wrap" FontSize="18"/>
Expand Down
14 changes: 7 additions & 7 deletions Views/AltaProductos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public AltaProductos()
private void CargarCombos()
{
CmbxCodigo.ItemsSource = Conexion.Sqlite.Lista<string>("SELECT CODIGO FROM PRODUCTOS WHERE OCULTO=0");
CmbxProveedor.ItemsSource = Conexion.Sqlite.Lista<string>("SELECT PROVEDOR FROM PRODUCTOS WHERE OCULTO=0");
CmbxCategoria.ItemsSource = Conexion.Sqlite.Lista<string>("SELECT CLASIFICACION FROM PRODUCTOS WHERE OCULTO=0");
CmbxProveedor.ItemsSource = Producto.ListarProvedores();
CmbxCategoria.ItemsSource = Producto.ListarCategorias();
}

private void Imagen_Click(object sender, RoutedEventArgs e)
Expand All @@ -46,14 +46,14 @@ private void Imagen_Click(object sender, RoutedEventArgs e)
if (abrir.ShowDialog() ?? false)
{
byte[] imagen = File.ReadAllBytes(abrir.FileName);
Producto.Imagen =imagen.BytesToBitmap();
Producto.Imagen = imagen.BytesToBitmap();
}

}

private void Guardar_Click(object sender, RoutedEventArgs e)
{
if(!Producto.Validar())
if (!Producto.Validar())
{
return;
}
Expand All @@ -79,13 +79,13 @@ private void CmbxCodigo_SelectionChanged(object sender, SelectionChangedEventArg
Producto = new Producto();
return;
}
TxtExistencia.IsEnabled =false;
TxtExistencia.IsEnabled = false;
Producto = Inventario.Producto.Obtener(seleccion);
}

private void Button_Click(object sender, RoutedEventArgs e)
private async void Button_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("¿Esta seguro que desea eliminar el producto '" + Producto.Nombre + "'?", "Atención", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
if (await Kit.Services.CustomMessageBox.Current.ShowYesNo("¿Esta seguro que desea eliminar el producto '" + Producto.Nombre + "'?", "Atención", "Si,eliminar", "Cancelar", Kit.Enums.CustomMessageBoxImage.Question) == Kit.Enums.CustomMessageBoxResult.Yes)
{
Producto.Baja();
Producto = new Producto();
Expand Down
13 changes: 9 additions & 4 deletions Views/BarraSuperior.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public partial class BarraSuperior : UserControl
public BarraSuperior()
{
InitializeComponent();
if (!Kit.Tools.Instance.IsInDesingMode)
{
Advertencias.Content = Alerta.ObtenerAlerta();
}
RecargarAlertas();
}

private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
Expand All @@ -49,5 +46,13 @@ private async void Back_Click(object sender, RoutedEventArgs e)
}
App.MainWindow.Navigate(new PantallaPrincipal());
}

public void RecargarAlertas()
{
if (!Kit.Tools.Instance.IsInDesingMode)
{
Advertencias.Content = Alerta.ObtenerAlerta();
}
}
}
}
5 changes: 2 additions & 3 deletions Views/Buscador.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Buscador()
{
this.Owner = App.MainWindow;
InitializeComponent();
List<string> categorias = Conexion.Sqlite.Lista<string>("SELECT CLASIFICACION FROM PRODUCTOS WHERE OCULTO = 0");
List<string> categorias = Producto.ListarCategorias();
categorias.Insert(0, string.Empty);
CmbxCategoria.ItemsSource = categorias;

Expand All @@ -36,8 +36,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
{
string Categoria = CmbxCategoria.Text;
string Busqueda = TxtBusqueda.Text;
List<Producto> productos = Producto.Buscar(Categoria, Busqueda);
ResBusqueda.ItemsSource = productos;
ResBusqueda.ItemsSource = Producto.Buscar(Categoria, Busqueda);
}

private void ResBusqueda_MouseDoubleClick(object sender, MouseButtonEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Views/EntradasSalidas.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<TextBlock Margin="5,0" DockPanel.Dock="Top" Text="Unidad" Grid.Column="3"/>
<TextBlock Grid.Column="3" Grid.Row="1" DataContext="{Binding ModeloEntradaSalida,ElementName=Me}" VerticalAlignment="Center" Text="{Binding Seleccion.Unidad}"/>

<Button Grid.Row="1" Background="{StaticResource ColorConfirmar}" Content="Agregar" VerticalAlignment="Center" BorderBrush="Black" Focusable="False" Cursor="Hand"
<Button Grid.Row="1" Background="{StaticResource ColorConfirmar}" Content="Seleccionar" VerticalAlignment="Center" BorderBrush="Black" Focusable="False" Cursor="Hand"
Margin="5,0" Click="Agregar" BorderThickness="1" Grid.Column="4" HorizontalAlignment="Stretch"/>
</Grid>
</Border>
Expand Down
2 changes: 1 addition & 1 deletion Views/LogIn.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
return;
}

Usuario usu = Usuario.Obtener(usuario);
Usuario usu = Usuario.ObtenerPorNombreNick(usuario);

if (usu is null)
{
Expand Down
6 changes: 6 additions & 0 deletions Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public void MostrarBarras(bool BarraSuperior, bool BarraInferior = true)
this.BarraInferior.Visibility = BarraInferior ? Visibility.Visible : Visibility.Collapsed;
this.BarraSuperior.Visibility = BarraSuperior ? Visibility.Visible : Visibility.Collapsed;
}

internal void RecargarAlertas()
{
this.BarraSuperior.RecargarAlertas();
}

private void Minimizar_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
Expand Down
4 changes: 2 additions & 2 deletions Views/PantallaPrincipal.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d" Background="{StaticResource MainBackground}"
xmlns:app="clr-namespace:Inventario"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800" >
<ui:NavigationView IsBackButtonVisible="Collapsed" IsSettingsVisible="False">


Expand Down Expand Up @@ -91,7 +91,7 @@
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<local:Alertas HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<local:Alertas x:Name="TablaAlertas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<local:GraficaPrincipal Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
</ui:NavigationView>
Expand Down
Loading

0 comments on commit 0cffcc6

Please sign in to comment.