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()); } }
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); } }
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); } }
public void setMarca(Marca marca) { this.marca = marca; }
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; }