public Boolean actualizarAlerta(Alerta Alerta) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "Update alerta set id_aula=@id_aula,descripcion=@descripcion,fecha_evento=@fecha_evento,fecha_recordatorio=@fecha_recordatorio,observaciones=@observaciones,id_alerta_estado=@id_alerta_estado,usuario_emisor=@emisor,usuario_destinatario=@destinatario,realizada=@realizada where id_alerta=@id;"; this.command.Parameters.Add(new SqlParameter("@id_aula", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@emisor", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@destinatario", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@id_alerta_estado", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50)); this.command.Parameters.Add(new SqlParameter("@fecha_evento", SqlDbType.DateTime)); this.command.Parameters.Add(new SqlParameter("@fecha_recordatorio", SqlDbType.DateTime)); this.command.Parameters.Add(new SqlParameter("@observaciones", SqlDbType.NVarChar, 50)); this.command.Parameters.Add(new SqlParameter("@realizada", SqlDbType.Bit)); this.command.Parameters["@descripcion"].Value = Alerta.Descripcion; this.command.Parameters["@id_aula"].Value = Alerta.IdAula; this.command.Parameters["@id_alerta_estado"].Value = Alerta.IdAlertaEstado; this.command.Parameters["@fecha_evento"].Value = Alerta.FechaEvento; this.command.Parameters["@fecha_recordatorio"].Value = Alerta.FechaRecordatorio; this.command.Parameters["@observaciones"].Value = Alerta.Observaciones; this.command.Parameters["@emisor"].Value = Alerta.UsuarioEmisor; this.command.Parameters["@destinatario"].Value = Alerta.UsuarioDestinatario; this.command.Parameters["@id"].Value = Alerta.Id; this.command.Parameters["@realizada"].Value = Alerta.Realizada; this.command.ExecuteNonQuery(); this.transaction.Commit(); return true; } catch (Exception e) { try { this.transaction.Rollback(); throw new Exception("Error al Actualizar." + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al rollback accion." + ex.Message); return false; } } finally { this.connection.Close(); } }
public static void send(Usuario origen,Usuario destino,Alerta alerta) { MailMessage m = new MailMessage(); SmtpClient sc = new SmtpClient(); //mensaje try { m.From = new MailAddress("*****@*****.**", "EspaciosUAM"); m.To.Add(new MailAddress(destino.Email, destino.Nombre)); m.CC.Add(new MailAddress(origen.Email,origen.Nombre)); m.Subject = "EspaciosUAM-Reservación aula "+alerta.Aula.Referencia; m.IsBodyHtml = true; m.Body = "Reservación"; string str = "<html><body><h1>Informe de Reservación</h1><h2>Este es un correo generado automáticamente para notificar la reservación realizadas en EspaciosUAM.Favor no responder a este correo si no a los destinatarios </h2>" + "<br/>Aula:" + alerta.Aula.Referencia + "<br/>Fecha Inicio:" + alerta.FechaEvento + "<br/>FechaFin:" + alerta.FechaRecordatorio + "<br/>Decripción:" + alerta.Descripcion + "<br/>Observaciónes:" + alerta.Observaciones+ "<br/>Estado:" + alerta.DescripcionEstado+ "<br/><br/>Origen:" + origen.Nombre+ "<br/>Destino:"+destino.Nombre + "</body></html>"; AlternateView av = AlternateView.CreateAlternateViewFromString(str, null, MediaTypeNames.Text.Html); m.AlternateViews.Add(av); sc.Host = "Pod51011.outlook.com"; sc.Port = 587; sc.Credentials = new System.Net.NetworkCredential("*****@*****.**", "siga2siga"); sc.EnableSsl = true; sc.Send(m); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
private Boolean guardarNotificacion() { //obtner inputs int id_aula = aula.Id; String descripcion = this.NotDescripcion.Text; DateTime fecha_evento = Convert.ToDateTime(this.dateTimeFecha.Text); DateTime fecha_recordatorio = Convert.ToDateTime(this.dateTimeRecordatorio.Text); String observaciones = this.NotObservacion.Text; int id_alerta_estado = Convert.ToInt32(this.cbAlertaEstado.SelectedValue); int usuario_emisor = this.usuario.Cod_Usua; int usuario_destinatario = Convert.ToInt32(this.cbDestinatario.SelectedValue); Alerta alerta = new Alerta(); alerta.IdAula = id_aula; alerta.Aula = aula; alerta.Descripcion = descripcion; alerta.FechaEvento = fecha_evento; alerta.FechaRecordatorio = fecha_recordatorio; alerta.Observaciones = observaciones; alerta.IdAlertaEstado = id_alerta_estado; alerta.UsuarioEmisor = usuario_emisor; alerta.UsuarioDestinatario = usuario_destinatario; alerta.DescripcionEstado = this.cbAlertaEstado.Text; try { db.insertAlerta(alerta); destino = this.usuarios.Find(o=>o.Cod_Usua==usuario_destinatario); Email.send(usuario,destino, alerta); return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; } }
public Boolean borrarAlerta(Alerta Alerta) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "delete from alerta where id_alerta=@id;"; this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); this.command.Parameters["@id"].Value = Alerta.Id; this.command.ExecuteNonQuery(); this.transaction.Commit(); return true; } catch (Exception e) { try { this.transaction.Rollback(); throw new Exception("Error al borrar registro. " + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al rollback acción. " + ex.Message); return false; } } finally { this.connection.Close(); } }
public Boolean insertAlerta(Alerta Alerta) { this.connection.Open(); this.command = this.connection.CreateCommand(); this.transaction = this.connection.BeginTransaction(); this.command.Connection = this.connection; this.command.Transaction = this.transaction; try { this.command.CommandText = "insert into alerta(id_aula,descripcion,fecha_evento,fecha_recordatorio,observaciones,id_alerta_estado,usuario_emisor,usuario_destinatario,realizada) values(@id_aula,@descripcion,@fecha_evento,@fecha_recordatorio,@observaciones,@id_alerta_estado,@usuario_emisor,@usuario_destinatario,@realizada);" + "SELECT CAST(scope_identity() AS int)"; this.command.Parameters.Add(new SqlParameter("@id_aula", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@usuario_emisor", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@usuario_destinatario", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@id_alerta_estado", SqlDbType.Int)); this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50)); this.command.Parameters.Add(new SqlParameter("@fecha_evento", SqlDbType.DateTime)); this.command.Parameters.Add(new SqlParameter("@fecha_recordatorio", SqlDbType.DateTime)); this.command.Parameters.Add(new SqlParameter("@observaciones", SqlDbType.NVarChar, 50)); this.command.Parameters.Add(new SqlParameter("@realizada", SqlDbType.Bit)); this.command.Parameters["@descripcion"].Value = Alerta.Descripcion; this.command.Parameters["@id_aula"].Value = Alerta.IdAula; this.command.Parameters["@id_alerta_estado"].Value = Alerta.IdAlertaEstado; this.command.Parameters["@fecha_evento"].Value = Alerta.FechaEvento; this.command.Parameters["@fecha_recordatorio"].Value = Alerta.FechaRecordatorio; this.command.Parameters["@observaciones"].Value = Alerta.Observaciones; this.command.Parameters["@usuario_emisor"].Value = Alerta.UsuarioEmisor; this.command.Parameters["@usuario_destinatario"].Value = Alerta.UsuarioDestinatario; this.command.Parameters["@realizada"].Value = false; this.lastUpdated = this.command.ExecuteScalar().ToString(); this.transaction.Commit(); return true; } catch (Exception e) { try { transaction.Rollback(); throw new Exception("Error al insertar registro. " + e.Message); return false; } catch (Exception ex) { throw new Exception("Error al roolback accion. " + ex.Message); } } finally { this.connection.Close(); } }
public List<Alerta> getAlertas(int idUsuario) { SqlDataReader dataReader2 = null; List<Alerta> Alertas = new List<Alerta>(); try { string query = "Select * from alerta where usuario_destinatario=" + idUsuario; command = new SqlCommand(query, connection); command.Connection.Open(); dataReader2 = command.ExecuteReader(); while (dataReader2.Read()) { Alerta edi = new Alerta(); edi.Id = Convert.ToInt32(dataReader2["id_alerta"].ToString()); edi.IdAula = Convert.ToInt32(dataReader2["id_aula"].ToString()); edi.Descripcion = dataReader2["descripcion"].ToString(); edi.FechaEvento = Convert.ToDateTime(dataReader2["fecha_evento"].ToString()); edi.FechaRecordatorio = Convert.ToDateTime(dataReader2["fecha_recordatorio"].ToString()); edi.Observaciones = dataReader2["observaciones"].ToString(); edi.IdAlertaEstado = Convert.ToInt32(dataReader2["id_alerta_estado"]); edi.UsuarioEmisor = Convert.ToInt32(dataReader2["usuario_emisor"]); edi.UsuarioDestinatario = Convert.ToInt32(dataReader2["usuario_destinatario"]); edi.Realizada = Convert.ToBoolean(dataReader2["realizada"]); Alertas.Add(edi); } command.Connection.Close(); foreach (Alerta a in Alertas) { a.Aula = this.getAula(a.IdAula); } foreach (Alerta a in Alertas) { a.DescripcionEstado = this.getDescripcionAlertaEstado(a.IdAlertaEstado); } return Alertas; } catch (Exception e) { throw new Exception("Error al obtener datos de Alerta. " + e.Message.ToString()); } finally { command.Connection.Close(); } }