Exemple #1
0
  /**
   * 添加登录信息
   *
   * @param loginInfo
   * @return
   */
  public boolean addLoginInfo(UserInfo loginInfo) {
    Logger.i(LoginInfoDao.class, "[登录信息数据操作类]:添加用户登录信息");
    SQLiteDatabase db = null;
    try {
      db = databaseHelper.getWritableDatabase();
      if (loginInfo != null) {
        // 开启事务
        db.beginTransaction();
        // 为保证数据只有一条,添加之前先进行删除
        db.delete(LoginInfoTable.Table_Name, null, null);
        ContentValues values = new ContentValues();

        values.put(LoginInfoTable.AccessToken, loginInfo.AccessToken);
        values.put(LoginInfoTable.ExpiresIn, loginInfo.ExpiresIn);
        values.put(LoginInfoTable.RefreshToken, loginInfo.RefreshToken);

        values.put(LoginInfoTable.Id, loginInfo.Id);
        values.put(LoginInfoTable.Code, loginInfo.Code);
        values.put(LoginInfoTable.Name, loginInfo.Name);

        values.put(LoginInfoTable.NameShort, loginInfo.NameShort);
        values.put(LoginInfoTable.BelongArea, loginInfo.BelongArea.value());
        values.put(LoginInfoTable.Sex, loginInfo.Sex.value());

        values.put(LoginInfoTable.Phone, loginInfo.Phone);
        values.put(LoginInfoTable.Photo, loginInfo.Photo);
        values.put(LoginInfoTable.Department, loginInfo.Department);

        values.put(LoginInfoTable.EipPhone, loginInfo.EipPhone);
        values.put(LoginInfoTable.BindPhone, loginInfo.BindPhone);
        values.put(LoginInfoTable.DefaultPassword, loginInfo.DefaultPassword);

        /* 插入数据库操作 */
        db.insert(LoginInfoTable.Table_Name, null, values);
        // 关闭事务
        db.setTransactionSuccessful();
      }
      return true;
    } catch (Exception e) {
      Logger.e(LoginInfoDao.class, "[登录信息数据操作类]:添加用户信息异常:", e);
      return false;
    } finally {
      if (db != null) {
        if (db.inTransaction()) {
          db.endTransaction();
        }
        db.close();
      }
    }
  }
Exemple #2
0
 /**
  * 删除登录信息
  *
  * @return true:成功,false:失败
  * @see
  */
 public boolean delLoginInfo() {
   Logger.i(LoginInfoDao.class, "[登录信息数据操作类]:删除登录信息");
   SQLiteDatabase db = null;
   try {
     db = databaseHelper.getWritableDatabase();
     db.delete(LoginInfoTable.Table_Name, null, null);
     return true;
   } catch (Exception e) {
     Logger.e(LoginInfoDao.class, "[登录信息数据操作类]:删除登录信息异常:", e);
     return false;
   } finally {
     if (db != null) {
       db.close();
     }
   }
 }