Nuevo Cambio En Personal
This commit is contained in:
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -111,6 +111,7 @@
|
||||
<Compile Include="database\conexion.cs" />
|
||||
<Compile Include="database\DAO.cs" />
|
||||
<Compile Include="database\modelos\Categoria.cs" />
|
||||
<Compile Include="database\modelos\Cliente.cs" />
|
||||
<Compile Include="database\modelos\Producto.cs" />
|
||||
<Compile Include="database\modelos\usuario.cs" />
|
||||
<Compile Include="database\service.cs" />
|
||||
|
||||
+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);"
|
||||
};
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace compabetov2.database.modelos
|
||||
{
|
||||
public class Cliente
|
||||
{
|
||||
public int idCliente;
|
||||
public string nombres;
|
||||
public string apellidos;
|
||||
public string calle;
|
||||
public string colonia;
|
||||
public string cp;
|
||||
public string no_ext;
|
||||
public string no_int;
|
||||
public string referencia;
|
||||
public string telefono;
|
||||
public string telefono_extra;
|
||||
|
||||
public Cliente(int idCliente = -1, string nombres = "", string apellidos = "", string calle = "",
|
||||
string colonia = "", string cp = "", string no_ext = "",string no_int = "", string referencia = "", string telefono = "", string telefono_extra = "")
|
||||
{
|
||||
this.idCliente = idCliente;
|
||||
this.nombres = nombres;
|
||||
this.apellidos = apellidos;
|
||||
this.calle = calle;
|
||||
this.colonia = colonia;
|
||||
this.cp = cp;
|
||||
this.no_ext = no_ext;
|
||||
this.no_int = no_int;
|
||||
this.referencia = referencia;
|
||||
this.telefono = telefono;
|
||||
this.telefono_extra = telefono_extra;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,5 +53,41 @@ namespace compabetov2.database
|
||||
{
|
||||
return DAO.insertarCategoriaDAO(categoria);
|
||||
}
|
||||
|
||||
public static bool insertarCliente(Cliente cliente)
|
||||
{
|
||||
return DAO.insertarClienteDAO(cliente);
|
||||
}
|
||||
|
||||
public static bool eliminarCliente(Cliente cliente)
|
||||
{
|
||||
return DAO.eliminarClienteDAO(cliente);
|
||||
}
|
||||
|
||||
public static List<Cliente> conseguirCliente()
|
||||
{
|
||||
List<Cliente> clientes = new List<Cliente>();
|
||||
|
||||
SQLiteDataReader reader = DAO.conseguirClientesDAO();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Cliente cliente = new Cliente(
|
||||
(int)reader["idCliente"],
|
||||
reader["nombres"].ToString(),
|
||||
reader["apellidos"].ToString(),
|
||||
reader["calle"].ToString(),
|
||||
reader["colonia"].ToString(),
|
||||
reader["cp"].ToString(),
|
||||
reader["no_ext"].ToString(),
|
||||
reader["no_int"].ToString(),
|
||||
reader["referencia"].ToString(),
|
||||
reader["telefono"].ToString(),
|
||||
reader["telefono_extra"].ToString()
|
||||
);
|
||||
clientes.Add(cliente);
|
||||
}
|
||||
return clientes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
<<<<<<< HEAD
|
||||
5f84ca15ab0cf8658a0603f2d37cc1ef407c340f
|
||||
=======
|
||||
02dc50247532cb20084f44304c5c95e6e614121351100c9987f88dd3c1f0e1c2
|
||||
>>>>>>> 715f763c719aade878f3297c3fdbd71fd7d60dcb
|
||||
|
||||
Reference in New Issue
Block a user