Skip to content

Commit

Permalink
Añado log errores, fecha y mensajes dinamicos
Browse files Browse the repository at this point in the history
  • Loading branch information
escu-git committed Sep 26, 2023
1 parent db6fcf8 commit eaafcd7
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 23 deletions.
3 changes: 1 addition & 2 deletions AdminCompra.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include "Sistema.h"
class AdminCompras :
public Sistema
class AdminCompra
{

};
Expand Down
37 changes: 37 additions & 0 deletions ErrorDto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "ErrorDto.h"

ErrorDto::ErrorDto() { _err = false; _mensajeError = ""; }

/// <summary>
/// Setea un nuevo error.
/// </summary>
/// <param name="err"></param>
/// <param name="mensajeError"></param>
void ErrorDto::setError(bool err, std::string mensajeError)
{
_err = err;
_mensajeError = mensajeError;
}

/// <summary>
///
/// </summary>
/// <returns>Retorna objeto Error</returns>
ErrorDto ErrorDto::getError() { return *this; }

/// <summary>
/// Obtiene el mensaje de error
/// </summary>
/// <returns>mensajeError</returns>
std::string ErrorDto::getErrorMensaje() { return _mensajeError; }

/// <summary>
/// Se limpian errores
/// </summary>
void ErrorDto::limpiarErrores()
{
_err = false;
_mensajeError = "";
}

bool ErrorDto::hasError() { return _err; }
23 changes: 23 additions & 0 deletions ErrorDto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <iostream>

class ErrorDto
{
private:
bool _err;
std::string _mensajeError;
public:
ErrorDto();

void setError(bool err, std::string mensajeError);

ErrorDto getError();

std::string getErrorMensaje();

void limpiarErrores();

bool hasError();

};

21 changes: 21 additions & 0 deletions Fecha.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
#include <ctime>
#include <iostream>
#include <chrono>
#include "fecha.h"

int Fecha::getDia() {
Expand Down Expand Up @@ -46,4 +48,23 @@ std::string Fecha::getNombreDia() {
return nombres[_diaSemana];
}
return "";
}

