diff --git a/.vs/compabetoOG/v17/.wsuo b/.vs/compabetoOG/v17/.wsuo index dade05e..4445312 100644 Binary files a/.vs/compabetoOG/v17/.wsuo and b/.vs/compabetoOG/v17/.wsuo differ diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 50aa0b1..fdccb2b 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index c7b4205..0db4eb0 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/bin/Debug/data.db b/bin/Debug/data.db index 7d74547..84b5e0b 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/database/DAO.cs b/database/DAO.cs index 4e16a91..567f2ff 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data.SQLite; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -106,14 +107,18 @@ namespace compabetov2.database { conexion.Open(); - string sql = "INSERT INTO Producto (nombre, descripcion, precio, stock, idcategoria) "+ - "VALUES (@nombre, @descripcion, @precio, @stock, @idcategoria)"; + string sql = "INSERT INTO Producto (nombre, descripcion, precio, img, stock, idcategoria) "+ + "VALUES (@nombre, @descripcion, @precio, @stock, @img, @idcategoria)"; + + string rutaDestino = guardarImg(producto.img); + 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("@img", rutaDestino); command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria); int filasAfectadas = command.ExecuteNonQuery(); @@ -140,6 +145,7 @@ namespace compabetov2.database string sql = "INSERT INTO Categoria (nombre, descripcion) " + "VALUES (@nombre, @descripcion)"; + using (SQLiteCommand command = new SQLiteCommand(sql, conexion)) { command.Parameters.AddWithValue("@nombre", categoria.nombre); @@ -158,6 +164,24 @@ namespace compabetov2.database } } + private static string guardarImg(String rutaImagen) + { + //consigue la carpeta del proyectro + string carpetaImagenes = Path.Combine(Aplication.StartupPath, "produtos_img"); + + //crear el directorio sino existe + if (!Directory.Exists(carpetaImagenes)) + { + Directory.CreateDirectory(carpetaImagenes); + } + + string nombreArchivo = Path.GetFileName(rutaImagen); + string rutaDestino = Path.Combine(carpetaImagenes, nombreArchivo); + File.Copy(rutaImagen, rutaDestino, true); + + return rutaDestino; + } + private static void crearDB() { var db_conexion = new Conexion(); diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 4e28561..b71689b 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/compabetov2.csproj.AssemblyReference.cache b/obj/Debug/compabetov2.csproj.AssemblyReference.cache index 1367df0..def87ca 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 cb2cdc3..b16573f 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -245f61b4e520a1fb9e0e2f4a53e49df7efd978ab +04ff0eea2625c5f041dc8598762cddc9006f263e8231100b6f207f00fb8b7971 diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index 74bbc9f..7733796 100644 Binary files a/obj/Debug/compabetov2.csproj.GenerateResource.cache and b/obj/Debug/compabetov2.csproj.GenerateResource.cache differ diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 50aa0b1..fdccb2b 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index c7b4205..0db4eb0 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