You are on page 1of 31

Hotel Management System public void

setBooking_id(int booking_id) {
Booking Class this.booking_id =
package I3.Classes; booking_id;
}
import java.util.ArrayList;
import java.util.Date;

/** public String


* getBookingType() {
* @author Faysal Ahmed return bookingType;
*/ }
public class Booking {
public void
// int CONFIRMED = 0; setBookingType(String
// int RESERVED = 1; bookingType) {
this.bookingType =
// required Object bookingType;
}
private UserInfo customer;
ArrayList<Room> rooms;

public void addRoom(String


private int booking_id; roomNo)
private long {
checkInDateTime; rooms.add(new
private long Room(roomNo));
checkOutDateTime;
private String bookingType; }
private int person;
//private int roomsFare; public void
removeRoom(String roomNo)
{
for(Room a: rooms)
public Booking() {
{
customer = new if(a.getRoom_no().equals(roomNo)
UserInfo(); )
rooms = new {
ArrayList<>(); rooms.remove(a);
booking_id = -1; }
bookingType = }
"Reserved"; }

} public int getPerson() {


return person;
public int getBooking_id() { }
return booking_id;
} public void setPerson(int
person) {
this.person = person;
} public long
getCheckOutDateTime() {
public ArrayList<Room> return checkOutDateTime;
getRooms() { }
return rooms;
} public void
setCheckOutDateTime(long
public int getRoomsFare() checkOutDateTime) {
{ this.checkOutDateTime =
int total = 0; checkOutDateTime;
for(Room room:rooms) }
{
total +=
room.getRoom_class().getPricePer
Day();
}
return total;
}
}
public UserInfo Extra Orders Class
getCustomer() { package I3.Classes;
return customer;
} /**
*
public void * @author Faysal Ahmed
setCustomer(UserInfo customer) { */
this.customer = public class ExtraOrders {
customer;
} private int order_id;
private int customer_id;
private String dateTime;
private int quantity;
public void private Item item;
setCheckOutDateTime(int //int order_total;
checkOutDateTime) {
this.checkOutDateTime = public int getOrder_id() {
checkOutDateTime; return order_id;
} }
public long public void setOrder_id(int
getCheckInDateTime() { order_id) {
return checkInDateTime; this.order_id =
} order_id;
}
public void
setCheckInDateTime(long public int getCustomer_id()
checkInDateTime) { {
this.checkInDateTime = return customer_id;
checkInDateTime; }
}
public void
setCustomer_id(int customer_id) /**
{ *
this.customer_id = * @author Faysal Ahmed
customer_id; */
} public class Food {

public String getDateTime() private int food_id;


{ private String name;
return dateTime; private int price;
}
public int getFood_id() {
public void return food_id;
setDateTime(String dateTime) { }
this.dateTime =
dateTime; public void setFood_id(int
} food_id) {
this.food_id = food_id;
public int getQuantity() { }
return quantity;
} public String getName() {
return name;
public void setQuantity(int }
quantity) {
this.quantity = public void setName(String
quantity; name) {
} this.name = name;
}
public Item getItem() {
return item; public int getPrice() {
} return price;
}
public void setItem(Item
item) { public void setPrice(int
this.item = item; price) {
} this.price = price;
}
public int calculateTotal()
{
return item.getPrice() *
quantity; }
}
Item Class
package I3.Classes;

/**
*
} * @author Faysal Ahmed
*/
Food Class public class Item {
package I3.Classes;
private int item_id; }
private String item_name;
private String description; Order Class
private int price; package I3.Classes;

public int getItem_id() { /**


return item_id; *
} * @author Faysal
*/
public void setItem_id(int public class Order {
item_id) {
this.item_id = item_id; int orderId;
} int bookingId;
String foodItem;
public String getItem_name() int price;
{ int quantity;
return item_name; int total;
}
public Order(int b,String
public void f,int p,int q, int t)
setItem_name(String item_name) { {
this.item_name = bookingId = b;
item_name; foodItem = f;
} price = p;
quantity = q;
public String total = t;
getDescription() { }
return description;
} public int getOrderId() {
return orderId;
public void }
setDescription(String
description) { public void setOrderId(int
this.description = orderId) {
description; this.orderId = orderId;
} }

public int getPrice() { public int getBookingId() {


return price; return bookingId;
} }

public void setPrice(int public void setBookingId(int


price) { bookingId) {
this.price = price; this.bookingId =
} bookingId;
}

public String getFoodItem()


{
return foodItem;
}
ArrayList<ExtraOrders>
public void orders;
setFoodItem(String foodItem) { int totalRentPrice;
this.foodItem = int daysStayed;
foodItem; private String payment_date;
} private String
payment_method;
public int getPrice() {
return price; private boolean hasDiscount;
} private float discount;

public void setPrice(int int totalBill;


price) {
this.price = price; public Payment(Booking b)
} {
booking = b;
public int getQuantity() { //totalRentPrice =
return quantity; b.getRoomsFare() * 1;
}
}
public void setQuantity(int
quantity) { public Booking getBooking()
this.quantity = {
quantity; return booking;
} }
public int getTotal() { public void
return total; setBooking(Booking booking) {
} this.booking = booking;
}
public void setTotal(int
total) { public String
this.total = total; getPayment_date() {
} return payment_date;
}

public void
} setPayment_date(String
Payment Class payment_date) {
package I3.Classes; this.payment_date =
payment_date;
import java.util.ArrayList; }

/** public String


* getPayment_method() {
* @author Faysal Ahmed return payment_method;
*/ }
public class Payment {
public void
//required Object setPayment_method(String
private Booking booking; payment_method) {
this.payment_method =
payment_method; Room Class
} package I3.Classes;

