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 146 147 148 149 150 151
| package classes;
import MyExceptions.DateException;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Calendar;
/**
*
* @author threis raphael
*/
public class cPrestation implements Serializable{
// <editor-fold desc="Variables" defaultstate="collapsed">
private int iMois;
private int iAnnee;
private cJournee[] cjJours;
private int iIdOuvrier;
private String sNom;
private String sPrenom;
// </editor-fold>
// <editor-fold desc="Constructeurs" defaultstate="collapsed">
/**
* Constructeur par défaut
*/
public cPrestation() {
iMois = 0;
iAnnee = 0;
iIdOuvrier = 0;
sNom = "";
sPrenom = "";
}
/**
* Initialise les prestations du mois pour l'ouvrier
* @param iId Identifiant de l'ouvrier.
* @param Nom Nom de l'ouvrier.
* @param Prenom Prénom de l'ouvrier
*/
public cPrestation(int iId, String Nom, String Prenom){
this.iIdOuvrier = iId;
this.sNom = Nom;
this.sPrenom = Prenom;
}
// </editor-fold>
// <editor-fold desc="Setter et Getter" defaultstate="collapsed">
public cJournee[] getCjJours() {
return cjJours;
}
/**
* Initialise le tableau des jours du mois avec le nombre de jours du mois.
*/
private void setCjJours() throws DateException {
if( this.iMois >= 0 && this.iAnnee >= 0)
{
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, this.iMois);
c.set(Calendar.YEAR, this.iAnnee);
c.set(Calendar.DAY_OF_MONTH, 1);
int nbJours = c.getActualMaximum(Calendar.DAY_OF_MONTH);
cjJours = new cJournee[nbJours];
}
else if(this.iMois<1){
throw new DateException("Le mois est incohérent !");
}
else if(this.iAnnee<1){
throw new DateException("L'année est incohérente !");
}
}
public int getAnnee() {
return iAnnee;
}
public void setAnnee(int iAnnee) {
this.iAnnee = iAnnee;
try{
setCjJours();
}
catch(DateException de){
System.out.println(de.getMessage());
}
}
public int getMois() {
return iMois;
}
public void setMois(int iMois) {
this.iMois = iMois;
try{
setCjJours();
}
catch(DateException de){
System.out.println(de.getMessage());
}
}
public int getIdOuvrier() {
return iIdOuvrier;
}
public void setIdOuvrier(int idOuvrier) {
this.iIdOuvrier = idOuvrier;
}
public String getNom() {
return sNom;
}
public void setNom(String sNom) {
this.sNom = sNom;
}
public String getPrenom() {
return sPrenom;
}
public void setPrenom(String sPrenom) {
this.sPrenom = sPrenom;
}
// </editor-fold>
/**
*
* @return boolean true si élément sauver avec succès
* false si une erreur est survenue
*/
public boolean save(){
try{
FileOutputStream fileOut = new FileOutputStream("c:\\deneigement\\"+iIdOuvrier+"-"+iAnnee+"-"+iMois+".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
}
catch(Exception e){
System.out.println("Erreur:"+e.getMessage());
return false;
}
return true;
}
public void setPrestation(float[] pPrestation){
}
} |
Partager