Menu v2
This commit is contained in:
+33
-3
@@ -129,6 +129,35 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarCategoriaDAO(Categoria categoria)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Categoria (nombre, descripcion) " +
|
||||
"VALUES (@nombre, @descripcion)";
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@nombre", categoria.nombre);
|
||||
command.Parameters.AddWithValue("@descripcion", categoria.descripcion);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void crearDB()
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
@@ -144,7 +173,7 @@ namespace compabetov2.database
|
||||
"DROP TABLE IF EXISTS Categoria",
|
||||
|
||||
"CREATE TABLE Empleado (idempleado INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT NOT NULL, "+
|
||||
"apellido TEXT NOT NULL, calle TEXT NOT NULL, fecha_contratacion TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL" +
|
||||
"apellido TEXT NOT NULL, calle TEXT NOT NULL, fecha_contratacion TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL," +
|
||||
"no_int TEXT NOT NULL, referencia TEXT NOT NULL, fecha_nac TEXT NOT NULL, telefono TEXT NOT NULL, activo INTEGER NOT NULL)",
|
||||
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||
@@ -153,9 +182,10 @@ 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, fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
|
||||
"precio DECIMAL(10, 2) NOT NULL, stock INTEGER NOT NULL, img TEXT 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, referencia, fecha_nac, telefono, activo) VALUES('jefe', '', '', '', '', '', '', '', '', '', 0);",
|
||||
"INSERT INTO Empleado ( nombre, apellido, calle, fecha_contratacion, colonia, cp, no_ext,no_int, referencia, fecha_nac, telefono, activo) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', 0);",
|
||||
"INSERT INTO Login ( tipo, usuario, contra, fk_idempleado) VALUES('admin', 'admin', '12345', 1);"
|
||||
};
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace compabetov2.database.modelos
|
||||
{
|
||||
public int idCategoria;
|
||||
public string nombre;
|
||||
public string descricion;
|
||||
public string descripcion;
|
||||
|
||||
public Categoria(int idCategoria, string nombre = "", string descricion = "")
|
||||
public Categoria(int idCategoria, string nombre = "", string descripcion = "")
|
||||
{
|
||||
this.idCategoria = idCategoria;
|
||||
this.nombre = nombre;
|
||||
this.descricion = descricion;
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ namespace compabetov2.database.modelos
|
||||
public string nombre;
|
||||
public string descripcion;
|
||||
public decimal precion;
|
||||
public string img;
|
||||
public int stock;
|
||||
public Categoria categoria;
|
||||
|
||||
public Producto( string nombre, string descripcion, decimal precion, Categoria categoria, int stock = 0, int idProducto = 0)
|
||||
public Producto(int idProducto = 0, string nombre = "", string descripcion = "", decimal precion = 0.0M, string img = "", int stock = 0, Categoria categoria = null)
|
||||
{
|
||||
this.idProducto = idProducto;
|
||||
this.nombre = nombre;
|
||||
this.descripcion = descripcion;
|
||||
this.precion = precion;
|
||||
this.img = img;
|
||||
this.stock = stock;
|
||||
this.categoria = categoria;
|
||||
}
|
||||
|
||||
+10
-4
@@ -30,12 +30,13 @@ namespace compabetov2.database
|
||||
reader["descripcion"].ToString());
|
||||
|
||||
Producto producto = new Producto(
|
||||
(int)reader["idproducto"],
|
||||
reader["nombre"].ToString(),
|
||||
reader["descripcion"].ToString(),
|
||||
(decimal)reader["precio"],
|
||||
categoria,
|
||||
(int)reader["stock"],
|
||||
(int)reader["idproducto"]);
|
||||
(decimal)reader["precio"],
|
||||
reader["img"].ToString(),
|
||||
(int)reader["stock"],
|
||||
categoria);
|
||||
|
||||
productos.Add(producto);
|
||||
}
|
||||
@@ -47,5 +48,10 @@ namespace compabetov2.database
|
||||
{
|
||||
return DAO.insertarProductoDAO(producto);
|
||||
}
|
||||
|
||||
public static bool insertarCategoriaDAO(Categoria categoria)
|
||||
{
|
||||
return DAO.insertarCategoriaDAO(categoria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user