Search in sources :

Example 1 with Urine

use of com.zyf.bean.Urine in project HeartWatchdogJsp by Viczyf.

the class UrineServlet method selectUrine.

public void selectUrine(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    UrineDao urinedao = new UrineDao();
    HttpSession session = request.getSession();
    // 获取用户对象
    User user = (User) session.getAttribute("user");
    int id = user.getUid();
    List urineList = urinedao.queryUrine(id);
    // request.setAttribute("urineList", urineList);
    JsonArray array = new JsonArray();
    for (int i = 0; i < urineList.size(); i++) {
        Urine single = (Urine) urineList.get(i);
        JsonObject ob = new JsonObject();
        ob.addProperty("id", i + 1);
        ob.addProperty("date", single.getDate());
        ob.addProperty("read", "<a href=\"UrineServlet?action=single&id=" + single.getId() + " \"target=\"_blank\">查看记录</a>");
        ob.addProperty("del", "<a href=\"UrineServlet?action=delete&id=" + single.getId() + "\">删除记录</a>");
        array.add(ob);
    }
    PrintWriter out = response.getWriter();
    out.print(array);
    System.out.println(array);
// RequestDispatcher rd = request.getRequestDispatcher("urinelist.jsp");
// request.setAttribute("listjson", array);
// rd.forward(request, response);
}
Also used : JsonArray(com.google.gson.JsonArray) Urine(com.zyf.bean.Urine) User(com.zyf.bean.User) HttpSession(javax.servlet.http.HttpSession) JsonObject(com.google.gson.JsonObject) List(java.util.List) UrineDao(com.zyf.dao.UrineDao) PrintWriter(java.io.PrintWriter)

Example 2 with Urine

use of com.zyf.bean.Urine in project HeartWatchdogJsp by Viczyf.

the class UrineServlet method singleUrine.

public void singleUrine(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    UrineDao urinedao = new UrineDao();
    int id = MyTools.strToint(request.getParameter("id"));
    HttpSession session = request.getSession();
    // 获取用户对象
    User user = (User) session.getAttribute("user");
    int uid = user.getUid();
    Urine urinesingle = urinedao.queryUrineSingle(id, uid);
    request.setAttribute("urinesingle", urinesingle);
    RequestDispatcher rd = request.getRequestDispatcher("urinesingle.jsp");
    rd.forward(request, response);
}
Also used : Urine(com.zyf.bean.Urine) User(com.zyf.bean.User) HttpSession(javax.servlet.http.HttpSession) UrineDao(com.zyf.dao.UrineDao) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 3 with Urine

use of com.zyf.bean.Urine in project HeartWatchdogJsp by Viczyf.

the class UrineDao method queryUrine.

public List queryUrine(int uid) {
    String sql = "";
    sql = "select * from urine where uid='" + uid + "' order by id desc";
    ArrayList list = null;
    Urine urine = null;
    ResultSet rs = this.connection.executeQuery(sql);
    if (rs != null) {
        list = new ArrayList();
        try {
            while (rs.next()) {
                urine = new Urine();
                urine.setId(rs.getInt(1));
                urine.setUid(rs.getInt(2));
                urine.setDate(rs.getString(3));
                urine.setLeu(rs.getString(4));
                urine.setNit(rs.getString(5));
                urine.setUbg(rs.getString(6));
                urine.setPro(rs.getString(7));
                urine.setPh(MyTools.strTofloat(rs.getString(8)));
                urine.setSg(MyTools.strTofloat(rs.getString(9)));
                urine.setCa(rs.getString(10));
                urine.setBld(rs.getString(11));
                urine.setKet(rs.getString(12));
                urine.setBil(rs.getString(13));
                urine.setGlu(rs.getString(14));
                urine.setVc(rs.getString(15));
                urine.setMa(rs.getString(16));
                urine.setCr(rs.getString(17));
                list.add(urine);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return list;
}
Also used : Urine(com.zyf.bean.Urine) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 4 with Urine

use of com.zyf.bean.Urine in project HeartWatchdogJsp by Viczyf.

the class UrineDao method queryUrineSingle.

public Urine queryUrineSingle(int id, int uid) {
    Urine urine = null;
    String sql = "select * from urine where id=" + id + " and uid=" + uid;
    ResultSet rs = this.connection.executeQuery(sql);
    try {
        if (rs.next()) {
            urine = new Urine();
            urine.setId(rs.getInt(1));
            urine.setUid(rs.getInt(2));
            urine.setDate(rs.getString(3));
            urine.setLeu(rs.getString(4));
            urine.setNit(rs.getString(5));
            urine.setUbg(rs.getString(6));
            urine.setPro(rs.getString(7));
            urine.setPh(MyTools.strTofloat(rs.getString(8)));
            urine.setSg(MyTools.strTofloat(rs.getString(9)));
            urine.setCa(rs.getString(10));
            urine.setBld(rs.getString(11));
            urine.setKet(rs.getString(12));
            urine.setBil(rs.getString(13));
            urine.setGlu(rs.getString(14));
            urine.setVc(rs.getString(15));
            urine.setMa(rs.getString(16));
            urine.setCr(rs.getString(17));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return urine;
}
Also used : Urine(com.zyf.bean.Urine) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 5 with Urine

use of com.zyf.bean.Urine in project HeartWatchdogJsp by Viczyf.

the class UrineServlet method deleteUrine.

public void deleteUrine(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String message = "";
    String forward = "";
    String href = "";
    UrineDao urinedao = new UrineDao();
    int id = MyTools.strToint(request.getParameter("id"));
    Urine urine = new Urine();
    urine.setId(id);
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    int uid = user.getUid();
    boolean mark = urinedao.delUrine(urine, uid);
    if (mark) {
        message = message + "<li>删除记录成功!</li>";
        forward = "tishi.jsp";
        href = href + "urinetime.jsp";
    } else {
        message = message + "<li>删除记录失败!</li>";
        forward = "tishi.jsp";
        href = href + "urinetime.jsp";
    }
    request.setAttribute("message", message);
    request.setAttribute("href", href);
    RequestDispatcher rd = request.getRequestDispatcher(forward);
    rd.forward(request, response);
}
Also used : Urine(com.zyf.bean.Urine) User(com.zyf.bean.User) HttpSession(javax.servlet.http.HttpSession) UrineDao(com.zyf.dao.UrineDao) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

Urine (com.zyf.bean.Urine)7 User (com.zyf.bean.User)4 UrineDao (com.zyf.dao.UrineDao)4 HttpSession (javax.servlet.http.HttpSession)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RequestDispatcher (javax.servlet.RequestDispatcher)2