⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sb_hotelmanagerbean.java~177~

📁 用j2ee开发的一个旅店管理系统
💻 JAVA~177~
字号:
package com.xc.hotelmanager.hotel.control.session;

import javax.ejb.*;
import java.util.*;

import com.xc.hotelmanager.hotel.model.*;
import com.xc.hotelmanager.hotel.exception.HotelManagerException;
import com.xc.hotelmanager.hotel.control.EjbGetter;
import java.sql.*;
import com.xc.hotelmanager.hotel.control.entity.*;
import java.util.Date;
import java.text.SimpleDateFormat;


public class SB_hotelmanagerBean implements SessionBean {
  SessionContext sessionContext;
  public void ejbCreate() throws CreateException {
    /**@todo Complete this method*/
  }
  public void ejbRemove() {
    /**@todo Complete this method*/
  }
  public void ejbActivate() {
    /**@todo Complete this method*/
  }
  public void ejbPassivate() {
    /**@todo Complete this method*/
  }
  public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
  }

  public int FindEmptyRoom(String type) throws HotelManagerException {
    int count=0;
    try{
            String sql="select roomid from Room,RoomType"
                       +" where Room.rtypeid=RoomType.rtypeid"
                       +" and RoomType.rtype='" +type
                       +"' and Room.rstuts='空净'";
            System.out.println(sql);
            Connection conn=EjbGetter.getDataSource().getConnection();
            Statement st=conn.createStatement();
            ResultSet rs=st.executeQuery(sql);
            //int i=rs.getRow();
            while(rs.next()){
              count=count+1;
            }
            return count;
        }
    catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
        }

  }
  private String ChooseRoom(int n, String type) throws HotelManagerException {
    String result="";
    int count=0;
    try{
      Connection conn=EjbGetter.getDataSource().getConnection();
      Statement st=conn.createStatement();
      String sql="select * from Room ,RoomType"
                 +" where Room.rtypeid=RoomType.rtypeid"
                 +" and Room.rstuts='空净' and RoomType.rtype='"+type+"'";
      ResultSet rs=st.executeQuery(sql);

      while((rs.next())&& (n!=0)){
        String id=rs.getString("roomid");
        TbRoom room=EjbGetter.getTbRoomHome().findByPrimaryKey(id);
        room.setRstuts("预订");
        //String sql1="update Room set rstuts='预订' where roomid="+id;
        //st.executeUpdate(sql1);
        result=result +"/"+ id;
        count=count+1;
        n=n-1;
      }
    }
    catch(Exception e){
        throw new HotelManagerException(e.getMessage());
    }
    return result;
  }

  public String  ResRoom(Reservation res, int num, String type) throws HotelManagerException {
    String rooms=ChooseRoom(num,type);
    String str="预留";
    String reid=getReservationId();
    //System.out.println(reid);
    //System.out.println(rooms);
    String s1="1";
    String s2=null;
    try{

      TbReservation record = EjbGetter.getTbReservationHome().create(reid);

      record.setRes(res);
      record.setRnum(rooms);
      record.setRestuts(str);

    }
    catch(Exception e){
       //throw new HotelManagerException(e.getMessage());
       s2="error";
       e.printStackTrace();

    }
     return s2;
  }

  public Collection getAllRoom() throws HotelManagerException {
    try{
            String sql="select * from Room";
            return this.loadRoomBySql(sql);
        }
        catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
        }

  }

  private Collection loadRoomBySql(String sql) throws Exception {
      Connection conn=EjbGetter.getDataSource().getConnection();
      Statement st=conn.createStatement();
      ResultSet rs=st.executeQuery(sql);
      Collection result=new Vector();

      while(rs.next()){
         Room room=new Room();
         room.setRoomid(rs.getString("roomid"));
         room.setRtypeid(rs.getString("rtypeid"));
         room.setRstuts(rs.getString("rstuts"));
         result.add(room);
         }
      rs.close();
      conn.close();
      return result;
    }

  public String getRoomtype(String id) throws HotelManagerException {
    try{
     TbRoomType record = EjbGetter.getTbRoomTypeHome().findByPrimaryKey(id);
     return record.getRtype();

    }
    catch(Exception e){
        throw new HotelManagerException(e.getMessage());
    }

  }

  private Collection loadRoomTypeBySql(String sql) throws Exception {
    Connection conn=EjbGetter.getDataSource().getConnection();
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery(sql);
    Collection result=new Vector();

    while(rs.next()){
      RoomType roomtype=new RoomType();
      roomtype.setRtypeid(rs.getString("rtypeid"));
      roomtype.setRprice(rs.getInt("rprice"));
      roomtype.setRtype(rs.getString("rtype"));

      result.add(roomtype);
    }
    rs.close();
    conn.close();
    return result;

  }

  private String getReservationId(){
      Date date=new Date();
      SimpleDateFormat df=new SimpleDateFormat("yyMMddHHmmss");
      String str=df.format(date);
      return str;


  }

  public Collection getRoomByType(String type) throws HotelManagerException {
    try{
            String sql="select roomid,Room.rtypeid,rstuts from RoomType,Room"
                       +" where Room.rtypeid=RoomType.rtypeid and rtype='"+type+"'";
            return this.loadRoomBySql(sql);
        }
        catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
        }

  }
  public void CancleRes(String id) throws HotelManagerException {
    try{

         TbReservation record = EjbGetter.getTbReservationHome().findByPrimaryKey(id);
         record.setRestuts("取消");
         String n=record.getRnum();
         ResetRoomStuts(n);
    }
    catch(Exception e){
        throw new HotelManagerException(e.getMessage());
    }
  }

  public Collection getAllRoomType() throws HotelManagerException {
    try{
             String sql="select * from RoomType";
             return this.loadRoomTypeBySql(sql);
         }
         catch(Exception ex){
             throw new HotelManagerException(ex.getMessage());
         }
  }
  public Collection SearchRes(String str) throws HotelManagerException {
    try{
             String sql="select * from Reservation where cname like'%"+str+"%' and restuts!='取消'";
             return this.loadRecordBySql(sql);
         }
         catch(Exception ex){
             throw new HotelManagerException(ex.getMessage());
         }
  }

  private Collection loadRecordBySql(String sql) throws Exception {
      Connection conn=EjbGetter.getDataSource().getConnection();
      Statement st=conn.createStatement();
      ResultSet rs=st.executeQuery(sql);
      Collection result=new Vector();

      while(rs.next()){
         Reservation re=new Reservation();

         re.setReid(rs.getString("reid"));
         re.setCid(rs.getString("cid"));
         re.setCname(rs.getString("cname"));
         re.setArrivetime(rs.getString("arrivetime"));
         re.setDays(rs.getInt("days"));
         re.setMembers(rs.getInt("members"));
         re.setPrepay(rs.getInt("prepay"));
         re.setRnum(rs.getString("rnum"));
         re.setRestuts(rs.getString("restuts"));

         result.add(re);
         }
      rs.close();
      conn.close();
      return result;
 }


 private void ResetRoomStuts(String str){
    int count=0;
    int len=str.length();
    try{
      for(int i=0;i<len;i++){
        String s1=str.substring(i,i+1);
        if (s1.equals("/")){
          if(i!=0){
             count=count+1;
             String s2=str.substring(count,i);

             TbRoom room = EjbGetter.getTbRoomHome().findByPrimaryKey(s2);
             room.setRstuts("空净");
             count=count+s2.length();
          }
       }
    }
    String s3=str.substring(count+1);
    TbRoom rs=EjbGetter.getTbRoomHome().findByPrimaryKey(s3);
    rs.setRstuts("空净");
    }
    catch(Exception e){
      e.printStackTrace();
    }
 }


  public Collection getAllRes() throws HotelManagerException {
    System.out.println("do getAllRes()");
    try{
             String sql="select * from Reservation";
             return this.loadRecordBySql(sql);
         }
         catch(Exception ex){
             throw new HotelManagerException(ex.getMessage());
         }
  }

  public int getRoomprice(String id) throws HotelManagerException {
    try{
             TbRoomType re=EjbGetter.getTbRoomTypeHome().findByPrimaryKey(id);
             System.out.println(re.getRprice());
             return re.getRprice();
         }
         catch(Exception ex){
             throw new HotelManagerException(ex.getMessage());
         }
  }

  public RoomType addRmtype(RoomType roomtype) throws HotelManagerException {
    try{
            TbRoomType ejbRoomType=EjbGetter.getTbRoomTypeHome().create(roomtype.getRtypeid());
            ejbRoomType.setRoomType(roomtype);
            return roomtype;
        }
        catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
        }

  }
  public void removeRoomType(String rtypeid) throws HotelManagerException {
    try{
           TbRoomType ejbRoomType=EjbGetter.getTbRoomTypeHome().findByPrimaryKey(rtypeid);
           ejbRoomType.remove();
       }
       catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
       }

  }
  public RoomType saveRoomType(RoomType roomtype) throws HotelManagerException {
    try{
             TbRoomType ejbRoomType=EjbGetter.getTbRoomTypeHome().findByPrimaryKey(roomtype.getRtypeid());
             ejbRoomType.setRoomType(roomtype);
             return roomtype;
         }
         catch(Exception ex){
             throw new HotelManagerException(ex.getMessage());
         }

  }


  public RoomType loadRoomType(String rtypeid) throws HotelManagerException {
        try{
            TbRoomType ejbRoomType=EjbGetter.getTbRoomTypeHome().findByPrimaryKey(rtypeid);
            return ejbRoomType.getRoomType();
        }
        catch(Exception ex){
            throw new HotelManagerException(ex.getMessage());
        }

    }


  public void CancleResByDate(String s) throws HotelManagerException {
    try{
           TbReservation t=EjbGetter.getTbReservationHome().findByPrimaryKey(s);

           if(t.getRestuts().equals("预留")){
             String h=DateCompare(t.getArrivetime());
             if(h.equals("0")){
             t.setRestuts("超期");
             ResetRoomStuts(t.getRnum());
          }

           }

       }
       catch(Exception ex){
           throw new HotelManagerException(ex.getMessage());
       }

  }


  private String DateCompare(String time) throws Exception {
    Date date=new Date();
  SimpleDateFormat df=new SimpleDateFormat("yyMMdd");
  SimpleDateFormat dy=new SimpleDateFormat("yy");
  SimpleDateFormat dm=new SimpleDateFormat("MM");
  SimpleDateFormat dd=new SimpleDateFormat("dd");
  String str=df.format(date);
  String p=null;
System.out.println(str);
System.out.println(time);

  if(str.equals(time)){p="1";
System.out.println("equals,p=1");
  }
  else{
System.out.println("not equals,do if-else");

    int n1=Integer.parseInt(time.substring(2,4));
    int n2=Integer.parseInt(time.substring(4));
    int n3=Integer.parseInt(dm.format(date));
    int n4=Integer.parseInt(dd.format(date));
    int n5=Integer.parseInt(time.substring(0,2));
    int n6=Integer.parseInt(dy.format(date));

    if(n5>n6){p="1";}
    else if(n6==n5){
    if(n3>n1){
      if(n4>n2){
        p="0";
      }
      else{
        if((n3==2)||(n3==4)||(n3==6)||(n3==9)||(n3==11)){
           if((n4+30-n2)>3) p="0";
           else p="1";
        }
        else{
           if((n4+31-n2)>3) p="0";
           else p="1";
        }
      }
    }
    else if(n3==n1){
       if((n4-n2)>3){p="0";}
       else{p="1";}
    }
    else{p="1";}
  }
  else{p="0";}

    String m2=String.valueOf(n1);
    String d2=String.valueOf(n2);
    if(m2.length()<2){m2="0"+m2;}
    if(d2.length()<2){d2="0"+d2;}

    if(str.equals(m2+d2)){
      p="0";
    }
  }
 return p;

  }

  public Collection getRoomByType1(String type) throws HotelManagerException {
  try{
          String sql="select roomid,Room.rtypeid,rstuts from RoomType,Room"
              +" where Room.rtypeid=RoomType.rtypeid"
                +" and RoomType.rtype='"+type+"' and Room.rstuts='空净'";

          return this.loadRoomBySql(sql);
      }
      catch(Exception ex){
          throw new HotelManagerException(ex.getMessage());
      }

}
  public int getRoompriceById(String roomid) throws HotelManagerException {
   try{
     TbRoom ro=EjbGetter.getTbRoomHome().findByPrimaryKey(roomid);
     String id=ro.getRtypeid();
     TbRoomType re=EjbGetter.getTbRoomTypeHome().findByPrimaryKey(id);
     System.out.println(re.getRprice());
     return re.getRprice();

   }
   catch(Exception e){
      throw new HotelManagerException(e.getMessage());
   }
  }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -