Пример #1
0
        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;
        }
Пример #2
0
        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();
        }
Пример #3
0
        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 });
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        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();
        }
Пример #6
0
        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()
                });
            }
        }
Пример #7
0
        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();
        }
Пример #8
0
        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();
            }
        }