grid con fallas
This commit is contained in:
+69
-3
@@ -75,6 +75,72 @@ namespace compabetov2.database
|
||||
}
|
||||
}
|
||||
|
||||
public static bool insertarEmpleadoDAO(Empleado empleado)
|
||||
{
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection conexion = db_conexion.get_connection())
|
||||
{
|
||||
conexion.Open();
|
||||
|
||||
string sql = "INSERT INTO Empleado (nombre, apellidos, calle, fecha_contratacion, estado, colonia, cp, no_ext, no_int, referencia, fecha_nac, telefono) " +
|
||||
"VALUES (@nombre, @apellidos, @calle, @fecha_contratacion, @estado, @colonia, @cp, @no_ext, @no_int, @referencia, @fecha_nac, @telefono)";
|
||||
|
||||
|
||||
|
||||
using (SQLiteCommand command = new SQLiteCommand(sql, conexion))
|
||||
{
|
||||
command.Parameters.AddWithValue("@nombre", empleado.nombre);
|
||||
command.Parameters.AddWithValue("@apellidos", empleado.apellidos);
|
||||
command.Parameters.AddWithValue("@calle", empleado.calle);
|
||||
command.Parameters.AddWithValue("@fecha_contratacion", empleado.fecha_contratacion);
|
||||
command.Parameters.AddWithValue("@estado", empleado.estado);
|
||||
command.Parameters.AddWithValue("@colonia", empleado.colonia);
|
||||
command.Parameters.AddWithValue("@cp", empleado.cp);
|
||||
command.Parameters.AddWithValue("@no_ext", empleado.no_ext);
|
||||
command.Parameters.AddWithValue("@no_int", empleado.no_int);
|
||||
command.Parameters.AddWithValue("@referencia", empleado.referencia);
|
||||
command.Parameters.AddWithValue("@fecha_nac", empleado.fecha_nac);
|
||||
command.Parameters.AddWithValue("@telefono", empleado.telefono);
|
||||
|
||||
int filasAfectadas = command.ExecuteNonQuery();
|
||||
|
||||
if (filasAfectadas > 0) { return true; }
|
||||
else { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static SQLiteDataReader conseguirEmpleadosDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
var db_conexion = new Conexion();
|
||||
try
|
||||
{
|
||||
SQLiteConnection conexion = db_conexion.get_connection();
|
||||
|
||||
conexion.Open();
|
||||
|
||||
string sql = "SELECT * FROM Empleado";
|
||||
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return reader;
|
||||
|
||||
}
|
||||
catch (SQLiteException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
public static SQLiteDataReader conseguirProductosDAO()
|
||||
{
|
||||
SQLiteDataReader reader = null;
|
||||
@@ -320,8 +386,8 @@ namespace compabetov2.database
|
||||
"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," +
|
||||
"no_int TEXT NOT NULL, referencia TEXT NOT NULL, fecha_nac TEXT NOT NULL, telefono TEXT NOT NULL, activo INTEGER NOT NULL)",
|
||||
"apellidos TEXT NOT NULL, calle TEXT NOT NULL, fecha_contratacion TEXT NOT NULL,estado 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)",
|
||||
|
||||
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
|
||||
"contra TEXT NOT NULL, fk_idempleado INTEGER NOT NULL, FOREIGN KEY (fk_idempleado) REFERENCES Empleado (idempleado))",
|
||||
@@ -336,7 +402,7 @@ namespace compabetov2.database
|
||||
"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 Empleado ( nombre, apellidos, calle, fecha_contratacion,estado, colonia, cp, no_ext,no_int, referencia, fecha_nac, telefono) VALUES('jefe', '', '', '', '', '', '', '', '', '', '', '');",
|
||||
"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
|
||||
{
|
||||
internal class Empleado
|
||||
{
|
||||
public int idempleado;
|
||||
public string nombre;
|
||||
public string apellidos;
|
||||
public string calle;
|
||||
public string fecha_contratacion;
|
||||
public string estado;
|
||||
public string colonia;
|
||||
public string cp;
|
||||
public string no_ext;
|
||||
public string no_int;
|
||||
public string referencia;
|
||||
public string fecha_nac;
|
||||
public string telefono;
|
||||
|
||||
public Empleado(int idempeado = -1, string nombre ="", string apellidos = "", string calle = "", string fecha_contratacion = "", string estado = "", string colonia = "", string cp = "", string no_ext = "", string no_int = "", string referencia = "", string fecha_nac = "", string telefono ="")
|
||||
{
|
||||
this.idempleado = idempeado;
|
||||
this.nombre = nombre;
|
||||
this.apellidos = apellidos;
|
||||
this.calle = calle;
|
||||
this.fecha_contratacion=fecha_contratacion;
|
||||
this.estado = estado;
|
||||
this.colonia = colonia;
|
||||
this.cp = cp;
|
||||
this.no_ext = no_ext;
|
||||
this.no_int = no_int;
|
||||
this.referencia = referencia;
|
||||
this.fecha_nac=fecha_nac;
|
||||
this.telefono = telefono;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Data.SQLite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using compabetov2.database;
|
||||
using compabetov2.database.modelos;
|
||||
|
||||
@@ -89,5 +90,46 @@ namespace compabetov2.database
|
||||
}
|
||||
return clientes;
|
||||
}
|
||||
|
||||
public static bool insertarEmpleado(Empleado empleado)
|
||||
{
|
||||
return DAO.insertarEmpleadoDAO(empleado);
|
||||
}
|
||||
|
||||
public static List<Empleado> conseguirEmpleados()
|
||||
{
|
||||
List<Empleado> empleados = new List<Empleado>();
|
||||
|
||||
using (SQLiteDataReader reader = DAO.conseguirEmpleadosDAO()) {
|
||||
if(reader == null) { MessageBox.Show("null");
|
||||
return empleados;
|
||||
} else
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Empleado empleado = new Empleado(
|
||||
(int)reader["idempleado"],
|
||||
(string)reader["nombre"].ToString(),
|
||||
(string)reader["apellidos"].ToString(),
|
||||
(string)reader["calle"].ToString(),
|
||||
(string)reader["fecha_contratacion"].ToString(),
|
||||
(string)reader["estado"].ToString(),
|
||||
(string)reader["colonia"].ToString(),
|
||||
(string)reader["cp"].ToString(),
|
||||
(string)reader["no_ext"].ToString(),
|
||||
(string)reader["no_int"].ToString(),
|
||||
(string)reader["referencia"].ToString(),
|
||||
(string)reader["fecha_nac"].ToString(),
|
||||
(string)reader["telefono"].ToString()
|
||||
);
|
||||
empleados.Add(empleado);
|
||||
}
|
||||
return empleados;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user