⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smclass.java

📁 计算机技术的快速发展
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = DBManager.getConnection();
      pstmt = conn.prepareStatement(MEMBER_COUNT);
      pstmt.setInt(1, this.classId);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    }
    catch (SQLException sqle) {

    }
    finally {
      DBManager.closeObject(conn, pstmt, rs);
    }
    return count;
  }

  /**
   * 获取该班级所有成员
   *
   * @return com.suninformation.schoolmate.SMMember[]
   * @throws UnacceptableException
   */
  public SMMember[] getSMMembers() throws UnacceptableException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    SMMember[] iSMMember = null;
    int number = getSMMemberCount();
    if (number >= 1) {
      iSMMember = new SMMember[number];
      try {
        conn = DBManager.getConnection();
        pstmt = conn.prepareStatement(ALL_MEMBER_FOR_THIS_CLASS);
        pstmt.setInt(1, this.classId);
        rs = pstmt.executeQuery();
        for (int i = 0; i < number && rs.next(); i++) {
          iSMMember[i] = new SMMember(rs.getString(1), this.classId);
        }
      }
      catch (Exception e) {
        throw new UnacceptableException("数据库操作失败!", e);
      }
      finally {
        DBManager.closeObject(conn, pstmt, rs);
      }
    }
    return iSMMember;
  }

  /**
   * 通过msgid获取班级留言
   *
   * @param msgid int
   * @return com.suninformation.schoolmate.SMMessage
   * @throws SMMessageNotFoundException
   * @throws UnacceptableException
   */
  public SMMessage getSMMessage(int msgid) throws SMMessageNotFoundException,
      UnacceptableException {
    return new SMMessage(msgid);
  }

  /**
   * 获取该班级所拥有的班级留言总数
   *
   * @return int
   * @throws UnacceptableException
   */
  public int getSMMessageCount() throws UnacceptableException {
    int count = -1;
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = DBManager.getConnection();
      pstmt = conn.prepareStatement(MESSAGE_COUNT);
      pstmt.setInt(1, this.classId);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        count = rs.getInt(1);
      }
    }
    catch (SQLException sqle) {
      throw new UnacceptableException(sqle.getMessage());
    }
    finally {
      DBManager.closeObject(conn, pstmt, rs);
    }
    return count;
  }

  /**
   * 获取该班所有留言
   *
   * @return com.suninformation.schoolmate.SMMessage[]
   * @throws UnacceptableException
   */
  public SMMessage[] getSMMeaages() throws UnacceptableException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    SMMessage[] iSMMessage = null;
    int number = getSMMessageCount();
    if (number >= 1) {
      iSMMessage = new SMMessage[number];
      try {
        conn = DBManager.getConnection();
        pstmt = conn.prepareStatement(ALL_MESSAGE_FOR_THIS_CLASS);
        pstmt.setInt(1, this.classId);
        rs = pstmt.executeQuery();
        for (int i = 0; i < number && rs.next(); i++) {
          iSMMessage[i] = new SMMessage(rs.getInt(1));
        }
      }
      catch (Exception e) {
        throw new UnacceptableException("数据库操作失败!", e);
      }
      finally {
        DBManager.closeObject(conn, pstmt, rs);
      }
    }
    return iSMMessage;
  }

  /**
   * 删除班级留言msgid
   *
   * @param msgid int
   * @throws UnacceptableException
   */
  public void deleteSMMessage(int msgid) throws UnacceptableException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = DBManager.getConnection();
      pstmt = conn.prepareStatement(DELETE_MESSAGE);
      pstmt.setInt(1, msgid);
      pstmt.executeUpdate();
    }
    catch (SQLException sqle) {
      throw new UnacceptableException("删除班级留言失败!", sqle);
    }
    finally {
      DBManager.closeObject(conn, pstmt, rs);
    }
  }

  /**
   * 删除班级所有留言
   *
   * @throws UnacceptableException
   */
  public void deleteSMMessages() throws UnacceptableException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = DBManager.getConnection();
      pstmt = conn.prepareStatement(DELETE_ALL_MESSAGE);
      pstmt.setInt(1, this.classId);
      pstmt.executeUpdate();
    }
    catch (SQLException sqle) {
      throw new UnacceptableException("删除班级留言失败!", sqle);
    }
    finally {
      DBManager.closeObject(conn, pstmt, rs);
    }
  }

  /**
   * 获取班级管理员列表
   *
   * @return SMMember[]
   * @throws UnacceptableException
   */
  public SMMember[] getClassManager() throws UnacceptableException {
    SMMember[] smm_p = null;
    try {
      SMMember[] smm = getSMMembers();
      int Count = 0;
      for (int i = 0; i < smm.length; i++) {
        if (smm[i].getMemberType() == 1) {
          Count++;
        }
      }
      if (Count > 0) {
        smm_p = new SMMember[Count];
        int j=0;
        for (int i = 0; i < smm.length; i++) {
          if (smm[i].getMemberType() == 1) {
            smm_p[j] = smm[i];j++;
          }
        }
      }
    }
    catch (Exception e) {
      throw new UnacceptableException(e.getMessage(), e);
    }
    return smm_p;
  }

  /**
   * 获取班级生日榜
   *
   * @return SMMember[]
   * @throws UnacceptableException
   */
  public SMMember[] getBirthdayMember() throws UnacceptableException {
    SMMember[] smm = this.getSMMembers();
    SMMember[] smm_p = null;
    int Count = 0;
    for (int i = 0; i < smm.length; i++) {
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      try {
        Date dt = smm[i].getUserInfo().getBirthday();
        String Month = dt.getMonth() < 10 ?
            "0" + String.valueOf(dt.getMonth() + 1) :
            String.valueOf(dt.getMonth() + 1);
        String Day = dt.getDate() < 10 ? "0" + String.valueOf(dt.getDate()) :
            String.valueOf(dt.getDate());
        dt = new Date(System.currentTimeMillis());
        String Year = String.valueOf(dt.getYear() + 1900);
        String enterdate = Year + "-" + Month + "-" + Day;
        Date t = new Date(formatter.parse(enterdate).getTime());
        long tt = (dt.getTime() - t.getTime()) / (1000 * 60 * 60 * 24);
        if (tt <= 3 && tt >= 0) {
          Count++;
        }
      }
      catch (Exception e) {
        throw new UnacceptableException(e);
      }
    }
    if (Count > 0) {
      smm_p = new SMMember[Count];
      int j=0;
      for (int i = 0; i < smm.length; i++) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
          Date dt = smm[i].getUserInfo().getBirthday();
          String Month = dt.getMonth() < 10 ?
              "0" + String.valueOf(dt.getMonth() + 1) :
              String.valueOf(dt.getMonth() + 1);
          String Day = dt.getDate() < 10 ? "0" + String.valueOf(dt.getDate()) :
              String.valueOf(dt.getDate());
          dt = new Date(System.currentTimeMillis());
          String Year = String.valueOf(dt.getYear() + 1900);
          String enterdate = Year + "-" + Month + "-" + Day;
          Date t = new Date(formatter.parse(enterdate).getTime());
          long tt = (dt.getTime() - t.getTime()) / (1000 * 60 * 60 * 24);
          if (tt <= 3 && tt >= 0) {
            smm_p[j] = smm[i];j++;
          }
        }
        catch (Exception e) {
          throw new UnacceptableException(e);
        }
      }
    }
    return smm_p;
  }

  //////////////////////////////////////////////////////////////////////////////

  //////////////////////////////////////////////////////////////////////////////

  /**
   * @return 返回 beginYear。
   */
  public String getBeginYear() {
    return beginYear;
  }

  /**
   * @param beginYear
   *            要设置的 beginYear。
   */
  public void setBeginYear(String beginYear) {
    this.beginYear = beginYear;
    this.isChanged = true;
  }

  /**
   * @return 返回 className。
   */
  public String getClassName() {
    return className;
  }

  /**
   * @param className
   *            要设置的 className。
   */
  public void setClassName(String className) {
    this.className = className;
    this.isChanged = true;
  }

  /**
   * @return 返回 classPronunciamento。
   */
  public String getClassPronunciamento() {
    return classPronunciamento;
  }

  /**
   * @param classPronunciamento
   *            要设置的 classPronunciamento。
   */
  public void setClassPronunciamento(String classPronunciamento) {
    this.classPronunciamento = classPronunciamento;
    this.isChanged = true;
  }

  /**
   * @return 返回 initiator。
   */
  public String getInitiator() {
    return initiator;
  }

  /**
   * @param initiator
   *            要设置的 initiator。
   */
  public void setInitiator(String initiator) {
    this.initiator = initiator;
    this.isChanged = true;
  }

  /**
   * @return 返回 classId。
   */
  public int getClassId() {
    return classId;
  }

  /**
   * @return 返回 createDate。
   */
  public Date getCreateDate() {
    return createDate;
  }

  /**
   * @return 返回 schoolId。
   */
  public int getSchoolId() {
    return schoolId;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -