diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eea4eeb --- /dev/null +++ b/.gitignore @@ -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 diff --git a/.gitignore.txt b/.gitignore.txt index a4d6d9c..df04b1f 100644 --- a/.gitignore.txt +++ b/.gitignore.txt @@ -1 +1,44 @@ -.vs/ \ No newline at end of file +# 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 \ No newline at end of file diff --git a/.vs/compabetoOG/v17/.wsuo b/.vs/compabetoOG/v17/.wsuo index 20f8fd6..dade05e 100644 Binary files a/.vs/compabetoOG/v17/.wsuo and b/.vs/compabetoOG/v17/.wsuo differ diff --git a/.vs/compabetov2/FileContentIndex/c43954da-ebf5-49ab-8834-3ef795943804.vsidx b/.vs/compabetov2/FileContentIndex/c43954da-ebf5-49ab-8834-3ef795943804.vsidx deleted file mode 100644 index d9f4ae0..0000000 Binary files a/.vs/compabetov2/FileContentIndex/c43954da-ebf5-49ab-8834-3ef795943804.vsidx and /dev/null differ diff --git a/database/DAO.cs b/database/DAO.cs index 9f079cd..eaab0c8 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -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(); + + using (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(); + 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) - { - while (reader.Read()) + 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);" diff --git a/database/modelos/Categoria.cs b/database/modelos/Categoria.cs new file mode 100644 index 0000000..c44dc3a --- /dev/null +++ b/database/modelos/Categoria.cs @@ -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; + } + } +} diff --git a/database/modelos/Producto.cs b/database/modelos/Producto.cs new file mode 100644 index 0000000..842cab7 --- /dev/null +++ b/database/modelos/Producto.cs @@ -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; + } + } +} diff --git a/database/service.cs b/database/service.cs index 178f20d..dc46f39 100644 --- a/database/service.cs +++ b/database/service.cs @@ -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 conseguirProductos() + { + List productos = new List(); + + 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); + } } } diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 10a1a65..4382aa9 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/obj/Debug/compabetov2.csproj.AssemblyReference.cache b/obj/Debug/compabetov2.csproj.AssemblyReference.cache index 1367df0..80e940b 100644 Binary files a/obj/Debug/compabetov2.csproj.AssemblyReference.cache and b/obj/Debug/compabetov2.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache index 31cc99c..f93bbe4 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1,5 @@ +<<<<<<< HEAD 05819d235d91141814c11abb2c220a18419f2908 +======= +0fb7daba789e834843a2b65248efd03b07d0f0ede738d9263d10b691f02055b9 +>>>>>>> d003e4c42794673ebd38c404faa45e958bf8ef42 diff --git a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt index 4ad3d7f..cbe0884 100644 --- a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt +++ b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt @@ -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