import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwvol9Web</p>
* <p>Description : Consultation , Liste des voies d'une zone (avec voies synonyme) </p>
* <p>Copyright : Copyright (c) 2013</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>24/04/2013</i>
* @version 1.0
 */
public class Jwlwvol9Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeVoies </p>
		 * <p>Description : Consultation ,  Consultation , Liste des voies d'une zone (avec voies synonyme)  </p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>24/04/2013</i>
		 * @version 1.0
		 */
		public static Jwlwvol9 getListeVoies (
			String nbrep,
			String page,
			String fonction,
			String f_cd_zpo,
			String f_type_portage,
			String f_tpr_groupe,
			String f_tpr_num,
			String f_mot_directeur_voie,
			String f_code_insee,
			String f_top_ts,
            String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwvol9 jwlwvol9 = new Jwlwvol9(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwvol9.Nwlwvol9Axwebent vWebent = jwlwvol9.new Nwlwvol9Axwebent();
			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;
			jwlwvol9.setNwlwvol9Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwvol9.Nwlwvol9Axweblst vWeblst = jwlwvol9.new Nwlwvol9Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwvol9.setNwlwvol9Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwvol9.Nwlwvol9Awlwvol9 vLwvol9 = jwlwvol9.new Nwlwvol9Awlwvol9();
			Jwlwvol9.Nwlwvol9Awlwvol9Demande vLwvol9Demande = jwlwvol9.new Nwlwvol9Awlwvol9Demande();
			
			Jwlwvol9.Nwlwvol9Awlwvol9DemandeCritere_select vLwvol9DemandeCritere = jwlwvol9.new Nwlwvol9Awlwvol9DemandeCritere_select();
			
			vLwvol9DemandeCritere.f_cd_zpo 		       = f_cd_zpo;
			vLwvol9DemandeCritere.f_type_portage  	   = f_type_portage;
			vLwvol9DemandeCritere.f_tpr_groupe  	   = f_tpr_groupe;
			vLwvol9DemandeCritere.f_tpr_num			   = f_tpr_num;
			vLwvol9DemandeCritere.f_mot_directeur_voie = f_mot_directeur_voie;
            vLwvol9DemandeCritere.f_code_insee 	   	   = f_code_insee;
            vLwvol9DemandeCritere.f_top_ts 	   		   = f_top_ts;
			
            vLwvol9Demande.critere_select = vLwvol9DemandeCritere;
			vLwvol9.demande = vLwvol9Demande;

			jwlwvol9.setNwlwvol9Awlwvol9 (vLwvol9);
			
		    // CALL SERVER
		    jwlwvol9.nwlwvol9();
				                                
	        // Verification du code retour
			vWebent = jwlwvol9.getNwlwvol9Axwebent();
			System.out.println("Code retour nwlwvol9() = " + 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
				Jwlwvol9.Nwlwvol9Awlwvol9_tab vWeblsttab = jwlwvol9.getNwlwvol9Awlwvol9_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.liste_voie_synonyme[i].voi_id 
									+ "; num_ordre="     + vWeblsttab.liste_voie_synonyme[i].code_insee
									+ "; cd_zpo_N ="  	 + vWeblsttab.liste_voie_synonyme[i].code_postal
									+ "; cd_zpo_R ="  	 + vWeblsttab.liste_voie_synonyme[i].matricule_mere
									+ "; cd_zpo_T ="  	 + vWeblsttab.liste_voie_synonyme[i].matricule_cible
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].libelle_voie
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].mot_directeur_voie
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].matricule_voie_syn
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].libelle_voie_syn
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].min_borne_p
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].min_borne_i
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].max_borne_p
									+ "; top_ref  =" 	 + vWeblsttab.liste_voie_synonyme[i].max_borne_i
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwvol9.getNwlwvol9Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwvol9.getNwlwvol9Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwvol9.getNwlwvol9Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwvol9.getNwlwvol9Axweblst().nb_pages_totales);
				}
			}
			return jwlwvol9;
			
	   } // End getListeVoies 

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>23/01/2013</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA01");
			JxweblogWeb.setPassword ("MADAA81");
			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_cd_zpo 			= "FC03";
			String f_type_portage 		= "R";
			String f_tpr_groupe 		= null;
			String f_tpr_num			= null ;
			String f_mot_directeur_voie	= "B" ;
			String f_code_insee 		= null;	
			String f_top_ts 			= null ;
			//--------------------Donnee test------------------
			getListeVoies(nbrep, page, fonction,
					f_cd_zpo, f_type_portage, f_tpr_groupe, f_tpr_num,
					f_mot_directeur_voie, f_code_insee, f_top_ts,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwvol9Web