1
0
Fork 0

Add search for client by name or id

This commit is contained in:
Ethanell 2022-06-29 23:10:45 +02:00
parent 538f00bef2
commit 06190ecb56
9 changed files with 64 additions and 28 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/dist/

View file

@ -7,14 +7,15 @@
<header> <header>
<nav style="display: flex; flex-direction: row; justify-content: space-between"> <nav style="display: flex; flex-direction: row; justify-content: space-between">
<div style="display: flex; flex-direction: row"> <div style="display: flex; flex-direction: row">
<p>Bienvenue ${user.login}</p> <p>Welcome ${user.login}</p>
</div> </div>
<div style="display: flex; flex-direction: row; justify-content: flex-end"> <div style="display: flex; flex-direction: row; justify-content: flex-end">
<form name="form" method="POST"> <form name="form" method="POST">
<input type="submit" formaction="logout.htm" value="Se déconnecter" /> <input type="submit" formaction="logout.htm" value="Log out" />
<input type="text" name="search" /> <input type="text" name="query" />
<input type="submit" formaction="search.htm" value="Chercher" /> <input hidden type="text" name="type" value="customer" />
<input type="submit" formaction="find.htm" value="Search user" />
</form> </form>
</div> </div>
</nav> </nav>

View file

@ -7,14 +7,15 @@
<header> <header>
<nav style="display: flex; flex-direction: row; justify-content: space-between"> <nav style="display: flex; flex-direction: row; justify-content: space-between">
<div style="display: flex; flex-direction: row"> <div style="display: flex; flex-direction: row">
<p>Bienvenue ${user.login}</p> <p>Welcome ${user.login}</p>
</div> </div>
<div style="display: flex; flex-direction: row; justify-content: flex-end"> <div style="display: flex; flex-direction: row; justify-content: flex-end">
<form name="form" method="POST"> <form name="form" method="POST">
<input type="submit" formaction="logout.htm" value="Se déconnecter" /> <input type="submit" formaction="logout.htm" value="Log out" />
<input type="text" name="search" /> <input type="text" name="query" />
<input type="submit" formaction="search.htm" value="Chercher" /> <input hidden type="text" name="type" value="customer" />
<input type="submit" formaction="find.htm" value="Search user" />
</form> </form>
</div> </div>
</nav> </nav>

View file

@ -136,7 +136,7 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List getClients(String name){ public List getClientsColums(String name){
List resultat=null; List resultat=null;
Transaction tx=null; Transaction tx=null;
try{ try{
@ -159,6 +159,28 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List getClientsColums(int _id){
List resultat=null;
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip from Customer a where a.customerId = :_id");
q.setInteger("_id", _id);
resultat=q.list();
}
catch (Exception e) {
e.printStackTrace();
}
finally{
if (session.isOpen())session.close();
}
return resultat;
}
public List getManufacturers(){ public List getManufacturers(){
List <Manufacturer> resultat=null; List <Manufacturer> resultat=null;
Transaction tx=null; Transaction tx=null;

View file

@ -149,21 +149,31 @@ public class BddController extends MultiActionController {
public ModelAndView find(HttpServletRequest request, public ModelAndView find(HttpServletRequest request,
HttpServletResponse response) throws Exception { HttpServletResponse response) throws Exception {
sessionInit(request); sessionInit(request);
String type = request.getParameter("type");
ModelAndView mv ; ModelAndView mv = new ModelAndView("resultat");
MagasinHelper requeteur = new MagasinHelper();
if (requeteur.getClients(request.getParameter("nom")).isEmpty() || request.getParameter("nom").equals("%") ){
mv= new ModelAndView("error");
mv.addObject("erreur", "0 enregistrement");
}
else{
mv= new ModelAndView("resultat");
mv.addObject("liste",requeteur.getClients(request.getParameter("nom")));
}
mv.addObject("user",session.getAttribute("user")); mv.addObject("user",session.getAttribute("user"));
mv.addObject("type", type);
String query = request.getParameter("query");
if (query == null || query.isEmpty())
mv.addObject("error", "No query");
else {
List<Customer> customers = new ArrayList<Customer>();
try {
customers.addAll(new MagasinHelper().getClientsColums(Integer.parseInt(query)));
} catch (NumberFormatException exception) {
}
query = "%".concat(query.concat("%"));
customers.addAll(new MagasinHelper().getClientsColums(query));
if (customers.size() == 0)
mv.addObject("error", "No user found :/");
else
mv.addObject("results", customers);
}
MagasinHelper helper = new MagasinHelper();
return mv; return mv;
} }
public ModelAndView formfind(HttpServletRequest request, public ModelAndView formfind(HttpServletRequest request,

View file

@ -7,14 +7,15 @@
<header> <header>
<nav style="display: flex; flex-direction: row; justify-content: space-between"> <nav style="display: flex; flex-direction: row; justify-content: space-between">
<div style="display: flex; flex-direction: row"> <div style="display: flex; flex-direction: row">
<p>Bienvenue ${user.login}</p> <p>Welcome ${user.login}</p>
</div> </div>
<div style="display: flex; flex-direction: row; justify-content: flex-end"> <div style="display: flex; flex-direction: row; justify-content: flex-end">
<form name="form" method="POST"> <form name="form" method="POST">
<input type="submit" formaction="logout.htm" value="Se déconnecter" /> <input type="submit" formaction="logout.htm" value="Log out" />
<input type="text" name="search" /> <input type="text" name="query" />
<input type="submit" formaction="search.htm" value="Chercher" /> <input hidden type="text" name="type" value="customer" />
<input type="submit" formaction="find.htm" value="Search user" />
</form> </form>
</div> </div>
</nav> </nav>