@ -26,6 +26,7 @@ import com.evolute.entity.evo.EvoDataProvider;
import com.evolute.utils.arrays.Virtual2DArray ;
import com.evolute.utils.sql.Expression ;
import com.evolute.utils.sql.Field ;
import com.evolute.utils.sql.Select ;
import com.evolute.utils.sql.Select2 ;
import com.evolute.utils.strings.StringPlainer ;
import com.sun.rave.web.ui.model.Option ;
@ -35,6 +36,8 @@ import db.data.siprp.outer.CausasData;
import db.data.siprp.outer.ControleData ;
import db.data.siprp.outer.MedidasData ;
import db.data.siprp.outer.RecomendacoesData ;
import db.data.siprp_local.outer.EstabelecimentosData ;
import db.data.siprp_local.outer.TrabalhadoresData ;
import global.Global ;
import java.sql.ResultSet ;
import java.sql.ResultSetMetaData ;
@ -1661,61 +1664,93 @@ public class AnalisesDataProvider extends GenericDataProvider
// Statement stlocal = dblocal.createStatement();
Statement stlocal = createLocalStatement ( ) ;
String sql = "" ;
// String sql = "";
StringTokenizer st = null ;
if ( nrMecanografico ! = null )
{
if ( nome ! = null )
{
String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (" ;
String sql2 = "" ;
String sql3 = ") AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico . toLowerCase ( ) + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'" ;
st = new StringTokenizer ( nome ) ;
int n = 0 ;
while ( st . hasMoreTokens ( ) )
{
if ( n > 0 )
{
sql2 + = "AND " ;
}
sql2 + = "trabalhadores.nome LIKE '%" + st . nextToken ( ) + "%' " ;
n + + ;
}
sql = sql1 + sql2 + sql3 ;
//sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (trabalhadores.nome LIKE '%" + nome + "%' AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%') AND estabelecimentos.empresa_id = " + empresa_id;
}
else
Expression expr = new Field ( EstabelecimentosData . EMPRESA_ID_FULL ) . isEqual ( empresa_id ) . and (
new Field ( TrabalhadoresData . INACTIVO_FULL ) . isEqual ( "n" ) ) . and (
new Field ( EstabelecimentosData . INACTIVO_FULL ) . isEqual ( "n" ) ) ;
Select select =
new Select2 ( new String [ ] { TrabalhadoresData . TABLENAME , EstabelecimentosData . TABLENAME } ,
new Integer [ ] { Select2 . JOIN_INNER } ,
new Expression [ ] { new Field ( TrabalhadoresData . ESTABELECIMENTO_ID_FULL ) . isEqual ( new Field ( EstabelecimentosData . ID_FULL ) ) } ,
new String [ ] { TrabalhadoresData . ID_FULL , TrabalhadoresData . NOME_FULL , TrabalhadoresData . DATA_NASCIMENTO_FULL ,
TrabalhadoresData . FUNCAO_PROPOSTA_FULL , TrabalhadoresData . DATA_ADMISSAO_FULL , TrabalhadoresData . NUMERO_MECANOGRAFICO_FULL ,
EstabelecimentosData . ID_FULL , EstabelecimentosData . NOME_FULL } ,
expr ,
null ,
null ,
null ,
null ) ;
if ( nome ! = null )
{
st = new StringTokenizer ( nome ) ;
while ( st . hasMoreTokens ( ) )
{
sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico . toLowerCase ( ) + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'" ;
expr = expr . and ( new Field ( TrabalhadoresData . NOME_FULL ) . isILike ( "'%" + st . nextToken ( ) + "%'" ) ) ;
}
}
else
if ( nrMecanografico ! = null )
{
if ( nome ! = null )
{
//sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%' AND estabelecimentos.empresa_id = " + empresa_id;
String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (" ;
String sql2 = "" ;
String sql3 = ") AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'" ;
st = new StringTokenizer ( nome ) ;
int n = 0 ;
while ( st . hasMoreTokens ( ) )
{
if ( n > 0 )
{
sql2 + = "AND " ;
}
sql2 + = "trabalhadores.nome LIKE '%" + st . nextToken ( ) + "%' " ;
n + + ;
}
sql = sql1 + sql2 + sql3 ;
}
expr = expr . and ( new Field ( TrabalhadoresData . NUMERO_MECANOGRAFICO_FULL ) . isILike ( nrMecanografico . toLowerCase ( ) ) ) ;
}
System . out . println ( "TRABALHADORES SQL A : " + sql ) ;
// if ( nrMecanografico != null )
// {
// if ( nome != null )
// {
//
//
//// String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (";
//// String sql2 = "";
//// String sql3 = ") AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
//// st = new StringTokenizer( nome );
//// int n = 0;
//// while ( st.hasMoreTokens() )
//// {
//// if ( n > 0 )
//// {
//// sql2 += "AND ";
//// }
//// sql2 += "trabalhadores.nome LIKE '%" + st.nextToken() + "%' ";
//// n++;
//// }
//// sql = sql1 + sql2 + sql3;
// //sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (trabalhadores.nome LIKE '%" + nome + "%' AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%') AND estabelecimentos.empresa_id = " + empresa_id;
// }
// else
// {
//// sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND LOWER(numero_mecanografico) LIKE '%" + nrMecanografico.toLowerCase() + "%' AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
// }
// }
// else
// {
// if ( nome != null )
// {
//// //sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%' AND estabelecimentos.empresa_id = " + empresa_id;
//// String sql1 = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.id, estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND (";
//// String sql2 = "";
//// String sql3 = ") AND estabelecimentos.empresa_id = " + empresa_id + " AND trabalhadores.inactivo = 'n'";
//// st = new StringTokenizer( nome );
//// int n = 0;
//// while ( st.hasMoreTokens() )
//// {
//// if ( n > 0 )
//// {
//// sql2 += "AND ";
//// }
//// sql2 += "trabalhadores.nome LIKE '%" + st.nextToken() + "%' ";
//// n++;
//// }
//// sql = sql1 + sql2 + sql3;
//
// }
// }
System . out . println ( "TRABALHADORES SQL A : " + select ) ;
// if(nrMecanografico != null)
// {
// sql = "SELECT * FROM trabalhadores WHERE LOWER(numero_mecanografico) = '" + nrMecanografico.toLowerCase() + "'";
@ -1724,27 +1759,41 @@ public class AnalisesDataProvider extends GenericDataProvider
// {
// sql = "SELECT trabalhadores.id, trabalhadores.nome, data_nascimento, funcao_proposta, data_admissao, numero_mecanografico , estabelecimentos.nome FROM trabalhadores, estabelecimentos WHERE estabelecimento_id = estabelecimentos.id AND trabalhadores.nome LIKE '%" + nome + "%'";
// }
ResultSet rslocal = stlocal . executeQuery ( sql ) ;
rslocal . first ( ) ;
do
// ResultSet rslocal = stlocal.executeQuery( sql );
// rslocal.first();
Virtual2DArray array = getLocalExecuter ( ) . executeQuery ( select ) ;
// do
// {
// Trabalhador t = new Trabalhador();
// t.setId( new Integer( rslocal.getInt( 1 ) ) ); //id
// String nome_trab = rslocal.getString( 2 );
// t.setNome( utils.Utils.unicodeToHTML( nome_trab ) );
// t.setData_nascimento( rslocal.getDate( "data_nascimento" ) );
// t.setFuncao( rslocal.getString( "funcao_proposta" ) );
// t.setData_admissao( rslocal.getDate( "data_admissao" ) );
// t.setNumero_mecanografico( rslocal.getString( "numero_mecanografico" ) );
// t.setEstabelecimento_id( new Integer( rslocal.getInt( 7 ) ) );
// //if(nome != null)
// //{
// t.setEstabelecimento( utils.Utils.unicodeToHTML( rslocal.getString( 8 ) ) );
// //}
//
// list.add( t );
// }
// while ( rslocal.next() );
for ( int n = 0 ; n < array . columnLength ( ) ; n + + )
{
Trabalhador t = new Trabalhador ( ) ;
t . setId ( new Integer ( rslocal . getInt ( 1 ) ) ) ; //id
String nome_trab = rslocal . getString ( 2 ) ;
t . setId ( ( Integer ) array . get ( n , 0 ) ) ;
String nome_trab = ( String ) array . get ( n , 1 ) ;
t . setNome ( utils . Utils . unicodeToHTML ( nome_trab ) ) ;
t . setData_nascimento ( rslocal . getDate ( "data_nascimento" ) ) ;
t . setFuncao ( rslocal . getString ( "funcao_proposta" ) ) ;
t . setData_admissao ( rslocal . getDate ( "data_admissao" ) ) ;
t . setNumero_mecanografico ( rslocal . getString ( "numero_mecanografico" ) ) ;
t . setEstabelecimento_id ( new Integer ( rslocal . getInt ( 7 ) ) ) ;
//if(nome != null)
//{
t . setEstabelecimento ( utils . Utils . unicodeToHTML ( rslocal . getString ( 8 ) ) ) ;
//}
list . add ( t ) ;
t . setData_nascimento ( ( java . sql . Date ) array . get ( n , 2 ) ) ;
t . setFuncao ( ( String ) array . get ( n , 3 ) ) ;
t . setData_admissao ( ( java . sql . Date ) array . get ( n , 4 ) ) ;
t . setNumero_mecanografico ( ( String ) array . get ( n , 5 ) ) ;
t . setEstabelecimento_id ( ( Integer ) array . get ( n , 6 ) ) ;
t . setEstabelecimento ( utils . Utils . unicodeToHTML ( ( String ) array . get ( n , 8 ) ) ) ;
}
while ( rslocal . next ( ) ) ;
return list ;
}