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();
}
}
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();
}
}
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;
}
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);
}
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();
}
}
Aggregations