Search in sources :

Example 31 with DatabaseHelper

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

the class BottinSyncJob method updateDb.

private void updateDb(final HashMap<String, List<FicheEmploye>> listeEmployeByService) {
    Log.d(TAG, "Mise à jour de la BD");
    DatabaseHelper dbHelper = new DatabaseHelper(getContext());
    try {
        Dao<FicheEmploye, ?> ficheEmployeDao = dbHelper.getDao(FicheEmploye.class);
        for (FicheEmploye ficheEmploye : ficheEmployeDao.queryForAll()) {
            ficheEmployeDao.delete(ficheEmploye);
        }
        for (String nomService : listeEmployeByService.keySet()) {
            List<FicheEmploye> listeEmployes = listeEmployeByService.get(nomService);
            if (listeEmployes.size() > 0) {
                for (FicheEmploye ficheEmploye : listeEmployeByService.get(nomService)) {
                    dbHelper.getDao(FicheEmploye.class).create(ficheEmploye);
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
        Log.e(DatabaseHelper.class.getName(), "SQLException", e);
        throw new RuntimeException(e);
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) ArrayOfFicheEmploye(ca.etsmtl.applets.etsmobile.model.ArrayOfFicheEmploye)

Example 32 with DatabaseHelper

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

the class WearService method onMessageReceived.

@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals("/today_req")) {
        final String message = new String(messageEvent.getData());
        List<Seances> seances = new ArrayList<>();
        DatabaseHelper databaseHelper = new DatabaseHelper(this);
        SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
        try {
            seances = databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", seancesFormatter.format(DateTime.now().toDate()) + "%").query();
            Collections.sort(seances, new SeanceComparator());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        new SendToDataLayerThread("/today_req", seances, this).start();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat) SeanceComparator(ca.etsmtl.applets.etsmobile.util.SeanceComparator)

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