import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwvom2Web</p>
 * <p>Description : ordonnancement et zonage numéro voie.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>07/03/2013</i>
 * @version 1.0
 */
 
public class Jwlwvom2Web {
	private static final int TAILLE = 40;

	/**
	 * <p>Titre : creatOrdonnancement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwvom2 creatOrdonnancement(
				String code_insee,
				String voi_id,
				String matricule_mere,
				String no_voie_creat,
				String no_ordre_creat,
				String matricule_voie,
				String top_choix_voie,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom2 jwlwvom2 = new Jwlwvom2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom2.Nwlwvom2Axwebent vWebent = jwlwvom2.new Nwlwvom2Axwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "CREAT";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom2.setNwlwvom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom2.Nwlwvom2Awlwvom2 vLwvom2 					= jwlwvom2.new Nwlwvom2Awlwvom2();
		Jwlwvom2.Nwlwvom2Awlwvom2Demande vLwvom2demDemande = jwlwvom2.new Nwlwvom2Awlwvom2Demande();
		vLwvom2demDemande.code_insee   	 = code_insee;
		vLwvom2demDemande.no_voie_creat	 = no_voie_creat;
		vLwvom2demDemande.no_ordre_creat = no_ordre_creat;
		vLwvom2demDemande.top_choix_voie = top_choix_voie;
		
		if(!"".equals(voi_id) && voi_id!=null){
			vLwvom2demDemande.voi_id = new BigDecimal(voi_id);
		}
		if(!"".equals(matricule_mere) && matricule_mere!=null){
			vLwvom2demDemande.matricule_mere = new BigDecimal(matricule_mere);
		}
		if(!"".equals(matricule_voie) && matricule_voie!=null){
			vLwvom2demDemande.matricule_voie = new BigDecimal(matricule_voie);
		}
		
		vLwvom2.demande = vLwvom2demDemande;
		
		jwlwvom2.setNwlwvom2Awlwvom2(vLwvom2);
		
		// CALL SERVER
		jwlwvom2.nwlwvom2();
		
		// Verification du code retour
		vWebent = jwlwvom2.getNwlwvom2Axwebent();
		System.out.println("Code retour nwlwvom2() = " + 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{
			System.out.println(vWebent.t_ano[0].lib_ano.trim());
			//affichage de reponse
			System.out.println("suite normal...");
		}
		return jwlwvom2;
	   } // End getOrdonnancement
	   
	//FIN  CREATION
	
	
	/**
	 * <p>Titre : setOrdonnancement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 * @top_action O': Ordonnancer 'D': Désordonnancer 'Z': Zoner 'N': Dézoner
	 */
	public static Jwlwvom2 setOrdonnancement(
		String code_insee,
		String voi_id,
		String matricule_mere,
		String matricule_voie,
		String num_voie[],
		String num_ordre[],
		String cd_zpo_n[],
        String cd_zpo_r[],
        String cd_zpo_t[],
		String top_choix_voie,
		String top_action,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom2 jwlwvom2 		  = new Jwlwvom2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom2.Nwlwvom2Axwebent vWebent = jwlwvom2.new Nwlwvom2Axwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "MODIF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom2.setNwlwvom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom2.Nwlwvom2Awlwvom2 vLwvom2 				= jwlwvom2.new Nwlwvom2Awlwvom2();
		Jwlwvom2.Nwlwvom2Awlwvom2Demande vLwvom2Demande = jwlwvom2.new Nwlwvom2Awlwvom2Demande();
		
		vLwvom2Demande.code_insee   	 = code_insee;
		vLwvom2Demande.top_choix_voie    = top_choix_voie;
		vLwvom2Demande.top_action        = top_action;
		
		if(!"".equals(voi_id) && voi_id!=null){
			vLwvom2Demande.voi_id = new BigDecimal(voi_id);
		}
		if(!"".equals(matricule_mere) && matricule_mere!=null){
			vLwvom2Demande.matricule_mere = new BigDecimal(matricule_mere);
		}
		if(!"".equals(matricule_voie) && matricule_voie!=null){
			vLwvom2Demande.matricule_voie = new BigDecimal(matricule_voie);
		}
		String[] tab_num_voie = new String[500];
		BigDecimal[] tab_num_ordre = new BigDecimal[500];
		int len = num_voie.length ;
		for(int i=0;i< len;i++){
			tab_num_voie[i]   = num_voie[i];
			if(!"".equals(num_ordre[i]) && num_ordre[i]!=null){
				tab_num_ordre[i]  = new BigDecimal(num_ordre[i]);
			}
		}
		String[] tab_cd_zpo_n = new String[500];
        String[] tab_cd_zpo_r = new String[500];
        String[] tab_cd_zpo_t = new String[500];
		if(cd_zpo_n!=null){
			len = cd_zpo_n.length ;
			for(int i=0;i< len;i++){
				tab_cd_zpo_n[i]   = cd_zpo_n[i];
				tab_cd_zpo_r[i]   = cd_zpo_r[i];
				tab_cd_zpo_t[i]   = cd_zpo_t[i];
			}
		}
		
		vLwvom2Demande.num_voie  = tab_num_voie;
		vLwvom2Demande.num_ordre = tab_num_ordre;
		vLwvom2Demande.cd_zpo_n  = tab_cd_zpo_n;
		vLwvom2Demande.cd_zpo_r  = tab_cd_zpo_r;
		vLwvom2Demande.cd_zpo_t  = tab_cd_zpo_t;
		
		vLwvom2.demande = vLwvom2Demande;
		
		jwlwvom2.setNwlwvom2Awlwvom2(vLwvom2);
		
		// CALL SERVER
		jwlwvom2.nwlwvom2();
		
		// Verification du code retour
		vWebent = jwlwvom2.getNwlwvom2Axwebent();
		System.out.println("Code retour nwlwvom2() = " + 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{
			System.out.println(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwvom2;
	   } // End setOrdonnancement
	   
	/**
	 * <p>Titre : setOrdonnancement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwvom2 deleteOrdonnancement(
		String code_insee,
		String voi_id,
		String matricule_mere,
		String num_voie[],
		String num_ordre[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom2 jwlwvom2 		  = new Jwlwvom2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom2.Nwlwvom2Axwebent vWebent = jwlwvom2.new Nwlwvom2Axwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "SUPP";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom2.setNwlwvom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom2.Nwlwvom2Awlwvom2 vLwvom2 				= jwlwvom2.new Nwlwvom2Awlwvom2();
		Jwlwvom2.Nwlwvom2Awlwvom2Demande vLwvom2Demande = jwlwvom2.new Nwlwvom2Awlwvom2Demande();
		
		vLwvom2Demande.code_insee   	 = code_insee;
		
		if(!"".equals(voi_id) && voi_id!=null){
			vLwvom2Demande.voi_id = new BigDecimal(voi_id);
		}
		if(!"".equals(matricule_mere) && matricule_mere!=null){
			vLwvom2Demande.matricule_mere = new BigDecimal(matricule_mere);
		}
		String[] tab_num_voie = new String[500];
		BigDecimal[] tab_num_ordre = new BigDecimal[500];
		int len = num_voie.length ;
		for(int i=0;i< len;i++){
			tab_num_voie[i]   = num_voie[i];
			if(!"".equals(num_ordre[i]) && num_ordre[i]!=null){
				tab_num_ordre[i]  = new BigDecimal(num_ordre[i]);
			}
		}
		vLwvom2Demande.num_voie  = tab_num_voie;
		vLwvom2Demande.num_ordre = tab_num_ordre;
		vLwvom2.demande = vLwvom2Demande;
		
		jwlwvom2.setNwlwvom2Awlwvom2(vLwvom2);
		
		// CALL SERVER
		jwlwvom2.nwlwvom2();
		
		// Verification du code retour
		vWebent = jwlwvom2.getNwlwvom2Axwebent();
		System.out.println("Code retour nwlwvom2() = " + 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{
			System.out.println(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwvom2;
	   } // End setOrdonnancement			

	/**
		 * <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>25/03/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA82");
			Broker broker 				    	= JxweblogWeb.logonBroker();
			Jxweblog jxweblog 				    = JxweblogWeb.getConnexion(broker);
			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;
			
			//Test de MODIFICATION
			//---------Donnee Test---------------
			String code_insee ="75105" ;
			String voi_id="0" ;
			String matricule_mere="1453644" ;
			String no_voie_creat="17" ;
			String no_ordre_creat="10" ;
			String matricule_voie="1453644" ;
			String[] tab_num_voie = {"2"} ;
			String[] tab_num_order = {"1"} ;
			String[] tab_cd_zpo_n = {null} ;
			String top_action = null ;
			//---------Donnee Test---------------
			setOrdonnancement(
				code_insee,
				voi_id,
				matricule_mere,
				matricule_voie,
				tab_num_voie,
				tab_num_order,
				tab_cd_zpo_n,
				tab_cd_zpo_n,
				tab_cd_zpo_n,
				null,
				top_action,
				groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			//Test de SUPPRESSION
			//---------Donnee Test---------------
			/*String lig_sel[] = new String[1] ;
			String cd_zpo[] = new String[1] ;
			String type_portage[]= new String[1] ;
			String cd_prt[]= new String[1] ;
			String res_isn[]= new String[1] ;
			String hprt_date_debut[]= new String[1] ;
			lig_sel[0]="S" ;
			cd_zpo[0]="AHAH" ;
			type_portage[0]="N" ;
			cd_prt[0]="0447" ;
			res_isn[0]="8" ;
			hprt_date_debut[0]="20630704" ;
			
			//---------Donnee Test---------------
			deleteOrdonnancement(
					lig_sel,
					cd_zpo,
					type_portage,
					cd_prt,
					res_isn,
					hprt_date_debut,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			//CREATION
			
		}

	//FIN  INTERROGATION

}