示例#1
0
        private void btnDeletaReceita_Click(object sender, EventArgs e)
        {
            // Confirma se o usuário realmente deseja sair do sistema
            DialogResult apagar = MessageBox.Show("Deseja realmente excluir essa receita do banco de dados?", "Excluir receita", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);

            if (apagar.ToString().ToUpper() == "YES")
            {
                //Resgatando o objeto
                Receita receita = new Receita();
                receita.Id = idReceitaDetalhe;

                if (receita.Apagar())
                {
                    MessageBox.Show("Exclusão do ingrediente foi bem sucedida", "Exclusão realizada", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

                    //Voltando para tela de receitas.
                    TelaReceita telaReceita = new TelaReceita()
                    {
                        telaInicio = telaInicioDetalhe
                    };
                    telaReceita.Show();
                    telaInicioDetalhe.Hide();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Não foi possível excluir o ingrediente", "Erro na exclusão", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
            }
        }
示例#2
0
        private void BtnMenuReceita_Click_1(object sender, EventArgs e)
        {
            TelaReceita telaReceita = new TelaReceita()
            {
                telaInicio = this
            };                  // Formulário "public" recebe a tela desta classe

            telaReceita.Show(); // Exibe a tela de receitas com o clique do usuário
            this.Hide();        // Esconde a tela inicial do programa
        }
示例#3
0
        private void BtnCancelaAlteracao_Click(object sender, EventArgs e)
        {
            TelaReceita telaReceita = new TelaReceita()
            {
                telaInicio = telaInicioAltera
            };

            telaReceita.Show();
            telaInicioAltera.Hide();
            this.Hide();
        }
示例#4
0
        private void BtnCancelaRegistro_Click(object sender, EventArgs e)
        {
            TelaReceita telaReceita = new TelaReceita()
            {
                telaInicio = telaInicioRegistro
            };

            telaReceita.Show();
            telaInicioRegistro.Hide();
            this.Hide();
        }
示例#5
0
        private void btnVoltaReceita_Click(object sender, EventArgs e)
        {
            TelaReceita telaReceita = new TelaReceita()
            {
                telaInicio = telaInicioDetalhe
            };

            telaReceita.Show();
            telaInicioDetalhe.Hide();
            this.Hide();
        }
示例#6
0
        private void BtnConfirmaRegistro_Click(object sender, EventArgs e)
        {
            try
            {
                if ((!txtNomeReceita.Text.Equals("")) && //nenhum valor pode ficar em branco.
                    (!cmbDificuldadeRegistroReceita.SelectedItem.Equals("")) &&
                    (!txtTempoPreparo.Text.Equals("")) &&
                    (!txtRendimentoReceita.Text.Equals("")) &&
                    (!richTxtModoPreparo.Text.Equals("")) &&
                    (!cmbCategoriaReceita.SelectedItem.ToString().Equals(""))
                    )
                {
                    //Criando o objeto
                    Receita receita = new Receita();
                    //receita.Ingrediente = new Ingrediente();
                    //Atribuindo novos valores.
                    receita.Nome            = Convert.ToString(txtNomeReceita.Text);
                    receita.Porcoes         = double.Parse(txtRendimentoReceita.Text.ToString());
                    receita.TempoPreparacao = int.Parse(txtTempoPreparo.Text.ToString());
                    receita.Categoria       = Convert.ToString(cmbCategoriaReceita.SelectedItem);
                    receita.Dificuldade     = int.Parse(cmbDificuldadeRegistroReceita.SelectedItem.ToString());
                    receita.Preparo         = Convert.ToString(richTxtModoPreparo.Text);

                    double valorTotal = 0;

                    if (receita.Cadastrar())
                    {
                        foreach (DataGridViewRow row in dataGridSelecaoIngrediente.Rows)
                        {
                            if (Convert.ToBoolean(row.Cells["columnSelecaoIngrediente"].Value) == true &&
                                receita.ObterReceita()
                                )
                            {
                                //Atribuindo os valores para o objeto receita.ingrediente
                                receita.Ingrediente.Id                 = int.Parse(row.Cells["columnIdIngrediente"].Value.ToString());
                                receita.Ingrediente.Quantidade         = double.Parse(row.Cells["columnQuantidadeIngrediente"].Value.ToString());
                                receita.Ingrediente.UnidadeMedidaPreco = row.Cells["columnUnidadeIngrediente"].Value.ToString();
                                receita.Ingrediente.Preco              = double.Parse(row.Cells["columnValorIngrediente"].Value.ToString());

                                receita.CadastrarIngrediente();
                                valorTotal += receita.Ingrediente.Preco;
                            }
                        }
                        //Cadastrando o custo total da receita.
                        //MessageBox.Show("ID do item cadastrado: "+receita.Id.ToString());//Tentando rastrear onde o codigo está falhando.
                        receita.Custo = valorTotal;
                        receita.AlterarCusto();

                        MessageBox.Show("Cadastro de receita bem sucedido.");
                        TelaReceita telaReceita = new TelaReceita()
                        {
                            telaInicio = telaInicioRegistro
                        };
                        telaReceita.Show();
                        telaInicioRegistro.Hide();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Não foi possível cadastrar a nova receita", "Erro no registro", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                    }
                }
                else
                {
                    MessageBox.Show("Todos os campos devem ser preenchidos", "Erro no registro", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível cadastrar a nova receita\n" + ex.Message, "Erro no registro", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            }
        }
示例#7
0
        private void BtnAlteraReceita_Click(object sender, EventArgs e)
        {
            try
            {
                if ((!txtNomeReceita.Text.Equals("")) && //nenhum valor pode ficar em branco.
                    (!cmbDificuldadeReceita.SelectedItem.Equals("")) &&
                    (!txtTempoPreparo.Text.Equals("")) &&
                    (!txtRendimentoReceita.Text.Equals("")) &&
                    (!richTxtModoPreparo.Text.Equals("")) &&
                    (!cmbCategoriaReceita.SelectedItem.ToString().Equals(""))
                    )
                {
                    //Resgatando o objeto
                    Receita receita = new Receita();
                    receita.Id = idReceitaDetalhe;

                    //Atribuindo novos valores ao objeto.
                    receita.Nome            = txtNomeReceita.Text;
                    receita.Custo           = double.Parse(txtValorReceita.Text);
                    receita.Porcoes         = double.Parse(txtRendimentoReceita.Text);
                    receita.TempoPreparacao = int.Parse(txtTempoPreparo.Text);
                    receita.Categoria       = cmbCategoriaReceita.SelectedItem.ToString();
                    receita.Dificuldade     = int.Parse(cmbDificuldadeReceita.SelectedItem.ToString());
                    receita.Preparo         = richTxtModoPreparo.Text;

                    if (receita.Alterar())                                               //Altera o valor dos dados primários
                    {
                        foreach (DataGridViewRow row in dataGridSelecaoIngrediente.Rows) //Altera os dados da lista de ingrediente.
                        {
                            if (Convert.ToBoolean(row.Cells["columnSelecaoIngrediente"].Value) == false)
                            { // Tirar ingrediente que estava cadastrado na receita e foi retirado pelo usuário.
                              // MessageBox.Show("Apagando ingredientes na lista da receita.");
                                receita.ApagarIngrediente();
                            }
                            else if (Convert.ToBoolean(row.Cells["columnSelecaoIngrediente"].Value) == true)
                            {
                                //Criando o  objeto.
                                // receita.ObterReceita();

                                //Atribuindo os valores para o objeto receita.ingrediente
                                receita.Ingrediente.Id                 = int.Parse(row.Cells["columnIdIngrediente"].Value.ToString());
                                receita.Ingrediente.Quantidade         = double.Parse(row.Cells["columnQuantidadeIngrediente"].Value.ToString());
                                receita.Ingrediente.UnidadeMedidaPreco = row.Cells["columnUnidadeIngrediente"].Value.ToString();
                                receita.Ingrediente.Preco              = double.Parse(row.Cells["columnValorIngrediente"].Value.ToString());

                                if (receita.ConfirmarIngredientesSelecionados())
                                {// Muda valores de item que ja está cadastrado previamente na receita.
                                 // MessageBox.Show("Alterando valor de ingredientes na lista.");
                                    receita.AlterarListaIngredientes();
                                    ;
                                }
                                else
                                {//Cadastra novos ingredientes.
                                    receita.CadastrarIngrediente();
                                    // MessageBox.Show("cadastrando novos itens itens.");
                                }
                            }
                        }

                        MessageBox.Show("Alteração realizada com sucesso", "Alteração realizada", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                        TelaReceita telaReceita = new TelaReceita()
                        {
                            telaInicio = telaInicioDetalhe
                        };
                        telaInicioDetalhe.Hide();
                        telaReceita.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Não foi possível alterar os dados", "Erro na alteração", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                    }
                }
                else
                {
                    MessageBox.Show("Todos os campos devem ser preenchidos", "Erro na alteração", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível alterar os dados\n" + ex.Message, "Erro na alteração", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }
        }