private void dataGridView1_DoubleClick(object sender, EventArgs e) { Planta planta = new Planta(); PlantaRepositorio repositorio = new PlantaRepositorio(); int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); planta = repositorio.ObterPeloId(id); if (planta == null) { MessageBox.Show("Não foi possivel obter o registro selecionado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } lblId.Text = planta.Id.ToString(); txtNome.Text = planta.Nome; mtxtAltura.Text = planta.Altura.ToString(); mtxtPeso.Text = planta.Peso.ToString(); if (planta.Carnivora == true) { rbSim.Checked = true; } else { rbNao.Checked = true; } btnSalvar.Enabled = false; btnEditar.Enabled = true; }
private void btnApagar_Click(object sender, EventArgs e) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); PlantaRepositorio repositorio = new PlantaRepositorio(); repositorio.Apagar(id); AtualizarTabela(); }
private void AtualizarTabela() { PlantaRepositorio repositorio = new PlantaRepositorio(); string busca = txtBusca.Text; List <Planta> plantas = repositorio.ObterTodos(busca); dataGridView1.RowCount = 0; for (int i = 0; i < plantas.Count; i++) { Planta planta = plantas[i]; dataGridView1.Rows.Add(new object[] { planta.Id, planta.Nome }); } }
private void Inserir() { Planta planta = new Planta(); planta.Nome = txtNome.Text; planta.Altura = Convert.ToDecimal(mtbAltura.Text); planta.Peso = Convert.ToDecimal(mtbPeso.Text); planta.Carnivora = rbSim.Checked; PlantaRepositorio repositorio = new PlantaRepositorio(); repositorio.Inserir(planta); }
private void Inserir() { Planta planta = new Planta(); planta.Nome = txtNome.Text; planta.Altura = Convert.ToDecimal(mtxtAltura.Text); planta.Peso = Convert.ToDecimal(mtxtPeso.Text); planta.Carnivora = rbSim.Checked; PlantaRepositorio repositorio = new PlantaRepositorio(); MessageBox.Show(repositorio.Inserir(planta), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); AtualizarTabela(); }
private void AtualizarTabela() { PlantaRepositorio repopositorio = new PlantaRepositorio(); string busca = txtBuscar.Text; List <Planta> plantas = repopositorio.ObterTodos(busca); dgvPlantas.RowCount = 0; for (int i = 0; i < plantas.Count; i++) { Planta planta = plantas[i]; dgvPlantas.Rows.Add(new object[] { planta.Id, planta.Nome, planta.Altura.ToString(), planta.Peso.ToString(), planta.Carnivora.ToString() }); } }
private void btnEditar_Click(object sender, EventArgs e) { Planta planta = new Planta(); planta.Id = Convert.ToInt32(lblId.Text); planta.Nome = txtNome.Text; planta.Peso = Convert.ToDecimal(mtxtPeso.Text); planta.Altura = Convert.ToDecimal(mtxtAltura.Text); planta.Carnivora = rbSim.Checked; PlantaRepositorio repositorio = new PlantaRepositorio(); repositorio.Alterar(planta); btnSalvar.Enabled = true; btnEditar.Enabled = false; MessageBox.Show("Editado com sucesso", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); AtualizarTabela(); }
private void btnEditar_Click(object sender, EventArgs e) { PlantaRepositorio repositorio = new PlantaRepositorio(); int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value); Planta planta = repositorio.ObterPeloId(id); if (planta != null) { txtNome.Text = planta.Nome; mtbAltura.Text = planta.Altura.ToString("0.00"); mtbPeso.Text = planta.Peso.ToString("000.00"); if (planta.Carnivora == true) { rbSim.Checked = true; } else { rbNao.Checked = false; } lblID.Text = planta.Id.ToString(); } }