CRUD de clientes
This commit is contained in:
+132
-5
@@ -107,10 +107,13 @@ namespace compabetov2.database
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Producto (nombre, descripcion, precio, stock, fk_idcategoria) "+
|
||||
"VALUES (@nombre, @descripcion, @precio,@stock, @idcategoria)";
|
||||
|
||||
|
||||
string sql = "INSERT INTO Producto (nombre, descripcion, precio,img, stock, fk_idcategoria) "+
|
||||
"VALUES (@nombre, @descripcion, @precio,@img , @stock, @idcategoria)";
|
||||
|
||||
if (!producto.img.Equals(""))
|
||||
{
|
||||
producto.img = guardarImg(producto.img);
|
||||
}
|
||||
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
@@ -118,6 +121,7 @@ namespace compabetov2.database
|
||||
command.Parameters.AddWithValue("@nombre", producto.nombre);
|
||||
command.Parameters.AddWithValue("@descripcion", producto.descripcion);
|
||||
command.Parameters.AddWithValue("@precio", producto.precion);
|
||||
command.Parameters.AddWithValue("@img", producto.img);
|
||||
command.Parameters.AddWithValue("@stock", producto.stock);
|
||||
command.Parameters.AddWithValue("@idcategoria", producto.categoria.idCategoria);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
@@ -134,6 +138,34 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool eliminarProductoDAO(Producto producto)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "DELETE FROM Producto WHERE idproducto = @idproducto";
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@idproducto", producto.idProducto);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarCategoriaDAO(Categoria categoria)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
@@ -164,6 +196,96 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarClienteDAO(Cliente cliente)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Cliente (nombres, apellidos, calle, colonia, cp, no_ext, no_int, referencia, telefono, telefono_extra) " +
|
||||
"VALUES (@nombres, @apellidos, @calle, @colonia, @cp, @no_ext, @no_int, @referencia, @telefono, @telefono_extra)";
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@nombre", cliente.nombres);
|
||||
command.Parameters.AddWithValue("@apellidios", cliente.apellidos);
|
||||
command.Parameters.AddWithValue("@calle", cliente.calle);
|
||||
command.Parameters.AddWithValue("@colonia", cliente.colonia);
|
||||
command.Parameters.AddWithValue("@cp", cliente.cp);
|
||||
command.Parameters.AddWithValue("@no_ext", cliente.no_ext);
|
||||
command.Parameters.AddWithValue("@no_int", cliente.no_int);
|
||||
command.Parameters.AddWithValue("@referencia", cliente.referencia);
|
||||
command.Parameters.AddWithValue("@telefono", cliente.telefono);
|
||||
command.Parameters.AddWithValue("@telefono_extra", cliente.telefono_extra);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool eliminarClienteDAO(Cliente cliente)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "DELETE FROM Cliente WHERE idCliente = @idCliente";
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@idCliente", cliente.idCliente);
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static SQLiteDataReader conseguirClientesDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM Cliente";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
private static string guardarImg(String rutaImagen)
|
||||
{
|
||||
//consigue la carpeta del proyectro
|
||||
@@ -195,6 +317,7 @@ namespace compabetov2.database
|
||||
"DROP TABLE IF EXISTS Empleado",
|
||||
"DROP TABLE IF EXISTS Producto",
|
||||
"DROP TABLE IF EXISTS Categoria",
|
||||
"DROP TABLE IF EXISTS Cliente",
|
||||
|
||||
"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," +
|
||||
@@ -206,9 +329,13 @@ 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, " +
|
||||
"precio DECIMAL(10, 2) NOT NULL, img TEXT NOT NULL, stock INTEGER NOT NULL, " +
|
||||
"fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
|
||||
|
||||
"CREATE TABLE Cliente (idcliente INTEGER PRIMARY KEY AUTOINCREMENT, nombres TEXT NOT NULL, apellidos TEXT NOT NULL, " +
|
||||
"calle 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, " +
|
||||
"telefono TEXT NOT NULL, telefono_extra TEXT NOT NULL)",
|
||||
|
||||
"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);"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user