std::string Fecha::hoy() {
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();

// Convierte el punto de tiempo actual a un objeto de tiempo local
std::time_t currentTime = std::chrono::system_clock::to_time_t(now);

// Convierte el tiempo local a una estructura tm para extraer la fecha
std::tm* localTime = std::localtime(&currentTime);

// Obtén los componentes de la fecha
_anio = localTime->tm_year + 1900; // Añade 1900 al año
_mes = localTime->tm_mon + 1; // Los meses comienzan desde 0
_dia = localTime->tm_mday; // Día del mes

// Imprime la fecha actual
std::string fecha =""+ std::to_string(_anio) + "/" + std::to_string(_mes) + "/"+ std::to_string(_dia)+"";
return fecha;
}
1 change: 1 addition & 0 deletions Fecha.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Fecha {
Fecha();
Fecha(int dia, int mes, int anio);
std::string toString();
std::string hoy();

private:
int _dia, _mes, _anio;
Expand Down
79 changes: 67 additions & 12 deletions InterfazUI.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,104 @@
#include <iostream>
#include "InterfazUI.h"
#include <string>
#include "Fecha.h"
#pragma warning (disable : 4996)

using namespace std;

#pragma region HelpersInterfaz
void header(string usuario = "") {
cout << "Sistema de Gestion" << endl;
cout << "------------------" << usuario << endl << endl;
void limpiarConsola() {
system("cls");
}
#pragma endregion

InterfazUI::InterfazUI(Sistema* sistema) : _sistema(sistema) {}

void InterfazUI::headerDinamico()
{
Fecha fecha;
string ahora = fecha.hoy();

limpiarConsola();
string usuario = _sistema->getUsuarioLogged();
bool error = _sistema->hasError();
cout << "Sistema de Gestion" << " - " << ahora << endl;
if (usuario != "") {
cout << "User: " << usuario << endl;
}
if (error) {
std::string error = _sistema->getError();
cout << "------------------" << endl;
cout << "Error: " << error << endl;
}
cout << "------------------" << endl << endl;
}
/// <summary>
/// Se controla que la opción seleccionada sea válida.
/// </summary>
bool InterfazUI::opcionesValidasMenu(int inicio, int fin, int seleccion, bool imprimir, bool admiteAtras)
{
bool error = _sistema->hasError();
if ((seleccion < inicio && !admiteAtras) || (seleccion > fin && !imprimir)) {
std::string mensaje = "Seleccione una opcion entre "+std::to_string(inicio)+" y "+std::to_string(fin);
_sistema->setError(mensaje);
return false;
}
if(error) _sistema->limpiarError();
return true;
}

//InterfazUI::InterfazUI() {}
InterfazUI::InterfazUI(Sistema* sistema) : _sistema(sistema){}

void InterfazUI::vistaLogin() {
header();
limpiarConsola();
headerDinamico();
std::string usuario;
cout << "Ingrese su nombre: ";
cin >> usuario;

_sistema->setUsuarioLogged(usuario);

system("cls");
cout << "Bienvenido " << usuario << endl;
}

void InterfazUI::menuPrincipal() {
string usuario = _sistema->getUsuarioLogged();
limpiarConsola();
string usuario = _sistema->getUsuarioLogged();
int opc;
header(usuario);
bool verificado=false;

while (!verificado) {
headerDinamico();
cout << "1) Compras - Stock" << endl;
cout << "2) Ventas" << endl;
cout << "3) ABM" << endl;
cout << "4) Reportes" << endl;
cout << "5) Configuracion" << endl;
cout << "6) Reporte" << endl;
cout << "7) Reporte" << endl;
cout << "0) Salir" << endl;
cout << "7) USUARIO" << endl;
cout << "0) Salir" << endl;
cin >> opc;
//Añadir validación opciones pantalla.
verificado = opcionesValidasMenu(1, 7, opc);
}
_sistema->setPantalla(opc);
}

void InterfazUI::subMenuCompras() {
int InterfazUI::subMenuCompras() {
string usuario = _sistema->getUsuarioLogged();
int opc;
bool verificado = false;

while (!verificado) {
headerDinamico();
cout << "1) Compra Productos" << endl;
cout << "2) Listar Productos" << endl;
cout << "3) Buscar Producto" << endl << endl;
cout << "0) <- Atras";
cin >> opc;
verificado = opcionesValidasMenu(1, 3, opc);
}
return opc;
}

void InterfazUI::subMenuVentas() {
Expand Down
7 changes: 6 additions & 1 deletion InterfazUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ class InterfazUI
public:
//InterfazUI();
InterfazUI(Sistema* sistema);

void headerDinamico();

bool opcionesValidasMenu(int inicio, int fin, int seleccion, bool imprimir = false, bool admiteAtras = true);

void vistaLogin();

void menuPrincipal();

void subMenuCompras();
int subMenuCompras();

void subMenuVentas();

Expand Down
9 changes: 7 additions & 2 deletions Sistema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ std::string Sistema::getUsuarioLogged() { return _usuarioLogged; }
void Sistema::setPantalla(int opc) { _pantalla = opc; }
int Sistema::getPantalla() { return _pantalla; }

void Sistema::setError(std::string mensaje) { _error.setError(true, mensaje); }
std::string Sistema::getError() { return _error.getErrorMensaje(); }
bool Sistema::hasError() { return _error.hasError(); }
void Sistema::limpiarError() { _error.limpiarErrores(); }

#pragma endregion

void Sistema::administrarPrograma() {
InterfazUI UI(this);
AdminLogin adm_login(this); //Facilitamos un puntero a la instancia de sistema para acceder a sus métodos.
AdminCompras adm_compras;
AdminCompra adm_compras;
AdminVentas adm_ventas;
AdminABM adm_ABM;

Expand All @@ -44,7 +49,7 @@ void Sistema::administrarPrograma() {

break;
case 2: //Submenú Compras/stock:
//adm_compras.;
UI.subMenuCompras();
break;
case 3: //Submenú Ventas:
cout << "Ventas";
Expand Down
14 changes: 8 additions & 6 deletions Sistema.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <iostream>
#include "ErrorDto.h"
using namespace std;

class Sistema
Expand All @@ -8,12 +9,7 @@ class Sistema
bool _encendido;
int _pantalla;
std::string _usuarioLogged;

//Handler de errores:
struct _error {
bool _err;
std::string _mensajeError;
};
ErrorDto _error;

public:
#pragma region Constructor
Expand All @@ -29,6 +25,12 @@ class Sistema

void setPantalla(int opc);
int getPantalla();

void setError(std::string mensaje);
std::string getError();
bool hasError();
void limpiarError();

#pragma endregion

#pragma region Métodos
Expand Down
2 changes: 2 additions & 0 deletions sistema_gestion_herrajes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<ClCompile Include="AdminVenta.cpp" />
<ClCompile Include="Archivo.cpp" />
<ClCompile Include="Categoria.cpp" />
<ClCompile Include="ErrorDto.cpp" />
<ClCompile Include="Fecha.cpp" />
<ClCompile Include="FechaHorario.cpp" />
<ClCompile Include="Horario.cpp" />
Expand All @@ -149,6 +150,7 @@
<ClInclude Include="AdminVenta.h" />
<ClInclude Include="Archivo.h" />
<ClInclude Include="Categoria.h" />
<ClInclude Include="ErrorDto.h" />
<ClInclude Include="Fecha.h" />
<ClInclude Include="FechaHorario.h" />
<ClInclude Include="Horario.h" />
Expand Down

0 comments on commit eaafcd7

Please sign in to comment.