1222carnivore  

今日代码:完成了所有精神状态评估表的功能
dao方法:

   public void AddUser_Spirit(int cognitiveFunction,int aggressiveBehavior,int depressionSymptoms,String FeelResult,String Username)
    {
        Connection connection =util.getConnection();
        PreparedStatement preparedStatement=null;

        try {
            String sql = "update 用户基本信息表 set 认知功能=?,攻击行为=?,抑郁症状=?,精神结果=? where 用户名=?";
            preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setInt(1, cognitiveFunction);
            preparedStatement.setInt(2, aggressiveBehavior);
            preparedStatement.setInt(3, depressionSymptoms);
            preparedStatement.setString(4, FeelResult);
            preparedStatement.setString(5, Username);
            preparedStatement.executeUpdate();

        } catch (SQLException  e) {
            e.printStackTrace();
        }finally{
            util.close(preparedStatement);
            util.close(connection);
        }
    }

Spirit_Result.jsp:

<div class="container">
  <div class="result-title">评估结果</div>
  <%
    // 获取表单数据
    String cognitiveFunctionStr = request.getParameter("cognitiveFunction");
    String aggressiveBehaviorStr = request.getParameter("aggressiveBehavior");
    String depressionSymptomsStr = request.getParameter("depressionSymptoms");

    int cognitiveFunction = cognitiveFunctionStr != null ? Integer.parseInt(cognitiveFunctionStr) : 0;
    int aggressiveBehavior = aggressiveBehaviorStr != null ? Integer.parseInt(aggressiveBehaviorStr) : 0;
    int depressionSymptoms = depressionSymptomsStr != null ? Integer.parseInt(depressionSymptomsStr) : 0;

    // 计算总分
    int totalScore = cognitiveFunction + aggressiveBehavior + depressionSymptoms;

    // 根据总分确定评估结果
    String FeelResult = "";
    switch (totalScore) {
      case 0:
        FeelResult = "能力完好";
        break;
      case 1:
        FeelResult = "轻度受损";
        break;
      case 2:
      case 3:
        FeelResult = "中度受损";
        break;
      default:
        FeelResult = "重度受损";
        break;
    }

    // 创建 bean 对象并设置属性
    bean bean = new bean();
    String Username = (String) session.getAttribute("Username");
    bean.setCognitiveFunction(cognitiveFunction);
    bean.setAggressiveBehavior(aggressiveBehavior);
    bean.setDepressionSymptoms(depressionSymptoms);
    bean.setTotalScore(totalScore);
    bean.setFeelResult(FeelResult);

    // 添加用户到数据库
    dao dao = new dao();
    dao.AddUser_Spirit(cognitiveFunction,aggressiveBehavior,depressionSymptoms,FeelResult,Username);
    out.print("<script type='text/javascript'>alert('录入成功!');</script>");
  %>
  <div class="result-description">您的评估结果为 <%= FeelResult %>!总分为 <%= totalScore %>。</div>
  <button class="back-button" onclick="window.location.href='/Menu.jsp'">返回主菜单</button>
</div>

效果:

posted on 2025-02-20 17:17  作业-----  阅读(13)  评论(0)    收藏  举报