Search in sources :

Example 1 with DatabaseHelper

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

the class SponsorManager method getSponsorList.

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

Example 2 with DatabaseHelper

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

the class SponsorManager method deleteExpiredSponsor.

public void deleteExpiredSponsor(SponsorList sponsorList) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, Sponsor> sponsorHashMap = new HashMap<String, Sponsor>();
    for (Sponsor sponsor : sponsorList) {
        sponsorHashMap.put(sponsor.getName(), sponsor);
    }
    ArrayList<Sponsor> dbSponsor;
    try {
        dbSponsor = (ArrayList<Sponsor>) dbHelper.getDao(Sponsor.class).queryForAll();
        for (Sponsor sponsorNew : dbSponsor) {
            if (!sponsorHashMap.containsKey(sponsorNew.getName())) {
                Dao<Sponsor, String> sponsorDao = dbHelper.getDao(Sponsor.class);
                sponsorDao.deleteById(sponsorNew.getName());
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Sponsor(ca.etsmtl.applets.etsmobile.model.Sponsor)

Example 3 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 4 with DatabaseHelper

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

the class HoraireManager method deleteExpiredSeances.

/**
 * Deletes entries in DB that doesn't exist on API
 *
 * @param listeSeances
 */
private void deleteExpiredSeances(listeSeances listeSeances) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    HashMap<String, Seances> listeSeancesInAPI = new HashMap<String, Seances>();
    // Building the list of entries in API
    for (Seances SeancesInAPI : listeSeances.ListeDesSeances) {
        SeancesInAPI.id = SeancesInAPI.coursGroupe + SeancesInAPI.dateDebut + SeancesInAPI.dateFin + SeancesInAPI.local;
        listeSeancesInAPI.put(SeancesInAPI.id, SeancesInAPI);
    }
    ArrayList<Seances> listeSeancesInDB = new ArrayList<Seances>();
    // Comparing entries on DB and API
    try {
        listeSeancesInDB = (ArrayList<Seances>) dbHelper.getDao(Seances.class).queryForAll();
        for (Seances SeancesInDB : listeSeancesInDB) {
            if (!listeSeancesInAPI.containsKey((String) SeancesInDB.id)) {
                Dao<Seances, String> SeancesDao = dbHelper.getDao(Seances.class);
                SeancesDao.deleteById(SeancesInDB.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) ca.etsmtl.applets.etsmobile.model.listeSeances(ca.etsmtl.applets.etsmobile.model.listeSeances) Seances(ca.etsmtl.applets.etsmobile.model.Seances)

Example 5 with DatabaseHelper

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

the class HoraireManager method updateCalendar.

/**
 * Creates/Updates a new calendar on the user's device
 *
 * @param joursRemplacesSelected true if the "Jours remplacés" calendar was selected
 * @param seancesSelected true if the "Séances" calendar was selected
 * @param calPublicSelected true if the "Calendrier public ÉTS" was selected
 * @throws Exception if there is an SQL when checking the replaced days (Jours remplacés)
 */
public void updateCalendar(boolean joursRemplacesSelected, boolean seancesSelected, boolean calPublicSelected) throws Exception {
    DatabaseHelper dbHelper = new DatabaseHelper(context);
    AndroidCalendarManager androidCalendarManager = new AndroidCalendarManager(context);
    androidCalendarManager.deleteCalendar(calendarName);
    androidCalendarManager.createCalendar(calendarName);
    SimpleDateFormat joursRemplacesFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CANADA_FRENCH);
    if (joursRemplacesSelected) {
        // Inserting JoursRemplaces in local calendar
        ArrayList<JoursRemplaces> listeJoursRemplaces = (ArrayList<JoursRemplaces>) dbHelper.getDao(JoursRemplaces.class).queryForAll();
        for (JoursRemplaces joursRemplaces : listeJoursRemplaces) {
            androidCalendarManager.insertEventInCalendar(calendarName, joursRemplaces.description, joursRemplaces.description, "", joursRemplacesFormatter.parse(joursRemplaces.dateOrigine), joursRemplacesFormatter.parse(joursRemplaces.dateOrigine));
        }
    }
    if (seancesSelected) {
        // Inserting Seances in local calendar
        SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CANADA_FRENCH);
        ArrayList<Seances> seances = (ArrayList<Seances>) dbHelper.getDao(Seances.class).queryForAll();
        for (Seances seance : seances) {
            androidCalendarManager.insertEventInCalendar(calendarName, seance.descriptionActivite.equals("Examen final") ? "Examen final " + seance.coursGroupe : seance.coursGroupe, seance.libelleCours + " - " + seance.descriptionActivite, seance.local, seancesFormatter.parse(seance.dateDebut), seancesFormatter.parse(seance.dateFin));
        }
    }
    if (calPublicSelected) {
        // Inserting public calendar ETS
        ArrayList<Event> events = (ArrayList<Event>) dbHelper.getDao(Event.class).queryForAll();
        for (Event event : events) {
            androidCalendarManager.insertEventInCalendar(calendarName, event.getTitle(), "", "", joursRemplacesFormatter.parse(event.getDateDebut()), joursRemplacesFormatter.parse(event.getDateFin()));
        }
    }
}
Also used : DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) ArrayList(java.util.ArrayList) Event(ca.etsmtl.applets.etsmobile.model.Event) ca.etsmtl.applets.etsmobile.model.listeSeances(ca.etsmtl.applets.etsmobile.model.listeSeances) Seances(ca.etsmtl.applets.etsmobile.model.Seances) ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces(ca.etsmtl.applets.etsmobile.model.listeJoursRemplaces) JoursRemplaces(ca.etsmtl.applets.etsmobile.model.JoursRemplaces) SimpleDateFormat(java.text.SimpleDateFormat)

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