agrgar producto en interfaz
This commit is contained in:
+5
-10
@@ -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);",
|
||||
|
||||
Reference in New Issue
Block a user