Search in sources :

Example 1 with Cours

use of ca.etsmtl.applets.etsmobile.model.Cours in project ETSMobile-Android2 by ApplETS.

the class NoteManager method deleteExpiredCours.

/**
     * Deletes courses in DB that doesn't exist on API
     *
     * @param
     */
public void deleteExpiredCours(ListeDeCours listeDeCours) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, Cours> coursHashMap = new HashMap<String, Cours>();
    for (Cours cours : listeDeCours.liste) {
        cours.id = cours.sigle + cours.session;
        coursHashMap.put(cours.id, cours);
    }
    ArrayList<Cours> dbCours = new ArrayList<Cours>();
    try {
        dbCours = (ArrayList<Cours>) dbHelper.getDao(Cours.class).queryForAll();
        ArrayList<ListeDesElementsEvaluation> dbliste = (ArrayList<ListeDesElementsEvaluation>) dbHelper.getDao(ListeDesElementsEvaluation.class).queryForAll();
        for (Cours coursNew : dbCours) {
            if (!coursHashMap.containsKey(coursNew.id)) {
                Dao<Cours, String> coursDao = dbHelper.getDao(Cours.class);
                coursDao.deleteById(coursNew.id);
                deleteExpiredListeDesElementsEvaluation(coursNew.id);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ListeDesElementsEvaluation(ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation) ListeDeCours(ca.etsmtl.applets.etsmobile.model.ListeDeCours) ArrayOfCours(ca.etsmtl.applets.etsmobile.model.ArrayOfCours) Cours(ca.etsmtl.applets.etsmobile.model.Cours)

Example 2 with Cours

use of ca.etsmtl.applets.etsmobile.model.Cours in project ETSMobile-Android2 by ApplETS.

the class NoteManager method updateCours.

public void updateCours(List<Cours> coursList) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    try {
        for (Cours cours : coursList) {
            // Id field upgraded to make difference between upgrading row or creating row
            cours.id = cours.sigle + cours.session;
            dbHelper.getDao(Cours.class).createOrUpdate(cours);
        }
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDeCours(ca.etsmtl.applets.etsmobile.model.ListeDeCours) ArrayOfCours(ca.etsmtl.applets.etsmobile.model.ArrayOfCours) Cours(ca.etsmtl.applets.etsmobile.model.Cours)

Example 3 with Cours

use of ca.etsmtl.applets.etsmobile.model.Cours in project ETSMobile-Android2 by ApplETS.

the class NoteManager method getCours.

public ArrayList<Cours> getCours() {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    ArrayList<Cours> coursList = null;
    try {
        coursList = (ArrayList<Cours>) dbHelper.getDao(Cours.class).queryForAll();
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return coursList;
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDeCours(ca.etsmtl.applets.etsmobile.model.ListeDeCours) ArrayOfCours(ca.etsmtl.applets.etsmobile.model.ArrayOfCours) Cours(ca.etsmtl.applets.etsmobile.model.Cours)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)3 ArrayOfCours (ca.etsmtl.applets.etsmobile.model.ArrayOfCours)3 Cours (ca.etsmtl.applets.etsmobile.model.Cours)3 ListeDeCours (ca.etsmtl.applets.etsmobile.model.ListeDeCours)3 SQLException (java.sql.SQLException)3 ListeDesElementsEvaluation (ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1