Search in sources :

Example 6 with DatabaseHelper

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

the class ProfilManager method getEtudiant.

public Etudiant getEtudiant() {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    Etudiant etudiant = null;
    try {
        List<Etudiant> etudiantList = dbHelper.getDao(Etudiant.class).queryForAll();
        if (!etudiantList.isEmpty())
            // Get Student if exists
            etudiant = etudiantList.get(0);
    } catch (SQLException e) {
        Log.e("SQL Exception", e.getMessage());
    }
    return etudiant;
}
Also used : Etudiant(ca.etsmtl.applets.etsmobile.model.Etudiant) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) SQLException(java.sql.SQLException)

Example 7 with DatabaseHelper

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

the class TodayFragment method updateUI.

@Override
void updateUI() {
    if (isAdded()) {
        dateTime = new DateTime();
        DateTime.Property pDoW = dateTime.dayOfWeek();
        DateTime.Property pDoM = dateTime.dayOfMonth();
        DateTime.Property pMoY = dateTime.monthOfYear();
        Locale locale = getResources().getConfiguration().locale;
        todaysTv.setText(getActivity().getString(R.string.horaire, pDoW.getAsText(locale), pDoM.getAsText(locale), pMoY.getAsText(locale)));
        databaseHelper = new DatabaseHelper(getActivity());
        listSeances = new ArrayList<Seances>();
        events = new ArrayList<Event>();
        try {
            SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
            listSeances = (ArrayList<Seances>) databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", seancesFormatter.format(dateTime.toDate()) + "%").query();
            Collections.sort(listSeances, new SeanceComparator());
            events = (ArrayList<Event>) databaseHelper.getDao(Event.class).queryBuilder().where().like("startDate", seancesFormatter.format(dateTime.toDate()) + "%").query();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ArrayList<TodayDataRowItem> dataRowItems = new ArrayList<TodayDataRowItem>();
        if (!events.isEmpty()) {
            dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_EVENT));
            for (Event event : events) {
                dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_EVENT, event));
            }
        }
        dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE));
        if (listSeances.isEmpty()) {
            tvNoCourses.setVisibility(View.VISIBLE);
        } else {
            for (Seances seances : listSeances) {
                dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_SEANCE, seances));
            }
            tvNoCourses.setVisibility(View.GONE);
        }
        adapter = new TodayAdapter(getActivity(), dataRowItems);
        todaysList.setAdapter(adapter);
    }
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) TodayAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.TodayAdapter) DateTime(org.joda.time.DateTime) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) SeanceComparator(ca.etsmtl.applets.etsmobile.util.SeanceComparator) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) Event(ca.etsmtl.applets.etsmobile.model.Event) Seances(ca.etsmtl.applets.etsmobile.model.Seances) SimpleDateFormat(java.text.SimpleDateFormat) TodayDataRowItem(ca.etsmtl.applets.etsmobile.ui.adapter.TodayDataRowItem)

Example 8 with DatabaseHelper

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

the class HoraireManager method deleteExpiredJoursRemplaces.

/**
 * Deletes entries in DB that doesn't exist on API
 *
 * @param listeJoursRemplaces
 */
private void deleteExpiredJoursRemplaces(listeJoursRemplaces listeJoursRemplaces) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, JoursRemplaces> listeJoursRemplacesInAPI = new HashMap<String, JoursRemplaces>();
    // Building the list of entries in API
    for (JoursRemplaces JoursRemplacesInAPI : listeJoursRemplaces.listeJours) {
        listeJoursRemplacesInAPI.put(JoursRemplacesInAPI.dateOrigine, JoursRemplacesInAPI);
    }
    ArrayList<JoursRemplaces> listeJoursRemplacesInDB = new ArrayList<JoursRemplaces>();
    // Comparing entries on DB and API
    try {
        listeJoursRemplacesInDB = (ArrayList<JoursRemplaces>) dbHelper.getDao(JoursRemplaces.class).queryForAll();
        for (JoursRemplaces JoursRemplacesInDB : listeJoursRemplacesInDB) {
            if (!listeJoursRemplacesInAPI.containsKey((String) JoursRemplacesInDB.dateOrigine)) {
                Dao<JoursRemplaces, String> JoursRemplacesDao = dbHelper.getDao(JoursRemplaces.class);
                JoursRemplacesDao.deleteById(JoursRemplacesInDB.dateOrigine);
            }
        }
    } 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) ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces(ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces) JoursRemplaces(ca.etsmtl.applets.etsmobile.model.JoursRemplaces)

Example 9 with DatabaseHelper

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

Example 10 with DatabaseHelper

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

the class NoteManager method deleteExpiredTrimestres.

/**
 * Deletes trimestres in DB that doesn't exist on API
 *
 * @param
 */
public void deleteExpiredTrimestres(ListeDeSessions listeDeSessions) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, Trimestre> trimestresHashMap = new HashMap<String, Trimestre>();
    for (Trimestre trimestre : listeDeSessions.liste) {
        trimestresHashMap.put(trimestre.abrege, trimestre);
    }
    ArrayList<Trimestre> dbTrimestres = new ArrayList<Trimestre>();
    try {
        dbTrimestres = (ArrayList<Trimestre>) dbHelper.getDao(Trimestre.class).queryForAll();
        for (Trimestre trimestreNew : dbTrimestres) {
            if (!trimestresHashMap.containsKey(trimestreNew.abrege)) {
                Dao<Trimestre, String> trimestreDao = dbHelper.getDao(Trimestre.class);
                trimestreDao.deleteById(trimestreNew.abrege);
            }
        }
    } 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) Trimestre(ca.etsmtl.applets.etsmobile.model.Trimestre)

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