Add search for client by name or id
This commit is contained in:
parent
538f00bef2
commit
06190ecb56
9 changed files with 64 additions and 28 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/dist/
|
Binary file not shown.
Binary file not shown.
|
@ -7,14 +7,15 @@
|
|||
<header>
|
||||
<nav style="display: flex; flex-direction: row; justify-content: space-between">
|
||||
<div style="display: flex; flex-direction: row">
|
||||
<p>Bienvenue ${user.login}</p>
|
||||
<p>Welcome ${user.login}</p>
|
||||
</div>
|
||||
<div style="display: flex; flex-direction: row; justify-content: flex-end">
|
||||
<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="submit" formaction="search.htm" value="Chercher" />
|
||||
<input type="text" name="query" />
|
||||
<input hidden type="text" name="type" value="customer" />
|
||||
<input type="submit" formaction="find.htm" value="Search user" />
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
<header>
|
||||
<nav style="display: flex; flex-direction: row; justify-content: space-between">
|
||||
<div style="display: flex; flex-direction: row">
|
||||
<p>Bienvenue ${user.login}</p>
|
||||
<p>Welcome ${user.login}</p>
|
||||
</div>
|
||||
<div style="display: flex; flex-direction: row; justify-content: flex-end">
|
||||
<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="submit" formaction="search.htm" value="Chercher" />
|
||||
<input type="text" name="query" />
|
||||
<input hidden type="text" name="type" value="customer" />
|
||||
<input type="submit" formaction="find.htm" value="Search user" />
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
Binary file not shown.
|
@ -136,7 +136,7 @@ public class MagasinHelper {
|
|||
return resultat;
|
||||
}
|
||||
|
||||
public List getClients(String name){
|
||||
public List getClientsColums(String name){
|
||||
List resultat=null;
|
||||
Transaction tx=null;
|
||||
try{
|
||||
|
@ -159,6 +159,28 @@ public class MagasinHelper {
|
|||
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(){
|
||||
List <Manufacturer> resultat=null;
|
||||
Transaction tx=null;
|
||||
|
|
|
@ -148,22 +148,32 @@ public class BddController extends MultiActionController {
|
|||
}
|
||||
public ModelAndView find(HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
sessionInit(request);
|
||||
|
||||
ModelAndView mv ;
|
||||
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")));
|
||||
|
||||
}
|
||||
sessionInit(request);
|
||||
String type = request.getParameter("type");
|
||||
ModelAndView mv = new ModelAndView("resultat");
|
||||
mv.addObject("user",session.getAttribute("user"));
|
||||
mv.addObject("type", type);
|
||||
|
||||
mv.addObject("user",session.getAttribute("user"));
|
||||
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;
|
||||
}
|
||||
public ModelAndView formfind(HttpServletRequest request,
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
<header>
|
||||
<nav style="display: flex; flex-direction: row; justify-content: space-between">
|
||||
<div style="display: flex; flex-direction: row">
|
||||
<p>Bienvenue ${user.login}</p>
|
||||
<p>Welcome ${user.login}</p>
|
||||
</div>
|
||||
<div style="display: flex; flex-direction: row; justify-content: flex-end">
|
||||
<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="submit" formaction="search.htm" value="Chercher" />
|
||||
<input type="text" name="query" />
|
||||
<input hidden type="text" name="type" value="customer" />
|
||||
<input type="submit" formaction="find.htm" value="Search user" />
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
Reference in a new issue