public boolean /**


isHasDiscount() { *
return hasDiscount; * @author Faysal Ahmed
} */
public class Room {
public void private int room_id;
setHasDiscount(boolean private String room_no;
hasDiscount) { private int bed_number;
this.hasDiscount =
hasDiscount; private boolean hasTV;
} private boolean hasWIFI;
private boolean hasGizer;
public float getDiscount() { private boolean hasPhone;
return discount;
}
private RoomFare room_class;
public void
setDiscount(float discount) {
this.discount = public Room(String roomNo)
discount; {
} room_no = roomNo;
}
public int public int getRoom_id() {
calculateTotalBill() return room_id;
{ }
int orderTotal = 0;
public void setRoom_id(int
for(ExtraOrders order: room_id) {
orders) this.room_id = room_id;
{ }
orderTotal +=
order.getQuantity() * public String getRoom_no() {
order.getItem().getPrice(); return room_no;
} }
totalBill = orderTotal+
totalRentPrice; public void
setRoom_no(String room_no) {
return totalBill; this.room_no = room_no;
} }

public int getBed_number() {


return bed_number;
}

} public void
setBed_number(int bed_number) {
this.bed_number = public void
bed_number; setRoom_class(RoomFare
} room_class) {
this.room_class =
public boolean isHasTV() { room_class;
return hasTV; }
}

public void setHasTV(boolean


hasTV) {
this.hasTV = hasTV;
}
}
public boolean isHasWIFI() { Room Fare Class
return hasWIFI; package I3.Classes;
}
/**
public void *
setHasWIFI(boolean hasWIFI) { * @author Faysal Ahmed
this.hasWIFI = hasWIFI; */
} public class RoomFare {
public boolean isHasGizer()
{
private String room_type;
return hasGizer;
} private int pricePerDay;

public void
setHasGizer(boolean hasGizer) {
this.hasGizer = public String getRoom_type()
hasGizer; {
} return room_type;
}
public boolean isHasPhone()
{ public void
return hasPhone; setRoom_type(String room_type) {
} this.room_type =
room_type;
public void }
setHasPhone(boolean hasPhone) {
this.hasPhone = public int getPricePerDay()
hasPhone; {
} return pricePerDay;
}

public RoomFare public void


getRoom_class() { setPricePerDay(int pricePerDay)
return room_class; {
} this.pricePerDay =
pricePerDay;
}
public String getAddress() {
return address;
} }
User Info Class
/* public void
* To change this license setAddress(String address) {
header, choose License Headers this.address = address;
in Project Properties. }
* To change this template file,
choose Tools | Templates public String getPhone_no()
* and open the template in the {
editor. return phone_no;
*/ }
package I3.Classes;
public void
/** setPhone_no(String phone_no) {
* this.phone_no =
* @author Faysal Ahmed phone_no;
*/ }
public class UserInfo {
public String getType() {
return type;
}
//USER PROPERTIES
public void setType(String
private int customer_id;
type) {
private String name;
this.type = type;
private String address;
}
private String phone_no;
private String type;

public int getCustomer_id()


{
return customer_id;
} }
Booking DB Class
public void package I3.DatabaseOperation;
setCustomer_id(int customer_id)
{ import I3.Classes.Booking;
this.customer_id = import I3.Classes.Order;
customer_id; import java.sql.Connection;
} import
java.sql.PreparedStatement;
public String getName() { import java.sql.ResultSet;
return name; import java.sql.SQLException;
} import javax.swing.JOptionPane;

