示例#1
0
        private void excluirIngrediente(object sender, EventArgs e)
        {
            int idIngrediente = Convert.ToInt32(dgIngrediente.SelectedRows[0].Cells[0].Value);

            usando = bd.produto_ingrediente.Where(f => f.id_ingrediente.Equals(idIngrediente)).FirstOrDefault();
            if (usando != null)
            {
                MessageBox.Show("Ingrediente sendo usado!");
            }
            else
            {
                var db = bd.ingrediente.Where(u => u.id.Equals(idIngrediente)).FirstOrDefault();
                bd.ingrediente.Remove(db);
                bd.SaveChanges();
                montarTabelaIngrediente();
            }
        }
示例#2
0
        private void BtnSalvarAlteracao_Click(object sender, EventArgs e)
        {
            int       idProduto   = Convert.ToInt32(dgProdutos.SelectedRows[0].Cells[0].Value);
            categoria selecionada = categorias.ElementAt(cbxCategoria.SelectedIndex);
            produto   alteracao   = new produto();

            if (String.IsNullOrWhiteSpace(txtNome.Text) && String.IsNullOrWhiteSpace(txtValor.Text))
            {
                MessageBox.Show("Não houve alteração!");
            }
            else
            {
                alteracao              = bd.produto.Single(c => c.id.Equals(idProduto));
                alteracao.nome         = txtNome.Text;
                alteracao.descricao    = txtDescricao.Text;
                alteracao.id_categoria = selecionada.id;
                alteracao.preco        = Convert.ToDecimal(txtValor.Text);
                bd.SaveChanges();
                montarTabela();
                txtNome.Clear();
                txtValor.Clear();
                txtDescricao.Clear();
                bd.SaveChanges();
                clbIngredientes.Items.Clear();
                carregaIngredientes();
                ingredientesUsados.ForEach(u =>
                {
                    produto_ingrediente novoProdIng = new produto_ingrediente()
                    {
                        id_produto     = idProduto,
                        id_ingrediente = u.id
                    };
                    bd.produto_ingrediente.Add(novoProdIng);
                    bd.SaveChanges();
                });
            }
            btnSalvarAlteracao.Visible = false;
        }
示例#3
0
        private void salvarCadastroProduto(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtNome.Text) || String.IsNullOrWhiteSpace(txtValor.Text))
            {
                MessageBox.Show("Preencha os campos!");
            }
            else
            {
                nomeUsado = bd.produto.Where(c => c.nome.Equals(txtNome.Text)).FirstOrDefault();
                if (nomeUsado == null)
                {
                    categoria selecionada = categorias.ElementAt(cbxCategoria.SelectedIndex);
                    produto   novo        = new produto()
                    {
                        nome         = txtNome.Text,
                        descricao    = txtDescricao.Text,
                        preco        = Convert.ToDecimal(txtValor.Text),
                        id_categoria = selecionada.id,
                        imagem       = caminhoFoto
                    };

                    bd.produto.Add(novo);
                    bd.SaveChanges();
                    montarTabela();
                    produto nomeProd = bd.produto.Where(u => u.nome.Equals(txtNome.Text)).FirstOrDefault();
                    ingredientesUsados.ForEach(u =>
                    {
                        produto_ingrediente novoProdIng = new produto_ingrediente()
                        {
                            id_produto     = nomeProd.id,
                            id_ingrediente = u.id
                        };
                        bd.produto_ingrediente.Add(novoProdIng);
                        bd.SaveChanges();
                    });
                    //bd.produto.ToList().ForEach(f =>
                    //{
                    //    if (txtNome.Text == f.nome)
                    //    {

                    //        ingredientesUsados.ForEach(u =>
                    //        {
                    //            produto_ingrediente novoProdIng = new produto_ingrediente()
                    //            {
                    //                id_produto = f.id,
                    //                id_ingrediente = u.id
                    //            };
                    //            bd.produto_ingrediente.Add(novoProdIng);
                    //        });
                    //    }
                    //});
                    txtNome.Clear();
                    txtValor.Clear();
                    txtDescricao.Clear();
                    bd.SaveChanges();
                    clbIngredientes.Items.Clear();
                    carregaIngredientes();
                }
                else
                {
                    MessageBox.Show("Produto ja cadastrado!");
                }
            }
        }