Пример #1
0
        private void salvar2(object sender, EventArgs e)
        {
            ingrediente ingredientes = new ingrediente();

            ingredientes.nome    = txtIngrediente.Text;
            ingredientes.estoque = Convert.ToInt16(numericUpDown1.Value);
            ingredientes.unidade = cbMedida.Text;
            bd.ingrediente.Add(ingredientes);
            bd.SaveChanges();
            carregarTabela();
            MessageBox.Show("Ingrediente salvo com sucesso");
            txtIngrediente.Clear();
            cbMedida.Text        = "";
            numericUpDown1.Value = 0;
        }
Пример #2
0
        private void excluir(object sender, EventArgs e)
        {
            int         ingredienteExcluir = Convert.ToInt32(tblIngredientes.SelectedRows[0].Cells[0].Value);
            ingrediente ingre = new ingrediente();

            bd.ingrediente.ToList().ForEach(i =>
            {
                if (i.id == ingredienteExcluir)
                {
                    ingre = i;
                }
            });
            bd.ingrediente.Remove(ingre);
            bd.SaveChanges();
            carregarTabela();
            txtIngrediente.Clear();
            cbMedida.Text        = "";
            numericUpDown1.Value = 0;
            MessageBox.Show("Ingrediente excluído com sucesso");
        }
Пример #3
0
        private void alterar(object sender, EventArgs e)
        {
            string      novoIngrediente = txtIngrediente.Text;
            decimal     novaQuantidade  = numericUpDown1.Value;
            string      novaUnidade     = cbMedida.Text;
            int         alterar         = Convert.ToInt32(tblIngredientes.SelectedRows[0].Cells[0].Value);
            ingrediente ingredienteNovo = new ingrediente();

            bd.ingrediente.ToList().ForEach(i =>
            {
                if (i.id == alterar)
                {
                    i.nome    = novoIngrediente;
                    i.estoque = Convert.ToInt32(novaQuantidade);
                    i.unidade = novaUnidade;
                    bd.SaveChanges();
                }
            });
            carregarTabela();
            txtIngrediente.Clear();
            cbMedida.Text        = "";
            numericUpDown1.Value = 0;
            MessageBox.Show("Ingrediente alterado com sucesso");
        }