0

Zk Filter Data based on Date.

asked 2015-05-12 05:56:41 +0800

manojkumarreddyn gravatar image manojkumarreddyn
1

Hai All,

    Please provide a simple example how to filter a data in GRID/CHART based on DATE.
delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2015-05-17 14:05:13 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Hi,

    <listbox mold="paging" sizedByContent="true" height="500px"
            span="true" autopaging="true" pagingPosition="bottom"
            model="@load(vm.lstChiamate)" selectedItem="@bind(vm.selected)"
            onSelect="@command('abilitaDelete')">
            <auxhead sclass="category-center">
                        <auxheader>
                            <image src="/images/search.png" />
                            <textbox id="filtroRagSoc" instant="true" width="50%"
                                onChange="@command('applicaFiltro')" />
                            <image src="/images/search.png" />
                            <datebox id="filtroDataVis" instant="true" width="80%"
                                locale="it_IT" mold="rounded" lenient="true" format="dd/MM/yyyy"
                                onChange="@command('applicaFiltro')" />

This simple listbox show some record. OnChange I fire a command: applicaFiltro

@Command
@NotifyChange("lstChiamate")
public void applicaFiltro() 
{
    ElencoChiamateClienti ut = new ElencoChiamateClienti();

    ut.setRagione_sociale(filtroRagSoc.getText());
    ut.setLogin_inserimento(filtroLogin.getText());
    ut.setCliente(filtroCli.intValue());

    SimpleDateFormat dfIn  = new SimpleDateFormat("dd/MM/yyyy");
    java.util.Date DataTransito=null;
    Boolean ok=true;

    if(ok && filtroDataVis.getValue() != null)
    {
        try 
        {
            DataTransito=dfIn.parse(filtroDataVis.getText());   

            Calendar c = Calendar.getInstance();
            c.setTime(DataTransito);
            c.set(Calendar.HOUR, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            Timestamp ts = new Timestamp(c.getTimeInMillis());
            ts.setNanos(0);

            ut.setData_visita(ts);

        } catch (WrongValueException e) 
        {
            ok=false;
            logger.error("Programma:"+gTitoloVideata+" Funzione:applicaFiltro " +"Errore:"+ e.getMessage());
            uv.apriMessagebox(gTitoloVideata, "Errore in applicaFiltro. \n"+e.getMessage(), win);

        } catch (ParseException e) 
        {
            ok=false;
            logger.error("Programma:"+gTitoloVideata+" Funzione:applicaFiltro " +"Errore:"+ e.getMessage());
            uv.apriMessagebox(gTitoloVideata, "Errore in applicaFiltro. \n"+e.getMessage(), win);

        }
        catch (java.lang.NullPointerException e)
        {
            ; // semplicemente non � stato compilato il campo e quindi non mi interessa
        }
    }

    ChiamateClientiDAO pdao = (ChiamateClientiDAO)SpringUtil.getBean("ChiamateClientiDAO");
    lstChiamate=pdao.findElencoVisite(ut);

    BindUtils.postNotifyChange(null,null,Adm_elenco_visite.this,"lstChiamate");
    selected=null;

}

The fields was bounded with @wire....

@Wire("#filtroRagSoc")
Textbox filtroRagSoc;
@Wire("#filtroCli")
Intbox filtroCli;
@Wire("#filtroDataVis")
Datebox filtroDataVis;

This was executed in afterCompose....

@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view)
{
    Selectors.wireComponents(view, this, false);
}

In DAO I search the record

    public List<ElencoChiamateClienti> findElencoVisite(ElencoChiamateClienti ec) throws org.springframework.dao.DataAccessException
{

    Format fmt = new SimpleDateFormat("yyyy-MM-dd");

    List<ElencoChiamateClienti> list=null;
    String sql ="select chc.progressivo,chc.cliente,cli.ragione_sociale,chc.data_chiamata,chc.esito_acquisto, "+
                "chc.esito_contatto,chc.data_visita,chc.agente,chc.chiamata_chiusa,chc.login_inserimento "+
                "from tp_chiamate_clienti chc, tg_clienti cli "+
                "where cli.progressivo = chc.cliente "+
                "  and chc.esito_contatto ='V' "+
                "  and chc.esito_acquisto ='X' "+
                "  and cli.ragione_sociale like '"+ec.getRagione_sociale()+"%' "+
                "  and chc.login_inserimento like '"+ec.getLogin_inserimento()+"%' ";   
    if(ec.getData_visita() != null)
        sql = sql + " and chc.data_visita between '"+ec.getData_visita()+"' and '"+fmt.format(ec.getData_visita())+" 23:59:59' ";


    if(ec.getCliente() > 0)
        sql = sql + " and cli.progressivo = "+Integer.toString(ec.getCliente());


    sql = sql + " order by data_visita, ragione_sociale";

That should be all that is needed. Luca

p.s. But this is a matter which should be considered a little presentation of the problem....

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-05-12 05:56:41 +0800

Seen: 23 times

Last updated: May 17 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More