コード例 #1
0
        private void TelaDetalheIngrediente_Load(object sender, EventArgs e)
        {
            try
            {
                //Preenchendo o combobox
                cboUnidadeIngrediente.DataSource = new string[] {
                    "g",
                    "kg",
                    "ml",
                    "l",
                    "un"
                };
                //Resgatando o objeto
                Ingrediente ingrediente = new Ingrediente();
                ingrediente.Id = idIngredienteDetalhe;

                if (ingrediente.ObterIngrediente())
                {
                    txtNomeIngrediente.Text            = ingrediente.Nome;
                    txtValorIngrediente.Text           = ingrediente.Preco.ToString();
                    txtQuantidadeIngrediente.Text      = ingrediente.Quantidade.ToString();
                    cboUnidadeIngrediente.SelectedItem = ingrediente.UnidadeMedidaPreco;
                }
                else
                {
                    MessageBox.Show("Não foi possível carregar todos os dados do ingrediente", "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível carregar todos os dados do ingrediente\n" + ex.Message, "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }
        }
コード例 #2
0
        private void BtnDeletaIngrediente_Click(object sender, EventArgs e)
        {
            // Confirma se o usuário realmente deseja sair do sistema
            DialogResult apagar = MessageBox.Show("Deseja realmente excluir esse ingrediente do banco de dados?", "Excluir ingrediente", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);

            if (apagar.ToString().ToUpper() == "YES")
            {
                //Resgatando o objeto
                Ingrediente ingrediente = new Ingrediente();
                ingrediente.Id = idIngredienteDetalhe;
                if (ingrediente.Apagar())
                {
                    MessageBox.Show("Exclusão do ingrediente foi bem sucedida", "Exclusão realizada", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

                    //Voltando para tela de ingredientes.
                    TelaIngrediente telaIngrediente = new TelaIngrediente()
                    {
                        telaInicio = telaInicialDetalhe
                    };
                    telaIngrediente.Show();
                    telaInicialDetalhe.Hide();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Não foi possível excluir o ingrediente", "Erro na exclusão", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
            }
        }
コード例 #3
0
        private void TelaIngrediente_Load(object sender, EventArgs e)
        {
            try
            {
                Ingrediente     ingrediente = new Ingrediente();
                MySqlDataReader reader      = ingrediente.Listar();

                if (reader != null && (reader.HasRows))
                {
                    while (reader.Read())
                    {
                        int n = dataGridIngrediente.Rows.Add();
                        //Dados que serão colocados no datagrid.
                        dataGridIngrediente.Rows[n].Cells["txtColumnIdIngrediente"].Value         = reader["id"];
                        dataGridIngrediente.Rows[n].Cells["txtColumnNomeIngrediente"].Value       = reader["nome"];
                        dataGridIngrediente.Rows[n].Cells["txtColumnValorIngrediente"].Value      = reader["preco"];
                        dataGridIngrediente.Rows[n].Cells["txtColumnUnidadeIngrediente"].Value    = reader["unidade"];
                        dataGridIngrediente.Rows[n].Cells["txtColumnQuantidadeIngrediente"].Value = reader["quantidade"];
                    }
                    //Ordenando pela coluna nome do ingrediente.
                    DataGridViewColumn columnToSort = dataGridIngrediente.Columns["txtColumnNomeIngrediente"];
                    dataGridIngrediente.Sort(columnToSort, ListSortDirection.Ascending);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível carregar todos os dados do ingrediente\n" + ex.Message, "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }
        }
コード例 #4
0
        private void BtnAlteraIngrediente_Click_1(object sender, EventArgs e)
        {
            //Resgatando o objeto
            Ingrediente ingrediente = new Ingrediente();

            ingrediente.Id = idIngredienteDetalhe;

            //Atribuindo novos valores.
            ingrediente.Nome               = txtNomeIngrediente.Text;
            ingrediente.Preco              = double.Parse(txtValorIngrediente.Text);
            ingrediente.Quantidade         = double.Parse(txtQuantidadeIngrediente.Text);
            ingrediente.UnidadeMedidaPreco = cboUnidadeIngrediente.SelectedItem.ToString();

            if ((!txtNomeIngrediente.Text.Equals("")) &&
                (!txtValorIngrediente.Text.Equals("")) &&
                (!txtQuantidadeIngrediente.Text.Equals("")) &&
                (!cboUnidadeIngrediente.SelectedItem.ToString().Equals(""))
                )
            {
                if (ingrediente.Alterar())
                {
                    MessageBox.Show("Alteração realizada com sucesso", "Alteração realizada", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                    TelaIngrediente telaIngrediente = new TelaIngrediente()
                    {
                        telaInicio = telaInicialDetalhe
                    };
                    telaIngrediente.Show();
                    telaInicialDetalhe.Hide();
                    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);
            }
        }
コード例 #5
0
        private void BtnConfirmaRegistro_Click(object sender, EventArgs e)
        {
            //Resgatando o objeto
            Ingrediente ingrediente = new Ingrediente();

            if ((!txtNomeIngrediente.Text.Equals("")) &&
                (!txtValorIngrediente.Text.Equals("")) &&
                (!txtQuantidadeIngrediente.Text.Equals("")) &&
                (!cboUnidadeRegistroIngrediente.SelectedItem.ToString().Equals(""))
                )
            {
                //Atribuindo novos valores.
                ingrediente.Nome               = txtNomeIngrediente.Text;
                ingrediente.Preco              = double.Parse(txtValorIngrediente.Text);
                ingrediente.Quantidade         = double.Parse(txtQuantidadeIngrediente.Text);
                ingrediente.UnidadeMedidaPreco = cboUnidadeRegistroIngrediente.SelectedItem.ToString();

                if (ingrediente.Cadastrar())
                {
                    MessageBox.Show("Registro realizado com sucesso", "Registro realizado", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                }
                else
                {
                    MessageBox.Show("Não foi possível cadastrar o novo ingrediente", "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);
            }
            TelaIngrediente telaIngrediente = new TelaIngrediente()
            {
                telaInicio = telaInicialRegistro
            };

            telaIngrediente.Show();
            telaInicialRegistro.Hide();
            this.Hide();
        }
コード例 #6
0
        private void TelaAlteraReceita_Load(object sender, EventArgs e)
        {
            try
            {
                //Preenchendo o combobox
                cmbCategoriaReceita.DataSource = new string[] {
                    "Bebida",
                    "Carne",
                    "Confeitaria",
                    "Marisco",
                    "Padaria",
                    "Pastelaria",
                    "Peixe",
                    "Salada",
                    "Sobremesa"
                };

                cmbDificuldadeAlteraReceita.DataSource = new string[] {
                    "1",
                    "2",
                    "3",
                    "4",
                    "5",
                    "6",
                    "7",
                    "8",
                    "9",
                    "10"
                };

                //Criando o objetos que guardará as incormações no banco de dados.
                Receita     receita     = new Receita();
                Ingrediente ingrediente = new Ingrediente();

                //objetos para acionar busca
                receita.Id = idReceitaAltera;

                if (receita.ObterReceita())
                {
                    //Atribuindo novos valores.
                    txtNomeReceita.Text                      = receita.Nome.ToString();
                    txtRendimentoReceita.Text                = receita.Porcoes.ToString();
                    txtValorReceita.Text                     = receita.Custo.ToString();
                    txtTempoPreparo.Text                     = receita.TempoPreparacao.ToString();
                    cmbCategoriaReceita.SelectedItem         = receita.Categoria;
                    cmbDificuldadeAlteraReceita.SelectedItem = receita.Dificuldade.ToString();
                    richTxtModoPreparo.Text                  = receita.Preparo;

                    //Carregando dataGrid com a lista de ingredientes relacionados a receita.
                    MySqlDataReader reader = ingrediente.Listar();

                    if (reader != null && (reader.HasRows))
                    {
                        double valorTotal = 0;

                        while (reader.Read())
                        {
                            int n = dataGridSelecaoIngrediente.Rows.Add();

                            dataGridSelecaoIngrediente.Rows[n].Cells["columnIdIngrediente"].Value         = reader["id"];
                            dataGridSelecaoIngrediente.Rows[n].Cells["columnNomeIngrediente"].Value       = reader["nome"];
                            dataGridSelecaoIngrediente.Rows[n].Cells["columnValorIngrediente"].Value      = reader["preco"];
                            dataGridSelecaoIngrediente.Rows[n].Cells["columnQuantidadeIngrediente"].Value = reader["quantidade"];
                            dataGridSelecaoIngrediente.Rows[n].Cells["columnUnidadeIngrediente"].Value    = reader["unidade"];
                            if (true)
                            {
                                //Calculando custo da receita.
                                valorTotal += Convert.ToDouble(dataGridSelecaoIngrediente.Rows[n].Cells["columnValorIngrediente"].Value);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Não foi possível carregar todos os dados da receita", "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível carregar todos os dados da receita\n" + ex.Message, "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }
        }
コード例 #7
0
        private void TelaRegistroReceita_Load(object sender, EventArgs e)
        {
            try
            {
                //Preenchendo os comboboxes
                cmbCategoriaReceita.DataSource = new string[] {
                    "Bebida",
                    "Carne",
                    "Confeitaria",
                    "Marisco",
                    "Padaria",
                    "Pastelaria",
                    "Peixe",
                    "Salada",
                    "Sobremesa"
                };
                cmbDificuldadeRegistroReceita.DataSource = new string[] {
                    "1",
                    "2",
                    "3",
                    "4",
                    "5",
                    "6",
                    "7",
                    "8",
                    "9",
                    "10"
                };

                //Gerando os objetos necesários para as operações
                //Receita receita = new Receita();
                Ingrediente listaIngrediente = new Ingrediente();

                //objetos para acionar busca
                //receita.Id = idReceitaAltera;
                //ingrediente.Id = 1;


                MySqlDataReader reader = listaIngrediente.Listar();


                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int n = dataGridSelecaoIngrediente.Rows.Add();

                        dataGridSelecaoIngrediente.Rows[n].Cells["columnIdIngrediente"].Value         = reader["id"];
                        dataGridSelecaoIngrediente.Rows[n].Cells["columnNomeIngrediente"].Value       = reader["nome"];
                        dataGridSelecaoIngrediente.Rows[n].Cells["columnValorIngrediente"].Value      = reader["preco"];
                        dataGridSelecaoIngrediente.Rows[n].Cells["columnQuantidadeIngrediente"].Value = reader["quantidade"];
                        dataGridSelecaoIngrediente.Rows[n].Cells["columnUnidadeIngrediente"].Value    = reader["unidade"];
                    }

                    //Ordenando lista pelo nome dos ingredientes.
                    DataGridViewColumn columnToSort = dataGridSelecaoIngrediente.Columns["columnNomeIngrediente"];
                    dataGridSelecaoIngrediente.Sort(columnToSort, ListSortDirection.Ascending);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível carregar todos os dados do ingrediente\n" + ex.Message, "Erro no carregamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
            }
        }