Design Standard for Filters

Asked

Viewed 382 times

9

First, filter in my current context is a list of objects to be used in Combobox type controls so that the user can choose from among the options.

My scenario is this: Screen 1 - Has filters of companies, stocks, customers, payment methods. Screen 2 - Has filters of companies and stocks. Screen 3 - Has filters of customers, cities, states.

My goal is to implement a design standard that uses the same structure, e.g.: Filtrotela, and add in the filters (companies, customers, stocks) depending on the screen that requested it.

These screens are from a windows Forms project, the request will be made to a WCF Service, which will make the query in a database and return the structure with all filters to the client (windows Forms).

Something around, WCF Service I "Screen 1" want the companies filters, stocks, customers and forms of payment, when receiving the msg back, would make the respective Binding for each control.

Can anyone indicate me a design pattern to address this issue?

  • 1

    Create view, and from Dae create filters

  • 1

    Thanks for the help @Luizvichiatto, but the data access layer already exists and even I already use views, my problem is to fit a Patterns design to handle the coming and going of the list of objects (filters) throughout the project.

  • uses as parameter in sql

3 answers

3

You can combine the @Rogeroliveira response on the SQL side with the default Builder and Interfaces Fluents on the C-side#.

Basically you would use the filter like this:

new FiltroTelaBuilder().porEmpresa(empresa).build();

Or so:

new FiltroTelaBuilder().porCliente(cliente).build();

Or so:

new FiltroTelaBuilder().porEmpresa(empresa).porCliente(cliente).build();

In all cases the method build() returns an immutable instance of FiltroTela.

There are different ways to implement this standard. This is the most common.

3

Answer originally posted in the body of the question by its own author

Well, I found a pattern that helped me and a lot, the Decorator, follows a reference link "Decorator Design Pattern" and below a small example of how was the implementation of the mounting of filters, which meets me by screen:

private Dictionary<string, object> FiltroTela1()
    {
        IFilter filtro = new Filter();
        filtro = new FilterCompany(filtro);
        filtro = new FilterCustomer(filtro);
        filtro = new FilterPaymentType(filtro);
        return filtro.Filters();
    }

private Dictionary<string, object> FiltroTela2()
    {
        IFilter filtro = new Filter();
        filtro = new FilterCustomer(filtro);
        filtro = new FilterPaymentType(filtro);
        return filtro.Filters();
    }

The two examples above use the Decorator to "decorate" my Filter object with the filters needed for each screen, and the "Filters" method gets from each filter the type and an object to be used as a criteria in the filter search.

On the other end "Server", I use the same pattern, it analyzes the received dictionary and gets the requested filters from the database, assembles a new filter, but with the list of each and returns to the screen, which in turn analyses the received filters and performs the Binding for the respective control.

1

I pass the filters as parameters in the Stored Procedure using this sql:

@parametro is null or campo = @parametro

Once you pass null in the parameter he will ignore, then simply pass parameters to SP if they are null you treat before.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.