Exemple #1
0
        public void Cadastrar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "INSERT INTO Estoque (id_produto, nome, qtde, preco, descricao) VALUES (@id_produto, @nome, @qtde, @preco, @descricao)";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                cmd.Parameters.Add(new NpgsqlParameter("@id_produto", this.ID));
                cmd.Parameters.Add(new NpgsqlParameter("@nome", this.Nome));
                cmd.Parameters.Add(new NpgsqlParameter("@qtde", this.QTDE));
                cmd.Parameters.Add(new NpgsqlParameter("@preco", this.Preco));
                cmd.Parameters.Add(new NpgsqlParameter("@descricao", this.Desc));
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception("   Erro!   " + e.Message);
            }

            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #2
0
        public void excluir()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "delete from estoque where id_produto=@id_produto;";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                cmd.Parameters.Add(new NpgsqlParameter("@id_produto", ID));

                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception("   Erro!   " + e.Message);
            }

            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #3
0
        public void alterar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "UPDATE estoque SET id_produto=@id_produto, nome=@nome, qtde=@qtde, preco=@preco, descricao=@descricao WHERE id_produto=@id_produto;";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                cmd.Parameters.Add(new NpgsqlParameter("@id_produto", this.ID));
                cmd.Parameters.Add(new NpgsqlParameter("@nome", this.Nome));
                cmd.Parameters.Add(new NpgsqlParameter("@qtde", this.QTDE));
                cmd.Parameters.Add(new NpgsqlParameter("@preco", this.Preco));
                cmd.Parameters.Add(new NpgsqlParameter("@descricao", this.Desc));

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("   Erro!   " + ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #4
0
        public void Cadastrar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "INSERT INTO departamentos (id_depto, nome, evento, frequencia) VALUES (@id_depto, @nome, @evento, @frequencia)";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                cmd.Parameters.Add(new NpgsqlParameter("@id_depto", this.ID));
                cmd.Parameters.Add(new NpgsqlParameter("@nome", this.Nome));
                cmd.Parameters.Add(new NpgsqlParameter("@evento", this.Evento));
                cmd.Parameters.Add(new NpgsqlParameter("@frequencia", this.Freq));
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw new Exception("   Erro!   " + e.Message);
            }

            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #5
0
        public void alterar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "UPDATE departamentos SET id_depto=@id_depto, nome=@nome, evento=@evento, frequencia=@frequencia WHERE id_depto=@id_depto;";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                cmd.Parameters.Add(new NpgsqlParameter("@id_depto", this.ID));
                cmd.Parameters.Add(new NpgsqlParameter("@nome", this.Nome));
                cmd.Parameters.Add(new NpgsqlParameter("@evento", this.Evento));
                cmd.Parameters.Add(new NpgsqlParameter("@frequencia", this.Freq));

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("   Erro!   " + ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #6
0
        public List <Produtos> Enter()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "SELECT * from estoque";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                NpgsqlDataReader dr = cmd.ExecuteReader();

                List <Produtos> listaProdutos = new List <Produtos>();
                while (dr.Read())
                {
                    Produtos novoProduto = new Produtos();
                    novoProduto.ID    = Convert.ToInt16(dr["id_produto"]);
                    novoProduto.Nome  = dr["Nome"].ToString();
                    novoProduto.QTDE  = Convert.ToInt16(dr["QTDE"]);
                    novoProduto.Preco = Convert.ToDouble(dr["Preco"]);
                    novoProduto.Desc  = dr["descricao"].ToString();

                    listaProdutos.Add(novoProduto);
                }

                return(listaProdutos);
            }
            catch (Exception ex)
            {
                throw new Exception("   Erro!   " + ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #7
0
        public List <Admins> Enter()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();

                string sql = "SELECT * from Admins";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                NpgsqlDataReader dr = cmd.ExecuteReader();

                List <Admins> listaAdmins = new List <Admins>();
                while (dr.Read())
                {
                    Admins novoAdmin = new Admins();
                    novoAdmin.ID    = Convert.ToInt16(dr["id"]);
                    novoAdmin.login = dr["Nome"].ToString();
                    novoAdmin.login = dr["login"].ToString();
                    novoAdmin.senha = dr["senha"].ToString();

                    listaAdmins.Add(novoAdmin);
                }

                return(listaAdmins);
            }
            catch (Exception ex)
            {
                throw new Exception("   Erro!   " + ex.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }
Exemple #8
0
        public List <Depto> Listar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();
                string sql = "SELECT * FROM departamentos";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                NpgsqlDataReader dr = cmd.ExecuteReader();

                List <Depto> listaDepto = new List <Depto>();
                while (dr.Read())
                {
                    Depto novoDepto = new Depto();
                    novoDepto.ID     = Convert.ToInt16(dr["id_depto"]);
                    novoDepto.Nome   = dr["Nome"].ToString();
                    novoDepto.Evento = dr["Evento"].ToString();
                    novoDepto.Freq   = Convert.ToInt16(dr["Frequencia"]);

                    listaDepto.Add(novoDepto);
                }
                return(listaDepto);
            }
            catch (Exception e)
            {
                throw new Exception("   Erro!   " + e.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }