/**
   * 保存message
   *
   * @param message
   * @return 返回这条messaged在db中的id
   */
  public synchronized Integer saveMessage(InviteMessage message) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int id = -1;
    if (db.isOpen()) {
      ContentValues values = new ContentValues();
      values.put(COLUMN_NAME_FROM, message.getFrom());
      values.put(COLUMN_NAME_GROUP_ID, message.getGroupId());
      values.put(COLUMN_NAME_GROUP_Name, message.getGroupName());
      values.put(COLUMN_NAME_REASON, message.getReason());
      values.put(COLUMN_NAME_TIME, message.getTime());
      values.put(COLUMN_NAME_STATUS, message.getStatus().ordinal());
      db.insert(TABLE_NAME, null, values);

      Cursor cursor = db.rawQuery("select last_insert_rowid() from " + TABLE_NAME, null);
      if (cursor.moveToFirst()) {
        id = cursor.getInt(0);
      }
    }
    return id;
  }
  /**
   * 获取messges
   *
   * @return
   */
  public List<InviteMessage> getMessagesList() {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    List<InviteMessage> msgs = new ArrayList<InviteMessage>();
    if (db.isOpen()) {
      Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + " desc", null);
      while (cursor.moveToNext()) {
        InviteMessage msg = new InviteMessage();
        int id = cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_ID));
        String from = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_FROM));
        String groupid = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_GROUP_ID));
        String groupname = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_GROUP_Name));
        String reason = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_REASON));
        long time = cursor.getLong(cursor.getColumnIndex(COLUMN_NAME_TIME));
        int isIniviteFromMe = cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_ISINVITEFROMME));
        int status = cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_STATUS));

        msg.setId(id);
        msg.setFrom(from);
        msg.setGroupId(groupid);
        msg.setGroupName(groupname);
        msg.setReason(reason);
        msg.setTime(time);
        if (status == InviteMesageStatus.BEINVITEED.ordinal())
          msg.setStatus(InviteMesageStatus.BEINVITEED);
        else if (status == InviteMesageStatus.BEAGREED.ordinal())
          msg.setStatus(InviteMesageStatus.BEAGREED);
        else if (status == InviteMesageStatus.BEREFUSED.ordinal())
          msg.setStatus(InviteMesageStatus.BEREFUSED);
        else if (status == InviteMesageStatus.AGREED.ordinal())
          msg.setStatus(InviteMesageStatus.AGREED);
        else if (status == InviteMesageStatus.REFUSED.ordinal())
          msg.setStatus(InviteMesageStatus.REFUSED);
        else if (status == InviteMesageStatus.BEAPPLYED.ordinal()) {
          msg.setStatus(InviteMesageStatus.BEAPPLYED);
        }
        msgs.add(msg);
      }
      cursor.close();
    }
    return msgs;
  }