private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text.Length == 0)
            {
                Comestivel comestivel = new Comestivel();
                comestivel.Nome           = txtNome.Text;
                comestivel.Valor          = Convert.ToDecimal(txtValor.Text);
                comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Value);
                comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
                comestivel.Marca          = txtMarca.Text;
                ComestivelRepository repository = new ComestivelRepository();
                repository.Inserir(comestivel);
                Close();
            }
            else
            {
                Comestivel comestivel = new Comestivel();
                comestivel.Id             = Convert.ToInt32(txtCodigo.Text);
                comestivel.Nome           = txtNome.Text;
                comestivel.Valor          = Convert.ToDecimal(txtValor.Text);
                comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Value);
                comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
                comestivel.Marca          = txtMarca.Text;
                ComestivelRepository repository = new ComestivelRepository();
                repository.Update(comestivel);

                MessageBox.Show("Editado com sucesso");
                Close();
            }
        }
        private void btnApagar_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);

            ComestivelRepository repository = new ComestivelRepository();

            repository.Delete(id);
            dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);
        }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);

            ComestivelRepository repository = new ComestivelRepository();
            Comestivel           comestivel = repository.ObterPeloID(id);

            CadastroComestiveis cadastroComestiveis = new CadastroComestiveis(comestivel);

            cadastroComestiveis.ShowDialog();
        }
        private void AtualizarTabela()
        {
            ComestivelRepository repository  = new ComestivelRepository();
            List <Comestivel>    comestiveis = repository.ObterTodos();

            dataGridView1.Rows.Clear();
            for (int i = 0; i < comestiveis.Count; i++)
            {
                Comestivel comestivel = comestiveis[i];
                dataGridView1.Rows.Add(new object[]
                {
                    comestivel.Id, comestivel.Nome, comestivel.Valor,
                    comestivel.DataVencimento, comestivel.Quantidade, comestivel.Marca
                });
            }
        }