Exemplo n.º 1
0
        public CadastroNoticia listarNoticia(int id)
        {
            conn = classeConexão.obterConexao();
            if (conn.State == ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand("select * from Noticia where idNoticia = @id", conn);
                cmd.Parameters.AddWithValue("@id", id);

                try
                {
                    CadastroNoticia a      = new CadastroNoticia();
                    SqlDataReader   reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        a.setId(id);

                        a.setId(int.Parse(reader[0].ToString()));
                        a.setTitulo(reader[1].ToString());
                        a.setDescricao(reader[2].ToString());
                        a.setData(DateTime.Parse(reader[3].ToString()));
                        a.setLink(reader[4].ToString());
                        return(a);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Erro: " + error);

                    return(null);
                }
                finally
                {
                    classeConexão.fecharConexao();
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private void btnCad_Click(object sender, EventArgs e)
        {
            if (!(txtTitulo.Text == "" || txtDesc.Text == "" || txtLink.Text == ""))
            {
                a.setTitulo(txtTitulo.Text);
                a.setDescricao(txtDesc.Text);
                a.setLink(txtLink.Text);
                c.criarNoticia(a);
                foreach (string h in clTags.CheckedItems)
                {
                    d.setNome(h.ToString());
                    c.associarTag(d, a);
                }

                txtDesc.Clear();
                txtLink.Clear();
                txtTitulo.Clear();
            }
            else
            {
                MessageBox.Show("Erro", "preencha todas os campos");
            }
            MessageBox.Show("Registro inserido com sucesso!");
        }