private void pictOK_Click(object sender, EventArgs e) { try { //if (textTitular.Text.Equals("")) throw new Exception("Campo Titular Incompleto."); if (tURL.Text.Trim().Equals("")) { throw new Exception("Imagen Requerida."); } String titular = textTitular.Text; ImagenesDB.WePassEntities1 contexto = new ImagenesDB.WePassEntities1(); ImagenesDB.Noticias n = new ImagenesDB.Noticias(); n.titular = titular; n.fechaPublicacion = DateTime.Today; ImageConverter _imageConverter = new ImageConverter(); n.imagen = (byte[])_imageConverter.ConvertTo(pict.Image, typeof(byte[])); contexto.Noticias.Add(n); contexto.SaveChanges(); this.Close(); } catch (Exception ex) { DialogResult emCierreDialog; string mensaje = "Se ha producido un error. " + ex.Message; string caption = "Lo sentimos..."; MessageBoxButtons buttons = MessageBoxButtons.OK; emCierreDialog = MessageBox.Show(mensaje, caption, buttons); } }
private void CargarNoticias() { noticias = new List <ImagenesDB.Noticias>(); ImagenesDB.WePassEntities1 contexto = new ImagenesDB.WePassEntities1(); //noticias = contexto.Noticias.ToList(); var query = from n in contexto.Noticias orderby n.fechaPublicacion select n; noticias = query.ToList <ImagenesDB.Noticias>(); if (noticias.Count > 1) { i = 0; timer1.Start(); CargarImagen(); } }
private void bBorrarNoticia_Click(object sender, EventArgs eventArgs, ImagenesDB.Noticias n) { DialogResult emCierreDialog; string mensaje = "¿Está seguro de que quiere eliminarla?"; string caption = "¡AVISO!"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; emCierreDialog = MessageBox.Show(mensaje, caption, buttons); if (emCierreDialog == DialogResult.Yes) { ImagenesDB.WePassEntities1 contexto = new ImagenesDB.WePassEntities1(); var listaNoticias = contexto.Noticias; n = contexto.Noticias.First(x => x.idNoticia == n.idNoticia); listaNoticias.Remove(n); contexto.SaveChanges(); cargarNoticias(); } }