74 lines
2.0 KiB
Java
74 lines
2.0 KiB
Java
package bdd;
|
|
|
|
import static bdd.CreateBdDepannTout.TABLE_CLIENT;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
|
import android.util.Log;
|
|
|
|
import metier.Client;
|
|
import bdd.CreateBdDepannTout;
|
|
|
|
public class ClientDAO {
|
|
private DAO dao = null;
|
|
private SQLiteDatabase db = null;
|
|
|
|
/**
|
|
* Constructeur
|
|
* @param context
|
|
*/
|
|
|
|
public ClientDAO(Context context){
|
|
dao = new DAO(context);
|
|
db = dao.open();
|
|
}
|
|
|
|
/**
|
|
* Fermeture de la base de données
|
|
*/
|
|
|
|
public void close() {
|
|
dao.close();
|
|
}
|
|
|
|
public Cursor readLesClients() {
|
|
String reqSql = "Select id as '_id', nom, prenom, adrMail, numTel, adrPostale FROM " + TABLE_CLIENT +";";
|
|
// 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(Client c) {
|
|
ContentValues values = new ContentValues();
|
|
values.put("nom", c.getNom());
|
|
values.put("prenom", c.getPrenom());
|
|
values.put("adrMail", c.getAdrMail());
|
|
values.put("numTel", c.getNumTel());
|
|
values.put("adrPostale", c.getAdrPostale());
|
|
Log.d("bdd", "insert, :" + c);
|
|
return db.insert(TABLE_CLIENT, null, values);
|
|
}
|
|
|
|
public void deleteClient(int idClient){
|
|
db.delete("client", "id = ?", new String[]{String.valueOf(idClient)});
|
|
db.close();
|
|
}
|
|
|
|
|
|
public void updateClient(int idClient, String nom, String prenom, String adrMail, String numTel, String adrPostale) {
|
|
ContentValues values = new ContentValues();
|
|
values.put("nom", nom);
|
|
values.put("prenom", prenom);
|
|
values.put("adrMail", adrMail);
|
|
values.put("numTel", numTel);
|
|
values.put("adrPostale", adrPostale);
|
|
|
|
db.update("client", values, "id = ?", new String[]{String.valueOf(idClient)});
|
|
}
|
|
|
|
|
|
} |