Search in sources :

Example 11 with DatabaseHelper

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

the class NoteManager method deleteExpiredListeDesElementsEvaluation.

/**
 * Deletes marks in DB that doesn't exist on API
 *
 * @param
 */
private void deleteExpiredListeDesElementsEvaluation(String id) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    try {
        Dao<ListeDesElementsEvaluation, String> listeDesElementsEvaluationDao = dbHelper.getDao(ListeDesElementsEvaluation.class);
        ListeDesElementsEvaluation listeDesElementsEvaluation = listeDesElementsEvaluationDao.queryForId(id);
        if (listeDesElementsEvaluation != null) {
            Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
            DeleteBuilder<ElementEvaluation, String> deleteBuilder = elementsEvaluationDao.deleteBuilder();
            Where where = deleteBuilder.where();
            where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
            deleteBuilder.delete();
        }
        listeDesElementsEvaluationDao.deleteById(id);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDesElementsEvaluation(ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation) Where(com.j256.ormlite.stmt.Where) ElementEvaluation(ca.etsmtl.applets.etsmobile.model.ElementEvaluation)

Example 12 with DatabaseHelper

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

Example 13 with DatabaseHelper

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

the class NoteManager method getListElementsEvaluation.

public ListeDesElementsEvaluation getListElementsEvaluation(String id) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    ListeDesElementsEvaluation listElementsEvaluation = null;
    try {
        Dao<ListeDesElementsEvaluation, String> listElementsEvaluationsDao = dbHelper.getDao(ListeDesElementsEvaluation.class);
        listElementsEvaluation = listElementsEvaluationsDao.queryForId(id);
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return listElementsEvaluation;
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ListeDesElementsEvaluation(ca.etsmtl.applets.etsmobile.model.ListeDesElementsEvaluation)

Example 14 with DatabaseHelper

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

the class BottinFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.menu_item_update:
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.menu_bottin_refresh).setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_bottin, null)).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //Suppression du bottin
                    DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
                    try {
                        Dao<FicheEmploye, ?> ficheEmployeDao = dbHelper.getDao(FicheEmploye.class);
                        List<FicheEmploye> ficheEmployeList = ficheEmployeDao.queryForAll();
                        for (FicheEmploye ficheEmploye : ficheEmployeList) {
                            ficheEmployeDao.delete(ficheEmploye);
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    //Mise à jour de la liste
                    listDataHeader = new ArrayList<>();
                    listDataChild = new HashMap<>();
                    listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
                    expListView.setAdapter(listAdapter);
                    updateUI();
                    dialogInterface.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
            builder.create().show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) ExpandableListAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) OnClickListener(android.view.View.OnClickListener)

Example 15 with DatabaseHelper

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

the class BottinFragment method onRequestSuccess.

@Override
public void onRequestSuccess(Object o) {
    super.onRequestSuccess(o);
    if (o instanceof HashMap<?, ?>) {
        mProgressDialog.hide();
        @SuppressWarnings("unchecked") HashMap<String, List<FicheEmploye>> listeEmployeByService = (HashMap<String, List<FicheEmploye>>) o;
        // Écriture dans la base de données
        DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
        for (String nomService : listeEmployeByService.keySet()) {
            List<FicheEmploye> listeEmployes = listeEmployeByService.get(nomService);
            if (listeEmployes.size() > 0) {
                for (FicheEmploye ficheEmploye : listeEmployeByService.get(nomService)) {
                    try {
                        dbHelper.getDao(FicheEmploye.class).createOrUpdate(ficheEmploye);
                    } catch (SQLException e) {
                        Log.e(DatabaseHelper.class.getName(), "SQLException", e);
                        throw new RuntimeException(e);
                    }
                }
            }
        }
        updateUI();
    }
}
Also used : HashMap(java.util.HashMap) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye)

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