87 lines
2.3 KiB
Java
87 lines
2.3 KiB
Java
package bdd;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.util.Log;
|
|
import android.widget.Toast;
|
|
|
|
import org.w3c.dom.Text;
|
|
|
|
import metier.Client;
|
|
import metier.Intervention;
|
|
|
|
public class InterventionDAO {
|
|
|
|
private DAO dao = null;
|
|
private SQLiteDatabase db = null;
|
|
/**
|
|
* Constructeur
|
|
* @param context
|
|
*/
|
|
|
|
public InterventionDAO(Context context){
|
|
dao = new DAO(context);
|
|
db = dao.open();
|
|
}
|
|
|
|
|
|
/**
|
|
* Fermeture de la base de données
|
|
*/
|
|
|
|
public void close() {
|
|
|
|
dao.close();
|
|
}
|
|
|
|
|
|
public Cursor readLesInterventions() {
|
|
String reqSql = "Select id as '_id', idCli as 'idCli', dateTime, observation FROM " +
|
|
CreateBdDepannTout.TABLE_INTER +";";
|
|
// Execution de la requête
|
|
Cursor c = db.rawQuery(reqSql, null);
|
|
Log.d("bdd", "le curseur contient " + c.getCount() + " lignes");
|
|
return c;
|
|
}
|
|
|
|
public long create(Intervention i ) {
|
|
ContentValues values = new ContentValues();
|
|
values.put("idCli", i.getIdCli());
|
|
values.put("dateTime", i.getDateTime());
|
|
values.put("observation", i.getObservation());
|
|
Log.d("bdd", "insert, :" + i);
|
|
return db.insert(CreateBdDepannTout.TABLE_INTER, null, values);
|
|
}
|
|
public void deleteIntervention(int id ){
|
|
// int ligneSuppr = db.delete("intervention", "id = ?", new String[]{String.valueOf(id)});
|
|
//// db.close();
|
|
// Log.d("DEBUG", "Nombre de lignes supprimées : " + ligneSuppr );
|
|
|
|
Log.d("DEBUG", "Tentative de suppression de l'intervention avec l'ID : " + id);
|
|
int ligneSuppr = db.delete("intervention", "id = ?", new String[]{String.valueOf(id)});
|
|
Log.d("DEBUG", "Nombre de lignes supprimées : " + ligneSuppr); // Affiche le nombre de lignes supprimées
|
|
db.close();
|
|
}
|
|
public void updateIntervention(int idInter, int idCli, String dateTime, String observation) {
|
|
ContentValues values = new ContentValues();
|
|
// values.put("idInter", idInter);
|
|
values.put("idCli", idCli);
|
|
values.put("dateTime", dateTime);
|
|
values.put("observation", observation);
|
|
|
|
db.update("intervention", values, "id = ?", new String[]{String.valueOf(idInter)});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|