/*
 * ListadoAction.java
 *
 * Created on 8 de noviembre de 2007, 16:03
 */

package servlets;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.*;
import org.apache.struts.actions.*;

import javabeans.*;
import modelo.*;
import java.util.*;
public class ListadoAction extends DispatchAction {   
    public ActionForward todas(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {      
         OpcionesForm of=(OpcionesForm)form;
         GestionLlamadas gl=getGestionLlamadas(request);  
         request.setAttribute("llamadas",gl.getTodasLlamadasTelefono(of.getNumero()));
         return mapping.findForward("listado");
    }
    
    public ActionForward portipo(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception { 
         OpcionesForm of=(OpcionesForm)form;
         GestionLlamadas gl=getGestionLlamadas(request);  
         request.setAttribute("llamadas",gl.getLlamadasTelefonoPorTipoTarifa(of.getNumero(),of.getTipo()));
         return mapping.findForward("listado"); 
        
    }
    
    public ActionForward porfecha(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {      
         OpcionesForm of=(OpcionesForm)form;       
         GestionLlamadas gl=getGestionLlamadas(request);           
         request.setAttribute("llamadas",gl.getLlamadasTelefonoApartirFecha(of.getNumero(),of.getFecha()));
         return mapping.findForward("listado");
    }
    
    private GestionLlamadas getGestionLlamadas(HttpServletRequest request){
        String driver=this.getServlet().getServletContext().getInitParameter("driver");
        String cadenaCon=this.getServlet().getServletContext().getInitParameter("cadenaCon");
        return new GestionLlamadas(driver,cadenaCon);     
    }
}
