Beispiel #1
0
  public void updateHomeWork(HomeWork hw) {
    try {
      mDb.beginTransaction();
      if (hw != null) {

        mUpdateHomeWorkStatement.clearBindings();
        if (hw.isComplite()) {
          mUpdateHomeWorkStatement.bindLong(1, 1);
          NotificationManager.getInstance().removeNotification(hw);

        } else {
          mUpdateHomeWorkStatement.bindLong(1, 0);
          NotificationManager.getInstance().addNewNotification(hw);
        }

        if (hw.getMessage() != null) {
          mUpdateHomeWorkStatement.bindString(2, hw.getMessage());
        }

        if (hw.getMessage() != null) {
          mUpdateHomeWorkStatement.bindBlob(3, Slipper.serializeObject(hw.getImages()));
        }

        mUpdateHomeWorkStatement.bindLong(4, hw.getId());
        mUpdateHomeWorkStatement.execute();
      }
      mDb.setTransactionSuccessful();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDb.endTransaction();
    }
  }
Beispiel #2
0
  public void saveHomeWork(HomeWork homeWork) {

    mDb.beginTransaction();
    try {
      mSaveHomeWorkStatement.clearBindings();
      if (homeWork.getDate() != null) {
        mSaveHomeWorkStatement.bindLong(
            1, homeWork.getDate().getTime() / CalendarManager.MILISECONDS_PER_DAY);
      }

      mSaveHomeWorkStatement.bindLong(2, homeWork.getLessonId());

      if (homeWork.getMessage() != null) {
        mSaveHomeWorkStatement.bindString(3, homeWork.getMessage());
      }

      if (homeWork.getImages() != null) {
        mSaveHomeWorkStatement.bindBlob(4, Slipper.serializeObject(homeWork.getImages()));
      }

      if (homeWork.isComplite()) {
        mSaveHomeWorkStatement.bindLong(5, 1);
      } else {
        mSaveHomeWorkStatement.bindLong(5, 0);
      }

      mSaveHomeWorkStatement.bindLong(6, PreferenceManager.getInstance().getGroupId());

      homeWork.setId(mSaveHomeWorkStatement.executeInsert());
      mDb.setTransactionSuccessful();
      NotificationManager.getInstance().addNewNotification(homeWork);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDb.endTransaction();
    }
  }