Exemplo n.º 1
0
        public List <Cliente> PesquisarPorNome(String nome)
        {
            List <Cliente>  clientes          = new List <Cliente>();
            FabricaConexoes connectionFactory = new FabricaConexoes();
            MySqlConnection connection        = connectionFactory.GetConnection();
            String          queryPesquisarId  = "SELECT idcliente, nome, telefone FROM cliente WHERE nome = @nome";

            connection.Open();
            MySqlCommand commandPesquisaId = new MySqlCommand(queryPesquisarId, connection);

            commandPesquisaId.Prepare();
            commandPesquisaId.Parameters.Add(new MySqlParameter("nome", nome));
            MySqlDataReader readerPesquisaId = commandPesquisaId.ExecuteReader();

            while (readerPesquisaId.Read())
            {
                Cliente cliente = new Cliente();
                cliente.idCliente = Convert.ToInt32(readerPesquisaId["idcliente"]);
                cliente.nome      = Convert.ToString(readerPesquisaId["nome"]);
                cliente.telefone  = Convert.ToInt32(readerPesquisaId["telefone"]);
                clientes.Add(cliente);
            }
            readerPesquisaId.Close();
            connection.Close();
            return(clientes);
        }
Exemplo n.º 2
0
        public void Remover(Cliente cliente)
        {
            FabricaConexoes connectionFactory = new FabricaConexoes();
            MySqlConnection connectionRemover = connectionFactory.GetConnection();

            String query = "DELETE FROM cliente WHERE idcliente = @idCliente";

            connectionRemover.Open();
            MySqlCommand commandRemover = new MySqlCommand(query, connectionRemover);

            commandRemover.Prepare();
            commandRemover.Parameters.Add(new MySqlParameter("idcliente", cliente.idCliente));
            commandRemover.ExecuteNonQuery();
            connectionRemover.Close();
        }
Exemplo n.º 3
0
        public void Inserir(Cliente cliente)
        {
            FabricaConexoes connectionFactory = new FabricaConexoes();
            MySqlConnection connectionInsert  = connectionFactory.GetConnection();

            String queryInserir = "INSERT INTO cliente(nome, telefone) values (@nome, @telefone)";

            connectionInsert.Open();
            MySqlCommand commandInserir = new MySqlCommand(queryInserir, connectionInsert);

            commandInserir.Prepare();
            commandInserir.Parameters.Add(new MySqlParameter("nome", cliente.nome));
            commandInserir.Parameters.Add(new MySqlParameter("telefone", cliente.telefone));
            commandInserir.ExecuteNonQuery();
            connectionInsert.Close();
        }
Exemplo n.º 4
0
        public void Modificar(Cliente cliente)
        {
            FabricaConexoes connectionFactory = new FabricaConexoes();
            MySqlConnection connection        = connectionFactory.GetConnection();

            String queryModificar = "UPDATE cliente set nome=@nome, telefone=@telefone WHERE idcliente = @idCliente";

            connection.Open();
            MySqlCommand commandModificar = new MySqlCommand(queryModificar, connection);

            commandModificar.Prepare();
            commandModificar.Parameters.Add(new MySqlParameter("idProduto", cliente.idCliente));
            commandModificar.Parameters.Add(new MySqlParameter("nome", cliente.nome));
            commandModificar.Parameters.Add(new MySqlParameter("telefone", cliente.telefone));
            commandModificar.ExecuteNonQuery();
            connection.Close();
        }
Exemplo n.º 5
0
        public Cliente PesquisarPorId(int idCliente)
        {
            Cliente         cliente           = new Cliente();
            FabricaConexoes connectionFactory = new FabricaConexoes();
            MySqlConnection connection        = connectionFactory.GetConnection();
            String          queryPesquisarId  = "SELECT idcliente, nome, telefone FROM cliente WHERE idcliente = @idCliente";

            connection.Open();
            MySqlCommand commandPesquisaId = new MySqlCommand(queryPesquisarId, connection);

            commandPesquisaId.Prepare();
            commandPesquisaId.Parameters.Add(new MySqlParameter("idProduto", idCliente));
            MySqlDataReader readerPesquisaId = commandPesquisaId.ExecuteReader();

            if (readerPesquisaId.Read())
            {
                cliente.idCliente = Convert.ToInt32(readerPesquisaId["idcliente"]);
                cliente.nome      = Convert.ToString(readerPesquisaId["nome"]);
                cliente.telefone  = Convert.ToInt32(readerPesquisaId["telefone"]);
            }
            readerPesquisaId.Close();
            connection.Close();
            return(cliente);
        }