Menu v1
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
# Carpeta de salida de compilación
|
||||
/bin/
|
||||
/obj/
|
||||
|
||||
# Archivos temporales
|
||||
*.user
|
||||
*.userosscache
|
||||
*.suo
|
||||
*.cache
|
||||
*.vscode
|
||||
*.vs
|
||||
|
||||
# Carpeta de paquetes NuGet
|
||||
packages/
|
||||
|
||||
# Carpeta de dependencias de proyectos .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# Carpeta de configuración de Visual Studio
|
||||
.vs2019/
|
||||
.vscode/
|
||||
|
||||
# Carpeta de salida de publicación
|
||||
publish/
|
||||
|
||||
# Archivos de registro y crash dumps
|
||||
*.log
|
||||
*.swp
|
||||
*.swo
|
||||
*.mdmp
|
||||
|
||||
# Archivos de configuración
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Carpeta de caché de Rider
|
||||
.idea/
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
+44
-1
@@ -1 +1,44 @@
|
||||
.vs/
|
||||
# Carpeta de salida de compilación
|
||||
/bin/
|
||||
/obj/
|
||||
|
||||
# Archivos temporales
|
||||
*.user
|
||||
*.userosscache
|
||||
*.suo
|
||||
*.cache
|
||||
*.vscode
|
||||
*.vs
|
||||
|
||||
# Carpeta de paquetes NuGet
|
||||
packages/
|
||||
|
||||
# Carpeta de dependencias de proyectos .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# Carpeta de configuración de Visual Studio
|
||||
.vs2019/
|
||||
.vscode/
|
||||
|
||||
# Carpeta de salida de publicación
|
||||
publish/
|
||||
|
||||
# Archivos de registro y crash dumps
|
||||
*.log
|
||||
*.swp
|
||||
*.swo
|
||||
*.mdmp
|
||||
|
||||
# Archivos de configuración
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Carpeta de caché de Rider
|
||||
.idea/
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
Binary file not shown.
Binary file not shown.
+101
-30
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
|
||||
namespace compabetov2.database
|
||||
{
|
||||
@@ -16,38 +17,46 @@ namespace compabetov2.database
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
SQLiteConnection conexion = db_conexion.get_connection();
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT usuario, contra FROM Login WHERE usuario = @param0";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
command.Parameters.AddWithValue($"@param{0}", usuario);
|
||||
SQLiteDataReader reader = command.ExecuteReader();
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection()) {
|
||||
conexion.Open();
|
||||
|
||||
if (reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
string sql = "SELECT usuario, contra FROM Login WHERE usuario = @param0";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
command.Parameters.AddWithValue($"@param{0}", usuario);
|
||||
SQLiteDataReader reader = command.ExecuteReader();
|
||||
|
||||
if (reader.HasRows)
|
||||
{
|
||||
if (reader["contra"].Equals(contra))
|
||||
while (reader.Read())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
return false;
|
||||
if (reader["contra"].Equals(contra))
|
||||
{
|
||||
conexion.Close();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
conexion.Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
conexion.Close();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
conexion.Close();
|
||||
return false;
|
||||
}
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Usuario o contraseña incorrectos");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
if (ex.Message.Contains("no such table"))
|
||||
@@ -65,6 +74,61 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static SQLiteDataReader conseguirProductosDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM Producto INNER JOIN Categoria ON Producto.fk_idcategoria = Categoria.idcategoria";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex) {
|
||||
MessageBox.Show(ex.Message);
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarProductoDAO(Producto producto)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Producto (nombre, descripcion, precio, stock, idcategoria) "+
|
||||
"VALUES (@nombre, @descripcion, @precio, @stock, @idcategoria)";
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@nombre", producto.nombre);
|
||||
command.Parameters.AddWithValue("@descripcion", producto.descripcion);
|
||||
command.Parameters.AddWithValue("@precio", producto.precion);
|
||||
command.Parameters.AddWithValue("@stock", producto.stock);
|
||||
command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if(filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void crearDB()
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
@@ -74,15 +138,22 @@ namespace compabetov2.database
|
||||
conexion.Open();
|
||||
string[] consultas = new string[]
|
||||
{
|
||||
"DROP TABLE IF EXISTS Empleado",
|
||||
"DROP TABLE IF EXISTS Login",
|
||||
"DROP TABLE IF EXISTS Empleado",
|
||||
"DROP TABLE IF EXISTS Producto",
|
||||
"DROP TABLE IF EXISTS Categoria",
|
||||
|
||||
"CREATE TABLE Empleado (idempleado INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, "+
|
||||
"apellido TEXT, calle TEXT, fecha_contratacion TEXT, colonia TEXT, cp TEXT, no_ext TEXT" +
|
||||
"no_int TEXT, referencia TEXT, fecha_nac TEXT, telefono TEXT, activo INTEGER)",
|
||||
"CREATE TABLE Empleado (idempleado INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, "+
|
||||
"apellido TEXT NOT NULL, calle TEXT NOT NULL, fecha_contratacion TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL" +
|
||||
"no_int TEXT NOT NULL, referencia TEXT NOT NULL, fecha_nac TEXT NOT NULL, telefono TEXT NOT NULL, activo INTEGER NOT NULL)",
|
||||
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT, usuario TEXT, "+
|
||||
"contra TEXT, fk_idempleado INTEGER, FOREIGN KEY (fk_idempleado) REFERENCES Empleado (idempleado))",
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||
"contra TEXT NOT NULL, fk_idempleado INTEGER NOT NULL, FOREIGN KEY (fk_idempleado) REFERENCES Empleado (idempleado))",
|
||||
|
||||
"CREATE TABLE Categoria (idcategoria INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, descripcion TEXT NOT NULL)",
|
||||
|
||||
"CREATE TABLE Producto (idproducto INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, descripcion TEXT NOT NULL, "+
|
||||
"precio DECIMAL(10, 2) NOT NULL, stock INTEGER NOT NULL, fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
|
||||
|
||||
"INSERT INTO Empleado ( nombre, apellido, calle, fecha_contratacion, colonia, cp, no_ext, referencia, fecha_nac, telefono, activo) VALUES('jefe', '', '', '', '', '', '', '', '', '', 0);",
|
||||
"INSERT INTO Login ( tipo, usuario, contra, fk_idempleado) VALUES('admin', 'admin', '12345', 1);"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
internal class Categoria
|
||||
{
|
||||
public int idCategoria;
|
||||
public string nombre;
|
||||
public string descricion;
|
||||
|
||||
public Categoria(int idCategoria, string nombre = "", string descricion = "")
|
||||
{
|
||||
this.idCategoria = idCategoria;
|
||||
this.nombre = nombre;
|
||||
this.descricion = descricion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
internal class Producto
|
||||
{
|
||||
public int idProducto;
|
||||
public string nombre;
|
||||
public string descripcion;
|
||||
public decimal precion;
|
||||
public int stock;
|
||||
public Categoria categoria;
|
||||
|
||||
public Producto( string nombre, string descripcion, decimal precion, Categoria categoria, int stock = 0, int idProducto = 0)
|
||||
{
|
||||
this.idProducto = idProducto;
|
||||
this.nombre = nombre;
|
||||
this.descripcion = descripcion;
|
||||
this.precion = precion;
|
||||
this.stock = stock;
|
||||
this.categoria = categoria;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SQLite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -14,5 +15,37 @@ namespace compabetov2.database
|
||||
{
|
||||
return DAO.iniciarSesionDAO(usuario.nombreUsuario, usuario.contra);
|
||||
}
|
||||
|
||||
public static List<Producto> conseguirProductos()
|
||||
{
|
||||
List<Producto> productos = new List<Producto>();
|
||||
|
||||
SQLiteDataReader reader = DAO.conseguirProductosDAO();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Categoria categoria = new Categoria(
|
||||
(int)reader["idcategoria"],
|
||||
reader["nombre"].ToString(),
|
||||
reader["descripcion"].ToString());
|
||||
|
||||
Producto producto = new Producto(
|
||||
reader["nombre"].ToString(),
|
||||
reader["descripcion"].ToString(),
|
||||
(decimal)reader["precio"],
|
||||
categoria,
|
||||
(int)reader["stock"],
|
||||
(int)reader["idproducto"]);
|
||||
|
||||
productos.Add(producto);
|
||||
}
|
||||
|
||||
return productos;
|
||||
}
|
||||
|
||||
public static bool insertarProducto(Producto producto)
|
||||
{
|
||||
return DAO.insertarProductoDAO(producto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1,5 @@
|
||||
<<<<<<< HEAD
|
||||
05819d235d91141814c11abb2c220a18419f2908
|
||||
=======
|
||||
0fb7daba789e834843a2b65248efd03b07d0f0ede738d9263d10b691f02055b9
|
||||
>>>>>>> d003e4c42794673ebd38c404faa45e958bf8ef42
|
||||
|
||||
@@ -18,3 +18,23 @@ C:\Users\Googl\Documents\compabetov2\bin\Debug\EntityFramework.xml
|
||||
C:\Users\Googl\Documents\compabetov2\bin\Debug\EntityFramework.SqlServer.xml
|
||||
C:\Users\Googl\Documents\compabetov2\bin\Debug\System.Data.SQLite.xml
|
||||
C:\Users\Googl\Documents\compabetov2\obj\Debug\compabetov2.csproj.CopyComplete
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\compabetov2.exe.config
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\compabetov2.exe
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\compabetov2.pdb
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\EntityFramework.dll
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\EntityFramework.SqlServer.dll
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\System.Data.SQLite.dll
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\System.Data.SQLite.EF6.dll
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\System.Data.SQLite.Linq.dll
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\EntityFramework.xml
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\EntityFramework.SqlServer.xml
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\bin\Debug\System.Data.SQLite.xml
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.csproj.AssemblyReference.cache
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.login.resources
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.MenuPrincipal.resources
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.Properties.Resources.resources
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.csproj.GenerateResource.cache
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.csproj.CoreCompileInputs.cache
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.csproj.CopyComplete
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.exe
|
||||
C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.pdb
|
||||
|
||||
Reference in New Issue
Block a user