interfaz invetario2

This commit is contained in:
Michael Robles
2023-12-22 23:23:04 -07:00
8 changed files with 40 additions and 4 deletions
+5 -2
View File
@@ -1,7 +1,10 @@
{ {
"ExpandedNodes": [ "ExpandedNodes": [
"" "",
"\\database",
"\\database\\modelos",
"\\Resources"
], ],
"SelectedNode": "\\compabetov2.sln", "SelectedNode": "\\.sln",
"PreviewInSolutionExplorer": false "PreviewInSolutionExplorer": false
} }
Binary file not shown.
BIN
View File
Binary file not shown.
+31 -2
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SQLite; using System.Data.SQLite;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -106,14 +107,23 @@ namespace compabetov2.database
{ {
conexion.Open(); conexion.Open();
string sql = "INSERT INTO Producto (nombre, descripcion, precio, stock, idcategoria) "+ string sql = "INSERT INTO Producto (nombre, descripcion, precio, img, stock, idcategoria) "+
"VALUES (@nombre, @descripcion, @precio, @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)) using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
{ {
command.Parameters.AddWithValue("@nombre", producto.nombre); command.Parameters.AddWithValue("@nombre", producto.nombre);
command.Parameters.AddWithValue("@descripcion", producto.descripcion); command.Parameters.AddWithValue("@descripcion", producto.descripcion);
command.Parameters.AddWithValue("@precio", producto.precion); command.Parameters.AddWithValue("@precio", producto.precion);
command.Parameters.AddWithValue("@stock", producto.stock); command.Parameters.AddWithValue("@stock", producto.stock);
command.Parameters.AddWithValue("@img", producto.img);
command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria); command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria);
int filasAfectadas = command.ExecuteNonQuery(); int filasAfectadas = command.ExecuteNonQuery();
@@ -140,6 +150,7 @@ namespace compabetov2.database
string sql = "INSERT INTO Categoria (nombre, descripcion) " + string sql = "INSERT INTO Categoria (nombre, descripcion) " +
"VALUES (@nombre, @descripcion)"; "VALUES (@nombre, @descripcion)";
using (SQLiteCommand command = new SQLiteCommand(sql, conexion)) using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
{ {
command.Parameters.AddWithValue("@nombre", categoria.nombre); 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() private static void crearDB()
{ {
var db_conexion = new Conexion(); var db_conexion = new Conexion();
@@ -1 +1,5 @@
<<<<<<< HEAD
5f84ca15ab0cf8658a0603f2d37cc1ef407c340f 5f84ca15ab0cf8658a0603f2d37cc1ef407c340f
=======
04ff0eea2625c5f041dc8598762cddc9006f263e8231100b6f207f00fb8b7971
>>>>>>> cf456518544ecfa44f10e88e75e2bc14d31d6702