import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwvol8Web</p>
* <p>Description : Consultation ,  Liste des zones reliées à une voie</p>
* <p>Copyright : Copyright (c) 2013</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>07/04/2013</i>
* @version 1.0
 */
public class Jwlwvol8Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeVoies </p>
		 * <p>Description : Consultation , Liste des voies </p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>07/04/2013</i>
		 * @version 1.0
		 * f_col_tri = Z par Zone, T par Type
		 * f_ordre_tri = O croissant, N décroissant
		 * f_filtre_type = N, R, T ou null
		 */
		public static Jwlwvol8 getListeVoies (
			String nbrep,
			String page,
			String fonction,
			String f_voi_id,
			String f_col_tri,
			String f_ordre_tri,
			String f_filtre_type,
			String f_cle_reprise,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwvol8 jwlwvol8 = new Jwlwvol8(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwvol8.Nwlwvol8Axwebent vWebent = jwlwvol8.new Nwlwvol8Axwebent();
			vWebent.dbid 		   	  = new BigDecimal (Constantes.DBID);
			vWebent.cible_exploitant  = Constantes.CD_CIBLE;
			vWebent.groupe_exploitant = groupe_exploitant;
			vWebent.numero_session 	  = new BigDecimal (numero_session);
			vWebent.utilisateur       = utilisateur;
			vWebent.transaction 	  = "WLWCLLST";
			vWebent.fonction 		  = fonction;
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			jwlwvol8.setNwlwvol8Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwvol8.Nwlwvol8Axweblst vWeblst = jwlwvol8.new Nwlwvol8Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwvol8.setNwlwvol8Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwvol8.Nwlwvol8Awlwvol8 vLwvol8 = jwlwvol8.new Nwlwvol8Awlwvol8();
			Jwlwvol8.Nwlwvol8Awlwvol8Demande vLwvol8Demande = jwlwvol8.new Nwlwvol8Awlwvol8Demande();
			
			Jwlwvol8.Nwlwvol8Awlwvol8DemandeCritere_select vLwvol8DemandeCritere = jwlwvol8.new Nwlwvol8Awlwvol8DemandeCritere_select();
			
			if(!"".equals(f_voi_id) && f_voi_id!=null){
				vLwvol8DemandeCritere.f_voi_id = new BigDecimal(f_voi_id);
			}
			if(!"".equals(f_cle_reprise) && f_cle_reprise!=null){
				vLwvol8DemandeCritere.f_cle_reprise = new BigDecimal(f_cle_reprise);
			}
			
			vLwvol8DemandeCritere.f_col_tri 	= f_col_tri;
			vLwvol8DemandeCritere.f_ordre_tri 	= f_ordre_tri;
			vLwvol8DemandeCritere.f_filtre_type = f_filtre_type;
					
            vLwvol8Demande.critere_select = vLwvol8DemandeCritere;
			vLwvol8.demande = vLwvol8Demande;

			jwlwvol8.setNwlwvol8Awlwvol8 (vLwvol8);
			
		    // CALL SERVER
		    jwlwvol8.nwlwvol8();
				                                
	        // Verification du code retour
			vWebent = jwlwvol8.getNwlwvol8Axwebent();
			System.out.println("Code retour nwlwvol8() = " + vWebent.code_retour.intValue());
			
			if(vWebent.code_retour.intValue() != 0){
				for(int i=0; i < vWebent.nb_ano.intValue(); i++){
				   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] :  " + vWebent.t_ano[i].lib_ano.trim() + " ");
			   	   }
				}
			else {
				//Recuperation du resultat si code retour OK
				Jwlwvol8.Nwlwvol8Awlwvol8_tab vWeblsttab = jwlwvol8.getNwlwvol8Awlwvol8_tab();
				
				//Affichage de la liste des resultats
				if(PRINT == "YES") {
					System.out.println("\n");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "  num_voie ="	 	+ vWeblsttab.ligne_ref[i].type_portage 
									+ "; cd_zpo_n ="     	+ vWeblsttab.ligne_ref[i].cd_zpo
									+ "; cd_zpo_t ="  	 	+ vWeblsttab.ligne_ref[i].lib_zpo
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwvol8.getNwlwvol8Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwvol8.getNwlwvol8Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwvol8.getNwlwvol8Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwvol8.getNwlwvol8Axweblst().nb_pages_totales);
				}
			}
			return jwlwvol8;
			
	   } // End getListeVoies 

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA91");
			Broker broker 	  = JxweblogWeb.logonBroker();
			Jxweblog jxweblog = JxweblogWeb.getConnexion(broker);
			PRINT = "YES";
			
			Jxweblog.NxweblogAxwebent connexion = jxweblog.getNxweblogAxwebent();
			String groupe_exploitant 			= connexion.groupe_exploitant;
			String numero_session 				= Integer.toString(connexion.numero_session.intValue());
			String utilisateur 					= connexion.utilisateur;
			String cd_cible						= connexion.cd_cible;
			String cd_stegrp 					= connexion.cd_stegrp;
		
			//--------------------Donnee test------------------
			String nbrep 		 = "20";
			String page 		 = "1";
			String fonction 	 = "I";

			String f_voi_id 	 = null; //obligatoire
			String f_col_tri	 = null;
			String f_ordre_tri	 = null;
			String f_filtre_type = null;
			String f_cle_reprise = null;
			//--------------------Donnee test------------------
			getListeVoies(nbrep, page, fonction,
						  f_voi_id, f_col_tri, f_ordre_tri, f_filtre_type, f_cle_reprise,
						  groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwvol8Web