public static void enviarCorreoNotificacion(DtoNotificaciones dto) { String descripcionSenal = RepositorioNotificaciones.ObtenerDescripcionSenal(dto); String mensaje = ""; if (descripcionSenal == "LUZ") { if (dto.Valor == 1) { mensaje = "Se ha normalizado el suministro de energía eléctrica."; } else { mensaje = "Se ha interrumpido el suministro de energía eléctrica."; } } if (descripcionSenal == "GAS") { if (dto.Valor < 500) { mensaje = "Se ha detectado una pérdida de gas."; } else { mensaje = "El nivel de gas en el ambiente, esta dentro de las condiciones normales."; } } MailMessage mail = new MailMessage(); mail.From = new System.Net.Mail.MailAddress("*****@*****.**"); mail.Subject = "Notificación SMART-HOME"; SmtpClient smtp = new SmtpClient(); smtp.Port = 587; // 465 smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("*****@*****.**", "viaje1234"); smtp.Host = "smtp.gmail.com"; //Hay que parametrizar las cuentas a enviar, y los mensajes segun señal y valor mail.To.Add(new MailAddress("*****@*****.**")); //mail.To.Add(new MailAddress("*****@*****.**")); mail.IsBodyHtml = true; string st = @"<html> <head> <title>Querido vecino</title> </head> <body> <h1>"; st += mensaje; st += @"</h1> <p>Smart-Home</p> </body> </html>"; mail.Body = st; smtp.Send(mail); }
public static void guardarNotificacion(DtoEventos evento) { DtoNotificaciones notificacion = new DtoNotificaciones(); notificacion.Id_Arduino = evento.Id_Arduino; notificacion.Id_Senal = evento.Id_Senal; notificacion.Valor = evento.Valor; notificacion.Fecha_Notificacion = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Argentina Standard Time")); RepositorioNotificaciones.Guardar(notificacion); enviarCorreoNotificacion(notificacion); }
public static List <DtoNotificaciones> ObtenerNotificaciones() { List <DtoNotificaciones> listaNotificaciones = new List <DtoNotificaciones>(); Acceso acceso = new Acceso(); try { acceso.conectarBD(); acceso.storedProcedure("PR_NOTIFICACIONES_SF"); // acceso.agregarParametros("p_apellido", parametro); SqlDataReader leerBD = acceso.leerDatos(); while (leerBD.Read()) { //Creo una entidad para guardar lo que viene de la DtoNotificaciones notificacion = new DtoNotificaciones(); notificacion.Id_Arduino = (int)leerBD["id_arduino"]; notificacion.V_Descripcion_Senal = leerBD["V_Descripcion_Senal"].ToString(); notificacion.Valor = (int)leerBD["valor"]; if (leerBD["fecha_notificacion"] != DBNull.Value) { notificacion.Fecha_Notificacion = (DateTime)leerBD["fecha_notificacion"]; } listaNotificaciones.Add(notificacion); } } catch (Exception ex) { var a = "Error message: " + ex.Message; if (ex.InnerException != null) { a = a + " Inner exception: " + ex.InnerException.Message; } a = a + " Stack trace: " + ex.StackTrace; System.ArgumentException bdEX = new System.ArgumentException("Mensaje: " + a, ex); throw bdEX; } finally { acceso.closeConexion(); } return(listaNotificaciones); }
public static void Guardar(DtoNotificaciones dtoNuevo) { Acceso acceso = new Acceso(); try { acceso.conectarBD(); acceso.storedProcedure("pr_notificaciones_g"); acceso.agregarParametros("id_arduino", dtoNuevo.Id_Arduino); acceso.agregarParametros("id_senal", dtoNuevo.Id_Senal); acceso.agregarParametros("valor", dtoNuevo.Valor); acceso.agregarParametros("fecha_notificacion", dtoNuevo.Fecha_Notificacion); acceso.executeNonQuery(); } catch (Exception ex) { var a = "Error message: " + ex.Message; if (ex.InnerException != null) { a = a + " Inner exception: " + ex.InnerException.Message; } a = a + " Stack trace: " + ex.StackTrace; System.ArgumentException bdEX = new System.ArgumentException("Mensaje: " + a, ex); throw bdEX; } finally { acceso.closeConexion(); } }
public static String ObtenerDescripcionSenal(DtoNotificaciones dtoNuevo) { String salida = ""; Acceso acceso = new Acceso(); try { acceso.conectarBD(); acceso.storedProcedure("PR_SENAL_L"); acceso.agregarParametros("id_senal", dtoNuevo.Id_Senal); SqlDataReader leerBD = acceso.leerDatos(); while (leerBD.Read()) { //Creo una entidad para guardar lo que viene de la DtoConfiguracion evento = new DtoConfiguracion(); salida = (String)leerBD["v_descripcion"]; } } catch (Exception ex) { var a = "Error message: " + ex.Message; if (ex.InnerException != null) { a = a + " Inner exception: " + ex.InnerException.Message; } a = a + " Stack trace: " + ex.StackTrace; System.ArgumentException bdEX = new System.ArgumentException("Mensaje: " + a, ex); throw bdEX; } finally { acceso.closeConexion(); } return(salida); }