1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| package com.ai.model;
import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.ai.dao.Dao;
//import com.ai.dao.PanneDao;
import com.ai.dao.ClientDao;
//import com.ai.dto.Materiel;
//import com.ai.dto.Panne;
import com.ai.dto.Client;
//import com.ai.util.PDFCreator;
import com.generatio.database.dto.Certificate;
@ManagedBean
@SessionScoped
public class ClientCtrl {
private Client client = new Client();
private Vector<Client> clientVect = new Vector<Client>();
private Integer listCount = 0;
private int selectedPk = -1;
private int selectedPannePk = -1;
private String clientHidden=null;
private String clientHidden2=null;
public String getClientHidden2() {
this.setClient(new Client());
return clientHidden2;
}
public void setClientHidden2(String clientHidden2) {
this.clientHidden2 = clientHidden2;
}
public void setClientHidden(String clientHidden) {
this.clientHidden = clientHidden;
}
public int getSelectedPannePk() {
return selectedPannePk;
}
public void setSelectedPannePk(int selectedPannePk) {
this.selectedPannePk = selectedPannePk;
}
public Integer getSelectedPk() {
return selectedPk;
}
public void setSelectedPk(Integer selectedPk) {
this.selectedPk = selectedPk;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public Vector<Client> getClientVect() {
return clientVect;
}
public void setClientVect(Vector<Client> clientVect) {
this.clientVect = clientVect;
}
public Integer getListCount() {
return listCount;
}
public void setListCount(Integer listCount) {
this.listCount = listCount;
}
public void setSelectedPk(int selectedPk) {
this.selectedPk = selectedPk;
}
public String getDate(){
SimpleDateFormat format=new SimpleDateFormat("dd MMMM yyyy");
return format.format(new Date());
}
public void refreshModel(){
this.setSelectedPk(-1);
this.setClient(new Client());
this.setClientVect(new ClientDao().getClientList());
this.setListCount(this.getClientVect().size());
}
@PostConstruct
public void init(){
refreshModel();
}
public String addNewClient() throws SQLException{
new ClientDao().addClient(this.getClient());
refreshModel();
return"clientList?facesRedirect=true";
}
public String deleteClient() throws SQLException{
if(this.getSelectedPk() != -1)
new ClientDao().deleteClient(this.getSelectedPk());
this.refreshModel();
return"clientList?facesRedirect=true";
}
public String update() throws SQLException{
if(this.getSelectedPk() != -1)
new ClientDao().updateClient(this.getSelectedPk(), this.getClient());
this.refreshModel();
return"clientList?facesRedirect=true";
}
} |