Esempio n. 1
0
 public List<Marca> selectAll()
 {
     FbConnection conn = ConnectionFactory.getConnection();
     FbCommand query = new FbCommand(SELECTALL, conn);
     FbDataReader reader = null;
     List<Marca> lista = null;
     try
     {
         conn.Open();
         reader = query.ExecuteReader();
         while (reader.Read())
         {
             Marca marca = new Marca();
             marca.setCodMarca(int.Parse(reader["codMarca"].ToString()));
             marca.setDescricao(reader["descricao"].ToString());
             lista.Add(marca);
         }
     }
     catch (FbException ex)
     {
         ex.Message.ToString();
     }
     finally
     {
         ConnectionFactory.closeAll(conn, query, reader);
     }
     return lista;
 }
 public MainWindow()
 {
     InitializeComponent();
     Marca marca = new Marca();
     MarcaDAO marcaDAO = new MarcaDAO();
     List<Marca> marcas = null;
     marca.setCodMarca(1);
     marcas = marcaDAO.selectAll();
     foreach (Marca m in marcas)
     {
         MessageBox.Show(m.getCodMarca() + " - " + m.getDescricao());
     }
 }
Esempio n. 3
0
 public void insert(Marca marca)
 {
     FbConnection conn = ConnectionFactory.getConnection();
     FbCommand query = new FbCommand(INSERT, conn);
     try
     {
         query.Parameters.AddWithValue("@descricao", marca.getDescricao());
         conn.Open();
         query.ExecuteNonQuery();
     }
     catch (FbException ex)
     {
         ex.Message.ToString();
     }
     finally
     {
         ConnectionFactory.closeAll(conn, query);
     }
 }
Esempio n. 4
0
 public void delete(Marca marca)
 {
     FbConnection conn = ConnectionFactory.getConnection();
     FbCommand query = new FbCommand(DELETE, conn);
     try
     {
         query.Parameters.AddWithValue("@codMarca", marca.getCodMarca());
         conn.Open();
         query.ExecuteNonQuery();
     }
     catch (FbException ex)
     {
         ex.Message.ToString();
     }
     finally
     {
         ConnectionFactory.closeAll(conn, query);
     }
 }
Esempio n. 5
0
 public void setMarca(Marca marca)
 {
     this.marca = marca;
 }
Esempio n. 6
0
 public Marca selectById(Marca marca)
 {
     FbConnection conn = ConnectionFactory.getConnection();
     FbCommand query = new FbCommand(SELECTBYID, conn);
     FbDataReader reader = null;
     try
     {
         query.Parameters.AddWithValue("@codMarca", marca.getCodMarca());
         conn.Open();
         reader = query.ExecuteReader();
         if (reader.Read()) {
             marca.setCodMarca(int.Parse(reader["codMarca"].ToString()));
             marca.setDescricao(reader["descricao"].ToString());
         }
     }
     catch (FbException ex)
     {
         ex.Message.ToString();
     }
     finally
     {
         ConnectionFactory.closeAll(conn, query, reader);
     }
     return marca;
 }