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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
package com.example.telegestion;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
public class InterventionRepository extends Repository<Intervention> {
public InterventionRepository(Context context) {
sqLiteOpenHelper = new InterventionOpenHelper(context, null);
}
@Override
public List<Intervention> GetAll() {
// TODO Auto-generated method stub
Cursor cursor = maBDD.query(InterventionOpenHelper.INTERVENTION_TABLE_NAME,
new String[] {
InterventionOpenHelper.COLUMN_IDLIGNE,
InterventionOpenHelper.COLUMN_DATE_CREATION,
InterventionOpenHelper.COLUMN_HEURE_CREATION,
InterventionOpenHelper.COLUMN_CODE_ASSO,
InterventionOpenHelper.COLUMN_ID_PA,
InterventionOpenHelper.COLUMN_NOM_PRENOM,
InterventionOpenHelper.COLUMN_ACTION_CODE,
InterventionOpenHelper.COLUMN_MOTIF_PAS_CODE,
InterventionOpenHelper.COLUMN_DATE_INTERVENTION,
InterventionOpenHelper.COLUMN_HEURE_INTERVENTION,
InterventionOpenHelper.COLUMN_CODE_PREST,
InterventionOpenHelper.COLUMN_A_POSITIONNER,
InterventionOpenHelper.COLUMN_LATTITUDE ,
InterventionOpenHelper.COLUMN_LONGITUDE,
InterventionOpenHelper.COLUMN_DATE_GPS,
InterventionOpenHelper.COLUMN_HEURE_GPS,
InterventionOpenHelper.COLUMN_KM,
InterventionOpenHelper.COLUMN_ANNULER,
InterventionOpenHelper.COLUMN_DATE_ANNULER,
InterventionOpenHelper.COLUMN_HEURE_ANNULER,
InterventionOpenHelper.COLUMN_A_TRANSMETTRE,
InterventionOpenHelper.COLUMN_DATE_TRANSMIS,
InterventionOpenHelper.COLUMN_HEURE_TRANSMIS
},
null, null, null,null, null);
return ConvertCursorToListObject(cursor);
}
@Override
public Intervention GetById(int id) {
Cursor cursor = maBDD.query(InterventionOpenHelper.INTERVENTION_TABLE_NAME,
new String[] {
InterventionOpenHelper.COLUMN_IDLIGNE,
InterventionOpenHelper.COLUMN_DATE_CREATION,
InterventionOpenHelper.COLUMN_HEURE_CREATION,
InterventionOpenHelper.COLUMN_CODE_ASSO,
InterventionOpenHelper.COLUMN_ID_PA,
InterventionOpenHelper.COLUMN_NOM_PRENOM,
InterventionOpenHelper.COLUMN_ACTION_CODE,
InterventionOpenHelper.COLUMN_MOTIF_PAS_CODE,
InterventionOpenHelper.COLUMN_DATE_INTERVENTION,
InterventionOpenHelper.COLUMN_HEURE_INTERVENTION,
InterventionOpenHelper.COLUMN_CODE_PREST,
InterventionOpenHelper.COLUMN_A_POSITIONNER,
InterventionOpenHelper.COLUMN_LATTITUDE ,
InterventionOpenHelper.COLUMN_LONGITUDE,
InterventionOpenHelper.COLUMN_DATE_GPS,
InterventionOpenHelper.COLUMN_HEURE_GPS,
InterventionOpenHelper.COLUMN_KM,
InterventionOpenHelper.COLUMN_ANNULER,
InterventionOpenHelper.COLUMN_DATE_ANNULER,
InterventionOpenHelper.COLUMN_HEURE_ANNULER,
InterventionOpenHelper.COLUMN_A_TRANSMETTRE,
InterventionOpenHelper.COLUMN_DATE_TRANSMIS,
InterventionOpenHelper.COLUMN_HEURE_TRANSMIS
},
InterventionOpenHelper.COLUMN_IDLIGNE + "=?",
new String[] { String.valueOf(id) },
null,null, null);
return ConvertCursorToObject(cursor);
}
@Override
public void Save(Intervention entite) {
DateFormat sfDate = new SimpleDateFormat("yyyy-MM-dd");
DateFormat sfHeure = new SimpleDateFormat("HH:mm:ss");
String sDateCreation = sfDate.format(entite.getDateCreation());
String sHeureCreation = sfHeure.format(entite.getHeureCreation());
String sDateInter = sfDate.format(entite.getDateIntervention());
String sHeureInter = sfHeure.format(entite.getHeureIntervention());
String sDateGPS = sfDate.format(entite.getDateGPS());
String sHeureGPS = sfHeure.format(entite.getHeureGPS());
String sDateAnnuler = sfDate.format(entite.getDateAnnuler());
String sHeureAnnuler = sfHeure.format(entite.getHeureAnnuler());
String sDateTransmis = sfDate.format(entite.getDateTransmis());
String sHeureTransmis = sfHeure.format(entite.getHeureTransmis());
// TODO Auto-generated method stub
ContentValues contentValues = new ContentValues();
contentValues.put(InterventionOpenHelper.COLUMN_IDLIGNE,entite.getIdLigne());
contentValues.put(InterventionOpenHelper.COLUMN_DATE_CREATION,sDateCreation);
contentValues.put(InterventionOpenHelper.COLUMN_HEURE_CREATION,sHeureCreation);
contentValues.put(InterventionOpenHelper.COLUMN_CODE_ASSO,entite.getCodeAsso());
contentValues.put(InterventionOpenHelper.COLUMN_ID_PA,entite.getIdPA());
contentValues.put(InterventionOpenHelper.COLUMN_NOM_PRENOM,entite.getNomPrenom());
contentValues.put(InterventionOpenHelper.COLUMN_ACTION_CODE,entite.getActionCode());
contentValues.put(InterventionOpenHelper.COLUMN_MOTIF_PAS_CODE,entite.getMotifPasCode());
contentValues.put(InterventionOpenHelper.COLUMN_DATE_INTERVENTION,sDateInter);
contentValues.put(InterventionOpenHelper.COLUMN_HEURE_INTERVENTION,sHeureInter);
contentValues.put(InterventionOpenHelper.COLUMN_CODE_PREST,entite.getCodePrest());
contentValues.put(InterventionOpenHelper.COLUMN_A_POSITIONNER,entite.isaPositionner());
contentValues.put(InterventionOpenHelper.COLUMN_LATTITUDE ,entite.getLattitude());
contentValues.put(InterventionOpenHelper.COLUMN_LONGITUDE,entite.getLongitude());
contentValues.put(InterventionOpenHelper.COLUMN_DATE_GPS,sDateGPS);
contentValues.put(InterventionOpenHelper.COLUMN_HEURE_GPS,sHeureGPS);
contentValues.put(InterventionOpenHelper.COLUMN_KM,entite.getKm());
contentValues.put(InterventionOpenHelper.COLUMN_ANNULER,entite.isAnnuler());
contentValues.put(InterventionOpenHelper.COLUMN_DATE_ANNULER,sDateAnnuler);
contentValues.put(InterventionOpenHelper.COLUMN_HEURE_ANNULER,sHeureAnnuler);
contentValues.put(InterventionOpenHelper.COLUMN_A_TRANSMETTRE,entite.isaTransmettre());
contentValues.put(InterventionOpenHelper.COLUMN_DATE_TRANSMIS,sDateTransmis);
contentValues.put(InterventionOpenHelper.COLUMN_HEURE_TRANSMIS,sHeureTransmis);
maBDD.insert(InterventionOpenHelper.INTERVENTION_TABLE_NAME, null, contentValues);
}
@Override
public void Update(Intervention entite) {
// TODO Auto-generated method stub
}
@Override
public void Delete(int id) {
// TODO Auto-generated method stub
maBDD.delete(InterventionOpenHelper.INTERVENTION_TABLE_NAME,
InterventionOpenHelper.COLUMN_IDLIGNE + "=?",
new String[] { String.valueOf(id) });
}
@Override
public List<Intervention> ConvertCursorToListObject(Cursor c) {
List<Intervention> liste = new ArrayList<Intervention>();
// Si la liste est vide
if (c.getCount() == 0)
return liste;
// position sur le premier item
c.moveToFirst();
// Pour chaque item
do {
Intervention inter = ConvertCursorToObject(c);
liste.add(inter);
} while (c.moveToNext());
// Fermeture du curseur
c.close();
return liste;
}
@Override
public Intervention ConvertCursorToObject(Cursor c) {
Intervention inter=null;
try{
Date cursorDateCrea = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_DATE_CREATION), "yyyy-MM-dd");
Date cursorHeureCrea = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_HEURE_CREATION), "HH:mm:ss");
Date cursorDateInter = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_DATE_INTERVENTION), "yyyy-MM-dd");
Date cursorHeureInter = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_HEURE_INTERVENTION), "HH:mm:ss");
Date cursorDateGPS = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_DATE_GPS), "yyyy-MM-dd");
Date cursorHeureGPS = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_HEURE_GPS), "HH:mm:ss");
Date cursorDateAnnuler = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_DATE_ANNULER), "yyyy-MM-dd");
Date cursorHeureAnnuler = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_HEURE_ANNULER), "HH:mm:ss");
Date cursorDateTransmis = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_DATE_TRANSMIS), "yyyy-MM-dd");
Date cursorHeureTransmis = stringToDate(c.getString(InterventionOpenHelper.NUM_COLUMN_HEURE_TRANSMIS), "HH:mm:ss");
inter = new Intervention(
c.getInt(InterventionOpenHelper.NUM_COLUMN_IDLIGNE),
cursorDateCrea,
cursorHeureCrea,
c.getString(InterventionOpenHelper.NUM_COLUMN_CODE_ASSO),
c.getInt(InterventionOpenHelper.NUM_COLUMN_ID_PA),
c.getString(InterventionOpenHelper.NUM_COLUMN_NOM_PRENOM),
c.getString(InterventionOpenHelper.NUM_COLUMN_ACTION_CODE),
c.getString(InterventionOpenHelper.NUM_COLUMN_MOTIF_PAS_CODE),
cursorDateInter,
cursorHeureInter,
c.getString(InterventionOpenHelper.NUM_COLUMN_CODE_PREST),
c.getInt(InterventionOpenHelper.NUM_COLUMN_A_POSITIONNER)==1,
c.getDouble(InterventionOpenHelper.NUM_COLUMN_LONGITUDE),
c.getDouble(InterventionOpenHelper.NUM_COLUMN_LATTITUDE),
cursorDateGPS,
cursorHeureGPS,
c.getString(InterventionOpenHelper.NUM_COLUMN_KM),
c.getInt(InterventionOpenHelper.NUM_COLUMN_ANNULER)==1,
cursorDateAnnuler,
cursorHeureAnnuler,
c.getInt(InterventionOpenHelper.NUM_COLUMN_A_TRANSMETTRE)==1,
cursorDateTransmis,
cursorHeureTransmis);
}catch(Exception e){
e.printStackTrace();
}
return inter;
}
@Override
public Intervention ConvertCursorToOneObject(Cursor c) {
c.moveToFirst();
Intervention inter = ConvertCursorToObject(c);
c.close();
return inter;
}
public static Date stringToDate(String sDate, String sFormat) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}
} |
Partager