Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cmckenzie6 committed Dec 8, 2014
1 parent 743944f commit 74288f7
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 436 deletions.
124 changes: 61 additions & 63 deletions Engine/HotelManager.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/*
MAIN CLASS -- RUN THIS FROM COMMAND LINE
MAIN CLASS -- RUN THIS FROM COMMAND LINE
PROGRAM OUTLINE
engine
- only contains MANAGERS, READERS, or WRITERS that do some sort of logical work
- does all logic handling and database management
- handles all input verification
database.info
- classes in this package are PURELY for holding INFORMATION
- Guest, Inventory, Reservation, Room etc.
- These will all work very closely with the engine
- Often will be created by GUI and then handled by ENGINE
all GUI packages
- PURELY FOT DISPLAY PURPOSES
- all information passed in will IMMEDIATELY be passed to INFO classes
PROGRAM OUTLINE
engine
- only contains MANAGERS, READERS, or WRITERS that do some sort of logical work
- does all logic handling and database management
- handles all input verification
database.info
- classes in this package are PURELY for holding INFORMATION
- Guest, Inventory, Reservation, Room etc.
- These will all work very closely with the engine
- Often will be created by GUI and then handled by ENGINE
all GUI packages
- PURELY FOT DISPLAY PURPOSES
- all information passed in will IMMEDIATELY be passed to INFO classes
*/

package engine;

//below imports are unused until file checking works
Expand All @@ -27,56 +26,55 @@
import java.io.Writer;

