/// <summary> /// Ingresa un nuevo préstamo en la base de datos /// </summary> /// <param name="nuevoPrest">Préstamo a ingresar. Objeto Préstamo que contiene los datos del préstamo a ingresar</param> /// <returns>True en caso de que el préstamo se haya ingresado correctamente, false de la contrario</returns> public bool agregarPrestamo(TOPrestamo nuevoPrest) { if (conex.State != ConnectionState.Open) { conex.Open(); } String qry = "insert into prestamo (numeroContrato, paciente, responsable, fechaPrestamo, fechaEntrega, estado, idArticulo, telefono) values (@con, @pac, @res, @fecPr, @fecEn, 1, @idArt, @tel);"; MySqlCommand cmd = new MySqlCommand(qry, conex); cmd.Parameters.AddWithValue("@con", nuevoPrest.numeroContrato); cmd.Parameters.AddWithValue("@pac", nuevoPrest.paciente); cmd.Parameters.AddWithValue("@res", nuevoPrest.responsable); cmd.Parameters.AddWithValue("@fecPr", nuevoPrest.fechaPrestamo); cmd.Parameters.AddWithValue("@fecEn", nuevoPrest.fechaEntrega); cmd.Parameters.AddWithValue("@idArt", nuevoPrest.idArticulo); cmd.Parameters.AddWithValue("@tel", nuevoPrest.telefono); int result = cmd.ExecuteNonQuery(); bool prestado = articuloPrestado(nuevoPrest.idArticulo); if (conex.State != ConnectionState.Closed) { conex.Close(); } if (prestado && result > 0) { return(true); } else { return(false); } }
/// <summary> /// Retorna los datos del préstamo según su número de contrato /// </summary> /// <param name="contrato">Número de contrato del préstamo</param> /// <returns>Demás datos del préstamo</returns> public TOPrestamo obtenerPrestamoContrato(string contrato) { if (conex.State != ConnectionState.Open) { conex.Open(); } string qry = "select paciente, responsable, FechaPrestamo, FechaEntrega, estado, telefono from prestamo where NumeroContrato = @numCont;"; MySqlCommand cmd = new MySqlCommand(qry, conex); cmd.Parameters.AddWithValue("@numCont", contrato); MySqlDataReader reader = cmd.ExecuteReader(); TOPrestamo prest = new TOPrestamo(); if (reader.HasRows) { while (reader.Read()) { prest.paciente = reader.GetString(0); prest.responsable = reader.GetString(1); prest.fechaPrestamo = reader.GetDateTime(2); prest.fechaEntrega = reader.GetDateTime(3); prest.estado = reader.GetBoolean(4); prest.telefono = reader.GetString(5); } } if (conex.State != ConnectionState.Closed) { conex.Close(); } return(prest); }
/// <summary> /// Retorna los datos del préstamo según su identificador /// </summary> /// <param name="idPrestamo">Identificador numérico del préstamo</param> /// <returns>Demás datos del préstamo</returns> public TOPrestamo obtenerPrestamo(int idPrestamo) { if (conex.State != ConnectionState.Open) { conex.Open(); } String qry = "select numeroContrato, paciente, responsable, fechaPrestamo, fechaEntrega, idArticulo, telefono from prestamo where idPrestamo = @idPrest;"; MySqlCommand cmd = new MySqlCommand(qry, conex); cmd.Parameters.AddWithValue("@idPrest", idPrestamo); MySqlDataReader reader = cmd.ExecuteReader(); TOPrestamo prestamo = new TOPrestamo(); if (reader.HasRows) { while (reader.Read()) { prestamo.numeroContrato = reader.GetString(0); prestamo.paciente = reader.GetString(1); prestamo.responsable = reader.GetString(2); prestamo.fechaPrestamo = reader.GetDateTime(3); prestamo.fechaEntrega = reader.GetDateTime(4); prestamo.idArticulo = reader.GetInt32(5); prestamo.telefono = reader.GetString(6); } } if (conex.State != ConnectionState.Closed) { conex.Close(); } return(prestamo); }
/// <summary> /// Retorna los datos del préstamo según su número de contrato /// </summary> /// <param name="contrato">Número de contrato del préstamo</param> /// <returns>Demás datos del préstamo</returns> public BLPrestamo obtenerPrestamoContrato(string contrato) { TOPrestamo toPrest = daoPrestamo.obtenerPrestamoContrato(contrato); BLPrestamo prestamo = new BLPrestamo(); prestamo.paciente = toPrest.paciente; prestamo.responsable = toPrest.responsable; prestamo.fechaPrestamo = toPrest.fechaPrestamo; prestamo.fechaEntrega = toPrest.fechaEntrega; prestamo.estado = toPrest.estado; return(prestamo); }
/// <summary> /// Retorna los datos del préstamo según su identificador /// </summary> /// <param name="idPrestamo">Identificador numérico del préstamo</param> /// <returns>Demás datos del préstamo</returns> public BLPrestamo obtenerPrestamo(int idPrestamo) { TOPrestamo toPrest = daoPrestamo.obtenerPrestamo(idPrestamo); BLPrestamo prest = new BLPrestamo(); prest.numeroContrato = toPrest.numeroContrato; prest.paciente = toPrest.paciente; prest.responsable = toPrest.responsable; prest.fechaPrestamo = toPrest.fechaPrestamo; prest.fechaEntrega = toPrest.fechaEntrega; prest.idArticulo = toPrest.idArticulo; return(prest); }
/// <summary> /// Retorna una lista con el histórico de préstamos asociados con el artículo especificado /// </summary> /// <param name="idArticulo">Identificador numérico del artículo</param> /// <returns>Lista con los préstamos asociados al artículo</returns> public List <TOPrestamo> prestamosArticulo(int idArticulo) { if (conex.State != ConnectionState.Open) { conex.Open(); } string qry = "select idPrestamo, numeroContrato, paciente, responsable, fechaPrestamo, fechaEntrega, telefono from prestamo where idArticulo = @idArt;"; MySqlCommand cmd = new MySqlCommand(qry, conex); cmd.Parameters.AddWithValue("@idArt", idArticulo); MySqlDataReader reader = cmd.ExecuteReader(); List <TOPrestamo> lista = new List <TOPrestamo>(); if (reader.HasRows) { while (reader.Read()) { TOPrestamo prest = new TOPrestamo(); prest.idPrestamo = reader.GetInt32(0); prest.numeroContrato = reader.GetString(1); prest.paciente = reader.GetString(2); prest.responsable = reader.GetString(3); prest.fechaPrestamo = reader.GetDateTime(4); prest.fechaEntrega = reader.GetDateTime(5); prest.telefono = reader.GetString(6); lista.Add(prest); } } if (conex.State != ConnectionState.Closed) { conex.Close(); } return(lista); }