示例#1
0
        public Censura getCensura(int cod)
        {
            Censura          g       = new Censura();
            NpgsqlConnection conexao = null;

            try
            {
                conexao = ConectaDB.getConexao();
                string sql = "SELECT cod, descricao FROM tbcensura WHERE status=true " +
                             "and cod=@cod";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);
                cmd.Parameters.AddWithValue("@cod", cod);
                NpgsqlDataReader npgsqlStatement = cmd.ExecuteReader();

                while (npgsqlStatement.Read())
                {
                    g.cod       = Convert.ToInt16(npgsqlStatement["cod"]);
                    g.descricao = Convert.ToString(npgsqlStatement["descricao"]);
                }
                return(g);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
示例#2
0
 private void btnSalvar_Click_1(object sender, EventArgs e)
 {
     if (txtDescricao.Text.Length > 0)
     {
         Censura c = new Censura();
         c.Descricao = txtDescricao.Text.ToUpper();
         if (cod > 0)
         {
             c.cod = cod;
             c.editar();
             MessageBox.Show("Censura editada com sucesso");
         }
         else
         {
             c.cadastrar();
             MessageBox.Show("Censura cadastrada com sucesso");
         }
         txtDescricao.Text = "";
         btnNovoEnable();
     }
     else
     {
         MessageBox.Show("Preencha o campo");
     }
 }
示例#3
0
        public List <Censura> getCensuras(String descricao)
        {
            ArrayList        censuras = new ArrayList();
            NpgsqlConnection conexao  = null;

            try
            {
                conexao = ConectaDB.getConexao();
                string sql = "SELECT cod, descricao FROM tbcensura WHERE status=true " +
                             "and descricao like @descricao";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);
                cmd.Parameters.AddWithValue("@descricao", "%" + descricao + "%");
                NpgsqlDataReader npgsqlStatement = cmd.ExecuteReader();


                while (npgsqlStatement.Read())
                {
                    Censura g = new Censura();
                    g.cod       = Convert.ToInt16(npgsqlStatement["cod"]);
                    g.descricao = Convert.ToString(npgsqlStatement["descricao"]);
                    censuras.Add(g);
                }
                return(censuras.Cast <Censura>().OrderBy(r => r.descricao).ToList());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }