コード例 #1
0
ファイル: ProdutoDAO.cs プロジェクト: UCLINF-20152-PI1/Beta
        public static bool Alterar(Produtos produto)
        {
            try
            {
                using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand())
                {
                    c.CommandType = System.Data.CommandType.Text;
                    c.CommandText = "UPDATE PRODUTOS SET nome=:nome, precovenda=:precovenda, precocusto=:precocusto, descricao=:descricao, categoriaid=:categoriaid WHERE produtoid = :codigo";
                    c.Parameters.Add("nome", OracleType.VarChar).Value = produto.getNome();
                    c.Parameters.Add("precovenda", OracleType.Float).Value = produto.getPrecoVenda();
                    c.Parameters.Add("precocusto", OracleType.Float).Value = produto.getPrecoCusto();
                    c.Parameters.Add("descricao", OracleType.VarChar).Value = produto.getDescricao();
                    c.Parameters.Add("categoriaid", OracleType.Int32).Value = produto.getCategoriaId();
                    c.Parameters.Add("codigo", OracleType.Int32).Value = produto.getProdutoId();

                    c.ExecuteNonQuery();
                }

                return true;
            }
            catch (OracleException e)
            {
                throw e;
            }
        }
コード例 #2
0
ファイル: ProdutoDAO.cs プロジェクト: UCLINF-20152-PI1/Beta
        public static Produtos Buscar(int codigo)
        {
            Produtos produtos = null;
            try
            {
                using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand())
                {
                    c.CommandType = System.Data.CommandType.Text;
                    c.CommandText = "SELECT produtoid, nome, precovenda, precocusto, descricao, categoriaid FROM produtos WHERE produtoid = :codigo";
                    c.Parameters.Add("codigo", OracleType.Int32).Value = codigo;

                    using (OracleDataReader leitor = c.ExecuteReader())
                    {
                        if (leitor.HasRows)
                        {
                            leitor.Read();
                            int bd_produtoid = leitor.GetInt32(0);
                            String bd_nome = leitor.GetString(1);
                            float bd_precoVenda = leitor.GetFloat(2);
                            float bd_precoCusto = leitor.GetFloat(3);
                            String bd_descricao = leitor.GetString(4);
                            int bd_categoriaid = leitor.GetInt32(5);

                            produtos= new Produtos(bd_produtoid, bd_nome, bd_precoVenda, bd_precoCusto, bd_descricao, bd_categoriaid);
                        }
                    }
                }
                return produtos;
            }
            catch (NullReferenceException e)
            {
                throw e;
            }
        }
コード例 #3
0
ファイル: ProdutosRN.cs プロジェクト: UCLINF-20152-PI1/Beta
 public static bool ValidaCaracter(Produtos produto)
 {
     for (int i = 0; i < produto.getNome().Length; i++)
         if (produto.getNome()[i].Equals('*') || produto.getNome()[i].Equals('&') || produto.getNome()[i].Equals('(') || produto.getNome()[i].Equals(')') || produto.getNome()[i].Equals('!') || produto.getNome()[i].Equals('@') || produto.getNome()[i].Equals('#') || produto.getNome()[i].Equals('$') || produto.getNome()[i].Equals('%') || produto.getNome()[i].Equals('¨') || produto.getNome()[i].Equals('_') || produto.getNome()[i].Equals('+') || produto.getNome()[i].Equals('=') || produto.getNome()[i].Equals('§') || produto.getNome()[i].Equals(',') || produto.getNome()[i].Equals('.') || produto.getNome()[i].Equals('/') || produto.getNome()[i].Equals('?') || produto.getNome()[i].Equals(':') || produto.getNome()[i].Equals(';') || produto.getNome()[i].Equals('|') || produto.getNome()[i].Equals(']') || produto.getNome()[i].Equals('}') || produto.getNome()[i].Equals('{') || produto.getNome()[i].Equals('['))
             throw new CaracterInvalidoException("O nome não pode conter caracter especial!");
     if (produto.getPrecoCusto() <= 0 || produto.getPrecoVenda() <= 0)
         throw new CaracterInvalidoException("O valor não pode ser negativo!");
     return true;
 }
コード例 #4
0
ファイル: ProdutoDAO.cs プロジェクト: IagoGabriel/Beta
 public static bool Inserir(Produtos produto)
 {
     try
     {
         using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand())
         {
             c.CommandType = System.Data.CommandType.Text;
             c.CommandText = "INSERT into PRODUTOS values(PRODUTOS_SEQ.NEXTVAL, :categoriaid, :nome, :precovenda, :precocusto, :status, :descricao, :categoriaid)";
             c.Parameters.Add("nome", OracleType.VarChar).Value = produto.getNome();
             c.Parameters.Add("precovenda", OracleType.Float).Value = produto.getPrecoVenda();
             c.Parameters.Add("precocusto", OracleType.Float).Value = produto.getPrecoCusto();
             c.Parameters.Add("status", OracleType.VarChar).Value = produto.getStatus();
             c.Parameters.Add("descricao", OracleType.VarChar).Value = produto.getDescricao();
             c.Parameters.Add("categoriaid", OracleType.Int32).Value = produto.getCategoriaId();
             c.ExecuteNonQuery();
             return true;
         }
     }
     catch (OracleException e)
     {
         throw e;
     }
 }
コード例 #5
0
ファイル: ProdutoDAO.cs プロジェクト: UCLINF-20152-PI1/Beta
 public static bool Gravar(Produtos produto)
 {
     return Inserir(produto);
 }
コード例 #6
0
ファイル: TelaProdutos.cs プロジェクト: IagoGabriel/Beta
        private void bEfetivar_Click(object sender, EventArgs e)
        {
            if (botao == 1)
            {
                if (tbNome.Text.Equals("") || tbPrecoVenda.Text.Equals("") || tbPrecoCusto.Text.Equals("") || tbStatus.Text.Equals("") || tbDescricao.Text.Equals("") || cbCategoria.Text.Equals(""))
                {
                    MessageBox.Show("Preencha todos os campos obrigatórios: *");
                }
                else
                {
                    if (tbDescricao.Text == "")
                    {
                        tbDescricao.Text = " ";
                    }
                    Produtos produto = new Produtos(CategoriaDAO.BuscaNome(cbCategoria.Text), tbNome.Text, tbPrecoVenda.Text, tbPrecoCusto.Text, tbStatus.Text, tbDescricao.Text);
                    if (ProdutoDAO.Inserir(produto))
                    {
                        // tem que ser cancelar //
                        bLimpar_Click(sender, e);
                        MessageBox.Show("Produto" + produto.getNome() + " foi cadastrado com sucesso!");
                    }
                }
            }

            if (botao == 2)
            {
                if (tbNome.Text.Equals("") || tbPrecoVenda.Text.Equals("") || tbPrecoCusto.Text.Equals("") || tbStatus.Text.Equals("") || tbDescricao.Text.Equals("") || cbCategoria.Text.Equals(""))
                {
                    MessageBox.Show("Preencha todos os campos obrigatórios: *");
                }
                else
                {
                    if (tbDescricao.Text == "")
                    {
                        tbDescricao.Text = " ";
                    }
                    Produtos produto = new Produtos(int.Parse(tbCodigo.Text), CategoriaDAO.BuscaNome(cbCategoria.Text), tbNome.Text, tbPrecoVenda.Text, tbPrecoCusto.Text, tbStatus.Text, tbDescricao.Text);

                    if (ProdutoDAO.Alterar(produto))
                    {
                        bLimpar_Click(sender, e);
                        MessageBox.Show("Produto " + produto.getNome() + " foi alterado com sucesso!");
                    }
                }
            }
        }
