import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwvol2Web</p>
* <p>Description : Consultation , Liste des voies </p>
* <p>Copyright : Copyright (c) 2013</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>23/01/2013</i>
* @version 1.0
 */
public class Jwlwvol2Web {	

		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>23/01/2013</i>
		 * @version 1.0
		 * @top_action O': Ordonnancer 'D': Désordonnancer 'Z': Zoner 'N': Dézoner
		 */
		public static Jwlwvol2 getListeVoies (
			String nbrep,
			String page,
			String fonction,
			String f_matricule_voie,
			String f_cd_insee,
			String f_mot_directeur,
			String f_top_liste,
			String f_top_filtre,
			String f_filtre_figaro,
			String f_filtre_zone,
			String f_top_filtre_zone,
			String f_col_tri,
			String f_ordre_tri,
			String f_cle_reprise,
			String f_top_ts,
			String f_borne_inf,
			String f_borne_sup,
            String f_num_ordre_inf,
			String f_type_affect,
            String f_zpo_affect,
            String f_top_valid,
			String f_top_action,
			String f_mode,			
            String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwvol2 jwlwvol2 = new Jwlwvol2(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwvol2.Nwlwvol2Axwebent vWebent = jwlwvol2.new Nwlwvol2Axwebent();
			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;
			jwlwvol2.setNwlwvol2Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwvol2.Nwlwvol2Axweblst vWeblst = jwlwvol2.new Nwlwvol2Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwvol2.setNwlwvol2Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwvol2.Nwlwvol2Awlwvol2 vLwvol2 = jwlwvol2.new Nwlwvol2Awlwvol2();
			Jwlwvol2.Nwlwvol2Awlwvol2Demande vLwvol2Demande = jwlwvol2.new Nwlwvol2Awlwvol2Demande();
			
			Jwlwvol2.Nwlwvol2Awlwvol2DemandeCritere_select vLwvol2DemandeCritere = jwlwvol2.new Nwlwvol2Awlwvol2DemandeCritere_select();
			
			if(!"".equals(f_matricule_voie) && f_matricule_voie!=null){
				vLwvol2DemandeCritere.f_matricule_voie 	   	= new BigDecimal(f_matricule_voie);
			}
			vLwvol2DemandeCritere.f_cd_insee  		    = f_cd_insee;
			vLwvol2DemandeCritere.f_mot_directeur  		= f_mot_directeur;
			vLwvol2DemandeCritere.f_top_liste  		    = f_top_liste;
			vLwvol2DemandeCritere.f_top_filtre  		= f_top_filtre;
            vLwvol2DemandeCritere.f_filtre_figaro 	   	= f_filtre_figaro;
            vLwvol2DemandeCritere.f_top_ts 	   			= f_top_ts;
            
			if(!"".equals(f_cle_reprise) && f_cle_reprise!= null){
				vLwvol2DemandeCritere.f_cle_reprise  =  new BigDecimal(f_cle_reprise);
			}
            vLwvol2DemandeCritere.f_filtre_zone  = f_filtre_zone;
			vLwvol2DemandeCritere.f_top_filtre_zone  = f_top_filtre_zone;
            vLwvol2DemandeCritere.f_col_tri		 = f_col_tri;
			vLwvol2DemandeCritere.f_ordre_tri	 = f_ordre_tri;
			vLwvol2DemandeCritere.f_borne_inf	 = f_borne_inf;
			vLwvol2DemandeCritere.f_borne_sup	 = f_borne_sup;
            vLwvol2DemandeCritere.f_num_ordre_inf= f_num_ordre_inf;
			vLwvol2DemandeCritere.f_type_affect	 = f_type_affect;
            vLwvol2DemandeCritere.f_zpo_affect	 = f_zpo_affect;
            vLwvol2DemandeCritere.f_top_valid	 = f_top_valid;
			vLwvol2DemandeCritere.f_top_action	 = f_top_action;
			vLwvol2DemandeCritere.mode	 	     = f_mode;
			
            vLwvol2Demande.critere_select = vLwvol2DemandeCritere;
			vLwvol2.demande = vLwvol2Demande;

			jwlwvol2.setNwlwvol2Awlwvol2 (vLwvol2);
			
		    // CALL SERVER
		    jwlwvol2.nwlwvol2();
				                                
	        // Verification du code retour
			vWebent = jwlwvol2.getNwlwvol2Axwebent();
			System.out.println("Code retour nwlwvol2() = " + 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
				Jwlwvol2.Nwlwvol2Awlwvol2_tab vWeblsttab = jwlwvol2.getNwlwvol2Awlwvol2_tab();
				
				//Affichage de la liste des resultats
				if(PRINT == "YES") {
					System.out.println("\n");
					System.out.println (
									  "CD-INSEE       	    ="   + vWeblsttab.cd_insee 
									+ "\n LOCALITE       	="   + vWeblsttab.localite
									+ "\n BUREAU-DIS     	="   + vWeblsttab.bureau_dis 
									+ "\n LIBELLE-VOIE   	="   + vWeblsttab.libelle_voie 
									+ "\n MOT-DIR-VOIE   	="   + vWeblsttab.mot_dir_voie
									+ "\n CODE-POSTAL   	=" 	 + vWeblsttab.code_postal
									+ "\n MATRICULE-VOIE 	=" 	 + vWeblsttab.matricule_voie
									+ "\n VOI-ID         	=" 	 + vWeblsttab.voi_id
									+ "\n BORNE-MAX      	=" 	 + vWeblsttab.borne_max
									+ "\n BORNE-MIN      	=" 	 + vWeblsttab.borne_min
									+ "\n TYPE-VOIE      	=" 	 + vWeblsttab.type_voie
									+ "\n TOP PAGE SUIVANTE =" 	 + vWeblsttab.top_page_suivante
									+ "\n CLE REPRISE		=" 	 + vWeblsttab.cle_reprise
									); 
							System.out.println("\n");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "  num_voie ="	 + vWeblsttab.ligne_ref[i].num_voie 
									+ "; num_ordre="     + vWeblsttab.ligne_ref[i].num_ordre
									+ "; cd_zpo_N ="  	 + vWeblsttab.ligne_ref[i].cd_zpo_n
									+ "; cd_zpo_R ="  	 + vWeblsttab.ligne_ref[i].cd_zpo_r
									+ "; cd_zpo_T ="  	 + vWeblsttab.ligne_ref[i].cd_zpo_t
									+ "; top_ref  =" 	 + vWeblsttab.ligne_ref[i].top_ref
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwvol2.getNwlwvol2Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwvol2.getNwlwvol2Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwvol2.getNwlwvol2Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwvol2.getNwlwvol2Axweblst().nb_pages_totales);
				}
			}
			return jwlwvol2;
			
	   } // 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 ("MADAA11");
			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_matricule_voie = "1457171";
			String f_cd_insee 	   	= "1457171";
			String f_mot_directeur 	= null;
			String f_top_liste		= "O" ;
			String f_top_filtre		= "T" ;
			String f_filtre_figaro 		= null;	
			String f_filtre_zone 		= null ;
			String f_top_filtre_zone 	= null ;
			String f_col_tri 			= "V" ;
			String f_ordre_tri 			= "O" ;
			String f_cle_reprise		= null ;
			String f_top_ts			    = null ;
			String f_borne_inf 			= null ;
			String f_borne_sup 			= null ;
            String f_num_ordre_inf 		= null ;
			String f_type_affect 		= null ;
            String f_zpo_affect 		= null ;
            String f_top_valid 			= null ;
			String f_top_action 		= null ;
			String f_mode				= null ; // 'M' affichage de la liste en mode mise à jour, 'D' pour débloquer sans plus lister
			//--------------------Donnee test------------------
			getListeVoies(nbrep, page, fonction, f_matricule_voie, f_cd_insee, f_mot_directeur, f_top_liste, f_top_filtre,
					f_filtre_figaro, f_filtre_zone, f_top_filtre_zone, f_col_tri, f_ordre_tri, f_cle_reprise, f_top_ts,
					f_borne_inf, f_borne_sup, f_num_ordre_inf, f_type_affect, f_zpo_affect,f_top_valid, f_top_action,
					f_mode, groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwvol2Web