public void setName(String public class BookingDb {


name) {
this.name = name; Connection conn;
}
PreparedStatement statement
= null; //System.out.println(">>>>>>>>>>
ResultSet result = null; " + insertQuery);

public BookingDb() { statement.execute();


conn =
DataBaseConnection.connectTODB()
; JOptionPane.showMessageDialog(nu
} ll, "successfully inserted new
Booking");
public void
insertBooking(Booking booking) { } catch
for (int i = 0; i < (SQLException ex) {
booking.getRooms().size(); i++)
{ JOptionPane.showMessageDialog(nu
try { ll, ex.toString() + "\n" +
String "InsertQuery booking Failed");
insertQuery = "insert into } finally {
booking"
+ flushStatementOnly();
"('customer_id','booking_room',' }
guests','check_in','check_out',' }
booking_type','has_checked_out')
" }
+ "
values(" public ResultSet
+ getBookingInformation() {
booking.getCustomer().getCustome try {
r_id() String query =
+ ",'" + "select * from booking";
booking.getRooms().get(i).getRoo statement =
m_no() + "'" conn.prepareStatement(query);
+ "," + result =
booking.getPerson() + "" statement.executeQuery();
+ "," + } catch (SQLException
booking.getCheckInDateTime() + ex) {
""
+ "," +
JOptionPane.showMessageDialog(nu
booking.getCheckOutDateTime() +
ll, ex.toString() + "\n error
""
coming from returning all
+ ",'" +
booking DB Operation");
booking.getBookingType() + "',"
}
+ 0
+ " )";
return result;
}
// ^^^ 0 for
has_checked_out
public ResultSet
statement =
getABooking(int bookingId) {
conn.prepareStatement(insertQuer
try {
y);
String query = }
"select * from booking where
booking_id = " + bookingId; public void
statement = updateCheckOut(int bookingId,
conn.prepareStatement(query); long checkOutTime) {
result = try {
statement.executeQuery(); String updateFood =
} catch (SQLException "update booking set
ex) { has_checked_out= 1, check_out =
" + checkOutTime + " where
JOptionPane.showMessageDialog(nu booking_id = " + bookingId;
ll, ex.toString() + "\n error
coming from returning A booking //
DB Operation"); System.out.println(">>>>>>>>>>
} "+ insertRoomTypeQuery);
statement =
return result; conn.prepareStatement(updateFood
} );

public ResultSet statement.execute();


bookingsReadyForOrder(String
roomName) {
try { JOptionPane.showMessageDialog(nu
// flushAll(); ll, "successfully update Check
String query = Out ");
"select
booking_id,booking_room,name } catch (SQLException
from booking join userInfo on ex) {
booking.customer_id =
userInfo.user_id where JOptionPane.showMessageDialog(nu
booking_room like '%" + roomName ll, ex.toString() + "\n" +
+ "%' and has_checked_out = 0 "updateCheckOut of BookingDB
order by booking_id desc"; Failed");
} finally {
System.out.println(query);
statement = flushStatementOnly();
conn.prepareStatement(query); }
result = }
statement.executeQuery();
public int getRoomPrice(int
} catch (SQLException bookingId) {
ex) {
int price = -1;
JOptionPane.showMessageDialog(nu try {
ll, ex.toString() + "\n error
coming from returning String query =
bookingsReadyForOrder "select price from booking join
method,BookingDb"); room on booking_room = room_no
} join roomType on type=
room_class where booking_id=" +
return result; bookingId;
} catch (SQLException
System.out.println(query); ex) {
statement =
conn.prepareStatement(query); JOptionPane.showMessageDialog(nu
result = ll, ex.toString() + "\n" +
statement.executeQuery(); "Order Failed");
price = } finally {
result.getInt("price");
//flushAll(); flushStatementOnly();
}
System.out.println(price);
flushAll(); }

} catch (SQLException public ResultSet


ex) { getAllPaymentInfo(int bookingId)
{
JOptionPane.showMessageDialog(nu try {
ll, ex.toString() + "\n error
coming from returning price String query =
getRoomPrice,bookingDB"); "select * from orderItem where
} booking_id=" + bookingId;

return price; System.out.println(query);


} statement =
conn.prepareStatement(query);
public void result =
insertOrder(Order order) { statement.executeQuery();
try { // price =
String insertOrder = result.getInt("price");
"insert into //flushAll();
orderItem('booking_id','item_foo //
d','price','quantity','total') System.out.println(price);
values(" + order.getBookingId() // flushAll();
+ ",'" + order.getFoodItem() +
"'," + order.getPrice() + "," + } catch (SQLException
order.getQuantity() + "," + ex) {
order.getTotal() + ")";
JOptionPane.showMessageDialog(nu
statement = ll, ex.toString() + "\n error
conn.prepareStatement(insertOrde coming from returning payment
r); getAllPaymentInfo,bookingDB");
}
System.out.println(">>>>>>>>>> " return result;
+ insertOrder); }
statement.execute();
public void flushAll() {
{
JOptionPane.showMessageDialog(nu try {
ll, "successfully inserted a new
Order"); statement.close();
result.close();
} catch public class CustomerDb {
(SQLException ex) { Connection conn;
PreparedStatement statement
System.err.print(ex.toString() + = null;
" >> CLOSING DB"); ResultSet result = null;
}
} public CustomerDb()
} {
conn =
public void DataBaseConnection.connectTODB()
flushStatementOnly() { ;
{ }
try { public void
insertCustomer(UserInfo user) {
statement.close(); try {
//conn.close(); String insertQuery =
} catch "insert into userInfo"
(SQLException ex) { + "('" +
"name" + "'," + "'" + "address"
System.err.print(ex.toString() + + "','" + "phone" + "','" +
" >> CLOSING DB"); "type" + "')"
} + "
} values('"
} +
user.getName()
} + "','" +
user.getAddress() + "'"
Customer DB Class + ",'" +
/* user.getPhone_no() + "'"
* To change this license + ",'" +
header, choose License Headers user.getType() + "'"
in Project Properties. + ")";
* To change this template file,
choose Tools | Templates
* and open the template in the //System.out.println(">>>>>>>>>>
editor. "+ insertQuery);
*/ statement =
package I3.DatabaseOperation; conn.prepareStatement(insertQuer
y);
import I3.Classes.UserInfo;
import java.sql.Connection; statement.execute();
import
java.sql.PreparedStatement;
import java.sql.ResultSet; JOptionPane.showMessageDialog(nu
import java.sql.SQLException; ll, "successfully inserted new
import javax.swing.JOptionPane; Customer");

/** } catch (SQLException


* ex) {
* @author Faysal Ahmed
*/ JOptionPane.showMessageDialog(nu
ll, ex.toString() + "\n" + } catch (SQLException
"InsertQuery Failed"); ex) {
}
finally JOptionPane.showMessageDialog(nu
{ ll, ex.toString() + "\n" +
"Update query Failed");
flushStatementOnly(); }
}
finally
{
}
flushStatementOnly();
public void }
updateCustomer(UserInfo user) {
// update userInfo set }
name = 'faysal' ,address =
'dhaka' where user_id = 3 public void
try { deleteCustomer(int userId)
String updateQuery = throws SQLException {
"update userInfo set name = '" try {
+ String deleteQuery =
user.getName() + "'," "delete from userInfo where
+ "address = user_id=" + userId;
'" + user.getAddress() + "'," statement =
+ "phone = conn.prepareStatement(deleteQuer
'" + user.getPhone_no() + "'," y);
+ "type = '" statement.execute();
+ user.getType() + "' where
user_id= " JOptionPane.showMessageDialog(nu
+ ll, "Deleted user");
user.getCustomer_id(); } catch (SQLException
ex) {

//System.out.println(">>>>>>>>>> JOptionPane.showMessageDialog(nu
"+ insertQuery); ll, ex.toString() + "\n" +
"Delete query Failed");
//System.out.println(updateQuery }
); finally
statement = {
conn.prepareStatement(updateQuer
y); flushStatementOnly();
}

//System.out.println(updateQuery }
);
statement.execute(); public ResultSet
getAllCustomer() {
try {
JOptionPane.showMessageDialog(nu String query =
ll, "successfully updated new "select * from userInfo";
Customer");
statement =
conn.prepareStatement(query);
result =
statement.executeQuery(); }
} catch (SQLException Data Base Connection Class
ex) { package I3.DatabaseOperation;

JOptionPane.showMessageDialog(nu import java.sql.Connection;


ll, ex.toString() + "\n error import java.sql.DriverManager;
coming from returning all import javax.swing.JOptionPane;
customer DB Operation"); import org.sqlite.*;
}

return result; /**


} *
private void * @author Faysal Ahmed
flushStatementOnly() */
{
{
try public class DataBaseConnection
{ {

statement.close(); //Connection conn = null;


public static Connection
//conn.close(); connectTODB()
} {
try {
catch(SQLException ex)
Class.forName("org.sqlite.JDBC")
{System.err.print(ex.toString() ;
+" >> CLOSING DB");} Connection conn =
} DriverManager.getConnection("jdb
} c:sqlite:hotel.sqlite");
public void flushAll() //
{ JOptionPane.showMessageDialog(nu
{ ll, "Connection Establishment");
try return conn;
{ } catch (Exception ex) {

statement.close(); JOptionPane.showMessageDialog(nu
ll, ex.toString());
result.close(); return null;
} }

catch(SQLException ex)
}
{System.err.print(ex.toString()
+" >> CLOSING DB");} }
} Data Base Operation Class
} package I3.DatabaseOperation;
import I3.Classes.Food; statement =
import I3.Classes.Item; conn.prepareStatement(insertQuer
import I3.Classes.Room; y);
import I3.Classes.RoomFare;
import I3.Classes.UserInfo; statement.execute();
import java.sql.Connection;
import
java.sql.PreparedStatement; JOptionPane.showMessageDialog(nu
import java.sql.ResultSet; ll, "successfully inserted new
import java.sql.SQLException; Customer");
import javax.swing.JOptionPane;
} catch (SQLException
/** ex) {
*
* @author Faysal Ahmed JOptionPane.showMessageDialog(nu
*/ ll, ex.toString() + "\n" +
public class DatabaseOperation { "InsertQuery Failed");
}
Connection conn = finally
DataBaseConnection.connectTODB() {
; flushStatmentOnly();
PreparedStatement statement }
= null;
ResultSet result = null;
}
public void public void flushAll()
insertCustomer(UserInfo user) {
throws SQLException { {
try { try
String insertQuery = {
"insert into userInfo"
+ "('" + statement.close();
"name" + "'," + "'" + "address"
+ "','" + "phone" + "','" +
result.close();
"type" + "')"
}
+ "
values('"
+ catch(SQLException ex)
user.getName()
+ "','" + {System.err.print(ex.toString()
user.getAddress() + "'" +" >> CLOSING DB");}
+ ",'" + }
user.getPhone_no() + "'" }
+ ",'" +
user.getType() + "'" public void
+ ")"; updateCustomer(UserInfo user) {
// update userInfo set
name = 'faysal' ,address =
'dhaka' where user_id = 3
//System.out.println(">>>>>>>>>>
"+ insertQuery); try {
String updateQuery =
"update userInfo set name = '"
+ statement.execute();
user.getName() + "',"
+ "address = JOptionPane.showMessageDialog(nu
'" + user.getAddress() + "'," ll, "Deleted user");
+ "phone = } catch (SQLException
'" + user.getPhone_no() + "'," ex) {
+ "type = '"
+ user.getType() + "' where JOptionPane.showMessageDialog(nu
user_id= " ll, ex.toString() + "\n" +
+ "Delete query Failed");
user.getCustomer_id(); }
finally
{
//System.out.println(">>>>>>>>>> flushStatmentOnly();
"+ insertQuery); }

//System.out.println(updateQuery }
);
statement = public ResultSet
conn.prepareStatement(updateQuer getAllCustomer() {
y); try {
String query =
"select * from userInfo";
//System.out.println(updateQuery statement =
); conn.prepareStatement(query);
statement.execute(); result =
statement.executeQuery();
} catch (SQLException
JOptionPane.showMessageDialog(nu ex) {
ll, "successfully updated new
Customer"); JOptionPane.showMessageDialog(nu
} catch (SQLException ll, ex.toString() + "\n error
ex) { coming from returning all
customer DB Operation");
JOptionPane.showMessageDialog(nu }
ll, ex.toString() + "\n" + finally
"Update query Failed"); {
} flushAll();
}
}
return result;
public void }
deleteCustomer(int userId)
throws SQLException {
try { ///
String deleteQuery = ********************************
"delete from userInfo where ********************************
user_id=" + userId; ******** SEARCH AND OTHERS
statement = ********************************
conn.prepareStatement(deleteQuer ****************
y);
public ResultSet
searchUser(String user) { //System.out.println("fetching
try { something");
String query = return result;
"select user_id,name,address }
from userInfo where name like
'%"+user+"%'"; public ResultSet
getAvailableRooms(long
statement = check_inTime)
conn.prepareStatement(query); {
result = try {
statement.executeQuery();
///SELECT room_no
FROM room LEFT OUTER JOIN
} catch (SQLException booking ON room.room_no =
ex) { booking.rooms WHERE
booking.rooms is null or
JOptionPane.showMessageDialog(nu booking.check_out <
ll, ex.toString() + "\n error strftime('%s', 'now')
coming from search user // SELECT distinct
function"); room_no FROM room LEFT OUTER
} JOIN booking ON room.room_no =
booking.rooms WHERE
//System.out.println("fetching booking.rooms is null or
something"); booking.check_out <
return result; strftime('%s', 'now') order by
} check_out desc
String query =
public ResultSet "SELECT room_no FROM room LEFT
searchAnUser(int id) OUTER JOIN booking ON
{ room.room_no =
try { booking.booking_room WHERE
String query = booking.booking_room is null or
"select * from userInfo where "+check_inTime+"<
user_id="+id; booking.check_in " +"or
booking.check_out
statement = <"+check_inTime+" group by
conn.prepareStatement(query); room.room_no order by room_no
result = ";
statement.executeQuery();
System.out.println(query);
statement =
conn.prepareStatement(query);
} catch (SQLException
result =
ex) {
statement.executeQuery();
} catch (SQLException
JOptionPane.showMessageDialog(nu ex) {
ll, ex.toString() + "\n error
coming from returning AN user
JOptionPane.showMessageDialog(nu
function");
ll, ex.toString() + "\n error
}
coming from returning free rooms result =
from getAvailable func."); statement.executeQuery();
} } catch (SQLException
ex) {

return result; JOptionPane.showMessageDialog(nu


} ll, ex.toString() + "\n error
coming from returning booking
public ResultSet info between two specific
getBookingInfo(long start_date, days");
long end_date,String roomNo) }
{
try {
/* return result;
}
select * from
booking where public int
(check_in <= getCustomerId(UserInfo user)
start_date and (check_out=0 or { int id = -1;
check_out<= end_date ) ) try {
or String query =
"select user_id from userInfo
(check_in>start_date and where name='"+user.getName()+"'
check_out< end_date) and phone ='"+user.getPhone_no()
or +"'";
(check_in
<=end_date and (check_out =0 or
check_out > end_date) ) System.out.println(query +"
<<<");
*/ statement =
conn.prepareStatement(query);
String query = result =
"select * from booking where statement.executeQuery();
booking_room = '"+ roomNo+"' AND
(" //System.out.println(" user id
+"( check_in "+ result.getInt("user_id"));
<= "+start_date +" and
( check_out = 0 or check_out<= id =
"+end_date+") ) or" result.getInt("user_id");
+"( check_in
>"+start_date+" and check_out< } catch (SQLException
"+end_date+" ) or" ex) {
+"( check_in
<= "+end_date +" and ( check_out JOptionPane.showMessageDialog(nu
=0 or check_out> "+end_date+") ) ll, ex.toString() + "\n error
)"; coming from returning AN user
function");
}
statement =
conn.prepareStatement(query); return id;
}
ResultSet result = null;

public void insertFood(Food


private void food) {
flushStatmentOnly() try {
{ String insertFood =
{ "insert into
try food('name','price') values('" +
{ food.getName() + "'," +
food.getPrice() + ")";
statement.close();
} //
System.out.println(">>>>>>>>>>
catch(SQLException ex) "+ insertRoomTypeQuery);
statement =
{System.err.print(ex.toString() conn.prepareStatement(insertFood
+" >> CLOSING DB");} );
}
} statement.execute();
}
Food DB Class
/* JOptionPane.showMessageDialog(nu
* To change this license ll, "successfully inserted a new
header, choose License Headers Food Type");
in Project Properties.
* To change this template file, } catch (SQLException
choose Tools | Templates ex) {
* and open the template in the
editor. JOptionPane.showMessageDialog(nu
*/ ll, ex.toString() + "\n" +
package I3.DatabaseOperation; "InsertQuery of Food Failed");
}
import I3.Classes.Food; finally
import java.sql.Connection; {
import flushStatmentOnly();
java.sql.PreparedStatement; }
import java.sql.ResultSet; }
import java.sql.SQLException;
import javax.swing.JOptionPane; public ResultSet getFoods()
{
/** try {
* String query =
* @author Faysal Ahmed "select * from food";
*/ statement =
public class FoodDb { conn.prepareStatement(query);
result =
Connection conn = statement.executeQuery();
DataBaseConnection.connectTODB() } catch (SQLException
; ex) {
PreparedStatement statement
= null; JOptionPane.showMessageDialog(nu
ll, ex.toString() + "\n error statement =
coming from returning all food conn.prepareStatement(deleteQuer
DB Operation"); y);
} statement.execute();

JOptionPane.showMessageDialog(nu
return result; ll, "Deleted food");
} } catch (SQLException
ex) {
public void updateFood(Food
food) { JOptionPane.showMessageDialog(nu
try { ll, ex.toString() + "\n" +
String updateFood = "Delete query FOod Failed");
"update food set name= '" + }
food.getName() + "', price= " + finally
food.getPrice() + " where {
food_id = " + food.getFood_id(); flushStatmentOnly();
}
//
System.out.println(">>>>>>>>>> }
"+ insertRoomTypeQuery);
statement = public void flushAll()
conn.prepareStatement(updateFood {
); {
try
statement.execute(); {

statement.close();
JOptionPane.showMessageDialog(nu
ll, "successfully updateFood "); result.close();
}
} catch (SQLException
ex) { catch(SQLException ex)
JOptionPane.showMessageDialog(nu {System.err.print(ex.toString()
ll, ex.toString() + "\n" + +" >> CLOSING DB");}
"updateFood of Food Failed"); }
} }
finally
{ private void
flushStatmentOnly(); flushStatmentOnly()
} {
} {
try
public void deleteFood(int {
foodId) {
try {
statement.close();
String deleteQuery =
}
"delete from food where
food_id=" + foodId;
catch(SQLException ex)
//
{System.err.print(ex.toString() System.out.println(">>>>>>>>>>
+" >> CLOSING DB");} "+ insertRoomTypeQuery);
} statement =
} conn.prepareStatement(insertItem
);
}
Item DB Class statement.execute();
/*
* To change this license
header, choose License Headers JOptionPane.showMessageDialog(nu
in Project Properties. ll, "successfully inserted a new
* To change this template file, insertItem");
choose Tools | Templates
* and open the template in the } catch (SQLException
editor. ex) {
*/
package I3.DatabaseOperation; JOptionPane.showMessageDialog(nu
ll, ex.toString() + "\n" +
import I3.Classes.Item; "InsertQuery of insertItem
import java.sql.Connection; Failed");
import }
java.sql.PreparedStatement; finally
import java.sql.ResultSet; {
import java.sql.SQLException; flushStatmentOnly();
import javax.swing.JOptionPane; }
}
/**
* public void updateItem(Item
* @author Faysal Ahmed item) {
*/ try {
public class ItemDb { String updateFood =
Connection conn = "update food set name= '" +
DataBaseConnection.connectTODB() item.getItem_name() + "', price=
; " + item.getPrice() +
PreparedStatement statement "description = '" +
= null; item.getDescription() + "' where
ResultSet result = null; item_id = " + item.getItem_id();

public void insertItem(Item //


item) { System.out.println(">>>>>>>>>>
try { "+ insertRoomTypeQuery);
String insertItem = statement =
"insert into conn.prepareStatement(updateFood
item('name','description','price );
') values('" +
item.getItem_name() + "','" + statement.execute();
item.getDescription() + "'," +
item.getPrice() + ")";
JOptionPane.showMessageDialog(nu
ll, "successfully updateitem ");
} catch (SQLException JOptionPane.showMessageDialog(nu
ex) { ll, ex.toString() + "\n" +
"Delete query Item Failed");
JOptionPane.showMessageDialog(nu }
ll, ex.toString() + "\n" + finally
"Update Item failed"); {
} flushStatmentOnly();
finally }
{ }
flushStatmentOnly();
} public void flushAll()
} {
{
public ResultSet getItems() try
{ {
try {
String query = statement.close();
"select * from item";
statement = result.close();
conn.prepareStatement(query); }
result =
statement.executeQuery(); catch(SQLException ex)
} catch (SQLException
ex) { {System.err.print(ex.toString()
+" >> CLOSING DB");}
JOptionPane.showMessageDialog(nu }
ll, ex.toString() + "\n error }
coming from returning all item
DB Operation"); private void
} flushStatmentOnly()
{
return result; {
} try
{
public void deleteItem(int
itemId) {
statement.close();
try {
}
String deleteQuery =
"delete from item where
catch(SQLException ex)
item_id=" + itemId;
statement =
conn.prepareStatement(deleteQuer {System.err.print(ex.toString()
y); +" >> CLOSING DB");}
statement.execute(); }
}
JOptionPane.showMessageDialog(nu
ll, "Deleted item"); }
} catch (SQLException Order DB Class
ex) { package I3.DatabaseOperation;

import I3.Classes.Order;
import java.sql.Connection; } catch (SQLException
import ex) {
java.sql.PreparedStatement;
import java.sql.ResultSet; JOptionPane.showMessageDialog(nu
import java.sql.SQLException; ll, ex.toString() + "\n" +
import javax.swing.JOptionPane; "Order Failed");
} finally {
/** flushStatmentOnly();
* }
* @author Faysal
*/ }

public void flushAll() {


/// ###### {
DORKAR NAI EI DB ER , ETA PORE try {
BAD DIYE DIBO
public class OrderDb { statement.close();
result.close();
Connection conn = } catch
DataBaseConnection.connectTODB() (SQLException ex) {
;
PreparedStatement statement System.err.print(ex.toString() +
= null; " >> CLOSING DB");
ResultSet result = null; }
}
public void }
insertOrder(Order order) {
try { private void
String insertOrder = flushStatmentOnly() {
"insert into {
orderItem('booking_id','item_foo try {
d','price','quantity','total')
values(" + order.getBookingId() statement.close();
+ ",'" + order.getFoodItem() + } catch
"'," + order.getPrice() + "," + (SQLException ex) {
order.getQuantity() + "," +
order.getTotal() + ")"; System.err.print(ex.toString() +
" >> CLOSING DB");
statement = }
conn.prepareStatement(insertOrde }
r); }
System.out.println(">>>>>>>>>> " }
+ insertOrder); Room DB Class
statement.execute(); /*
* To change this license
header, choose License Headers
JOptionPane.showMessageDialog(nu in Project Properties.
ll, "successfully inserted a new * To change this template file,
Order"); choose Tools | Templates
* and open the template in the
editor.
*/ System.out.println(">>>>>>>>>>
package I3.DatabaseOperation; "+
room.getRoom_class().getRoom_typ
import I3.Classes.Room; e());
import I3.Classes.RoomFare; statement =
import java.sql.Connection; conn.prepareStatement(insertQuer
import y);
java.sql.PreparedStatement;
import java.sql.ResultSet; statement.execute();
import java.sql.SQLException;
import javax.swing.JOptionPane;
JOptionPane.showMessageDialog(nu
/** ll, "successfully inserted a new
* Room ");
* @author Faysal Ahmed
*/ } catch (SQLException
public class RoomDb { ex) {
Connection conn =
DataBaseConnection.connectTODB() JOptionPane.showMessageDialog(nu
; ll, ex.toString() + "\n" +
PreparedStatement statement "InsertQuery of Room Class
= null; Failed");
ResultSet result = null; }
finally
public void insertRoom(Room {
room) { flushStatmentOnly();
try { }
String insertQuery = }
"insert into
room('room_no','bed_number','tv' public ResultSet getRooms()
,'wifi','gizer','phone','room_cl {
ass')" try {
+ " String query =
values('" "select * from room";
+ statement =
room.getRoom_no() conn.prepareStatement(query);
+ "'," + result =
room.getBed_number() + "" statement.executeQuery();
+ ",'" + } catch (SQLException
room.isHasTV() + "'" ex) {
+ ",'" +
room.isHasWIFI() + "'" JOptionPane.showMessageDialog(nu
+ ",'" + ll, ex.toString() + "\n error
room.isHasGizer() + "'" coming from returning all Room
+ ",'" + DB Operation");
room.isHasPhone() + "'" }
+ ",'" +
room.getRoom_class().getRoom_typ return result;
e() + "'" }
+ ")";
public void deleteRoom(int
public int getNoOfRooms() roomId) {
{
int rooms = -1; try {
try { String deleteQuery =
String query = "delete from room where
"select count(room_no) as room_id=" + roomId;
noRoom from room"; statement =
statement = conn.prepareStatement(deleteQuer
conn.prepareStatement(query); y);
result = statement.execute();
statement.executeQuery();
while(result.next()) JOptionPane.showMessageDialog(nu
{ ll, "Deleted room");
rooms = } catch (SQLException
result.getInt("noRoom"); ex) {
}
} catch (SQLException JOptionPane.showMessageDialog(nu
ex) { ll, ex.toString() + "\n" +
"Delete query room Failed");
JOptionPane.showMessageDialog(nu }
ll, ex.toString() + "\n error finally
coming count Room DB {
Operation"); flushStatmentOnly();
} }
}
return rooms;
} public void updateRoom(Room
room)
public ResultSet {
getAllRoomNames() try {
{ String updateQuery
try { ="update room set room_no = '"
String query =
"select room_no from room"; +room.getRoom_no()+"',
statement = bed_number="
conn.prepareStatement(query);
result = +room.getBed_number()+", tv = '"
statement.executeQuery();
} catch (SQLException +boolToString(room.isHasTV())
ex) { +"', wifi = '"

JOptionPane.showMessageDialog(nu +boolToString(room.isHasWIFI())
ll, ex.toString() + "\n error +"',gizer = '"
coming from returning all
Room_No ROOM DB Operation"); +boolToString(room.isHasGizer())
} +"', phone = '"

return result; +boolToString(room.isHasPhone())


} +"', room_class= '"
String
+room.getRoom_class().getRoom_ty insertRoomTypeQuery = "insert
pe()+"', meal_id = " into roomType values('" +
; roomType.getRoom_type() + "'," +
roomType.getPricePerDay() + ")";

System.out.println(">>>>>>>>>> System.out.println(">>>>>>>>>> "


"+ updateQuery); + insertRoomTypeQuery);

//System.out.println(updateQuery statement =
); conn.prepareStatement(insertRoom
statement = TypeQuery);
conn.prepareStatement(updateQuer
y); statement.execute();

//System.out.println(updateQuery JOptionPane.showMessageDialog(nu
); ll, "successfully inserted a new
statement.execute(); Room Type");

} catch (SQLException
JOptionPane.showMessageDialog(nu ex) {
ll, "successfully updated a
room"); JOptionPane.showMessageDialog(nu
} catch (SQLException ll, ex.toString() + "\n" +
ex) { "InsertQuery Failed");
}
JOptionPane.showMessageDialog(nu finally
ll, ex.toString() + "\n" + {
"Update query Failed"); flushStatmentOnly();
} }
finally }
{
public ResultSet
flushStatmentOnly(); getRoomType() {
} try {
String query =
} "select * from roomType";
statement =
public String conn.prepareStatement(query);
boolToString(boolean value) { result =
return value ? "true" : statement.executeQuery();
"false"; } catch (SQLException
} ex) {

public void JOptionPane.showMessageDialog(nu


insertRoomType(RoomFare ll, ex.toString() + "\n error
roomType) { coming from returning all Room
try { Type DB Operation");
}
}
return result;
} catch(SQLException ex)

public void {System.err.print(ex.toString()


updateRoomType(RoomFare +" >> CLOSING DB");}
roomType) { }
try { }
String
updateRoomTypeQuery = "update private void
roomType set price= " + flushStatmentOnly()
roomType.getPricePerDay() + " {
where type='" + {
roomType.getRoom_type() + "'"; try
{

//System.out.println(">>>>>>>>>> statement.close();
"+ updateRoomTypeQuery); }
statement =
conn.prepareStatement(updateRoom catch(SQLException ex)
TypeQuery);
{System.err.print(ex.toString()
statement.execute(); +" >> CLOSING DB");}
}
}
JOptionPane.showMessageDialog(nu
ll, "successfully updated a }
Room Type"); Booking Table Model Class
package I3.TableModel;
} catch (SQLException
ex) { import
I3.DatabaseOperation.BookingDb;
JOptionPane.showMessageDialog(nu import
ll, ex.toString() + "\n" + I3.DatabaseOperation.DatabaseOpe
"UpdateQuery Failed"); ration;
} import
finally I3.DatabaseOperation.RoomDb;
{ import java.sql.ResultSet;
flushStatmentOnly(); import java.sql.SQLException;
} import
} java.text.SimpleDateFormat;
import java.util.Calendar;
public void flushAll() import java.util.Date;
{ import java.util.logging.Level;
{ import java.util.logging.Logger;
try import javax.swing.JOptionPane;
{ import
javax.swing.table.AbstractTableM
statement.close(); odel;

result.close(); /**
* columnNames[i] =
* @author Faysal Ahmed today+"";
*/ }
public class BookingTableModel }
extends AbstractTableModel {
public int
private String[] getMonthLimit(Date x)
columnNames; {
private Date date; SimpleDateFormat ft =
private Object[][] data; new SimpleDateFormat("M");
int y =
public Integer.parseInt(ft.format(x));
BookingTableModel(long start
,long end) { //System.err.println("dsfsd>>>
iniColNames(); "+ y);
fetchDataFromDB(start, if(y ==2)
end); return 28;
else if (y ==1|| y ==3||
// y ==5|| y ==7|| y ==8|| y ==10
System.out.println("today > || y== 12)
"+Calendar.DAY_OF_MONTH+"\n 10 return 31;
day later"+ else return 30;
(Calendar.DAY_OF_MONTH+10)); }
@Override
} public int getRowCount() {
return data.length;
public void iniColNames() { }

date = new Date(); @Override


SimpleDateFormat ft = public int getColumnCount()
new SimpleDateFormat("d"); {
// -1 , because date return
starts with 0 columnNames.length;
int today = }
( Integer.parseInt(ft.format(dat
e))-1 )%getMonthLimit(date); @Override
public Object getValueAt(int
//System.out.println(today+", row, int col) {
today"); return data[row][col];
columnNames = new }
String[11];
columnNames[0] = "#"; @Override
for(int i =1;i<11;i++) public String
{ getColumnName(int col) {
return columnNames[col];
today = today }
%getMonthLimit(date);
today ++; @Override
// public boolean
System.out.println(today+" , isCellEditable(int row, int
loop today"); column) {
return false;
} System.out.println("coming here
for " + roomName);
public void long
fetchDataFromDB(long start, long check_in =
end) { Long.parseLong(result.getString(
"check_in"));
try { long
int rows = new check_out =
RoomDb().getNoOfRooms(); Long.parseLong(result.getString(
"check_out"));
// 11 columns,
because i want to display only System.out.println("check in "
10 days record + new
data = new Date(check_in*1000).toString() +
Object[rows][11]; " .... check out "+ new
// initialization Date(check_out*1000).toString())
for(int ;
i=0;i<rows;i++)
{ if(check_in<= (start) &&
for(int ( check_out == 0 || check_out<=
j=0;j<data[0].length;j++) end))
{ {
data[i][j]=
""; System.out.println("first LOOP "
} + roomName);
}
ResultSet result; data[i][1] = "<<";
ResultSet roomNames;
roomNames = new
}
RoomDb().getAllRoomNames();
else
//result = new
if(check_in > start &&
DatabaseOperation().getBookingIn
check_out< end)
fo(43243214, 4321432);

for (int i = 0; i < {


rows; i++) {
if int checkIn =
(roomNames.next()) { Integer.parseInt(new
String SimpleDateFormat("d").format(new
roomName = Date(check_in*1000)));
roomNames.getString("room_no");
data[i][0] = int checkOut =
roomName; Integer.parseInt(new
result = new SimpleDateFormat("d").format(new
DatabaseOperation().getBookingIn Date(check_out*1000)));
fo(start, end, roomName);
while int getToday =
(result.next()) { Integer.parseInt(new
SimpleDateFormat("d").format(new
Date(start*1000)));
* To change this template file,
System.out.println("xxxxxxxxx "+ choose Tools | Templates
getToday+"........ "+ checkIn); * and open the template in the
editor.
data[i][(checkIn-getToday)+1] = */
">"; package I3.TableModel;

data[i][(checkOut-getToday)+1] = import java.awt.Color;


"<"; import java.awt.Component;
import
} javax.swing.DefaultCellEditor;
import javax.swing.JTable;
else import
if(check_in<= end && ( check_out javax.swing.table.DefaultTableCe
== 0 || check_out > end)) llRenderer;
{ import
int javax.swing.table.JTableHeader;
xx = Integer.parseInt(new
SimpleDateFormat("d").format(new /**
Date(check_in*1000))); *
int * @author Faysal
getToday = Integer.parseInt(new */
SimpleDateFormat("d").format(new public class CustomCellRenderer
Date(start*1000))); extends DefaultTableCellRenderer
{
System.out.println(".....
@Override
"+getToday+ " ...........
public Component
"+xx);
getTableCellRendererComponent(JT
able table, Object value,
data[i][(xx-getToday)+1] =">>"; boolean isSelected, boolean
} hasFocus, int row, int column) {
} Component c =
} super.getTableCellRendererCompon
} ent(table, value, isSelected,
hasFocus, row, column);
} catch (SQLException
ex) {
//System.out.println("workings")
JOptionPane.showMessageDialog(nu ;
ll, "from Booking table model /*
class\n " + ex.toString());
}
if (value.equals("<<"))
{
}
c.setBackground(new
}
java.awt.Color(0, 0, 255));
Custom Cell Renderer Class
}
else
/*
{
* To change this license
header, choose License Headers
in Project Properties.
c.setBackground(table.getBackgro setBackground(table.getBackgroun
und()); d());
} }

// for creating row


header illusion if (value.equals(">"))
{
*/ c.setBackground(new
if(column == 0) java.awt.Color(0, 0, 255));
{ }
else
{
setForeground(table.getTableHead
er().getForeground()); c.setBackground(table.getBackgro
und());
setBackground(Color.LIGHT_GRAY); }

setFont(table.getTableHeader().g
etFont()); return c;
} }
else
{ }

You might also like