383 lines
12 KiB
C#
383 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SQLite;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using compabetov2.database;
|
|
using compabetov2.database.modelos;
|
|
|
|
namespace compabetov2.database
|
|
{
|
|
internal class service
|
|
{
|
|
public static bool iniciarSesion(Usuario usuario)
|
|
{
|
|
return DAO.iniciarSesionDAO(usuario.nombreUsuario, usuario.contra);
|
|
}
|
|
public static LoginModel conseguirInicioSesion(string usuario)
|
|
{
|
|
SQLiteDataReader reader = DAO.conseguirInicioSesionDAO(usuario);
|
|
|
|
while (reader.Read())
|
|
{
|
|
return new LoginModel(
|
|
reader["usuario"].ToString(),
|
|
"",
|
|
reader["tipo"].ToString()
|
|
);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
public static bool crearLogin(LoginModel loginModel, int idEmpleado)
|
|
{
|
|
return DAO.crearLoginDAO(loginModel, idEmpleado);
|
|
}
|
|
|
|
public static List<Producto> conseguirProductos()
|
|
{
|
|
List<Producto> productos = new List<Producto>();
|
|
|
|
SQLiteDataReader reader = DAO.conseguirProductosDAO();
|
|
|
|
while (reader.Read())
|
|
{
|
|
Categoria categoria = new Categoria(
|
|
int.Parse(reader["idcategoria"].ToString()),
|
|
reader["nombre"].ToString(),
|
|
reader["descripcion"].ToString());
|
|
|
|
Producto producto = new Producto(
|
|
int.Parse(reader["idproducto"].ToString()),
|
|
reader["nombre"].ToString(),
|
|
reader["descripcion"].ToString(),
|
|
decimal.Parse(reader["precio"].ToString()),
|
|
reader["img"].ToString(),
|
|
int.Parse(reader["stock"].ToString()),
|
|
categoria);
|
|
|
|
productos.Add(producto);
|
|
}
|
|
|
|
return productos;
|
|
}
|
|
|
|
public static bool insertarProducto(Producto producto)
|
|
{
|
|
return DAO.insertarProductoDAO(producto);
|
|
}
|
|
|
|
public static bool insertarCategoriaDAO(Categoria categoria)
|
|
{
|
|
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;
|
|
}
|
|
|
|
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()) {
|
|
|
|
|
|
while (reader.Read())
|
|
{
|
|
long fkIdLoginTemp = reader.GetInt64(14);
|
|
int fkIdLogin = Convert.ToInt32(fkIdLoginTemp);
|
|
|
|
long id = reader.GetInt64(0);
|
|
Empleado empleado = new Empleado(
|
|
Convert.ToInt32(id),
|
|
reader["nombre"].ToString(),
|
|
reader["apellidos"].ToString(),
|
|
reader["calle"].ToString(),
|
|
reader["fecha_contratacion"].ToString(),
|
|
reader["estado"].ToString(),
|
|
reader["colonia"].ToString(),
|
|
reader["cp"].ToString(),
|
|
reader["no_ext"].ToString(),
|
|
reader["no_int"].ToString(),
|
|
reader["referencia"].ToString(),
|
|
reader["fecha_nac"].ToString(),
|
|
reader["telefono"].ToString(),
|
|
reader["img"].ToString(),
|
|
fkIdLogin
|
|
) ;
|
|
empleados.Add(empleado);
|
|
}
|
|
return empleados;
|
|
|
|
}
|
|
}
|
|
|
|
public static bool aumentarStock(List<Producto> stockNuevo)
|
|
{
|
|
return DAO.aumentarStockDAO(stockNuevo);
|
|
}
|
|
|
|
public static bool eliminarEmpleado(Empleado empleado)
|
|
{
|
|
return DAO.eliminarEmpleadoDAO(empleado);
|
|
}
|
|
|
|
public static bool actualizarEmpleado(Empleado empleado)
|
|
{
|
|
return DAO.actualizarEmpleadoDAO(empleado);
|
|
}
|
|
|
|
public static bool verificarExistenciaLogin(LoginModel loginModel)
|
|
{
|
|
return DAO.verificarExistenciaLoginDAO(loginModel);
|
|
}
|
|
|
|
public static bool eliminarLogin(Empleado empleado)
|
|
{
|
|
return DAO.eliminarLoginDAO(empleado);
|
|
}
|
|
|
|
public static bool modificarContra(Empleado empleado, string contra)
|
|
{
|
|
return DAO.modificarContraDAO(empleado, contra);
|
|
}
|
|
|
|
public static List<Merma> conseguirMerma()
|
|
{
|
|
List<Merma> mermas = new List<Merma>();
|
|
SQLiteDataReader reader = DAO.conseguirMermaDAO();
|
|
|
|
while (reader.Read())
|
|
{
|
|
Merma merma = new Merma(
|
|
reader.GetInt64(0),
|
|
reader.GetString(1),
|
|
reader.GetString(2),
|
|
reader.GetString(3)
|
|
);
|
|
mermas.Add(merma);
|
|
}
|
|
|
|
return mermas;
|
|
}
|
|
|
|
public static bool crearVentaDAO(VentaModel venta, List<DetalleVentaModel> detalleVentas)
|
|
{
|
|
return DAO.crearVentaDAO(venta, detalleVentas);
|
|
}
|
|
|
|
public static bool insertarMerma(Merma merma)
|
|
{
|
|
return DAO.insertarMermaDAO(merma);
|
|
}
|
|
|
|
public static bool eliminarMerma(Merma merma)
|
|
{
|
|
return DAO.eliminarMermaDAO(merma);
|
|
}
|
|
|
|
public static bool actualizarMerma(Merma merma)
|
|
{
|
|
return DAO.actualizarMermaDAO(merma);
|
|
}
|
|
|
|
public static bool crearCuenta(Cuenta cuenta, List<DetalleCuentaModel> detalleCuentas)
|
|
{
|
|
return DAO.crearCuentaDAO(cuenta, detalleCuentas);
|
|
}
|
|
|
|
public static List<Cuenta> conseguirCuentaDAO()
|
|
{
|
|
List<Cuenta> cuentas = new List<Cuenta>();
|
|
SQLiteDataReader reader = DAO.conseguirCuentaDAO();
|
|
|
|
while(reader.Read())
|
|
{
|
|
long idCuenta = reader.GetInt64(0);
|
|
long total = reader.GetInt64(1);
|
|
string fecha = reader["fecha"].ToString();
|
|
string estado = reader["estado"].ToString();
|
|
string descripcion = reader["descripcion"].ToString();
|
|
string cliente = reader["cliente"].ToString();
|
|
|
|
Cuenta cuenta = new Cuenta(
|
|
(int) total,
|
|
fecha,
|
|
estado,
|
|
descripcion,
|
|
cliente,
|
|
(int)idCuenta
|
|
);
|
|
cuentas.Add(cuenta);
|
|
}
|
|
return cuentas;
|
|
}
|
|
|
|
public static List<DetalleCuentaModel> conseguirDetalleCuante(int idCuenta)
|
|
{
|
|
List<DetalleCuentaModel> detallesCuentas = new List<DetalleCuentaModel>();
|
|
|
|
SQLiteDataReader reader = DAO.conseguirDetalleCuanteDAO(idCuenta);
|
|
|
|
while (reader.Read())
|
|
{
|
|
int idProducto = (int)reader.GetInt64(0);
|
|
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(
|
|
new Producto(idProducto, reader["nombre"].ToString()),
|
|
(int)reader.GetInt64(2)
|
|
);
|
|
detallesCuentas.Add(detalleCuenta);
|
|
}
|
|
|
|
return detallesCuentas;
|
|
}
|
|
|
|
public static bool cancelarCuenta(int idCuenta)
|
|
{
|
|
return DAO.cancelarCuentaDAO(idCuenta);
|
|
}
|
|
|
|
public static bool saldarCuenta(Cuenta cuenta, List<DetalleCuentaModel> detallesCuentas)
|
|
{
|
|
return DAO.saldarCuentaDAO(cuenta, detallesCuentas);
|
|
}
|
|
|
|
public static Dictionary<string, dynamic> filtrarVentaFechaMes(DateTime fecha)
|
|
{
|
|
Dictionary<string, dynamic> estadisticas = new Dictionary<string, dynamic>();
|
|
SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha);
|
|
string formatoFecha = "dd/MM/yyyy h:mm:ss tt";
|
|
decimal totalDia = 0;
|
|
decimal totalMes = 0;
|
|
List<VentaModel> ventas = new List<VentaModel>();
|
|
while (reader.Read())
|
|
{
|
|
VentaModel venta = new VentaModel(
|
|
reader.GetDecimal(2),
|
|
(int)reader.GetInt64(0),
|
|
reader.GetString(1)
|
|
);
|
|
DateTime fechaVenta = DateTime.ParseExact(venta.fecha, formatoFecha, CultureInfo.InvariantCulture);
|
|
if (fecha.Day == fechaVenta.Day)
|
|
{
|
|
totalDia += venta.total;
|
|
}
|
|
totalMes += venta.total;
|
|
ventas.Add(venta);
|
|
}
|
|
|
|
estadisticas.Add("ventasDia", totalDia);
|
|
estadisticas.Add("ventasMes", totalMes);
|
|
MessageBox.Show($"{totalDia} -- {totalMes}");
|
|
|
|
return estadisticas;
|
|
}
|
|
|
|
public static bool crearEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
|
{
|
|
return DAO.crearEnvio(envio, detallesEnvio);
|
|
}
|
|
|
|
public static List<Envio> conseguirEnvio()
|
|
{
|
|
List<Envio> envios = new List<Envio>();
|
|
SQLiteDataReader reader = DAO.conseguirEnvioDAO();
|
|
|
|
while (reader.Read())
|
|
{
|
|
Envio envio = new Envio(
|
|
(int)reader.GetInt64(0),
|
|
reader.GetString(1),
|
|
reader.GetString(2),
|
|
reader.GetString(3),
|
|
reader.GetString(4),
|
|
reader.GetString(5),
|
|
reader.GetString(7),
|
|
reader.GetDecimal(6)
|
|
) ;
|
|
|
|
envios.Add(envio);
|
|
}
|
|
|
|
return envios;
|
|
}
|
|
|
|
public static List<DetalleEnvioModel> conseguirDetalleEnvio(int idEnvio)
|
|
{
|
|
List<DetalleEnvioModel> detallesEnvio = new List<DetalleEnvioModel>();
|
|
|
|
SQLiteDataReader reader = DAO.conseguirDetalleEnvioDAO(idEnvio);
|
|
|
|
while (reader.Read())
|
|
{
|
|
int idProducto = (int)reader.GetInt64(0);
|
|
DetalleEnvioModel detalleEnvio = new DetalleEnvioModel(
|
|
idEnvio,
|
|
new Producto(idProducto, reader["nombre"].ToString()),
|
|
(int)reader.GetInt64(2)
|
|
);
|
|
detallesEnvio.Add(detalleEnvio);
|
|
}
|
|
|
|
return detallesEnvio;
|
|
}
|
|
|
|
public static bool editarEnvio(Envio envio)
|
|
{
|
|
return DAO.editarEnvioDAO(envio);
|
|
}
|
|
|
|
|
|
public static bool cancelarEnvio(int idEnvio)
|
|
{
|
|
return DAO.cancelarEnvioDAO(idEnvio);
|
|
}
|
|
|
|
public static bool concluirEnvio(Envio envio, List<DetalleEnvioModel> detallesEnvio)
|
|
{
|
|
return DAO.concluirEnvioDAO(envio, detallesEnvio);
|
|
}
|
|
}
|
|
}
|