房产信息管理系统--购买房产

购买房产:顾客在浏览房产信息后,点击查看房产详细信息界面时,可以点击“交易”按钮,该房产状态信息改为 “意向”状态(3分)

还有一点题目没提到,就是还得将房产基本信息表中的顾客ID改为该用户的ID

此功能涉及的就是改,改房产状态信息

代码

User_PurchaseHouse.jsp

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="com.Util.util" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>部分房产信息</title>
</head>
<body>

<table border="1" cellspacing="0">
<tr>
<td align="center" width=6%>房产编号</td>
<td align="center" width=10%>房产地址</td>
<td align="center" width=6%>销售报价</td>
</tr>
<%
int i=0;
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql= " select * from 房产基本信息表 ";
preparedStatement=connection.prepareStatement(sql);

rs=preparedStatement.executeQuery();
while(rs.next())
{
if(rs.getObject(7).equals("在售"))
{
i++;
%>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><a href='User_PurchaseHouse_back1.jsp?Address=<%=rs.getObject(3)%>'><%=rs.getObject(3) %></a></td>
<td align="center"><%=rs.getObject(6) %></td>
</tr>
<%
}
}
if(i==0)
{
out.print("<script language='javaScript'> alert('没有查询到有关信息'); window.history.back(-1); </script>");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}

%>
</table>

<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" >
<br>
</p>
</body>
</html>

User_PurchaseHouse_back1.jsp

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细房产信息</title>
</head>
<body>

<%
String Address = (String)request.getParameter("Address");
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from 房产基本信息表";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(Address.equals(rs.getObject(3)))
{
//重要
String HouseID= (String) rs.getObject(1);
session.setAttribute("HouseID",HouseID);
%>
<table border="1"cellspacing="0"style="text-align:center;">
<tr>
<td align="center" width=5%>房产编号</td>
<td align="center" width=5%>户型</td>
<td align="center" width=10%>房产地址</td>
<td align="center" width=5%>建造年份</td>
<td align="center" width=5%>建造面积</td>
<td align="center" width=5%>销售报价</td>
<td align="center" width=5%>销售状态</td>
<td align="center" width=5%>房产经纪人ID</td>
<td align="center" width=5%>顾客ID</td>
</tr>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
<td align="center"><%=rs.getObject(8) %></td>
<td align="center"><%=rs.getObject(9) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<form action="User_PurchaseHouse_back2.jsp" method="get">

<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="submit" value="交易">
<br>
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='User_Menu.jsp'" /> <br>
</p>
</form>
</body>
</html>

User_PurchaseHouse_back2.jsp

<%@ page import="com.Dao.dao" %><%--
Created by IntelliJ IDEA.
User: mendianyu
Date: 2022/11/5
Time: 19:38
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
String UserID= (String) session.getAttribute("UserID");
String HouseID= (String) session.getAttribute("HouseID");
String Status="意向";
dao dao=new dao();
dao.PurchaseHouse(UserID,Status,HouseID);
out.print("<script language='javaScript'> alert('已将该房产纳入意向');</script>");
response.setHeader("refresh", "0;url=User_Menu.jsp");

%>
</body>
</html>

Dao方法
public void PurchaseHouse(String UserID,String Status,String HouseID)
{
Connection connection =util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "update 房产基本信息表 set 顾客ID=?,销售状态=? where 房产编号=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,UserID);
preparedStatement.setString(2,Status);
preparedStatement.setString(3,HouseID);
preparedStatement.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}
posted @ 2022-11-11 18:34  Men!  阅读(55)  评论(0编辑  收藏  举报