Download javax.swing.GroupLayout jPanel1Layout = new javax.swing

Document related concepts
no text concepts found
Transcript
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Contents
1. Model classes............................................................................................................................................. 2
2.
1.1.
Bill.Java ............................................................................................................................................. 2
1.2.
Dish.Java ........................................................................................................................................... 4
1.3.
Order.Java .......................................................................................................................................... 5
1.4.
Waiter.Java ........................................................................................................................................ 7
Hibernate Classes ...................................................................................................................................... 9
2.1.
3.
4.
5.
2.1.1.
Bill.hbm.xml .............................................................................................................................. 9
2.1.2.
Dish.hbm.xml .......................................................................................................................... 10
2.1.3.
Waiter.hbm.xml ....................................................................................................................... 10
2.1.4.
Order.hbm.xml......................................................................................................................... 11
2.2.
hibernateUtil.java ............................................................................................................................ 12
2.3.
hibernate.cfg.xml ............................................................................................................................. 13
2.4.
hibernate.reveng.xml ....................................................................................................................... 14
Server Side............................................................................................................................................... 14
3.1.
RestaurantServer.............................................................................................................................. 14
3.2.
RestaurantService ............................................................................................................................ 16
3.3.
ServerController .............................................................................................................................. 19
3.4.
UserController ................................................................................................................................. 22
3.5.
OrderController ............................................................................................................................... 25
3.6.
DishController ................................................................................................................................. 29
Client Side ............................................................................................................................................... 33
4.1.
OrderGUI......................................................................................................................................... 33
4.2.
AdministrationGUI .......................................................................................................................... 41
4.3.
LoginGUI ........................................................................................................................................ 46
4.4.
RMSMain ........................................................................................................................................ 52
4.5.
BillingGUI ....................................................................................................................................... 59
4.6.
DishHandler ..................................................................................................................................... 70
4.7.
WaiterHandler ................................................................................................................................. 81
Class Diagrams ........................................................................................................................................ 90
5.1.
1
Hbm.xml classes ................................................................................................................................ 9
Client Side ....................................................................................................................................... 90
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
5.2.
Server Side....................................................................................................................................... 91
5.3.
Model............................................................................................................................................... 92
1. Model classes
1.1. Bill.Java
package RMS;
// Generated 16-11-2010 14:28:02 by Hibernate Tools 3.2.1.GA
import java.util.Date;
/**
* Bill generated by hbm2java
*/
public class Bill implements java.io.Serializable {
private int billno;
private int tableno;
private String status;
private String waiter;
private Date datetime;
public Bill() {
}
public Bill(int billno) {
this.billno = billno;
}
public Bill(int billno, int tableno, String status, String waiter, Date datetime) {
this.billno = billno;
this.tableno = tableno;
this.status = status;
2
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
this.waiter = waiter;
this.datetime = datetime;
}
public int getBillno() {
return this.billno;
}
public void setBillno(int billno) {
this.billno = billno;
}
public int getTableno() {
return this.tableno;
}
public void setTableno(int tableno) {
this.tableno = tableno;
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String getWaiter() {
return this.waiter;
}
public void setWaiter(String waiter) {
this.waiter = waiter;
}
3
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public Date getDatetime() {
return this.datetime;
}
public void setDatetime(Date datetime) {
this.datetime = datetime;
}
}
1.2. Dish.Java
package RMS;
// Generated 16-11-2010 14:28:02 by Hibernate Tools 3.2.1.GA
/**
* Dish generated by hbm2java
*/
public class Dish implements java.io.Serializable {
private int dishno;
private String dishname;
private double dishprice;
public Dish() {
}
public Dish(int dishno, String dishname, double dishprice) {
this.dishno = dishno;
this.dishname = dishname;
this.dishprice = dishprice;
}
public int getDishno() {
return this.dishno;
}
4
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public void setDishno(int dishno) {
this.dishno = dishno;
}
public String getDishname() {
return this.dishname;
}
public void setDishname(String dishname) {
this.dishname = dishname;
}
public double getDishprice() {
return this.dishprice;
}
public void setDishprice(double dishprice) {
this.dishprice = dishprice;
}
}
1.3. Order.Java
package RMS;
import java.io.Serializable;
/**
*
* @author Graycie
*/
public class Order implements Serializable{
5
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
private int billno;
private String dishname;
private int amount;
private double price;
public Order() {
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getDishname() {
return dishname;
}
public void setDishname(String dishname) {
this.dishname = dishname;
}
public int getBillno() {
return billno;
6
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
public void setBillno(int billno) {
this.billno = billno;
}
public Order( String dishName,int billNo, int amount, double price) {
this.billno = billNo;
this.dishname = dishName;
this.amount = amount;
this.price = price;
}
}
1.4. Waiter.Java
package RMS;
// Generated 01-12-2010 18:57:09 by Hibernate Tools 3.2.1.GA
/**
* Waiter generated by hbm2java
*/
public class Waiter implements java.io.Serializable {
private int waiterid;
private String waitername;
private String waiterpassword;
private String position;
public Waiter() {
}
public Waiter(int waiterid) {
this.waiterid = waiterid;
7
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
public Waiter(int waiterid, String waitername, String waiterpassword, String position) {
this.waiterid = waiterid;
this.waitername = waitername;
this.waiterpassword = waiterpassword;
this.position = position;
}
public int getWaiterid() {
return this.waiterid;
}
public void setWaiterid(int waiterid) {
this.waiterid = waiterid;
}
public String getWaitername() {
return this.waitername;
}
public void setWaitername(String waitername) {
this.waitername = waitername;
}
public String getWaiterpassword() {
return this.waiterpassword;
}
public void setWaiterpassword(String waiterpassword) {
this.waiterpassword = waiterpassword;
}
public String getPosition() {
return this.position;
8
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
public void setPosition(String position) {
this.position = position;
}
}
2. Hibernate Classes
2.1. Hbm.xml classes
2.1.1. Bill.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-11-2010 14:28:04 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="RMS.Bill" schema="RMS" table="BILL">
<id name="billno" type="integer">
<column name="BILLNO" precision="22" scale="0"/>
<generator class="assigned"/>
</id>
<property name="tableno" type="integer">
<column name="TABLENO" precision="22" scale="0"/>
</property>
<property name="status" type="string">
<column length="20" name="STATUS"/>
</property>
<property name="waiter" type="string">
<column length="40" name="WAITER"/>
</property>
9
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
<property name="datetime" type="date">
<column name="DATETIME"/>
</property>
</class>
</hibernate-mapping>
2.1.2. Dish.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-11-2010 14:28:04 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="RMS.Dish" schema="RMS" table="DISH">
<id name="dishno" type="int">
<column name="DISHNO" precision="22" scale="0"/>
<generator class="assigned"/>
</id>
<property name="dishname" type="string">
<column length="45" name="DISHNAME" not-null="true"/>
</property>
<property name="dishprice" type="double">
<column name="DISHPRICE" not-null="true" precision="5"/>
</property>
</class>
</hibernate-mapping>
2.1.3. Waiter.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
10
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
<!-- Generated 01-12-2010 18:57:11 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="RMS.Waiter" schema="RMS" table="WAITER">
<id name="waiterid" type="big_decimal">
<column name="WAITERID" precision="22" scale="0"/>
<generator class="assigned"/>
</id>
<property name="waitername" type="string">
<column length="4000" name="WAITERNAME"/>
</property>
<property name="waiterpassword" type="string">
<column length="4000" name="WAITERPASSWORD"/>
</property>
<property name="position" type="string">
<column length="4000" name="POSITION"/>
</property>
</class>
</hibernate-mapping>
2.1.4. Order.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="RMS.Order" optimisticlock="version" polymorphism="implicit" select-before-update="false">
<id name="dishname" type="string">
<column name="dishname"/>
<generator class="assigned"/>
11
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
</id>
<property name="billno" type="int">
<column name="billno"/>
</property>
<property name="amount" type="int">
<column name="amount"/>
</property>
<property name="price" type="double">
<column name="price"/>
</property>
</class>
</hibernate-mapping>
2.2. hibernateUtil.java
package RMS;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
/**
* Hibernate Utility class with a convenient method to get Session Factory object.
*
* @author Graycie
*/
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
12
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
2.3. hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.connection.username">RMS</property>
<property name="hibernate.connection.password">admin</property>
<mapping resource="RMS/Billline.hbm.xml"/>
<mapping resource="RMS/Bill.hbm.xml"/>
<mapping resource="RMS/order.hbm.xml"/>
13
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
<mapping resource="RMS/Waiter.hbm.xml"/>
<mapping resource="RMS/Dish.hbm.xml"/>
</session-factory>
</hibernate-configuration>
2.4. hibernate.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD
3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-schema="RMS"/>
<table-filter match-name="DISH"/>
<table-filter match-name="BILLLINE"/>
<table-filter match-name="BILL"/>
<table-filter match-name="users"/>
</hibernate-reverse-engineering>
3. Server Side
3.1. RestaurantServer
package RMSServer;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
14
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
/**
*
* @author Graycie
*/
public class RestaurantServer {
private static final Logger LOGGER = Logger.getLogger("restaurantserver");
public static int PORTNO = 7777;
public RestaurantServer(int portNo) throws SQLException {
try {
PORTNO = portNo;
LOGGER.log(Level.INFO, "Server is running");
final ExecutorService pool = Executors.newCachedThreadPool();
ServerSocket welcomeSocket = new ServerSocket(portNo);
while (true) {
final Socket connectionSocket = welcomeSocket.accept();
RestaurantService service = new RestaurantService(connectionSocket);
pool.execute(service);
}
} catch (IOException ex) {
Logger.getLogger(RestaurantServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(final String[] args) {
final Runnable chatThread = new Runnable() {
private RestaurantServer restServer;
public void run() {
15
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
try {
restServer = new RestaurantServer(7777);
} catch (SQLException ex) {
Logger.getLogger(RestaurantServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
new Thread(chatThread).start();
}
}
3.2. RestaurantService
package RMSServer;
import RMS.Order;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Graycie
16
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
*/
public class RestaurantService implements Runnable {
private static final Logger LOGGER = Logger.getLogger("restaurantserver");
private Socket connectionSocket;
private ServerController serverController;
public RestaurantService(Socket connectionSocket) throws SQLException {
this.connectionSocket = connectionSocket;
serverController = new ServerController();
LOGGER.log(Level.INFO, "Restaurant server has started");
}
public void run() {
try {
BufferedReader requestFromClient = new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
String request = requestFromClient.readLine();
PrintStream responseToclient = new PrintStream(connectionSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(connectionSocket.getOutputStream());
String response = null;
while (request != null) {
LOGGER.log(Level.INFO, "request recieved" + request);
System.out.println("request" + request);
final String[] requestParts = request.split(" ", 6);
final String method = requestParts[0];
if (method.equalsIgnoreCase("make")) {
serverController.makeOrder(requestParts);
response = "Order has been made successfully";
} else if (method.equalsIgnoreCase("print")) {
17
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
LOGGER.log(Level.INFO, "restaurantservice.calling print bill");
ArrayList<Order> orderlist = serverController.printBill(requestParts);
oos.writeObject(orderlist);
} else if (method.equalsIgnoreCase("paid")) {
serverController.paidBill(requestParts);
response = "Bill recorded as paid";
System.out.println(response);
LOGGER.log(Level.INFO, "restaurantservice.calling pay bill");
} else if (method.equalsIgnoreCase("login")) {
response = serverController.logIn(requestParts);
System.out.println(response);
LOGGER.log(Level.INFO, "restaurantservice.calling login");
} else if (method.equalsIgnoreCase("get")) {
response = serverController.getposition(requestParts);
System.out.println(response);
LOGGER.log(Level.INFO, "restaurantservice.calling login");
} else if (method.equalsIgnoreCase("add")) {
if (serverController.adddish(requestParts) == true) {
response = "successful";
}
System.out.println(response);
LOGGER.log(Level.INFO, "restaurantservice.calling login");
} else if (method.equalsIgnoreCase("fetch")) {
ArrayList<Dish> dishlist = serverController.getdish(requestParts);
oos.writeObject(dishlist);
LOGGER.log(Level.INFO, "restaurantservice.calling login");
} else if (method.equalsIgnoreCase("edit")) {
18
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
response = serverController.editdish(requestParts);
System.out.println(response);
LOGGER.log(Level.INFO, "restaurantservice.calling login");
} else {
response = "illegal method";
}
responseToclient.println(response);
oos.flush();
oos.close();
LOGGER.log(Level.INFO, "response sent to client");
responseToclient.flush();
request = requestFromClient.readLine();
}
} catch (SQLException ex) {
Logger.getLogger(RestaurantService.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(RestaurantService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
3.3. ServerController
package RMSServer;
import RMS.Order;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
19
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
import java.util.logging.Logger;
/**
*
* @author Graycie
*/
public class ServerController {
private static final Logger LOGGER = Logger.getLogger("ServerController");
private OrderController orderController;
private UserController userController;
private DishControlller dishControlller;
public ServerController() throws SQLException {
LOGGER.log(Level.INFO, "database connection openedI");
orderController = new OrderController();
userController = new UserController();
dishControlller = new DishControlller();
}
public synchronized void makeOrder(String[] requestParts) throws SQLException {
String waitername = requestParts[2];
String tableNostr = requestParts[4];
int tableNo = Integer.parseInt(tableNostr);
String dishNostr = requestParts[5];
orderController.makeOrder(waitername, tableNo, dishNostr);
}
public synchronized ArrayList<Order> printBill(String[] requestParts) throws SQLException {
String tableNoStr = requestParts[2];
int tableNo = Integer.parseInt(tableNoStr);
20
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
ArrayList<Order> list = orderController.printBill(tableNo);
return list;
}
public synchronized boolean paidBill(String[] requestParts) {
String billnostr = requestParts[2];
int billno = Integer.parseInt(billnostr);
return orderController.paidBill(billno);
}
public String logIn(String[] requestParts) {
String username = requestParts[1];
String password = requestParts[2];
String response = userController.validateUser(username, password);
return response;
}
public String getposition(String[] requestParts) {
String username = requestParts[2];
String response = userController.getPosition(username);
return response;
}
public boolean adddish(String[] requestParts) {
String dishNostr = requestParts[2];
String dishPrice = requestParts[3];
String dishname = requestParts[4];
boolean response = dishControlller.adddish(dishNostr, dishname, dishPrice);
return response;
}
21
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public ArrayList<Dish> getdish(String[] requestParts) {
String dishNostr = requestParts[2];
ArrayList<Dish> dishlist = dishControlller.getdish(dishNostr);
return dishlist;
}
public synchronized String editdish(String[] requestParts) {
String response = null;
String dishno = requestParts[2];
String att = requestParts[3];
String newatt = requestParts[4];
if (att.equalsIgnoreCase("name")) {
response = dishControlller.editdishbyname(dishno, newatt);
} else if (att.equalsIgnoreCase("number")) {
response = dishControlller.editdishbynumber(dishno, newatt);
} else if (att.equalsIgnoreCase("price")) {
response = dishControlller.editdishbyprice(dishno, newatt);
} else {
response = null;
}
return response;
}
}
3.4. UserController
package RMSServer;
import RMS.HibernateUtil;
//import RMS.Users;
import java.util.List;
22
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
*
* @author Graycie
*/
public class UserController {
public boolean createUser(String username, String password, String email, String address) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
Query q = session.createQuery("select max(bl.billlineno) from Billline as bl");
List list = q.list();
int maxid = (Integer) list.get(0);
int id = maxid + 1;
Users user = new Users(id, username, password, email, address);
session.save(user);
newTransaction.commit();
session.close();
return true;
}
public String validateUser(String username, String password) {
String response = null;
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
23
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Query query1 = session.createSQLQuery("select enc_dec.decrypt(waiterpassword) from waiter where
firstname='" + username + "'");
List list = query1.list();
if (list == null) {
response = "reenter information";
}
String realpass = list.get(0).toString();
Query query2 = session.createSQLQuery("select lastname from waiter where firstname='" + username
+ "'");
List list1 = query2.list();
String firstname = username;
String lastname = list1.get(0).toString();
newTransaction.commit();
session.close();
if (realpass.equals(password)) {
response = firstname + " " + lastname;
} else {
response = null;
}
return response;
}
String getPosition(String username) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
String [] name=username.split(" ");
System.out.println(name.toString());
String firstname=name[0];
24
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Query q=session.createSQLQuery("select position from waiter where firstname='"+firstname+"'");
List list=q.list();
String position=list.get(0).toString();
newTransaction.commit();
session.close();
return position;
}
}
3.5. OrderController
package RMSServer;
import RMS.Bill;
import RMS.Billline;
import RMS.HibernateUtil;
import RMS.Order;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
*
25
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
* @author Graycie
*/
public class OrderController {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
java.util.Date date = new java.util.Date(System.currentTimeMillis());
public boolean makeOrder(String waitername,int tableNo, String dishNostr) {
String query2 = null;
int billno = createBillNo();
Bill b = new Bill(billno, tableNo, "not paid", waitername, date);
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
session.save(b);
String[] dishNoArray = dishNostr.split("\\.");
ArrayList<Integer> dishNoList = new ArrayList<Integer>();
for (String dishNostring : dishNoArray) {
int dishNoInArray = Integer.parseInt(dishNostring);
dishNoList.add(dishNoInArray);
System.out.println(dishNoList.toString());
}
HashMap<Integer, Integer> hm = this.getAmount(dishNoList);
System.out.println(hm.toString());
java.util.Iterator iterator = hm.entrySet().iterator();
int billlineno = createBillLineNo();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
int dishNo = (Integer) entry.getKey();
int amount = (Integer) entry.getValue();
26
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Billline bl = new Billline(billlineno, billno, dishNo, amount);
session.save(bl);
billlineno++;
}
newTransaction.commit();
session.close();
return true;
}
public ArrayList<Order> printBill(int tableNo) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
ArrayList<Order> list = (ArrayList<Order>) session.createSQLQuery("select d.dishname as dishname,
b.billno as billno, bl.amount as amount, d.dishprice as price from Bill b, Billline bl, Dish d where d.dishNo
in (select bl.dishno from Billline where bl.billno in (select b.billno from Bill where b.tableno=" + tableNo + "
and b.status='not paid'))").addEntity(Order.class).list();
for(Order o: list){
System.out.println(o.toString());
}
newTransaction.commit();
session.close();
return list;
}
public int createBillNo() {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
Query q = session.createQuery("select max(b.billno) from Bill as b");
List list = q.list();
int billno = (Integer) list.get(0);
27
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
int newBillNo = billno + 1;
newTransaction.commit();
session.close();
return newBillNo;
}
private HashMap<Integer, Integer> getAmount(ArrayList<Integer> dishNoList) {
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
int amount = 0;
for (int dishNo : dishNoList) {
amount = Collections.frequency(dishNoList, dishNo);
hm.put(dishNo, amount);
}
return hm;
}
private int createBillLineNo() {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
Query q = session.createQuery("select max(bl.billlineno) from Billline as bl");
List list = q.list();
int billlineno = (Integer) list.get(0);
int newbilllineno = billlineno + 1;
System.out.println("" + newbilllineno);
newTransaction.commit();
session.close();
return newbilllineno;
}
public boolean paidBill(int billno) {
28
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
List list=session.createQuery("from Bill as b where billno="+billno).list();
Bill b=(Bill)list.get(0);
b.setStatus("paid");
session.update(b);
newTransaction.commit();
session.close();
return true;
}
}
3.6. DishController
package RMSServer;
import RMS.Dish;
import RMS.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
*
* @author Graycie
*/
public class DishControlller {
public DishControlller() {
}
public boolean adddish(String dishNostr, String dishname, String dishPricestr) {
29
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
int dishno = Integer.parseInt(dishNostr);
double dishprice = Double.parseDouble(dishPricestr);
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
Dish d = new Dish(dishno, dishname, dishprice);
session.save(d);
newTransaction.commit();
session.close();
return true;
}
public ArrayList<Dish> getdish(String dishNostr) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
int dishno=Integer.parseInt(dishNostr);
ArrayList<Dish>dishlist=(ArrayList<Dish>)session.createSQLQuery("select * from dish where
dishno="+dishno).list();
newTransaction.commit();
session.close();
return dishlist;
}
public String editdishbyname(String dishnostr,String newatt) {
String response=null;
int dishno=Integer.parseInt(dishnostr);
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
List list=session.createSQLQuery("update dish set dishname='"+newatt+"' where
dishno='"+dishno+"'").list();
30
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
newTransaction.commit();
session.close();
if (list!=null){
response="successful";
}
response="unsuccessful";
return response;
}
String editdishbynumber(String dishnostr,String newatt) {
String response=null;
int dishno=Integer.parseInt(dishnostr);
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = session.beginTransaction();
List list=session.createSQLQuery("update dish set dishno='"+newatt+"' where
dishno='"+dishno+"'").list();
newTransaction.commit();
session.close();
if (list!=null){
response="successful";
}
response="unsuccessful";
return response;
}
String editdishbyprice(String dishnostr,String newatt) {
String response=null;
int dishno=Integer.parseInt(dishnostr);
Session session = HibernateUtil.getSessionFactory().openSession();
31
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Transaction newTransaction = session.beginTransaction();
List list=session.createSQLQuery("update dish set dishprice='"+newatt+"' where
dishno='"+dishno+"'").list();
newTransaction.commit();
session.close();
if (list!=null){
response="successful";
}
response="unsuccessful";
return response;
}
}
3.7. RestaurantServerException
package RMSServer;
/**
*
* @author
*/
public class RestServerException extends java.lang.Exception {
public RestServerException() {/*...*/}
public RestServerException(final String message) { super(message); }
public RestServerException(final Throwable throwable) { super(throwable); }
}
32
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
4. Client Side
4.1. OrderGUI
/*
* OrderGUI.java
*
* Created on 28-09-2010, 19:20:26
*/
package RMSClient;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
/**
*
* @author Grace ,Wanling
*/
public class OrderGUI extends javax.swing.JFrame {
/** Creates new form OrderGUI */
RestaurantController rc;
public static String systemuser;
public OrderGUI(RestaurantController rc) {
initComponents();
this.rc=rc;
}
33
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public OrderGUI() {
initComponents();
rc=new RestaurantController("localhost", 7777);
this.setTitle("MAKE ORDER WINDOW");
}
public OrderGUI(String username) {
initComponents();
rc=new RestaurantController("localhost", 7777);
this.setTitle("MAKE ORDER WINDOW");
systemuser=username;
}
public void getOrder() {
String tableNostr = tableField.getText();
int tableNo = Integer.parseInt(tableNostr);
String dishNostr = jTextArea1.getText();
String[] dishNoArray = dishNostr.split("\n");
String dishString="";
for (String dishNostring : dishNoArray) {
dishString=dishString+dishNostring+"."
}
try {
rc.makeOrder(tableNo, dishString);
JOptionPane.showMessageDialog(this, "order successfully made");
} catch (RestServerException ex) {
Logger.getLogger(OrderGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(OrderGUI.class.getName()).log(Level.SEVERE, null, ex);
34
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField2 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
tableField = new javax.swing.JTextField();
dishField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jTextField2.setText("jTextField2");
jLabel2.setText("jLabel2");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
35
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jButton1.setText("make order");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("Orders");
tableField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tableFieldActionPerformed(evt);
}
});
dishField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dishFieldActionPerformed(evt);
}
});
jLabel3.setText("table number");
jLabel5.setText("dish number");
jButton2.setText("New Order");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
36
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(dishField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tableField,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel5))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2)
.addComponent(jButton1))))
.addGap(51, 51, 51))
37
47,
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
14,
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tableField,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(43, 43, 43)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(dishField,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
84,
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
28,
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2)
.addContainerGap(27, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
38
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
getOrder();
}
private void dishFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String newline = "\n";
String text = dishField.getText();
jTextArea1.append(text + newline);
dishField.selectAll();
//Make sure the new text is visible, even if there
//was a selection in the text area.
jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
}
39
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
private void tableFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dishField.setText("");
tableField.setText("");
Document doc=jTextArea1.getDocument();
try {
doc.remove(0, doc.getLength());
} catch (BadLocationException ex) {
Logger.getLogger(OrderGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new OrderGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField dishField;
private javax.swing.JButton jButton1;
40
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField tableField;
// End of variables declaration
}
4.2. AdministrationGUI
package RMSClient;
/**
* * @author Grace,Wanling
*/
public class AdministrationGUI extends javax.swing.JFrame {
/** Creates new form AdministrationGUI */
public AdministrationGUI() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
41
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
addDish = new javax.swing.JButton();
createWaiter = new javax.swing.JButton();
editWaiter = new javax.swing.JButton();
editDish = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));
setForeground(new java.awt.Color(255, 102, 102));
setIconImages(null);
addDish.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
addDish.setFont(new java.awt.Font("Lucida Bright", 1, 12)); // NOI18N
addDish.setText("Add Dish");
addDish.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addDishActionPerformed(evt);
}
});
createWaiter.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
createWaiter.setFont(new java.awt.Font("Lucida Bright", 1, 12)); // NOI18N
createWaiter.setForeground(new java.awt.Color(51, 51, 51));
createWaiter.setText("Create waiter");
createWaiter.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
createWaiter.addActionListener(new java.awt.event.ActionListener() {
42
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public void actionPerformed(java.awt.event.ActionEvent evt) {
createWaiterActionPerformed(evt);
}
});
editWaiter.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
editWaiter.setFont(new java.awt.Font("Lucida Bright", 1, 12)); // NOI18N
editWaiter.setText("Edit Waiter");
editWaiter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editWaiterActionPerformed(evt);
}});
editDish.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.highlight"));
editDish.setFont(new java.awt.Font("Lucida Bright", 1, 12)); // NOI18N
editDish.setText("Edit Dish");
editDish.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editDishActionPerformed(evt);
}
});
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/RMSClient/rms picture.jpg"))); //
NOI18N
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
43
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
.addComponent(jLabel1,
Short.MAX_VALUE)
javax.swing.GroupLayout.PREFERRED_SIZE,
366,
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(editDish,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addComponent(createWaiter,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addComponent(addDish,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addComponent(editWaiter,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addGap(18, 18, 18))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(addDish)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(createWaiter)
.addGap(18, 18, 18)
.addComponent(editWaiter)
.addGap(18, 18, 18)
.addComponent(editDish)
.addGap(196, 196, 196))
44
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void addDishActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
addDish();
}
private void createWaiterActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
createWaiter();
}
private void editWaiterActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
editWaiter();
}
private void editDishActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
editDish();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AdministrationGUI().setVisible(true);
45
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton addDish;
private javax.swing.JButton createWaiter;
private javax.swing.JButton editDish;
private javax.swing.JButton editWaiter;
private javax.swing.JLabel jLabel1;
// End of variables declaration
private void addDish() {
new DishGUI().setVisible(true);
}
private void createWaiter() {
throw new UnsupportedOperationException("Not yet implemented");
}
private void editWaiter() {
throw new UnsupportedOperationException("Not yet implemented");
}
private void editDish() {
new DishGUI().setVisible(true);
}}
4.3. RMSLogin
package RMSClient;
import java.io.IOException;
import java.util.logging.Level;
46
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/***
* @author Graycie
*/
public class RMSlogin extends javax.swing.JFrame {
RestaurantController rc;
/** Creates new form RMSlogin */
public RMSlogin() {
initComponents();
rc = new RestaurantController("localhost", 7777);
this.setTitle("LOGIN WINDOW");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
47
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Username");
jLabel2.setText("Password");
jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jPasswordField1ActionPerformed(evt);
}
});
jButton1.setText("Submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(72, 72, 72)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
48
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
.addComponent(jLabel1))
.addGap(60, 60, 60)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField1)
.addComponent(jTextField1,
Short.MAX_VALUE))))
javax.swing.GroupLayout.DEFAULT_SIZE,
76,
.addContainerGap(144, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(63, 63, 63)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(45, 45, 45)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jPasswordField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)
.addComponent(jButton1)
.addContainerGap(83, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
49
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
);
pack();
}// </editor-fold>
private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
login();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RMSlogin().setVisible(true);
50
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
private void login() {
try {
String originalUsername = jTextField1.getText();
char[] passwordchar = jPasswordField1.getPassword();
String password = new String(passwordchar);
char oldchar=originalUsername.charAt(0);
char newchar= Character.toUpperCase(oldchar);
String username=originalUsername.replace(oldchar, newchar);
System.out.println("sent username"+username);
String[] responses = (rc.login(username, password)).split(" ");
String response = responses[1];
System.out.println(response);
if (response == null) {
JOptionPane.showMessageDialog(this, "wrong credentials,try again");
jTextField1.setText(" ");
jPasswordField1.setText("");
51
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
} else if ((response != null) && response.equals("reenter information")) {
JOptionPane.showMessageDialog(this, "try again,make sure name begins withe uppercase letter");
jTextField1.setText(" ");
jPasswordField1.setText("");
} else {
new RMSMain(username+" "+response).setVisible(true);
this.setFocusable(true);
jTextField1.setText(" ");
jPasswordField1.setText(" ");
}
this.dispose();
} catch (IOException ex) {
Logger.getLogger(RMSlogin.class.getName()).log(Level.SEVERE, null, ex);
}}}
4.4. RMSMain
package RMSClient;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class RMSMain extends javax.swing.JFrame {
String user;
RestaurantController rc;
/** Creates new form RMSMain */
52
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public RMSMain() {
rc = new RestaurantController("localhost", 7777);
initComponents();
}
public RMSMain(String username) {
rc = new RestaurantController("localhost", 7777);
initComponents();
this.setTitle("WABIMAMA MAIN WINDOW");
this.user = username;
jTextField1.setText(username);
}
public RMSMain(RestaurantController rc) {
rc = new RestaurantController("localhost", 7777);
initComponents();
this.setTitle("WABIMAMA MAIN WINDOW");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
53
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("User:");
jTextField1.setEditable(false);
jTextField1.setText(this.user);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}});
jButton1.setText("ORDER");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
} });
jButton2.setText("GETBILL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
} });
jButton3.setText("LOG OUT");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
54
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
});
jButton4.setText("ADMINISTRATION");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(68, 68, 68)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45,
Short.MAX_VALUE)
.addComponent(jButton4)
.addGap(23, 23, 23))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(245, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton3)
.addComponent(jButton2)
55
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
.addComponent(jButton1))
.addGap(89, 89, 89))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4))
.addGap(32, 32, 32)
.addComponent(jButton1)
.addGap(34, 34, 34)
.addComponent(jButton2)
.addGap(34, 34, 34)
.addComponent(jButton3)
.addContainerGap(77, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
56
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
new RMSlogin().setVisible(true);
this.setFocusable(true);
RestaurantController.clientSocket.close();
} catch (IOException ex) {
Logger.getLogger(RMSMain.class.getName()).log(Level.SEVERE, null, ex);
} }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new OrderGUI(user).setVisible(true);
this.setFocusable(true);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new BillGUI(user).setVisible(true);
this.setFocusable(true);
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
57
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
loginadministration();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RMSMain().setVisible(true);
}});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
private void loginadministration() {
try {
String username = jTextField1.getText();
String position = rc.getPermission(username);
58
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
System.out.println(position);
if (position.contains("manager")) {
new AdministrationGUI().setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "login as manager");
}
} catch (IOException ex) {
Logger.getLogger(RMSMain.class.getName()).log(Level.SEVERE, null, ex);
}}}
4.5. BillingGUI
package RMSClient;
import RMS.Order;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class BillGUI extends javax.swing.JFrame {
/** Creates new form BillGUI */
RestaurantController rc;
public BillGUI(RestaurantController rc) {
this.rc = rc;
initComponents();
}
public BillGUI(String username) {
59
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
initComponents();
rc = new RestaurantController("localhost", 7777);
this.setTitle("Billing GUI, Waiter-"+username);
public BillGUI() {
initComponents();
rc = new RestaurantController("localhost", 7777);
this.setTitle("Billing GUI");
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
60
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jTextField3 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jTextField4 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Table No:");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jButton1.setText("PrintBill");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jScrollPane1.setViewportView(jTable1);
jLabel2.setText("Table No");
jLabel3.setText("Bill Number");
jTextField2.setEditable(false);
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
61
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
jTextField2ActionPerformed(evt);
}
});
jTextField3.setEditable(false);
jButton2.setText("Paid");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("New Bill");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel4.setText("Total Price");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
62
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 62,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(92, 92, 92)
.addComponent(jButton1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 54,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71,
Short.MAX_VALUE)
.addComponent(jLabel3)
.addGap(41, 41, 41)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 62,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 75,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77,
Short.MAX_VALUE)
63
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton3)
.addComponent(jButton2))
.addGap(84, 84, 84))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
64
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
65
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
printBill();
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
paidBill();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
newBill();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BillGUI().setVisible(true);
}
});
66
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
// End of variables declaration
private void printBill() {
ArrayList<Order> orderList = null;
String tableNostr = jTextField1.getText();
try {
orderList = rc.printBill(tableNostr);
} catch (ClassNotFoundException ex) {
Logger.getLogger(BillGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(BillGUI.class.getName()).log(Level.SEVERE, null, ex);
}
67
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jTextField1.setText("");
Order sampleOrder = orderList.get(0);
int billNo = sampleOrder.getBillno();
jTextField3.setText("" + billNo);
jTextField2.setText(tableNostr);
jTextField4.setText("");
double totalprice=0;
for (Order o: orderList){
totalprice=totalprice+o.getAmount()*o.getPrice();
jTextField4.setText(""+totalprice);
}
DefaultTableModel aModel = new DefaultTableModel() {
//setting the jtable read only
@Override
public boolean isCellEditable(int row, int column) {
return false;
}};
//setting the column name
Object[] tableColumnNames = new Object[4];
tableColumnNames[0] = "Dish Name";
tableColumnNames[1] = "Amount";
tableColumnNames[2] = "@Price";
tableColumnNames[3] = "Total";
aModel.setColumnIdentifiers(tableColumnNames);
if (orderList == null) {
this.jTable1.setModel(aModel);
return;
68
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
Object[] objects = new Object[4];
ListIterator<Order> lstrg = orderList.listIterator();
//populating the tablemodel
while (lstrg.hasNext()) {
Order order = lstrg.next();
objects[0] = order.getDishname();
objects[1] = order.getAmount();
objects[2] = order.getPrice();
objects[3] = order.getAmount() * order.getPrice();
aModel.addRow(objects);
}
//binding the jtable to the model
this.jTable1.setModel(aModel);
}
private void paidBill() {
String billNostr=jTextField3.getText();
int billno=Integer.parseInt(billNostr);
try {
rc.paidBill(billno);
JOptionPane.showMessageDialog(this, "bill saved as paid");
} catch (IOException ex) {
Logger.getLogger(BillGUI.class.getName()).log(Level.SEVERE, null, ex);
}}
private void newBill() {
this.dispose();
new BillGUI(OrderGUI.systemuser).setVisible(true);
69
2010
//
jTextField1.setText("");
//
jTextField2.setText("");
//
jTextField3.setText("");
//
jTextField4.setText("");
//
jTable1.setModel(null);
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}}
4.6. DishGUI
/*
* DishGUI.java
*
* Created on 08-12-2010, 13:29:06
*/
package RMSClient;
import RMS.Dish;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class DishGUI extends javax.swing.JFrame {
RestaurantController rc;
/** Creates new form DishGUI */
public DishGUI() {
initComponents();
rc = new RestaurantController("localhost", 7777);
70
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
71
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"DishName", "DishNumber", "DishPrice"
}) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.Integer.class, java.lang.Double.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jButton1.setText("Add Dish");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
72
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Get Dish");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Edit Dish");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel1.setText("DishNo");
jLabel2.setText("Name");
jLabel3.setText("Price");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
73
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 92,
Short.MAX_VALUE)
.addComponent(jTextField2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125,
Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(38, 38, 38))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(38, 38, 38))))
);
jPanel1Layout.setVerticalGroup(
74
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(22, 22, 22)
.addComponent(jButton2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
javax.swing.GroupLayout.PREFERRED_SIZE)
75
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
.addGap(34, 34, 34)
.addComponent(jButton3)
.addContainerGap(138, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
76
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
addDish();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
getDish();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
editDish();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DishGUI().setVisible(true);
} }); }
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
77
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
private void addDish() {
try {
String dishno = jTextField1.getText();
String dishname = jTextField2.getText();
String dishprice = jTextField3.getText();
rc.adddish(dishno, dishname, dishprice);
ArrayList<Dish> dishList = (ArrayList<Dish>) rc.getDish(dishno);
DefaultTableModel aModel = new DefaultTableModel() {
//setting the jtable read only
@Override
public boolean isCellEditable(int row, int column) {
return false;
} };
//setting the column name
Object[] tableColumnNames = new Object[4];
tableColumnNames[0] = "DishName";
tableColumnNames[1] = "DishNumber";
tableColumnNames[2] = "DishPrice";
aModel.setColumnIdentifiers(tableColumnNames);
if (dishList == null) {
this.jTable1.setModel(aModel);
return;
78
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
Object[] objects = new Object[4];
ListIterator<Dish> lstrg = dishList.listIterator();
//populating the tablemodel
while (lstrg.hasNext()) {
Dish dish = (Dish)lstrg.next();
objects[0] = dish.getDishname();
objects[1] = dish.getDishno();
objects[2] = dish.getDishprice();
aModel.addRow(objects);
}
//binding the jtable to the model
this.jTable1.setModel(aModel);
jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
} catch (ClassNotFoundException ex) {
Logger.getLogger(DishGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DishGUI.class.getName()).log(Level.SEVERE, null, ex);
}}
private void getDish() {
try {
Object[] possibilities = null;
String dishnostr = (String) JOptionPane.showInputDialog(this, "Enter the dish Number",
possibilities);
ArrayList<Dish> dishlist = (ArrayList<Dish>) rc.getDish(dishnostr);
79
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
if (dishlist == null) {
JOptionPane.showMessageDialog(this, "try again, dish not found");
}
DefaultTableModel aModel = new DefaultTableModel() {
//setting the jtable read only
@Override
public boolean isCellEditable(int row, int column) {
return false;
} };
//setting the column name
Object[] tableColumnNames = new Object[4];
tableColumnNames[0] = "DishName";
tableColumnNames[1] = "DishNumber";
tableColumnNames[2] = "DishPrice";
aModel.setColumnIdentifiers(tableColumnNames);
if (dishlist == null) {
this.jTable1.setModel(aModel);
return;
}
Object[] objects = new Object[4];
ListIterator<Dish> lstrg = dishlist.listIterator();
//populating the tablemodel
while (lstrg.hasNext()) {
Dish dish = (Dish)lstrg.next();
objects[0] = dish.getDishname();
objects[1] = dish.getDishno();
objects[2] = dish.getDishprice();
80
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
aModel.addRow(objects);
}
} catch (IOException ex) {
Logger.getLogger(DishGUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DishGUI.class.getName()).log(Level.SEVERE, null, ex);
}}
private void editDish() {
getDish();
Object[] possibilities = {"Name", "Number", "Price"};
String att = (String) JOptionPane.showInputDialog(this, "select attribute to change", possibilities);
String dishnostr = (String) JOptionPane.showInputDialog(this, "enter dishno");
String newatt = (String) JOptionPane.showInputDialog(this, "enter new attribute");
int n = JOptionPane.showConfirmDialog(
this,
"change " + att + " to " + newatt + "?",
"Confirm edit",
JOptionPane.YES_NO_OPTION);
if (n == 0) {
try {
rc.editdish(dishnostr,att, newatt);
} catch (IOException ex) {
Logger.getLogger(DishGUI.class.getName()).log(Level.SEVERE, null, ex);
}} }
}
4.7. WaiterHandler
81
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
/*
* WaiterHandler.java
** Created on 08-12-2010, 13:29:30
*/
package RMSClient;
/**
** @author Graycie
*/
public class WaiterHandler extends javax.swing.JFrame {
/** Creates new form WaiterHandler */
public WaiterHandler() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
82
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WaiterHandler().setVisible(true);
} });
}
// Variables declaration - do not modify
// End of variables declaration
}
4.8. RestaurantController
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package RMSClient;
import RMS.Order;
import java.io.BufferedReader;
83
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
** @author
*/
public class RestaurantController {
// private final String systemUser;
private String RMSServerHost = "localhost";
private int RMSServerPort = 7777;
private static final Logger LOGGER = Logger.getLogger("restaurantserver");
public static Socket clientSocket;
public RestaurantController( String chatServerHost, int chatServerPort) {
this.RMSServerHost = chatServerHost;
this.RMSServerPort = chatServerPort;
}
public boolean makeOrder(int tableNo, String dishString) throws RestServerException, IOException {
LOGGER.log(Level.INFO, "makeOrder in RestaurantController");
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
84
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "make order " + OrderGUI.systemuser+" "+tableNo + " " + dishString;
outtoserver.println(request);
LOGGER.log(Level.INFO, "request sent" + request);
outtoserver.flush();
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
return true;
}
public ArrayList<Order> printBill(String tableNo) throws IOException, ClassNotFoundException {
LOGGER.log(Level.INFO, "restaurantController.PrinBill");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
String request = "print bill " + tableNo;
outtoserver.println(request);
LOGGER.log(Level.INFO, "request sent" + request);
ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
ArrayList<Order> orderlist = (ArrayList<Order>) ois.readObject();
for (Order o : orderlist) {
System.out.println(o.getDishname());
}
outtoserver.flush();
return orderlist;
}
85
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
public void paidBill(int billNo) throws IOException {
LOGGER.log(Level.INFO, "restaurantController.PaidBill");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "paid bill " + billNo;
outtoserver.println(request);
LOGGER.log(Level.INFO, "request sent" + request);
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
outtoserver.flush();
}
public String login(String username, String password) throws IOException {
LOGGER.log(Level.INFO, "restaurantController.PaidBill");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "login " + username + " " + password;
outtoserver.println(request);
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
outtoserver.flush();
return responseFromServer;
86
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
}
public String getPermission(String username) throws IOException {
LOGGER.log(Level.INFO, "restaurantController.getpermission");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "get position " + username;
outtoserver.println(request);
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
outtoserver.flush();
return responseFromServer;
}
public boolean adddish(String dishno, String dishname, String dishprice) throws IOException {
LOGGER.log(Level.INFO, "restaurantController.adddish");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "add dish "+dishno+" "+dishprice+" "+dishname;
outtoserver.println(request);
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
outtoserver.flush();
87
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
return true;
}
public ArrayList<Dish>getDish(String dishno) throws IOException, ClassNotFoundException {
LOGGER.log(Level.INFO, "restaurantController.getdish");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
String request = "fetch dish "+dishno;
outtoserver.println(request);
ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
ArrayList<Dish> dishlist = (ArrayList<Dish>) ois.readObject();
//
for (Object o : dishlist) {
//
Dish d=(Dish)o;
//
System.out.println(d.getDishname());
//
}
outtoserver.flush();
return dishlist;
}
public boolean editdish(String dishno,String att, String newatt) throws IOException {
LOGGER.log(Level.INFO, "restaurantController.editdish");
clientSocket = null;
clientSocket = new Socket(RMSServerHost, RMSServerPort);
PrintStream outtoserver = new PrintStream(clientSocket.getOutputStream());
BufferedReader infromserver = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
String request = "edit dish "+dishno+" " + att+" "+ newatt;
outtoserver.println(request);
88
2010
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
String responseFromServer = infromserver.readLine();
LOGGER.log(Level.INFO, "response from server" + responseFromServer);
outtoserver.flush();
return true;
}}
4.9. RestaurantServerException
package RMSServer;
/**
* * @author Graycie
*/
public class RestServerException extends java.lang.Exception {
public RestServerException() {/*...*/}
public RestServerException(final String message) { super(message); }
public RestServerException(final Throwable throwable) { super(throwable); }
}
89
2010
5. Class Diagrams
5.1. Client Side
90
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
5.2. Server Side
91
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
2010
5.3. Model
92
Project Name: Restaurant Management System
Members: Wanling Feng, Grace Mureithi
Related documents