package com.jdgl.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import com.jdbc.DButil.DButil;
import com.jdgl.Util;
import com.jdgl.entity.Room;
import com.jdgl.entity.VipCard;
public class JdService {
public List<Room> showList(int roomNum)
{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
Room r=null;
List<Room> roomList=new LinkedList<Room>();
String sql="select * from room where 1=1";
try {
conn=DButil.getConn();
if(roomNum!=0)
{
sql+=" and room_num="+roomNum;
}
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
r=new Room(rs.getInt("room_num"),rs.getInt("room_stat"),rs.getInt("room_price"),rs.getString("custom"));
roomList.add(r);
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
DButil.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return roomList;
}
// public void moveIn(String room_num)
// {
// int price=0;
// String room_num=request.getParameter("room_num");
// System.out.println(room_num);
// String id=request.getParameter("sfz");
// System.out.println(id);
// String vipId=request.getParameter("vipid");
// String sql="Update room set room_stat=1 where room_num=?";
// String sql5="Update room set custom=? where room_num=?";
// String sql1="select * from room where room_num="+room_num;
// Connection conn=null;
// PreparedStatement ps=null;
// ResultSet rs=null;
// try{
// conn=DButil.getConn();
// ps=conn.prepareStatement(sql);
// ps.setString(1, room_num);
// ps.executeUpdate();
// ps=conn.prepareStatement(sql1);
// rs=ps.executeQuery();
// ps=conn.prepareStatement(sql5);
// ps.setString(1, id);
// ps.setString(2, room_num);
// ps.executeUpdate();
// if(rs.next()){
// System.out.print(rs.getString("room_price"));
// price=rs.getInt("room_price");
// }
// }
@Test
public void vipLog(VipCard vc)
{
String sql = "insert into vip (idCard,name,phone,sex) values (?,?,?,?)";
Object[] obj = {vc.getIdCard(),vc.getName(),vc.getPhone(),vc.getSex()};
try {
DButil.update(sql, obj);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int returnId()
{
int id = 0;
String sql = "select * from vip order by id desc limit 0,1";
try {
ResultSet rs = DButil.select(sql);
rs.next();
id = rs.getInt("id");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return id;
}
public long calPrice(String roomNum,long divDay)
{
int roomPrice = 0;
long price = 0;
String sql = "select room_price from room where room_num = "+roomNum;
try {
ResultSet rs = DButil.select(sql);
rs.next();
roomPrice = rs.getInt("room_price");
System.out.println(roomPrice);
System.out.println(divDay);
price = roomPrice * divDay;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return price;
}
public long calPrice(String roomNum,Date nowDay,Date toDay)
{
int roomPrice = 0;
long price = 0;
long nd = 1000*24*60*60;
long diff = toDay.getTime()-nowDay.getTime();
long divDay = diff/nd;
String sql = "select room_price from room where room_num = "+roomNum;
try {
ResultSet rs = DButil.select(sql);
rs.next();
roomPrice = rs.getInt("room_price");
// System.out.println(roomPrice);
// System.out.println(divDay);
price = roomPrice * divDay;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return price;
}
public void moveIn(String idCard,String name,double money,String phone,String sex,String roomNum,String type,Date nowDay,Date toDay)
{
String searchSql = "select * from custom where id = "+idCard;
String customSql = "insert into custom values (?,?,?,?,?,?)";
String roomSql = "update room set room_stat=?, custom=?, movein_date=? , moveout_date=? where room_num=?";
Object[] obj1 = {idCard,money,type,phone,sex,name};
Object[] obj2 = {1,idCard,nowDay,toDay,roomNum};
ResultSet rs = null;
try {
rs = DButil.select(searchSql);
if(rs.next())
{
DButil.update(roomSql, obj2);
}else {
DButil.update(customSql, obj1);
DButil.update(roomSql, obj2);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void vipMoveIn(String vipCard,double money,String roomNum,String type,Date nowDay,Date toDay,HttpServletRequest request,HttpServletResponse response)
{
String sql = "select * from vip where id = "+vipCard;
String customSql = "insert into custom values (?,?,?,?,?,?)";
String roomSql = "update room set room_stat=?, custom=?, movein_date=? , moveout_date=? where room_num=?";
ResultSet rs = null;
try {
rs = DButil.select(sql);
if(rs.next())
{
String name = rs.getString("name");
String phone = rs.getString("phone");
int sex = rs.getInt("sex");
String idCard = rs.getString("idCard");
Object[] obj1 = {idCard,money,type,phone,sex,name};
Object[] obj2 = {1,idCard,nowDay,toDay,roomNum};
DButil.update(customSql, obj1);
DButil.update(roomSql, obj2);
}else {
request.setAttribute("errorMsg", "会员卡号不存在");
request.getRequestDispatcher("success/ErrorVip.jsp").forward(request, response);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public int preMoveOut(String roomNum)
{
String sql = "select * from room,custom where custom.id = room.custom and room_num = "+roomNum;
ResultSet rs = null;
int money = 0;
try {
rs = DButil.select(sql);
rs.next();
money = rs.getInt("costMoney");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return money;
}
public String getCustom(String roomNum)
{
String sql = "select * from room where room_num = "+roomNum;
ResultSet rs = null;
String custom = null;
try {
rs = DButil.select(sql);
rs.next();
custom = rs.getString("custom");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return custom;
}
public void MoveOut(String roomNum,String doPerson,String[] ulCosts)
{
Date date1 = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(date1);
// System.out.println(date);
String updateSql = "update room set room_stat =2,custom = null,movein_date=null,moveout_date=null where room_num = "+roomNum;
String insertSql = "insert into jdorder (customer_id,room,money,order_data,costThing,do_person) values (?,?,?,?,?,?)";
// System.out.println("-----"+roomNum);
String selectSql = "select * from room,custom where room.custom = custom.id and room_num = "+roomNum;
String deleteSql = "delete from custom where id =?";
String ulCost = Util.doStringArray(ulCosts);
ResultSet rs = null;
try {
rs = DButil.select(selectSql);
rs.next();
String idCard = rs.getString("id");
int money = rs.getInt("costMoney");
Object[] obj1 = {idCard};
Object[] obj = {idCard,roomNum,money,date,ulCost,doPerson};
DButil.update0(updateSql);
DButil.update(deleteSql, obj1);
DButil.update(insertSql, obj);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void cle
土豆片片
- 粉丝: 1859
- 资源: 5869
最新资源
- (2025)国家基层糖尿病防治管理指南认证考试试题及答案.docx
- (2025)国家公务员录用考试行测常识题库及答案.docx
- (2025)汉字听写大会试题库(附答案).docx
- (2025)国家开放大学《中国法律史》形成性考核1-4与参考答案.docx
- (2025)工业机器人技术题库及答案.docx
- (2025)科创板股票投资知识题库及答案.docx
- (2025)护理三基基础知识考试题库(含答案).docx
- 知识领域:仪器仪表,变流器,自动控制 关键词:光伏MPPT,电压控制器,微电网,河南求同电气,光伏模拟实验系统
- STM32F107各种接口程序合集工程文件 包含串口,CAN,时钟芯片,FLASH,外包AT25320储存,数据结构,枚举,适合刚刚出来工作的工程师以及进阶工程师 1.提供AD STM32F107原
- 基于fpga的多功能pwm模块设计 可应用于:dab,llc,buck,boost,全桥,推娩等dcdc电路 功能: 1.输出多路互补的pwm 2.每路互补pwm死区可调 3.每路互补pwm频率独立
- nianhuishougao
- 三菱PLC分拣程序基于三菱FX系列的分拣程序,可用于学习
- 电力系统的物理信息神经网络python源代码 代码按照高水平文章复现 介绍了一种在电力系统中应用物理信息神经网络的框架 利用控制电力系统的基本物理定律,并受到机器学习领域最新发展的启发,我们提出了一
- 知识领域:变流器,自动控制 关键词:软锁相环,河南求同电气,电压不平衡,微电网并网系统,变流器
- 三菱FX3U与4台英威腾GD系列变频器通讯案例实战程序 有注释,并附送程序,有接线方式,设置 器件:三菱FX3U的PLC,4台英威腾GD系列变频器,昆仑通态 功能:实现频率设
- 中颖正弦波矢量电动车控制器 1-提供原理图 2-提供pcb图 3-提供C源代码(主芯片SH79F3213) 带自学习功能,可任意匹配电机
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