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
|
public class DataBaseManager extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "wishlist.db";
private static final int DATABASE_VERSION = 2;
public DataBaseManager(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String strSql = "create table Jupe ("+" Id integer primary key autoincrement, "+" Type_ text not null, "+" Ref_ text not null, "+" Couleur text not null, "+" Taille text not null, "+" Coche integer not null "+")";
db.execSQL(strSql);
strSql = "create table Accessoire ("+ " Id integer primary key autoincrement, "+ " Type_ text not null, "+ " Couleur text not null, "+ " Motif text not null, "+ " Coche integer not null "+ ")";
db.execSQL(strSql);
strSql = "create table Tshirt ("+ " Id integer primary key autoincrement, "+ " Annee text not null, "+ " Couleur text not null, "+ " Taille text not null, "+ " Coche integer not null "+ ")";
db.execSQL(strSql);
strSql = "create table Affiliation ("+ " Id_produit integer, "+ " Id_client integer not null, "+ " Type text not null "+ ")";
db.execSQL(strSql);
strSql = "create table Client ("+ " Id_client integer primary key autoincrement, "+ " Nom text not null, "+ " Prenom text not null, "+ " Mail text not null, "+ " Password text not null, "+ " Morpho text not null "+ ")";
db.execSQL(strSql);
Log.i("DATABASE", "OnCreate invoked");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String strSQL = "drop table Jupe";
db.execSQL(strSQL);
this.onCreate(db);
Log.i("DATABASE", "Onupgrade invoked");
}
public void insertJupe(String type_, String ref_, String couleur, String taille, int coche) {
String strSql = "insert into Jupe (Type_, Ref_, Couleur, Taille, Coche) values ('"+ type_ + "',' " + ref_ + "','" + couleur + "','" + taille + "'," + coche + ")";
this.getWritableDatabase().execSQL(strSql);
Log.i("DATABASE", "Jupe insert invoked");
}
public void insertAccessoire(String type_, String couleur, String motif, int coche) {
String strSql = "insert into Accessoire (Type_, Couleur, Motif, Coche) values ('" + type_ + "','" + couleur + "','" + motif + "'," + coche + ")";
this.getWritableDatabase().execSQL(strSql);
Log.i("DATABASE", "Accessoire insert invoked");
}
public void insertTshirt(String annee, String couleur, String taille, int coche) {
String strSql = "insert into Tshirt (Annee, Couleur, Taille, Coche) values ('" + annee + "','" + couleur + "','" + taille + "'," + coche + ")";
this.getWritableDatabase().execSQL(strSql);
Log.i("DATABASE", "Tshirt insert invoked");
}
public void insertAffiliation(int id_produit, int id_client, String type) {
String strSql = "insert into Affiliation (Id_produit, Id_client, Type) values (" + id_produit + "," + id_client + ",'" + type + "')";
this.getWritableDatabase().execSQL(strSql);
Log.i("DATABASE", "Affiliation insert invoked");
}
public void insertClient(String prenom, String nom, String mail, String password, String morpho) {
String strSql = "insert into Client (Prenom, Nom, Mail, Password, Morpho) values (UPPER('" + prenom + "'),UPPER('" + nom + "'),'" + mail + "','" + password + "','" + morpho + "')";
this.getWritableDatabase().execSQL(strSql);
Log.i("DATABASE", "Client insert invoked");
}
public List<Client_WL_Jupe> ReadWLJupe(int id_recherche) {
List<Client_WL_Jupe> WLJupe = new ArrayList<>();
String StrSqljupe = "SELECT Jupe.Type_,Jupe.Ref_,Jupe.Couleur,Jupe.Taille FROM Jupe WHERE Jupe.Id IN ( SELECT Id_produit FROM Affiliation WHERE Id_client="+id_recherche+" AND Type='Jupe')";
Cursor cursorjupe = this.getReadableDatabase().rawQuery(StrSqljupe, null);
cursorjupe.moveToFirst();
while (!cursorjupe.isAfterLast()) {
Client_WL_Jupe client_wl_jupe = new Client_WL_Jupe(cursorjupe.getString(0), cursorjupe.getString(1), cursorjupe.getString(2), cursorjupe.getString(3));
WLJupe.add(client_wl_jupe);
cursorjupe.moveToNext();
}
cursorjupe.close();
return (WLJupe);
}
public List<Client_WL_Accessoire> ReadWLAccessoire(int id_recherche) {
List<Client_WL_Accessoire> WLacc = new ArrayList<>();
String StrSqlacc = "SELECT Accessoire.Type_, Accessoire.Couleur, Accessoire.Motif FROM Accessoire WHERE Accessoire.Id IN ( SELECT Id_produit FROM Affiliation WHERE Id_client="+id_recherche+" AND Type='Accessoire')";
Cursor cursoracc = this.getReadableDatabase().rawQuery(StrSqlacc, null);
cursoracc.moveToFirst();
while (!cursoracc.isAfterLast()) {
Client_WL_Accessoire client_wl_accessoire = new Client_WL_Accessoire(cursoracc.getString(0), cursoracc.getString(1), cursoracc.getString(2));
WLacc.add(client_wl_accessoire);
cursoracc.moveToNext();
}
cursoracc.close();
return (WLacc);
}
public List<Client_WL_Tshirt> ReadWLTshirt(int id_recherche) {
List<Client_WL_Tshirt> WLt = new ArrayList<>();
String StrSqlt = "SELECT Tshirt.Annee, Tshirt.Couleur, Tshirt.Taille FROM Tshirt WHERE Tshirt.Id IN ( SELECT Id_produit FROM Affiliation WHERE Id_client="+id_recherche+" AND Type='Tshirt')";
Cursor cursort = this.getReadableDatabase().rawQuery(StrSqlt, null);
cursort.moveToFirst();
while (!cursort.isAfterLast()) {
Client_WL_Tshirt client_wl_tshirt = new Client_WL_Tshirt(cursort.getString(0), cursort.getString(1), cursort.getString(2));
WLt.add(client_wl_tshirt);
cursort.moveToNext();
}
cursort.close();
return (WLt);
}
} |
Partager