import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwtcm1Web</p>
 * <p>Description : Création/suppr tronçons.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>05/04/2013</i>
 * @version 1.0
 */
 
public class Jwlwtcm1Web {
	private static final int TAILLE = 50;

	/**
	 * <p>Titre : createTroncon</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>05/04/2013</i>
	 * @version 1.0
	 */
	public static Jwlwtcm1 createTroncon(
				String no_ordre_creat,
				String mot_directeur,
				String min_borne_p,
				String min_borne_i,
				String max_borne_p,
				String max_borne_i,
				String cd_zpo,
				String type_portage,
				String tpr_groupe,
				String tpr_num,
				String voi_id,	
				String lib_voie_creat,	
				String matricule_mere,	
				String cd_insee,	
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtcm1 jwlwtcm1 = new Jwlwtcm1(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtcm1.Nwlwtcm1Axwebent vWebent = jwlwtcm1.new Nwlwtcm1Axwebent();
		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;
		jwlwtcm1.setNwlwtcm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtcm1.Nwlwtcm1Awlwtcm1 vLwtcm1 					= jwlwtcm1.new Nwlwtcm1Awlwtcm1();
		Jwlwtcm1.Nwlwtcm1Awlwtcm1Param vLwtcm1Param = jwlwtcm1.new Nwlwtcm1Awlwtcm1Param();
		vLwtcm1Param.cd_action   	 = "C";
		vLwtcm1Param.no_ordre_creat	 = no_ordre_creat;
		vLwtcm1Param.mot_directeur   = mot_directeur;
		vLwtcm1Param.lib_voie_creat  = lib_voie_creat;
		vLwtcm1Param.code_insee        = cd_insee;
		
		vLwtcm1Param.min_borne_p = min_borne_p;
		vLwtcm1Param.min_borne_i = min_borne_i;
		vLwtcm1Param.max_borne_p = max_borne_p;
		vLwtcm1Param.max_borne_i = max_borne_i;
		
		vLwtcm1Param.cd_zpo   	  = cd_zpo;
		vLwtcm1Param.type_portage = type_portage;
		vLwtcm1Param.tpr_groupe   = tpr_groupe;
		vLwtcm1Param.tpr_num   	  = tpr_num;
		
		if(!"".equals(voi_id) && voi_id!=null){
			vLwtcm1Param.voi_id   	  = new BigDecimal(voi_id);
		}
		if(!"".equals(matricule_mere) && matricule_mere!=null){
			vLwtcm1Param.matricule_mere   	  = new BigDecimal(matricule_mere);
		}
		
		vLwtcm1.param = vLwtcm1Param;
		
		jwlwtcm1.setNwlwtcm1Awlwtcm1(vLwtcm1);
		
		// CALL SERVER
		jwlwtcm1.nwlwtcm1();
		
		// Verification du code retour
		vWebent = jwlwtcm1.getNwlwtcm1Axwebent();
		System.out.println("Code retour nwlwtcm1() = " + 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{
			Jwlwtcm1.Nwlwtcm1Awlwtcm1Info_retour infoRetour = jwlwtcm1.new Nwlwtcm1Awlwtcm1Info_retour();
			infoRetour = jwlwtcm1.getNwlwtcm1Awlwtcm1().info_retour;
			System.out.println("Message: "); ;
			System.out.println(" CODE-RET: " + infoRetour.code_ret.trim() ); ;
			System.out.println(" TYPE-RET: " + infoRetour.type_ret.trim() ); ;
			System.out.println(" LIB-RET : " + infoRetour.lib_ret.trim() ); ;
			System.out.println("suite normal...");
		}
		return jwlwtcm1;
	   } // End getTroncon
	   
	//FIN  createION
	
	
	/**
	 * <p>Titre : setTroncon</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 Jwlwtcm1 deleteTroncon(
		String cd_zpo,
		String type_portage,
		String tpr_groupe,
		String tpr_num,
		String tpo_id[],
		String no_ordre[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtcm1 jwlwtcm1 		  = new Jwlwtcm1(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtcm1.Nwlwtcm1Axwebent vWebent = jwlwtcm1.new Nwlwtcm1Axwebent();
		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 		  = null;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwtcm1.setNwlwtcm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtcm1.Nwlwtcm1Awlwtcm1 vLwtcm1 		    = jwlwtcm1.new Nwlwtcm1Awlwtcm1();
		Jwlwtcm1.Nwlwtcm1Awlwtcm1Param vLwtcm1Param = jwlwtcm1.new Nwlwtcm1Awlwtcm1Param();
		
		vLwtcm1Param.cd_action 	  = "S";
		vLwtcm1Param.cd_zpo    	  = cd_zpo;
		vLwtcm1Param.type_portage = type_portage;
		vLwtcm1Param.tpr_groupe   = tpr_groupe;
		vLwtcm1Param.tpr_num   	  = tpr_num;
		
		Jwlwtcm1.Nwlwtcm1Awlwtcm1ParamTab_stock vLwtcm1TabStock[] = new Jwlwtcm1.Nwlwtcm1Awlwtcm1ParamTab_stock[TAILLE];
		for (int i = 0; i < TAILLE ; i++) {
			vLwtcm1TabStock[i] = jwlwtcm1.new Nwlwtcm1Awlwtcm1ParamTab_stock();
		}
		for (int i = 0; i < tpo_id.length; i++) {
			if(!"".equals(tpo_id[i]) && tpo_id[i]!=null)
				vLwtcm1TabStock[i].tpo_id   = new BigDecimal(tpo_id[i]);
			if(!"".equals(no_ordre[i]) && no_ordre[i]!=null)
				vLwtcm1TabStock[i].no_ordre = new BigDecimal(no_ordre[i]);
		}
		vLwtcm1Param.tab_stock = vLwtcm1TabStock;
		vLwtcm1.param = vLwtcm1Param;
		
		
		jwlwtcm1.setNwlwtcm1Awlwtcm1(vLwtcm1);
		
		// CALL SERVER
		jwlwtcm1.nwlwtcm1();
		
		// Verification du code retour
		vWebent = jwlwtcm1.getNwlwtcm1Axwebent();
		System.out.println("Code retour nwlwtcm1() = " + 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{
			Jwlwtcm1.Nwlwtcm1Awlwtcm1Info_retour infoRetour = jwlwtcm1.new Nwlwtcm1Awlwtcm1Info_retour();
			infoRetour = jwlwtcm1.getNwlwtcm1Awlwtcm1().info_retour;
			System.out.println("Message: "); ;
			System.out.println(" CODE-RET: " + infoRetour.code_ret.trim() ); ;
			System.out.println(" TYPE-RET: " + infoRetour.type_ret.trim() ); ;
			System.out.println(" LIB-RET : " + infoRetour.lib_ret.trim() ); ;
			System.out.println("suite normal...");
		}
		
		return jwlwtcm1;
	   } // End setTroncon			

	/**
		 * <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 ("MADAA92");
			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 SUPPRESSION
			//---------Donnee Test---------------
			/*String cd_zpo 		= null;
			String type_portage = null;
			String tpr_groupe 	= null;
			String tpr_num 		= null;
			String tpo_id[] 	= null;
			String no_ordre[] 	= null;
			//---------Donnee Test---------------
			deleteTroncon(cd_zpo, type_portage, tpr_groupe, tpr_num, tpo_id, no_ordre,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
			
			//Test de CREATION
			//---------Donnee Test---------------
			String no_ordre_creat = "1";
			String mot_directeur  = "ANNE";
			String min_borne_p    = "0010";
			String min_borne_i    = "0011";
			String max_borne_p    = "0012";
			String max_borne_i    = "0011";
			String cd_zpo         = "0001";
			String type_portage   = "N";
			String tpr_groupe 	  = "5";
			String tpr_num 		  = "102";
			String voi_id 		  = "27858";
			String lib_voie_creat = "RUE SAINTE ANNE" ;	
			String matricule_mere = "1452969" ;	
			String cd_insee		  = "75101" ;	
			//---------Donnee Test---------------
			createTroncon(no_ordre_creat, mot_directeur, min_borne_p,
					min_borne_i, max_borne_p, max_borne_i, cd_zpo,
					type_portage, tpr_groupe, tpr_num,voi_id, lib_voie_creat,  matricule_mere, cd_insee, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
					
			//Test de SUPPRESSION
			//---------Donnee Test---------------
			/*String cd_zpo         = "0001";
			String type_portage   = "N";
			String tpr_groupe 	  = "5";
			String tpr_num 		  = "501";
			
			String tpo_id[] = new String[TAILLE];
			
			String no_ordre[] = new String[TAILLE];
			no_ordre[0] = "2";
			no_ordre[1] = "5";
			//---------Donnee Test---------------
			deleteTroncon(cd_zpo, type_portage,
					tpr_groupe, tpr_num, tpo_id, no_ordre,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			
		}

}