agrgar producto en interfaz

This commit is contained in:
carlos
2023-12-23 00:56:14 -06:00
parent 73b64b70a8
commit 565ef45950
16 changed files with 142 additions and 85 deletions
+5 -10
View File
@@ -107,14 +107,10 @@ namespace compabetov2.database
{
conexion.Open();
string sql = "INSERT INTO Producto (nombre, descripcion, precio, img, stock, idcategoria) "+
"VALUES (@nombre, @descripcion, @precio, @stock, @img, @idcategoria)";
string sql = "INSERT INTO Producto (nombre, descripcion, precio, stock, fk_idcategoria) "+
"VALUES (@nombre, @descripcion, @precio,@stock, @idcategoria)";
if (!producto.img.Equals(""))
{
string rutaDestino = guardarImg(producto.img);
producto.img = rutaDestino;
}
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
@@ -123,7 +119,6 @@ namespace compabetov2.database
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();
@@ -172,7 +167,7 @@ namespace compabetov2.database
private static string guardarImg(String rutaImagen)
{
//consigue la carpeta del proyectro
string carpetaImagenes = Path.Combine(Aplication.StartupPath, "produtos_img");
string carpetaImagenes = Path.Combine(Application.StartupPath, "produtos_img");
//crear el directorio sino existe
if (!Directory.Exists(carpetaImagenes))
@@ -211,7 +206,7 @@ namespace compabetov2.database
"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, img 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,no_int, referencia, fecha_nac, telefono, activo) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', 0);",
+1 -1
View File
@@ -12,7 +12,7 @@ namespace compabetov2.database.modelos
public string nombre;
public string descripcion;
public Categoria(int idCategoria, string nombre = "", string descripcion = "")
public Categoria(int idCategoria = 0, string nombre = "", string descripcion = "")
{
this.idCategoria = idCategoria;
this.nombre = nombre;