コード例 #7
0
ファイル: TelaProdutos.cs プロジェクト: UCLINF-20152-PI1/Beta
        private void bEfetivar_Click(object sender, EventArgs e)
        {
            try
            {
                if (botao == 1) //Cadastrar
                {
                    if (tbNome.Text.Equals("") || tbPrecoVenda.Text.Equals("") || tbPrecoCusto.Text.Equals("") || cbCategoria.Text.Equals(""))
                    {
                        MessageBox.Show("Preencha todos os campos obrigatórios: *");
                    }
                    else
                    {
                        if (tbDescricao.Text == "")
                        {
                            tbDescricao.Text = " ";
                        }
                        Produtos produto = new Produtos(tbNome.Text, float.Parse(tbPrecoVenda.Text), float.Parse(tbPrecoCusto.Text), tbDescricao.Text, CategoriaDAO.BuscaNome(cbCategoria.Text));
                        if (ProdutosRN.Salvar(produto))
                        {
                            if(ingredientesNovo != null){
                                for(int i = 0; i < ingredientesNovo.Count; i++){
                                    Comida_IngredientesRN.Salvar(new Comida_Ingrediente(IngredienteDAO.BuscaCodigo(ingredientesNovo[i].getNome()), ProdutoDAO.Buscar(tbNome.Text), ingredientesNovo[i].getQuantidade()));
                                }
                            }
                            bCancelar_Click(sender, e);
                            MessageBox.Show("Produto " + produto.getNome() + " foi cadastrado com sucesso!");
                        }
                    }
                }

                if (botao == 2) //Alterar
                {
                    if (tbNome.Text.Equals("") || tbPrecoVenda.Text.Equals("") || tbPrecoCusto.Text.Equals("") || cbCategoria.Text.Equals(""))
                    {
                        MessageBox.Show("Preencha todos os campos obrigatórios: *");
                    }
                    else
                    {
                        if (tbDescricao.Text == "")
                        {
                            tbDescricao.Text = " ";
                        }
                        Produtos produto = new Produtos(int.Parse(tbCodigo.Text),tbNome.Text, float.Parse(tbPrecoVenda.Text), float.Parse(tbPrecoCusto.Text), tbDescricao.Text, CategoriaDAO.BuscaNome(cbCategoria.Text));

                        if (ProdutosRN.Alterar(produto))
                        {
                            int codigo = ProdutoDAO.Buscar(tbNome.Text);
                            if (listaIngredientes.Count > 0 && ingredientesNovo.Count > 0)
                            {
                                List<String> ingredientes = new List<String>();
                                for (int j = 0; j < listaIngredientes.Count; j++)
                                {
                                    ingredientes.Add(listaIngredientes[j].getNome());
                                }
                                for (int i = 0; i < ingredientesNovo.Count; i++)
                                {
                                    if (ingredientes.Contains(ingredientesNovo[i].getNome()))
                                    {
                                        ingredientes.Remove(listaIngredientes[i].getNome());
                                        Comida_IngredientesRN.Alterar(new Comida_Ingrediente(IngredienteDAO.BuscaCodigo(ingredientesNovo[i].getNome()), codigo, ingredientesNovo[i].getQuantidade()));
                                    }
                                    else
                                    {
                                        Comida_IngredientesRN.Salvar(new Comida_Ingrediente(IngredienteDAO.BuscaCodigo(ingredientesNovo[i].getNome()), codigo, ingredientesNovo[i].getQuantidade()));
                                    }
                                }
                                for (int k = 0; k < listaIngredientes.Count; k++ )
                                {
                                    for (int x = 0; x < ingredientes.Count; x++ )
                                    {
                                        if (listaIngredientes[k].getNome().Equals(ingredientes[x]))
                                        {
                                            Comida_IngredienteDAO.ExcluirCodigo(codigo, IngredienteDAO.BuscaCodigo(listaIngredientes[k].getNome()));
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (listaIngredientes.Count > 0 && ingredientesNovo.Count == 0)
                                {
                                    Comida_IngredienteDAO.ExcluirTodosCodigo(int.Parse(tbCodigo.Text));
                                }
                                else
                                {
                                    if (listaIngredientes.Count == 0 && ingredientesNovo.Count > 0)
                                    {
                                        for (int i = 0; i < ingredientesNovo.Count; i++ )
                                        {
                                           Comida_IngredientesRN.Salvar(new Comida_Ingrediente(IngredienteDAO.BuscaCodigo(ingredientesNovo[i].getNome()), codigo, ingredientesNovo[i].getQuantidade()));
                                        }
                                    }
                                }
                            }
                            bCancelar_Click(sender, e);
                            MessageBox.Show("Produto " + produto.getNome() + " foi alterado com sucesso!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ingredientesNovo = new List<ListaIngredientes>();
                if (ex.Message.Contains("unique constraint"))
                {
                    MessageBox.Show("Um valor único não foi informado.");
                }
                else
                {
                    MessageBox.Show("Ocorreu um erro: " + ex.Message);
                }
            }
        }
コード例 #8
0
ファイル: ProdutosRN.cs プロジェクト: UCLINF-20152-PI1/Beta
 public static bool Salvar(Produtos produto)
 {
     if (ValidaCaracter(produto))
         return ProdutoDAO.Gravar(produto);
     return false;
 }
コード例 #9
0
ファイル: ProdutosRN.cs プロジェクト: UCLINF-20152-PI1/Beta
 public static bool Alterar(Produtos produto)
 {
     if (ValidaCaracter(produto))
         return ProdutoDAO.Alterar(produto);
     return false;
 }