diff --git a/DBAppV2.cpp b/DBAppV2.cpp index 17bc1ee..4fb481f 100755 --- a/DBAppV2.cpp +++ b/DBAppV2.cpp @@ -1,35 +1,18 @@ //#include #include "User.h" +#include "Parser.h" +#include "DBEngine.h" using namespace std; +//Global objects used through the app +DBEngine engine; vector users; - -// struct loginCredentials -// { - // string name; - // string password; - - // loginCredentials(string n, string p) - // { - // name = n; - // password = p; - // } - -// }; - - -void yourAccount() -{ - cout<<"*********************************"< boards; +vector mesages; +vector groups; +vector
articles; +User currentUser; void goToBoard() { @@ -67,16 +50,6 @@ void boardMenu() } -void showMessages() -{ - cout<<"Messages will be displayed soon"<> newName; + currentUser.setName(newName); + //Have it update the relation here + cout << "\nName successfully changed!\n" << endl; + mainMenu(); +} + +void changePassword() +{ + cout<<"Enter new password: "<> newPassword; + currentUser.setPassword(newPassword); + //Have it update the relation here + cout << "\nPassword successfully changed!\n" << endl; + mainMenu(); +} + +void changePhone() +{ + cout<<"Enter new phone number: "<> newPhoneNumber; + currentUser.setPhone(newPhoneNumber); + //Have it update the relation here + cout << "\nPhone Number successfully changed!\n" << endl; + mainMenu(); +} + +void changeFax() +{ + cout<<"Enter new fax number: "<> newFaxNumber; + currentUser.setFax(newFaxNumber); + //Have it update the relation here + cout << "\nFax Number successfully changed!\n" << endl; + mainMenu(); +} + +void changePostal() +{ + cout<<"Enter new fax number: "<> newPostalNumber; + currentUser.setPostal(newPostalNumber); + //Have it update the relation here + cout << "\nPostal Number successfully changed!\n" << endl; + mainMenu(); +} + +void editAccountMenu() +{ + cout<<"*********************************"<> choice; + switch(choice) + { + case 0: changeUsername(); break; + case 1: changePassword(); break; + case 2: changePhone(); break; + case 3: changeFax(); break; + case 4: changePostal(); break; + case 5: mainMenu(); break; + } +} + +void yourAccount() +{ + cout<<"*********************************"<> choice; + switch(choice) + { + case 0: mainMenu(); break; + case 1: editAccountMenu(); break; + } +} + +void showMessages() +{ + //Causing seg fault +// Relation temp = engine.getTableFromName("Messages"); + //temp.display(); + cout<<"\n\n0. Return to main menu"<> choice; + switch(choice) + { + case 0: mainMenu(); break; + } +} void eventHandler(int choice) { @@ -233,26 +325,86 @@ void eventHandler(int choice) int main() { - //needs to load all the relations - at least the user relation - - - - User u0("JOHN_CENA", "UberWrestling", "111-222-3333", "444-555-6666", "77432", true); - User u1("user1", "gig'em!", "111-222-3333", "444-555-6666", "77432", false); - - User u2("user1", "gig'em!", "111-222-3333", "444-555-6666", "77432", false); - User u3("user2", "gig'em!", "111-222-3333", "444-555-6666", "77432", false); - User u4("user3", "gig'em!", "111-222-3333", "444-555-6666", "77432", false); - + + //Hard Coded Sample Tuples + User u0("JOHN_CENA", "UberWrestling", "111-222-3333", "444-555-6666", "76432", true); + User u1("Lo Wang", "Rice", "098-765-4321", "454-455-1923", "45123", false); + User u2("Duke", "Nukem", "123-456-7890", "464-555-5431", "12362", false); + User u3("Caleb", "Blood", "107-293-4856", "474-655-3421", "42231", false); + User u4("Taggert", "Green", "666-666-6666", "484-755-6317", "66666", false); users.push_back(u0); users.push_back(u1); users.push_back(u2); users.push_back(u3); users.push_back(u4); + + Message m0("JOHN_CENA", "Duke", "10/6/2015", "Who's champ?"); + Message m1("Taggert", "Caleb", "12/24/1997", "I'm faster"); + Message m2("Caleb", "Lo Wang", "4/13/1998", "Extra crispy"); + mesages.push_back(m0); + mesages.push_back(m1); + mesages.push_back(m2); + //User Relation & Attributes + Attribute userAt1("Name", "VARCHAR(20)", true); + Attribute userAt2("Phone Number", "VARCHAR(20)", false); + Attribute userAt3("Fax Number", "VARCHAR(20)", false); + Attribute userAt4("Postal Address", "VARCHAR(20)", false); + vector userAttributes; + userAttributes.push_back(userAt1); + userAttributes.push_back(userAt2); + userAttributes.push_back(userAt3); + userAttributes.push_back(userAt4); + Relation userRelation("User Relation", userAttributes); + for(int i = 0 ; i < users.size(); ++i) { + userRelation.insertTuple(users[i].getInfo()); + } + + //Message Relation & Attributes + Attribute messageAt1("Sender", "VARCHAR(20)", true); + Attribute messageAt2("Receiver", "VARCHAR(20)", false); + Attribute messageAt3("Time Stamp", "VARCHAR(20)", false); + Attribute messageAt4("Text", "VARCHAR(20)", false); + vector messageAttributes; + messageAttributes.push_back(messageAt1); + messageAttributes.push_back(messageAt2); + messageAttributes.push_back(messageAt3); + messageAttributes.push_back(messageAt4); + Relation messageRelation("Messages", messageAttributes); + + for(int i = 0 ; i < mesages.size(); ++i) { + messageRelation.insertTuple(mesages[i].getInfo()); + } + + //Board Relation & Attributes + Attribute boardAt1("Name", "VARCHAR(20)", true); + Attribute boardAt2("Description", "VARCHAR(20)", false); + Attribute boardAt3("Group", "VARCHAR(20)", false); + vector boardAttributes; + boardAttributes.push_back(boardAt1); + boardAttributes.push_back(boardAt2); + boardAttributes.push_back(boardAt3); + Relation boardRelation("Board Relation", boardAttributes); + + //Group Relation & Attributes + Attribute groupAt1("Name", "VARCHAR(20)", true); + Attribute groupAt2("Description", "VARCHAR(20)", false); + vector groupAttributes; + groupAttributes.push_back(groupAt1); + groupAttributes.push_back(groupAt2); + Relation groupRelation("Group Relation", groupAttributes); + + //Article Relation & Attributes + Attribute articleAt1("Author", "VARCHAR(20)", true); + Attribute articleAt2("Time Stamp", "VARCHAR(20)", false); + Attribute articleAt3("Length", "VARCHAR(20)", false); + vector articleAttributes; + articleAttributes.push_back(articleAt1); + articleAttributes.push_back(articleAt2); + articleAttributes.push_back(articleAt3); + Relation articleRelation("Article Relation", articleAttributes); - DBEngine v8; cout<<"***************************************"<