static void Main(string[] args) { DaoEstadoCuenta daoEstadoCuenta = new DaoEstadoCuenta(); daoEstadoCuenta.Servidor = "http://Localhost:9090"; daoEstadoCuenta.BaseDatos = "Prueba"; PlantillaEstadoCuenta plantilla = new PlantillaEstadoCuenta(); plantilla.Estado = false; plantilla.FechaRegistro = System.DateTime.Now; plantilla.Mesaje = "Plantilla Demo 3333"; plantilla.NumeroCredito = 11112; plantilla.NumeroIdentificacion = 11111112; plantilla.RutaCorreoPlantilla ="w:\\"; plantilla.RutaPlantilla = "d:\\"; string mensaje; daoEstadoCuenta.InsertarEstadoCuenta(plantilla,out mensaje); List<PlantillaEstadoCuenta> lista = daoEstadoCuenta.Consulta(11111112, 11112); // bool resultado = daoEstadoCuenta.EliminarEstadoCuenta(plantilla,out mensaje ); PlantillaEstadoCuenta plbus; bool encontrado = daoEstadoCuenta.BusquedaEstadoDeCuenta(11111111, 11111, System.DateTime.Now,out plbus); EstadoCuentaDatos datos = new EstadoCuentaDatos(); DateTime fecha = new DateTime(2014,2,5); datos.ObtenerInsumosPlantilla(33, fecha); GenerarPlantillas generarPlantilla = new GenerarPlantillas(fecha,33); generarPlantilla.PublicarEstadoCuenta += delegate { Console.WriteLine("PlantillaGenerada.............."); }; generarPlantilla.ObtenerInsumos(); Console.ReadLine(); }
/// <summary> /// metodo que valida la informacion de la plantilla antes de enviarlo a la clase Dao /// </summary> public void Insertar(PlantillaEstadoCuenta plantilla) { if (this.PlantillaEstadoCuenta.FechaRegistro == DateTime.MinValue || this.PlantillaEstadoCuenta.FechaRegistro == DateTime.MaxValue || this.PlantillaEstadoCuenta.Estado == false || this.PlantillaEstadoCuenta.NumeroCredito == 0 || this.PlantillaEstadoCuenta == null || this.PlantillaEstadoCuenta.NumeroIdentificacion == 0 || this.PlantillaEstadoCuenta.NumeroIdentificacion == null || this.PlantillaEstadoCuenta.RutaPlantilla == string.Empty || this.PlantillaEstadoCuenta.RutaPlantilla == null || this.PlantillaEstadoCuenta.Mesaje == string.Empty || this.PlantillaEstadoCuenta.Mesaje == null) { throw new Exception("Todos los valores de la la plantilla estado de cuenta deben tener un valor valido."); } else { try { IApplicationContext ctx = ContextRegistry.GetContext(); // aca se realiza el proceso de insercion de los datos IDaoInsertar DaoBaseDatos = ctx.GetObject("MotorDB") as IDaoInsertar; DaoBaseDatos.Insertar(plantilla); } catch (ExcepcionDatosEstadoCuenta excepcion) { throw excepcion; } catch (Exception exepcion) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Se presentó un error no controlado en la clase LogicaEstadoCuenta, en el método Insertar()."); mensajeError.Append(" Detalle del error " + exepcion.Message); throw new ExcepcionLogicaEstadoCuenta(mensajeError.ToString(), exepcion); } } }
/// <summary> /// Metodo encargado de insertar la información de una plantilla de estado cuenta /// </summary> /// <param name="estadoCuenta"></param> public void Insertar(PlantillaEstadoCuenta estadoCuenta) { try { StringBuilder comandoInsert = new StringBuilder(); comandoInsert.Append(" INSERT INTO ESTADOCUENTA "); comandoInsert.Append("(RUTA_PLANTILLA, FECHA_REGISTRO,NUMERO_IDENTIFICACION, NUMERO_CREDITO, MENSAJE, RUTACORREO, FORMATO) "); comandoInsert.Append(" VALUES "); comandoInsert.Append(" (:RUTA_PLANTILLA, trunc(:FECHA_REGISTRO), :NUMERO_IDENTIFICACION, :NUMERO_CREDITO, :MENSAJE,:RUTACORREO, :FORMATO) "); using (SqlConnection conexion = new SqlConnection(this.CadenaConexion)) { using (SqlCommand comando = new SqlCommand(comandoInsert.ToString(), conexion)) { SqlParameter parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.NVarChar; parametro.ParameterName = ":RUTA_PLANTILLA"; parametro.Value = estadoCuenta.RutaPlantilla; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.Date; parametro.ParameterName = ":FECHA_REGISTRO"; parametro.Value = estadoCuenta.FechaRegistro; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.Decimal; parametro.ParameterName = ":NUMERO_IDENTIFICACION"; parametro.Value = estadoCuenta.NumeroIdentificacion; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.Decimal; parametro.ParameterName = ":NUMERO_CREDITO"; parametro.Value = estadoCuenta.NumeroCredito; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.NVarChar; parametro.ParameterName = ":MENSAJE"; parametro.Value = estadoCuenta.Mesaje; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.NVarChar; parametro.ParameterName = ":RUTACORREO"; parametro.Value = estadoCuenta.Mesaje; comando.Parameters.Add(parametro); parametro = new SqlParameter(); parametro.SqlDbType = System.Data.SqlDbType.NVarChar; parametro.ParameterName = ":FORMATO"; parametro.Value = estadoCuenta.Mesaje; comando.Parameters.Add(parametro); conexion.Open(); comando.ExecuteNonQuery(); conexion.Close(); } } } catch (SqlException excepcion) { StringBuilder mensajeError = this.ConstruyeMensajeError(estadoCuenta); mensajeError.Append(excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } catch (Exception excepcion) { StringBuilder mensajeError = this.ConstruyeMensajeError(estadoCuenta); mensajeError.Append(excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } }
/// <summary> /// Método que convierte el objeto OracleDataReader en una lista de Objetos /// </summary> /// <param name="resultado"></param> /// <returns></returns> private List<PlantillaEstadoCuenta> MapeoDataReaderPlantillaEstadoCuenta(SqlDataReader resultado) { int numeroFila = 1; List<PlantillaEstadoCuenta> listaEstadoCuenta = new List<PlantillaEstadoCuenta>(); try { while (resultado.Read()) { PlantillaEstadoCuenta plantilla = new PlantillaEstadoCuenta(); plantilla.RutaPlantilla = resultado.GetValue(0).ToString(); plantilla.FechaRegistro = DateTime.Parse(resultado.GetValue(1).ToString()); plantilla.NumeroIdentificacion = decimal.Parse(resultado.GetValue(2).ToString()); plantilla.NumeroCredito = decimal.Parse(resultado.GetValue(3).ToString()); plantilla.Mesaje = resultado.GetValue(4).ToString(); listaEstadoCuenta.Add(plantilla); numeroFila = numeroFila + 1; } } catch (Exception excepcion) { string mensajeError = "Error al momento de convertir registro de la consulta a objeto plantilla. en el registro " + numeroFila + "Descripción del error: " + excepcion.Message; throw new Exception(mensajeError, excepcion); } return listaEstadoCuenta; }
/// <summary> /// Construye un mensaje de error para detallar apropiadamente el mensaje de error /// </summary> /// <param name="plantillaEstadoCuenta"></param> /// <returns></returns> private StringBuilder ConstruyeMensajeError(PlantillaEstadoCuenta plantillaEstadoCuenta) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Error presentado en la clase DaoEstadoCuenta al momento de insertar un registro en base de datos. "); mensajeError.Append("el registro Posee los siguientes Datos. Ruta: " + plantillaEstadoCuenta.RutaPlantilla + ", "); mensajeError.Append("número de identificación " + plantillaEstadoCuenta.NumeroIdentificacion + ", número credito" ); mensajeError.Append(plantillaEstadoCuenta.NumeroCredito + ", fecha " + plantillaEstadoCuenta.FechaRegistro.ToString("YYYY/MM/DD")); mensajeError.Append(". Detalle del error: " ); return mensajeError; }
/// <summary> /// Metodo que actualiza la información de un estado de cuenta. /// </summary> /// <param name="plantilla"></param> public bool ActualizarEstadoCuenta(PlantillaEstadoCuenta plantilla, out string mensaje) { mensaje = string.Empty; bool actualizacion = false; try { PlantillaEstadoCuenta plantillaBusqueda; bool resultadoBusqueda = this.BusquedaEstadoDeCuenta(plantilla.NumeroIdentificacion, plantilla.NumeroCredito, plantilla.FechaRegistro, out plantillaBusqueda); if (resultadoBusqueda) { using (DocumentStore almacenamientoNsq = new DocumentStore()) { almacenamientoNsq.Url = this.Servidor; almacenamientoNsq.DefaultDatabase = this.BaseDatos; almacenamientoNsq.Initialize(); using (var session = almacenamientoNsq.OpenSession()) { PlantillaEstadoCuenta plantillaModificar; plantillaModificar = session.Load<PlantillaEstadoCuenta>("PlantillaEstadoCuentas/" + plantillaBusqueda.Id.ToString()); plantillaModificar.Estado = plantilla.Estado; plantillaModificar.FechaRegistro = plantilla.FechaRegistro; plantillaModificar.Mesaje = plantilla.Mesaje; plantillaModificar.NumeroCredito = plantilla.NumeroCredito; plantillaModificar.NumeroIdentificacion = plantilla.NumeroIdentificacion; plantillaModificar.RutaCorreoPlantilla = plantilla.RutaCorreoPlantilla; plantillaModificar.RutaPlantilla = plantilla.RutaPlantilla; session.SaveChanges(); actualizacion = true; } } } else { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("No existe una plantilla registrada para el numero de identificación "); mensajeError.Append(plantilla.NumeroIdentificacion); mensajeError.Append(" el numero de crédito "); mensajeError.Append(plantilla.NumeroCredito); mensajeError.Append(" y fecha "); mensajeError.Append(plantilla.FechaRegistro.ToString("yyy/MM/dd")); mensaje = mensajeError.ToString(); } } catch (Exception excepcion) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Se presento un error en la clase DaoEstadoCuenta "); mensajeError.Append(" para acceso NoSQl en el metodo EliminarEstadoCuenta "); mensajeError.Append(". Detalle del error: " + excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } return actualizacion; }
/// <summary> /// Metodo que inserta una entidad estado de cuenta en la base de datos no relacional. /// </summary> /// <param name="plantilla">Información del estado de cuenta.</param> /// <param name="mensaje">Mensaje con el detalle del error.</param> /// <returns>Verdadero o False según el resultado de la operación.</returns> public bool InsertarEstadoCuenta(PlantillaEstadoCuenta plantilla, out string mensaje) { mensaje = string.Empty; bool insercion = false; try { using (DocumentStore almacenamientoNsq = new DocumentStore()) { almacenamientoNsq.Url = this.Servidor; almacenamientoNsq.DefaultDatabase = this.BaseDatos; almacenamientoNsq.Initialize(); PlantillaEstadoCuenta plantillaBusqueda; if (!this.BusquedaEstadoDeCuenta(plantilla.NumeroIdentificacion, plantilla.NumeroCredito, plantilla.FechaRegistro, out plantillaBusqueda)) { using (var session = almacenamientoNsq.OpenSession()) { session.Store(plantilla); session.SaveChanges(); insercion = true; } } else { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Ya existe una plantilla registrada para el numero de identificación "); mensajeError.Append(plantilla.NumeroIdentificacion); mensajeError.Append(" el numero de crédito "); mensajeError.Append(plantilla.NumeroCredito); mensajeError.Append(" y fecha "); mensajeError.Append(plantilla.FechaRegistro.ToString("yyy/MM/dd")); mensaje = mensajeError.ToString(); } } } catch (Exception excepcion) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Se presento un error en la clase DaoEstadoCuenta "); mensajeError.Append(" para acceso NoSQl en el metodo Insertar "); mensajeError.Append(". Detalle del error: " + excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } return insercion; }
/// <summary> /// Metodo que elimina la información de un estado de cuenta en base de datos. /// </summary> /// <param name="plantilla">Informacion del estado de cuenta a borrar.</param> public bool EliminarEstadoCuenta(PlantillaEstadoCuenta plantilla, out string mensaje) { bool eliminar = false; mensaje = string.Empty; try { PlantillaEstadoCuenta plantillaBusqueda; bool resultadoBusqueda = this.BusquedaEstadoDeCuenta(plantilla.NumeroIdentificacion, plantilla.NumeroCredito, plantilla.FechaRegistro, out plantillaBusqueda); if (resultadoBusqueda) { using (DocumentStore almacenamientoNsq = new DocumentStore()) { almacenamientoNsq.Url = this.Servidor; almacenamientoNsq.DefaultDatabase = this.BaseDatos; almacenamientoNsq.Initialize(); using (var session = almacenamientoNsq.OpenSession()) { session.Advanced.DocumentStore.DatabaseCommands.Delete("PlantillaEstadoCuentas/" + plantillaBusqueda.Id.ToString(), null); session.SaveChanges(); eliminar = true; } } } else { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("No existe una plantilla registrada para el numero de identificación "); mensajeError.Append(plantilla.NumeroIdentificacion); mensajeError.Append(" el numero de crédito "); mensajeError.Append(plantilla.NumeroCredito); mensajeError.Append(" y fecha "); mensajeError.Append(plantilla.FechaRegistro.ToString("yyy/MM/dd")); mensaje = mensajeError.ToString(); } } catch (Exception excepcion) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Se presento un error en la clase DaoEstadoCuenta "); mensajeError.Append(" para acceso NoSQl en el metodo EliminarEstadoCuenta "); mensajeError.Append(". Detalle del error: " + excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } return eliminar; }
/// <summary> /// Método que busca un estado de cuenta en todo el repositorio /// </summary> /// <param name="identificacion">Número de identificación del cliente</param> /// <param name="credito">Número de credito del cliente.</param> /// <param name="fecha">Fecha de publicación del documento estado de cuenta.</param> /// <returns>Lista de documentos estados de cuenta.</returns> public bool BusquedaEstadoDeCuenta(decimal identificacion, decimal credito, DateTime fecha, out PlantillaEstadoCuenta resultaPlantilla) { resultaPlantilla = new PlantillaEstadoCuenta(); bool resultado = false; try { using (DocumentStore almacenamientoNsq = new DocumentStore()) { almacenamientoNsq.Url = this.Servidor; almacenamientoNsq.DefaultDatabase = this.BaseDatos; almacenamientoNsq.Initialize(); using (var session = almacenamientoNsq.OpenSession()) { int nroRegistros = (from plantilla in session.Query<PlantillaEstadoCuenta>() where plantilla.NumeroIdentificacion == identificacion && plantilla.NumeroCredito == credito && fecha.Day == plantilla.FechaRegistro.Day && fecha.Month == plantilla.FechaRegistro.Month && fecha.Year == plantilla.FechaRegistro.Year select plantilla).Count(); if (nroRegistros == 1) { resultado = true; resultaPlantilla = (from plantilla in session.Query<PlantillaEstadoCuenta>() where plantilla.NumeroIdentificacion == identificacion && plantilla.NumeroCredito == credito && fecha.Day == plantilla.FechaRegistro.Day && fecha.Month == plantilla.FechaRegistro.Month && fecha.Year == plantilla.FechaRegistro.Year select plantilla).First(); } else if (nroRegistros > 1) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Existe mas de una plantilla por el criterio de busqueda."); throw new Exception(mensajeError.ToString()); } } } } catch (Exception excepcion) { StringBuilder mensajeError = new StringBuilder(); mensajeError.Append("Se presento un error en la clase DaoEstadoCuenta "); mensajeError.Append(" para acceso NoSQl en el metodo BusquedaEstadoCuenta "); mensajeError.Append(". Detalle del error: " + excepcion.Message); throw new ExcepcionDatosEstadoCuenta(mensajeError.ToString(), excepcion); } return resultado; }
/// <summary> /// Constructor de la clase /// </summary> /// <param name="plantilla"></param> public LogicaEstadoCuenta(PlantillaEstadoCuenta plantilla) { this.PlantillaEstadoCuenta = plantilla; }