import jav.classp;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckRoom_Servlet extends HttpServlet {
// 从订房来
classp cla = new classp();
public CheckRoom_Servlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
// 从OrderStep1。jps来
// 要去添加客户
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 获取客户所选的时间和客房类型
String intime = new String(request.getParameter("inTime").getBytes(
"ISO-8859-1"));
String outtime = new String(request.getParameter("outTime").getBytes(
"ISO-8859-1"));
Integer rtype = new Integer(request.getParameter("roomType"));
// 根据两个时间计算入住的天数
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
if (intime.equals("") | outtime.equals("")) {
out
.println("<script language='javascript'>alert('请填写完整!');history.back();</script>");
return;
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
long days = 1;
try {
Date d1 = df.parse(intime);
Date d2 = df.parse(outtime);
long diff = d2.getTime() - d1.getTime();
days = (diff / (1000 * 60 * 60 * 24));
} catch (Exception e) {
e.printStackTrace();
}
// 进行检查
// sql语句
/*
* String sql = "select * from " + "Room_Order_View " +
* "where IntRoomState=1 or IntRoomState=0 " + " and IntRoomType=" +
* rtype +" and convert(varchar(10),Outime,120)>'"+intime+"'";
*/
String sql = "select * from Room where IntRoomState=1";
Double roomprice = null;
Collection rid = new ArrayList();
boolean isfull = true;
try {
Statement stmt = cla.con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String strrid = rs.getString("IntRoomID");
roomprice = rs.getDouble("DRoomPrice");
rid.add(strrid);
isfull = false;
}
rs.close();
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (isfull) // 若为满则跳转
{
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("OrderStep1.jsp");
requestDispatcher.forward(request, response);
} else// 若为空则跳转
{
// 获取其他信息
// 将信息加入到request的session中
// request.getSession().setAttribute("roomid", cr.rid);
request.getSession().setAttribute("roomid", rid);
request.getSession().setAttribute("roomprice", roomprice);
request.getSession().setAttribute("od_outtime", outtime);
request.getSession().setAttribute("od_intime", intime);
request.getSession().setAttribute("r_roomtype", rtype);
request.getSession().setAttribute("days", days);
// 跳转到用户信息录入
Integer isold = (Integer) request.getSession()
.getAttribute("isold");
if (isold == null) {
isold = 0;
}
if (isold == 1) {
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("addOrder.jsp");
requestDispatcher.forward(request, response);
} else {
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("addguestPro.jsp");
requestDispatcher.forward(request, response);
}
//
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void init() throws ServletException {
// Put your code here
}
}
- 1
- 2
前往页