Search in sources :

Example 16 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class Utility method loadNotifications.

/**
     * Gets MonÉTS notifications and update DB
     * @param context
     * @param requestListener
     */
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
    final SecurePreferences securePreferences = new SecurePreferences(context);
    final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
    MonETSNotificationsRequest monETSNotificationsRequest;
    if (!allNotifsLoaded) {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
    } else {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
    }
    final DataManager dataManager = DataManager.getInstance(context);
    dataManager.start();
    final DatabaseHelper databaseHelper = new DatabaseHelper(context);
    dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            requestListener.onRequestFailure(spiceException);
            dataManager.stop();
        }

        @Override
        public void onRequestSuccess(Object o) {
            if (o instanceof MonETSNotificationList) {
                try {
                    Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
                    MonETSNotificationList list = (MonETSNotificationList) o;
                    for (MonETSNotification monETSNotification : list) {
                        dao.createOrUpdate(monETSNotification);
                    }
                    if (!allNotifsLoaded) {
                        securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
                    }
                    requestListener.onRequestSuccess(list);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            dataManager.stop();
        }
    });
}
Also used : MonETSNotificationList(ca.etsmtl.applets.etsmobile.model.MonETSNotificationList) MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) SQLException(java.sql.SQLException) DataManager(ca.etsmtl.applets.etsmobile.http.DataManager) Dao(com.j256.ormlite.dao.Dao) MonETSNotificationsRequest(ca.etsmtl.applets.etsmobile.http.MonETSNotificationsRequest) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper)

Example 17 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class NoteManager method updateElementsEvaluation.

/**
 * Rajout de l'id pour identifier les éléments d'évaluation par rapport au cours effectué dans une session
 */
public void updateElementsEvaluation(ListeDesElementsEvaluation listElementsEvaluation) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    try {
        dbHelper.getDao(ListeDesElementsEvaluation.class).createOrUpdate(listElementsEvaluation);
        for (ElementEvaluation elementEvaluation : listElementsEvaluation.liste) {
            elementEvaluation.id = listElementsEvaluation.id + elementEvaluation.nom;
            elementEvaluation.listeDesElementsEvaluation = listElementsEvaluation;
            dbHelper.getDao(ElementEvaluation.class).createOrUpdate(elementEvaluation);
        }
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDesElementsEvaluation(ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

Example 18 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class NoteManager method getTrimestres.

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

Example 19 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper 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) Cours(ca.etsmtl.applets.etsmobile.model.Cours)

Example 20 with DatabaseHelper

use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.

the class NoteManager method remove.

public void remove() {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    try {
        // Delete all rows that contains an Etudiant and listeDesProgrammes classes
        dbHelper.getDao(Cours.class).deleteBuilder().delete();
        dbHelper.getDao(Trimestre.class).deleteBuilder().delete();
        dbHelper.getDao(ListeDesElementsEvaluation.class).deleteBuilder().delete();
        dbHelper.getDao(ElementEvaluation.class).deleteBuilder().delete();
    // dbHelper.getDao(Programme.class).deleteBuilder().delete();
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException)

Aggregations

DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)32 SQLException (java.sql.SQLException)27 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)9 ElementEvaluation (ca.etsmtl.applets.etsmobile.model.ElementEvaluation)4 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)4 ListeDesElementsEvaluation (ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)4 Seances (ca.etsmtl.applets.etsmobile.model.Seances)4 Cours (ca.etsmtl.applets.etsmobile.model.Cours)3 Event (ca.etsmtl.applets.etsmobile.model.Event)3 ListeDeCours (ca.etsmtl.applets.etsmobile.model.ListeDeCours)3 Where (com.j256.ormlite.stmt.Where)3 JoursRemplaces (ca.etsmtl.applets.etsmobile.model.JoursRemplaces)2 MonETSNotification (ca.etsmtl.applets.etsmobile.model.MonETSNotification)2 Sponsor (ca.etsmtl.applets.etsmobile.model.Sponsor)2 Trimestre (ca.etsmtl.applets.etsmobile.model.Trimestre)2 ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces (ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces)2 ca.etsmtl.applets.etsmobile.model.listeSeances (ca.etsmtl.applets.etsmobile.model.listeSeances)2 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)2 SeanceComparator (ca.etsmtl.applets.etsmobile.util.SeanceComparator)2