public class HotelManager {
public static void main(String[] args){

public static void main(String[] args) {
mainframe.gui.LoginFrame master = new mainframe.gui.LoginFrame();
master.setLocationRelativeTo(null); //centers spawned window
master.getRootPane().setDefaultButton(master.LoginButton);
master.setVisible(true);

/*
* The following will check for flat file existence
* If needed files do not exist, they will be created in a new database folder
*/


String GuestDB = new File("").getAbsolutePath()+"\\database_files\\guestDatabaseFile.txt";
String RoomReservationDB = new File("").getAbsolutePath()+"\\database_files\\reservationDatabaseFile.txt";
String InventoryDB = new File("").getAbsolutePath()+"\\database_files\\inventoryDatabaseFile.txt";
String OrderHistoryDB = new File("").getAbsolutePath()+"\\database_files\\orderDatabaseFile.txt";
String UserDB = new File("").getAbsolutePath()+"\\database_files\\userDatabaseFile.txt";
String RoomDB = new File("").getAbsolutePath()+"\\database_files\\roomDatabaseFile.txt";

File directory = new File(new File("").getAbsolutePath()+"\\database_files");
boolean result = false;

if (directory.exists()) {
System.out.println("Folder already exists");
}
else {
/*
* The following will check for flat file existence
* If needed files do not exist, they will be created in a new database folder
*/
String GuestDB = new File("").getAbsolutePath() + "\\database_files\\guestDatabaseFile.txt";
String RoomReservationDB = new File("").getAbsolutePath() + "\\database_files\\reservationDatabaseFile.txt";
String InventoryDB = new File("").getAbsolutePath() + "\\database_files\\inventoryDatabaseFile.txt";
String OrderHistoryDB = new File("").getAbsolutePath() + "\\database_files\\orderDatabaseFile.txt";
String UserDB = new File("").getAbsolutePath() + "\\database_files\\userDatabaseFile.txt";
String RoomDB = new File("").getAbsolutePath() + "\\database_files\\roomDatabaseFile.txt";

File directory = new File(new File("").getAbsolutePath() + "\\database_files");
boolean result = false;

if (directory.exists()) {
System.out.println("Folder already exists");
} else {
result = directory.mkdirs();
System.out.println(result);
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(GuestDB), "utf-8"))) {
writer.write("DB1 Guest DB:0"); //:0 is essential for guestID creation
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
//creation of Guest Database
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(GuestDB), "utf-8"))) {
writer.write("DB1 Guest DB:0"); //:0 is essential for guestID creation
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
writer.write("DB1 Guest DB:2\n" +
"0;John;Doe;10 Basic Street Atlanta, GA 30303;555-123-4567;johndoe@server.com\n" +
"1;Jack;Normal;800 Marietta St Atlanta, GA;" +
"30318;222-222-2222;jnormal@web.net\n"); //:0 is essential for guestID creation
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
}
//creation of Reservation Database
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(RoomReservationDB), "utf-8"))) {
writer.write("DB2 Room Reservation DB");
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
writer.write("DB2 Room Reservation DB\n" +
"0;2;2;2015 1 11;2014 12 8;102;0;Feather pillow\n" +
"1;3;0;2015 3 7;2015 3 12;214;1;");
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
//creation of Inventory Database
Expand All @@ -94,35 +92,35 @@ public static void main(String[] args){
+ "Beer;50;2.99\n"
+ "Popsicle;20;1.99\n"
+ "Candy;30;.99");
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
//creation of Order History Database
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(OrderHistoryDB), "utf-8"))) {
writer.write("DB4 Order History DB:0");
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
writer.write("DB4 Order History DB:2\n" +
"\n" +
"0;0;John;Doe;102;Beer:1:2.99,Beer:1:2.99,Chicken:1:9.99,;Peanut allergy;15.97;0;12/08/14 14:09\n" +
"\n" +
"1;1;Jack;Normal;214;Wine:1:4.99,Candy:1:0.99,Steak:1:12.99,;;18.97;0;12/08/14 14:10");
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
//creation of User Database
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(UserDB), "utf-8"))) {
writer.write("DB5 UserDB DB1;admin;password");
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
//creation of Room Database
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(RoomDB), "utf-8"))) {
writer.write("DB6 Room(calendar) DB");
}
catch (IOException ex){
System.out.println("Exception found: "+ex);
} catch (IOException ex) {
System.out.println("Exception found: " + ex);
System.exit(1);
}
}
}
}
}
3 changes: 3 additions & 0 deletions database/info/ReservationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public int setComments(String coms){
Comments = coms;
return 0;
}
public String getGuestID(){
return GuestID;
}
//for use by databaseManager class primarily
public String toString(){
return GuestID+";"+NumOfPersons+";"+TypeOfRoom+";"+CheckIn+";"+CheckOut+";"+RoomNum+";"+SpecialPref+";"+Comments;
Expand Down
118 changes: 96 additions & 22 deletions engine/ReservationDBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* to rservation creation. Guest ID will be used to link the guest to the
* appropriate reservation.
*/

package engine;

import database.info.*;
Expand All @@ -18,7 +17,7 @@
public class ReservationDBManager {

//IMPORTANT: gets path to database files
String nameOfFile = new File("").getAbsolutePath()+"\\database_files";
String nameOfFile = new File("").getAbsolutePath() + "\\database_files";

//variables for comparison and setting
public static String _GuestID;
Expand All @@ -31,44 +30,119 @@ public class ReservationDBManager {
public static String _Comments;

//FLAG VARIABLES
static final int SUCCESSFUL_OPERATION = 1;
static final int SUCCESSFUL_OPERATION = 1;

static final int FAILED_DUPLICATE_RECORD = 13;
static final int FAILED_FILE_READ = 17;

static final int NEW_RECORD = 21;
static final int FAILED_ADDED_RECORD = 23;

//attempts to add new guest to database
//checks database to prevent duplication of guests
//GuestInfo class is passed in to obtain necessary new guest info
public int addReservation(ReservationInfo NewReservation){
public int addReservation(ReservationInfo NewReservation) {
nameOfFile = nameOfFile + "\\reservationDatabaseFile.txt"; //provides full path to file
//System.out.println("File path is:" + nameOfFile); //TEST
int nReturnValue;
//piecing together the new line to be added to data file
String newRecord = NewReservation.toString();
System.out.println("newRecord Test: "+newRecord); //TEST
System.out.println("newRecord Test: " + newRecord); //TEST
ArrayList theRecords = new ArrayList(); //theRecords will hold entire database file
File file = new File(nameOfFile);
//file writing happening here
FileWriter writer;
//no input checking s required here, has already been handled elsewhere
try {
writer = new FileWriter(file, true);
PrintWriter printer = new PrintWriter(writer);
printer.append("\n"); //most Managers will need this
printer.append(newRecord);
printer.close();
System.out.println("SUCCESSFUL WRITE");
nReturnValue = SUCCESSFUL_OPERATION;
return nReturnValue;
}
catch (IOException ee) {
System.err.println("Error: " + ee.getMessage() +"..stack: " + ee.getStackTrace().toString() );
ee.printStackTrace();
nReturnValue = FAILED_ADDED_RECORD;
return nReturnValue;
}
try {
writer = new FileWriter(file, true);
PrintWriter printer = new PrintWriter(writer);
printer.append("\n"); //most Managers will need this
printer.append(newRecord);
printer.close();
System.out.println("SUCCESSFUL WRITE");
nReturnValue = SUCCESSFUL_OPERATION;
return nReturnValue;
} catch (IOException ee) {
System.err.println("Error: " + ee.getMessage() + "..stack: " + ee.getStackTrace().toString());
ee.printStackTrace();
nReturnValue = FAILED_ADDED_RECORD;
return nReturnValue;
}
}

public ArrayList<String> printAllRecords(ReservationInfo Reservation) {
//Variables
nameOfFile = nameOfFile + "\\reservationDatabaseFile.txt";
String strLine = "";
String[] fields;
ArrayList theRecords = new ArrayList();
boolean isSearching = true;
ArrayList<String> finalOutput = new ArrayList<String>();
//opening and reading database file for comparison purposes
try {
//Get all the file records in the Array
theRecords = DatabaseReader.DBreadFile(nameOfFile);
} //try
catch (Exception ee) {
System.err.println("Error: " + ee.getMessage() + "..stack: " + ee.getStackTrace().toString());
} //catch
int iCount = 1;
int nRecCount = theRecords.size();
Iterator itr = theRecords.iterator();
itr.next(); //skips the first line of file, which contains database name
while (itr.hasNext() && isSearching == true) {
if (iCount < nRecCount + 1) {
try {
strLine = (String) theRecords.get(iCount);
strLine = strLine.trim();
finalOutput.add(strLine);
} catch (IndexOutOfBoundsException e) {
//reached end of file
isSearching = false;
}
} //if
iCount++;
} //while
return finalOutput;

}

//method to search for items
public String searchDB(ReservationInfo Reservation) {
//Variables
nameOfFile = nameOfFile + "\\reservationDatabaseFile.txt";
String strLine;
String[] fields;
ArrayList theRecords = new ArrayList();
//opening and reading database file for comparison purposes
try {
//Get all the file records in the Array
theRecords = DatabaseReader.DBreadFile(nameOfFile);
} //try

catch (Exception ee) {
System.err.println("Error: " + ee.getMessage() +"..stack: " + ee.getStackTrace().toString() );
} //catch
int iCount = 1;
int nRecCount = theRecords.size();
Iterator itr = theRecords.iterator();
itr.next(); //skips the first line of file, which contains database name
while (itr.hasNext()) {
if (iCount < nRecCount + 1) {
strLine = (String) theRecords.get(iCount);
strLine = strLine.trim();
System.out.println(strLine);
fields = strLine.split(";"); //delimiter is ;

_GuestID = fields[0].trim();

if (_GuestID.toLowerCase().equals(Reservation.getGuestID().toLowerCase())) {
return strLine;
}
} //if
iCount++;
} //while
return "Error: no matching item found in reservationDatabaseFile.txt.";

}
}
Loading

0 comments on commit 74288f7

Please sign in to comment.