Example #1
0
        public VerNoticia(int id, bool p)
        {
            InitializeComponent();
            this.id  = id;
            permisos = p;

            Noticia n = new Noticia(id);

            label1.Text = n.titulo;
            try
            {
                label1.Text = label1.Text.Substring(0, 45) + "...";
            } catch (Exception ex)
            {
            }

            textBox1.Text = "Fecha de publicación: " + n.fecha + "\r\n" + "\r\n" + n.texto;
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("¿Seguro que quieres eliminar la noticia?", "Confirmación", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    var selectedCell = dataGridView1.SelectedCells[0];
                    int id           = (int)dataGridView1.Rows[selectedCell.RowIndex].Cells[1].Value;

                    Noticia.deleteNoticia(id);

                    actualizar();
                } catch (Exception ex)
                {
                }
            }
        }
Example #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "" || textBox2.Text == "")
     {
         MessageBox.Show("No se pueden dejar campos vacíos.", "Alerta", MessageBoxButtons.OK);
     }
     else
     {
         try
         {
             Noticia.subirNoticia(textBox1.Text, textBox2.Text);
             MessageBox.Show("Noticia creada.", "Alerta", MessageBoxButtons.OK);
             this.Close();
         } catch (Exception ex)
         {
             MessageBox.Show("¡Ha habido un error! Quizás has añadido un caracter no soportado o un título/cuerpo de noticia demasiado extenso.", "Error", MessageBoxButtons.OK);
         }
     }
 }
Example #4
0
        private void prepararNoticias()
        {
            lNoticias.Visible = false;
            panel1.Visible    = false;
            panel2.Visible    = false;
            panel3.Visible    = false;

            try
            {
                List <Noticia> lista = Noticia.listaNoticias();

                int len = lista.Count();

                if (len > 0)
                {
                    lNoticias.Visible = true;
                    panel1.Visible    = true;

                    idNoticia1  = lista[0].id;
                    label2.Text = lista[0].titulo;
                    try
                    {
                        label2.Text = lista[0].titulo.Substring(0, 28) + "...";
                    } catch (Exception ex)
                    {
                    }

                    label3.Text = Regex.Replace(lista[0].texto, ".{42}", "$0\n");
                    try
                    {
                        label3.Text = label3.Text.Substring(0, 126) + "...";
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (len > 1)
                {
                    panel2.Visible = true;
                    idNoticia2     = lista[1].id;

                    label5.Text = lista[1].titulo;
                    try
                    {
                        label5.Text = lista[1].titulo.Substring(0, 28) + "...";
                    }
                    catch (Exception ex)
                    {
                    }

                    label4.Text = Regex.Replace(lista[1].texto, ".{42}", "$0\n");
                    try
                    {
                        label4.Text = label4.Text.Substring(0, 126) + "...";
                    }
                    catch (Exception ex)
                    {
                    }
                }
                if (len > 2)
                {
                    panel3.Visible = true;
                    idNoticia3     = lista[2].id;

                    label7.Text = lista[2].titulo;
                    try
                    {
                        label7.Text = lista[2].titulo.Substring(0, 28) + "...";
                    }
                    catch (Exception ex)
                    {
                    }

                    label6.Text = Regex.Replace(lista[2].texto, ".{42}", "$0\n");
                    try
                    {
                        label6.Text = label6.Text.Substring(0, 126) + "...";
                    }
                    catch (Exception ex)
                    {
                    }
                }
            } catch (Exception exG)
            {
            }
        }