示例#1
0
  private void actionValiderCaddy(
      HttpServletRequest request, HttpServletResponse response, ServletContext sc) {
    OracleAccess oracle = (OracleAccess) getVariableSession(request, "oracle");
    BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
    LinkedList<Integer> listInserer = new LinkedList<Integer>();
    for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
      oracle.initCallProc("PACKAGE_RECHERCHE", "insertCommande", 3);
      boolean ok =
          oracle.doInsertCommande(
              beanMovieCaddy.getId(), beanMovieCaddy.getQuantite(), beanMovieCaddy.getPhysique());
      if (ok) {
        listInserer.add(beanMovieCaddy.getId());
      }
    }

    int taille = beanCaddy.getListMovie().size();
    for (int idInserer : listInserer) {
      int i = 0;
      while (i < taille) {
        if (beanCaddy.getListMovie().get(i).getId() == idInserer) {
          beanCaddy.getListMovie().remove(i);
          break;
        }
        i++;
      }
    }
    addVariableSession(request, "beanCaddy", beanCaddy);
    setCaddy(request, sc);
  }
示例#2
0
 private void actionViderItemCaddy(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc) {
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   beanCaddy.getListMovie().clear();
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
示例#3
0
 private void actionCommander(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc) {
   int idMovie = Integer.parseInt(request.getParameter("idMovie"));
   int quantite = Integer.parseInt(request.getParameter("quantite"));
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   boolean found = false;
   if (beanCaddy == null) {
     beanCaddy = new BeanCaddy();
   } else {
     for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
       if (beanMovieCaddy.getId() == idMovie) {
         beanMovieCaddy.addQuantite(quantite);
         found = true;
         break;
       }
     }
   }
   if (found == false) {
     BeanResultat beanResultat = (BeanResultat) getVariableSession(request, "beanResultat");
     BeanMovieCaddy beanMovieToAdd = null;
     for (BeanMovie beanMovie : beanResultat.getListMovie()) {
       if (beanMovie.getId() == idMovie) {
         beanMovieToAdd = new BeanMovieCaddy(beanMovie);
         beanMovieToAdd.setQuantite(quantite);
         break;
       }
     }
     beanCaddy.add(beanMovieToAdd);
   }
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
示例#4
0
 private void actionSwitcherDigitale(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc, int id) {
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
     if (beanMovieCaddy.getId() == id) {
       if (beanMovieCaddy.getPhysique() == 1) {
         beanMovieCaddy.setPhysique(0);
       } else {
         beanMovieCaddy.setPhysique(1);
       }
     }
   }
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
示例#5
0
  private void actionDeleteItemsCaddy(
      HttpServletRequest request, HttpServletResponse response, ServletContext sc) {
    Enumeration<String> parameterNames = request.getParameterNames();
    ArrayList<String> listeParametre = Collections.list(parameterNames);
    LinkedList<Integer> listeId = new LinkedList<Integer>();
    for (String param : listeParametre) {
      if (param.contains("checkbox")) {
        String checkbox = request.getParameter(param);
        if (checkbox != null) {
          String[] split = param.split("checkbox");
          String num = split[1];
          int id = Integer.parseInt(num);
          listeId.add(id);
        }
      }
    }

    BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
    int cpt = 0;
    int count = listeId.size();
    while (cpt < count) {
      int i = 0;
      int id = listeId.get(cpt);
      int size = beanCaddy.getListMovie().size();
      while (i < size) {
        if (beanCaddy.getListMovie().get(i).getId() == id) {
          beanCaddy.getListMovie().remove(i);
          cpt++;
          break;
        }
        i++;
      }
    }
    addVariableSession(request, "beanCaddy", beanCaddy);
    setCaddy(request, sc);
  }
示例#6
0
 private void actionAjouterItemCaddy(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc, int id) {
   int quantiteAdd = Integer.parseInt(request.getParameter("quantiteAdd"));
   if (quantiteAdd < 0) {
     quantiteAdd *= -1;
   }
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
     if (beanMovieCaddy.getId() == id) {
       beanMovieCaddy.addQuantite(quantiteAdd);
       break;
     }
   }
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
示例#7
0
 private void actionRetirerItemCaddy(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc, int id) {
   int quantiteRemove = Integer.parseInt(request.getParameter("quantiteRemove"));
   BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
   for (BeanMovieCaddy beanMovieCaddy : beanCaddy.getListMovie()) {
     if (beanMovieCaddy.getId() == id) {
       int qte = beanMovieCaddy.getQuantite();
       if (qte - quantiteRemove < 1) {
         beanMovieCaddy.removeQuantite(0);
       } else {
         beanMovieCaddy.removeQuantite(quantiteRemove);
       }
       break;
     }
   }
   addVariableSession(request, "beanCaddy", beanCaddy);
   setCaddy(request, sc);
 }
示例#8
0
 private void traitementAction(
     HttpServletRequest request, HttpServletResponse response, ServletContext sc, String action) {
   if (action == null) {
     this.rediriger(request, response, sc, "/Accueil.jsp");
   } else if (action.equals("Recherche")) {
     this.rediriger(request, response, sc, "/Recherche.jsp");
   } else if (action.equals("Rechercher")) {
     actionRechercher(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("resultat")) {
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("getImage")) {
     int idMovie = Integer.parseInt(request.getParameter("idMovie"));
     BeanResultat beanResultat = (BeanResultat) getVariableSession(request, "beanResultat");
     LinkedList<BeanMovie> listMovie = beanResultat.getListMovie();
     for (BeanMovie beanMovie : listMovie) {
       if (beanMovie.getId() == idMovie) {
         Blob imageBlob = beanMovie.getAffiche();
         response.setContentType("image/jpeg");
         byte[] bytes;
         try {
           bytes = imageBlob.getBytes(1, (int) imageBlob.length());
           bytes = resize(bytes, 138, 97);
           response.setContentLength(bytes.length);
           response.getOutputStream().write(bytes);
           response.getOutputStream().flush();
           response.getOutputStream().close();
         } catch (Exception ex) {
           Logger.getLogger(ServletControle.class.getName()).log(Level.SEVERE, null, ex);
         }
       }
     }
   } else if (action.equals("getImageCaddy")) {
     int idMovie = Integer.parseInt(request.getParameter("idMovie"));
     BeanCaddy beanCaddy = (BeanCaddy) getVariableSession(request, "beanCaddy");
     LinkedList<BeanMovieCaddy> listMovie = beanCaddy.getListMovie();
     for (BeanMovieCaddy beanMovie : listMovie) {
       if (beanMovie.getId() == idMovie) {
         Blob imageBlob = beanMovie.getAffiche();
         response.setContentType("image/jpeg");
         byte[] bytes;
         try {
           bytes = imageBlob.getBytes(1, (int) imageBlob.length());
           bytes = resize(bytes, 138, 97);
           response.setContentLength(bytes.length);
           response.getOutputStream().write(bytes);
           response.getOutputStream().flush();
           response.getOutputStream().close();
         } catch (Exception ex) {
           Logger.getLogger(ServletControle.class.getName()).log(Level.SEVERE, null, ex);
         }
       }
     }
   } else if (action.equals("details")) {
     actionDetails(request, response, sc);
     this.rediriger(request, response, sc, "/Details.jsp");
   } else if (action.equals("getPage")) {
     actionGetPage(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("getPageCaddy")) {
     this.rediriger(
         request, response, sc, "/Caddy.jsp?numPage=" + request.getParameter("numPage"));
   } else if (action.equals("trier")) {
     actionTrier(request, response, sc);
     this.rediriger(request, response, sc, "/Results.jsp");
   } else if (action.equals("commander")) {
     actionCommander(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("deconnecter")) {
     actionDeconnecter(request, response, sc);
     rediriger(request, response, sc, "/index.jsp");
   } else if (action.equals("caddy")) {
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("actionCaddy")) {
     traiterActionCaddy(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else if (action.equals("error")) {
     rediriger(request, response, sc, "/error.jsp");
   } else if (action.equals("validerCaddy")) {
     actionValiderCaddy(request, response, sc);
     rediriger(request, response, sc, "/Caddy.jsp?numPage=0");
   } else {
     this.rediriger(request, response, sc, "/Accueil.jsp");
   }
 }