Guest User

Untitled

a guest
Apr 9th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.95 KB | None | 0 0
  1. //MainASPER.cpp
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <iomanip>
  6. #include <fstream>
  7. #include <sstream>
  8. #include <cstdlib>
  9. using namespace std;
  10.  
  11. #include "Owner.h"
  12. #include "Client.h"
  13. #include "Staff.h"
  14.  
  15. void OwnerToFile();
  16. void PersonToFile();
  17. void StaffMenu();
  18. void ViewAddSuiteOwner();
  19. void AddSuiteOwner();
  20. void AddUser();
  21. void ClientMenu();
  22. void DeleteUsers();
  23. void outputOwner();
  24. void outputUser();
  25. void OwnerMenu();
  26. void ViewAllSuite();
  27. void DisplayUser();
  28.  
  29. int main (){
  30.  
  31. fstream check("PersonDetails.dat", ios::in | ios::out | ios::binary);
  32.  
  33. Person PersonY;
  34.  
  35. string username;
  36. string password;
  37.  
  38. cout << "*************************************************************" << endl;
  39. cout << "* APSER SERVICE APARTMENT MANAGEMENT SYSTEM (SAMS) *" << endl;
  40. cout << "* *" << endl;
  41. cout << "*-----------------------------------------------------------*" << endl;
  42. cout << "* Login *" << endl;
  43. cout << "*-----------------------------------------------------------*" << endl;
  44. cout << "* *" << endl;
  45. cout << "*************************************************************" << endl;
  46. cout << " " << endl;
  47. cout << "Please Enter Your Username: ";
  48. cin >> username;
  49. cout << "Please Enter Your Password: ";
  50. cin >> password;
  51.  
  52. while(!check.eof())
  53. {
  54. check.read(reinterpret_cast<char*>(&PersonY), sizeof(Person));
  55. if(PersonY.getUsername() == username && PersonY.getPassword() == password)
  56. break;
  57. }
  58.  
  59. if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 1)
  60. StaffMenu();
  61. else if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 2)
  62. OwnerMenu();
  63. else if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 3)
  64. ClientMenu();
  65. else
  66. cerr << "Wrong username and password entered" << endl;
  67.  
  68. check.flush();
  69. check.close();
  70.  
  71. }
  72.  
  73. void StaffMenu() {
  74. int StaffChoice = 0;
  75.  
  76. system("cls");
  77.  
  78. cout << "***************************************************************************" <<endl;
  79. cout << "* APSER SERVICE APARTMENT MANAGEMENT SYSTEM (SAMS) *" << endl;
  80. cout << "*-------------------------------------------------------------------------*" <<endl;
  81. cout << "*---------------------------You have login as a Staff---------------------*" <<endl;
  82. cout << "* 1 - Display User *" <<endl;
  83. cout << "* 2 - Add User *" <<endl;
  84. cout << "* 3 - Delete Suite Records *" <<endl;
  85. cout << "* 4 - View/Add Suite Records *" <<endl;
  86. cout << "*-------------------------------------------------------------------------*" <<endl;
  87. cout << "* 5 - Back To Login *" <<endl;
  88. cout << "* 6 - Exit *" <<endl;
  89. cout << "***************************************************************************" <<endl;
  90.  
  91. cin >> StaffChoice;
  92.  
  93. switch(StaffChoice)
  94. {
  95. case 1:
  96. DisplayUser();
  97. break;
  98. case 2:
  99. AddUser();
  100. break;
  101. case 3:
  102. DeleteUsers();
  103. break;
  104. case 4:
  105. ViewAddSuiteOwner();
  106. break;
  107. case 5:
  108. main();
  109. break;
  110. case 6:
  111. exit(1);
  112. break;
  113. default:
  114. cerr << "Invalid Choice" << endl;
  115. break;
  116. }
  117.  
  118. }
  119.  
  120. void ViewAddSuiteOwner() {
  121.  
  122. int decision;
  123.  
  124. cout << "*****************************************" << endl;
  125. cout << "* SUITE RECORDS *" << endl;
  126. cout << "*---------------------------------------*" << endl;
  127. cout << "* 1 - Add Suite Owner *" << endl;
  128. cout << "* 2 - View All Suite *" << endl;
  129. cout << "*---------------------------------------*" << endl;
  130. cout << "* 0 - Exit *" << endl;
  131. cout << "*****************************************" << endl;
  132. cin >> decision;
  133.  
  134. if(decision == 1)
  135. AddSuiteOwner();
  136. else if(decision == 2)
  137. ViewAllSuite();
  138. else if (decision == 0)
  139. StaffMenu();
  140. else
  141. cout << "Invalid Input, Please Re-enter Again" << endl;
  142.  
  143. }
  144.  
  145. void AddSuiteOwner() {
  146.  
  147. fstream addSuite("SuiteOwnerDetails.dat", ios::in | ios::out | ios::binary);
  148. fstream addOwner("PersonDetails.dat", ios::in | ios::out | ios::binary);
  149.  
  150. int ID;
  151. do{
  152.  
  153. cout << "Enter id number between (1-50): ";
  154. cin >> ID;
  155.  
  156. } while(ID < 1 || ID > 50);
  157.  
  158. addOwner.seekg((ID - 1)*sizeof(Person));
  159.  
  160. Person add;
  161. addOwner.read(reinterpret_cast<char *>(&add), sizeof(Person));
  162.  
  163. if(add.getAccID() == 0)
  164. {
  165. int SuiteID;
  166. int UserType=2;
  167. string Username;
  168. string Password;
  169. string ContactNo;
  170. string Address;
  171. string SuiteAddress;
  172. int NBD;
  173. int NBT;
  174. int Facilities;
  175. int Area;
  176. int Rental;
  177. int Availability=0; // 0=Free/Available at default, 1=Booked;
  178.  
  179. cout << "Enter username : " << endl;
  180. cin >> Username;
  181. cout << "Enter password : " << endl;
  182. cin >> Password;
  183. cout << "Enter contact no : " << endl;
  184. cin >> ContactNo;
  185. cout << "Enter address : " << endl;
  186. cin >> Address;
  187.  
  188. cout << "Enter suiteID : " << endl;
  189. cin >> SuiteID;
  190. cout << "Enter address : " << endl;
  191. cin >> SuiteAddress;
  192. cout << "Enter no of bedrooms : " << endl;
  193. cin >> NBD;
  194. cout << "Enter no of bathrooms : " << endl;
  195. cin >> NBT;
  196. cout << "1. TV" << endl;
  197. cout << "2. Heater" << endl;
  198. cout << "3. Air-condiotioner" << endl;
  199. cout << "4. Internet" << endl;
  200. cout << "Type any number of facilities you want to include" << endl;
  201. cin >> Facilities;
  202. cout << "Enter area of the apartment : " << endl;
  203. cin >> Area;
  204. cout << "Enter the rental types (1-Daily, 2-Weekly, 3-Monthly) : " << endl;
  205. cin >> Rental;
  206.  
  207. add.setPerson(ID, UserType, Username, Password, ContactNo, Address);
  208.  
  209. addOwner.seekp((ID-1) * sizeof(Person));
  210. addOwner.write(reinterpret_cast<const char *>(&add), sizeof(Person));
  211.  
  212. Owner Add;
  213. Add.setOwner(ID,UserType, Username, Password, ContactNo, Address, SuiteID, SuiteAddress, NBD, NBT, Facilities, Area , Rental, Availability);
  214. addSuite.seekp((SuiteID - 1) * sizeof(Owner));
  215. addSuite.write(reinterpret_cast<const char*>(&Add), sizeof(Owner));
  216. }
  217. else
  218. cerr << "The ID number has been used" << endl;
  219.  
  220.  
  221. }
  222.  
  223. void ViewAllSuite()
  224. {
  225. /*
  226. fstream output("SuiteOwnerDetails.dat", ios::in | ios::out | ios::binary);
  227. output.seekg(0);
  228.  
  229. Owner viewas;
  230.  
  231. while(!output.eof())
  232. {
  233. output.read(reinterpret_cast< char *>(&viewas), sizeof(Owner));
  234. outputOwner(viewas.getAccID(), viewas.getUserType(),viewas.getUsername(), viewas.getPassword(), viewas.getContactNo(), viewas.getAddress(), viewas.getSuiteID(), viewas.getSuiteAddress(), viewas.getNoBedrooms(),viewas.getNoBathrooms(),viewas.getFacilities(),viewas.getArea(),viewas.getRent(),viewas.getAvailability());
  235.  
  236. }
  237.  
  238. */
  239. }
  240. //Done
  241. void DisplayUser()
  242. {
  243. /*
  244. fstream display("PersonDetails.dat", ios::in | ios::out | ios::binary);
  245. display.seekg(0);
  246.  
  247. Person show;
  248.  
  249. display.read(reinterpret_cast<char *>(&show), sizeof(Person));
  250.  
  251. cout << left << " | " << setw(10) << "ID"
  252. << " | " << setw(10) << "User Type"
  253. << " | " << setw(25) << "Username"
  254. << " | " << setw(25) << "Password"
  255. << " | " << setw(11) << "Contact No"
  256. << " | " << setw(35) << "Address" <<endl;
  257. while(!display.eof())
  258. {
  259.  
  260. display.read(reinterpret_cast< char *>(&show), sizeof(Person));
  261. outputUser(show.getAccID(), show.getUserType(),show.getUsername(), show.getPassword(), show.getContactNo(), show.getAddress());
  262.  
  263. }
  264. */
  265. }
  266. //
  267. void AddUser() //Staff and Client only
  268. {
  269. fstream input("PersonDetails.dat", ios::in | ios::out | ios::binary);
  270. int ID;
  271. do{
  272.  
  273. cout << "Enter id number between (1-50): ";
  274. cin >> ID;
  275.  
  276. } while(ID < 1 || ID > 50);
  277.  
  278. input.seekg((ID - 1)*sizeof(Person));
  279.  
  280. Person add;
  281. input.read(reinterpret_cast<char *>(&add), sizeof(Person));
  282.  
  283. if(add.getAccID() == 0)
  284. {
  285. int UserType;
  286. string Username;
  287. string Password;
  288. string ContactNo;
  289. string Address;
  290. int choice = 0;
  291.  
  292. cout << "Enter username : " << endl;
  293. cin >> Username;
  294. cout << "Enter password : " << endl;
  295. cin >> Password;
  296. cout << "Enter contact no : " << endl;
  297. cin >> ContactNo;
  298. cout << "Enter address : " << endl;
  299. cin >> Address;
  300. do{
  301.  
  302. cout << "1. Staff" << endl;
  303. cout << "2. Client"<<endl;
  304. cout << "Choose User Type : " << endl;
  305. cin >> choice;
  306. if(choice == 1)
  307. UserType = 1;
  308. else if(choice == 2)
  309. UserType = 3;
  310. else //Invalid
  311. break;
  312. }while(choice <= 0 || choice >= 4);
  313.  
  314. add.setPerson(ID, UserType, Username, Password, ContactNo, Address);
  315.  
  316. input.seekp((ID-1) * sizeof(Person));
  317. input.write(reinterpret_cast<const char *>(&add), sizeof(Person));
  318.  
  319. }
  320. else
  321. cerr << "The ID number has been used" << endl;
  322. }
  323.  
  324. void DeleteUsers()
  325. {
  326. fstream deleteRecord("PersonDetails.dat", ios::in | ios::out | ios::binary);
  327. int ID;
  328.  
  329. do{
  330.  
  331. cout << "Enter id number between (1-50) that you want to delete: ";
  332. cin >> ID;
  333.  
  334. } while(ID < 1 || ID > 100);
  335.  
  336. deleteRecord.seekg((ID - 1)*sizeof(Person));
  337.  
  338. Person Check;
  339. deleteRecord.read(reinterpret_cast<char *>(&Check), sizeof(Person));
  340.  
  341. if(Check.getAccID() != 0)
  342. {
  343. Person Delete;
  344.  
  345. Delete.setPerson(0, 0, "", "", "", "");
  346.  
  347. deleteRecord.seekp((ID - 1) * sizeof(Person));
  348.  
  349. deleteRecord.write(reinterpret_cast<const char*>(&Delete), sizeof(Person));
  350.  
  351. cout << "ID #" << ID << " is deleted." << endl;
  352. }
  353. else
  354. cerr << "ID #" << ID << " is empty." << endl;
  355.  
  356. }
  357.  
  358. void outputUser(int ID, int UserType, const string Username, const string Password, const string ContactNo, const string Address)
  359. {
  360. cout << left << " | " << setw(10) << ID
  361. << " | " << setw(10) << UserType
  362. << " | " << setw(25) << Username
  363. << " | " << setw(25) << Password
  364. << " | " << setw(11) << ContactNo
  365. << " | " << setw(35) << Address <<endl;
  366.  
  367.  
  368. }
  369.  
  370. void outputOwner(int ID, int UserType, string Username, string Password, string ContactNo, string Address, int SuiteID,string SuiteAddress, int NoBedrooms, int NoBathrooms, int Facilities,int Area, int Rent, int Availability)
  371. {
  372. cout << left << " | " << setw(10) << ID
  373. << " | " << setw(10) << UserType
  374. << " | " << setw(25) << Username
  375. << " | " << setw(25) << Password
  376. << " | " << setw(11) << ContactNo
  377. << " | " << setw(35) << Address
  378. << " | " << setw(10) << SuiteID
  379. << " | " << setw(25) << SuiteAddress
  380. << " | " << setw(10) << NoBedrooms
  381. << " | " << setw(10) << NoBathrooms
  382. << " | " << setw(15) << Facilities
  383. << " | " << setw(10) << Area
  384. << " | " << setw(25) << Rent
  385. << " | " << setw(10) << Availability <<endl;
  386.  
  387. }
  388. void ClientMenu()
  389. {
  390.  
  391. }
  392.  
  393. void OwnerMenu()
  394. {
  395.  
  396. }
Add Comment
Please, Sign In to add comment