diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index ab51f88..23762ee 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -1,7 +1,10 @@ { "ExpandedNodes": [ - "" + "", + "\\database", + "\\database\\modelos", + "\\Resources" ], - "SelectedNode": "\\compabetov2.sln", + "SelectedNode": "\\.sln", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/.vs/compabetoOG/v17/.wsuo b/.vs/compabetoOG/v17/.wsuo index dade05e..4a738b9 100644 Binary files a/.vs/compabetoOG/v17/.wsuo and b/.vs/compabetoOG/v17/.wsuo differ diff --git a/.vs/compabetov2/FileContentIndex/723b65bf-e24d-471e-89ca-2fcd677ca28f.vsidx b/.vs/compabetov2/FileContentIndex/723b65bf-e24d-471e-89ca-2fcd677ca28f.vsidx deleted file mode 100644 index 434127c..0000000 Binary files a/.vs/compabetov2/FileContentIndex/723b65bf-e24d-471e-89ca-2fcd677ca28f.vsidx and /dev/null differ diff --git a/.vs/compabetov2/FileContentIndex/86aca791-b698-42f2-86ed-c7837ac73c72.vsidx b/.vs/compabetov2/FileContentIndex/86aca791-b698-42f2-86ed-c7837ac73c72.vsidx deleted file mode 100644 index d3c94a1..0000000 Binary files a/.vs/compabetov2/FileContentIndex/86aca791-b698-42f2-86ed-c7837ac73c72.vsidx and /dev/null 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..2759ea4 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,23 @@ 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)"; + + if (!producto.img.Equals("")) + { + string rutaDestino = guardarImg(producto.img); + producto.img = rutaDestino; + } + + 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", producto.img); command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria); int filasAfectadas = command.ExecuteNonQuery(); @@ -140,6 +150,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 +169,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.CoreCompileInputs.cache b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache index 82bdfcd..647574e 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1,5 @@ +<<<<<<< HEAD 5f84ca15ab0cf8658a0603f2d37cc1ef407c340f +======= +04ff0eea2625c5f041dc8598762cddc9006f263e8231100b6f207f00fb8b7971 +>>>>>>> cf456518544ecfa44f10e88e75e2bc14d31d6702