Professional Documents
Culture Documents
setBooking_id(int booking_id) {
Booking Class this.booking_id =
package I3.Classes; booking_id;
}
import java.util.ArrayList;
import java.util.Date;
/**
*
} * @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 void
} setPayment_date(String
Payment Class payment_date) {
package I3.Classes; this.payment_date =
payment_date;
import java.util.ArrayList; }
} 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
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;
}
//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;
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) {
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();
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
*/ }
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 = '"
//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) {
//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() { }
setFont(table.getTableHeader().g
etFont()); return c;
} }
else
{ }