示例#1
0
        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);
            }
        }
示例#2
0
        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();
            }
        }