Advertisement
Guest User

Untitled

a guest
May 6th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.57 KB | None | 0 0
  1. #ifndef D2SDATABASE
  2. #define D2SDATABASE
  3. #include <windows.h>
  4. #include "Users.h"
  5. #include "tutorial.h"
  6. #include "tinyxml2.h"
  7. #include <deque>
  8.  
  9. using namespace std;
  10.  
  11. void d2sDatabaseSystem();
  12. void databaseWelcomeMessage();
  13. int databaseOptions();
  14. void databaseWrite();
  15. void databaseRead();
  16. void databaseSearch();
  17. int selectDatabase(string s);
  18. void makeUser();
  19. void readUsers();
  20. void readExams();
  21. void readJobs();
  22. int makeUserMenu();
  23. void makeExam();
  24. void makeJob();
  25. User* searchUserDatabase(char *, string, bool);
  26. Exam* searchExamDatabase(char * attribute, string searchItem, bool remove);
  27. void searchUsers(bool);
  28. void searchExams(bool);
  29. int chooseUserSearchAttribute();
  30. int chooseExamSearchAttribute();
  31. string chooseUserSearchKey(string);
  32. string chooseExamSearchKey(string);
  33. void searchCourses(bool remove);
  34. int chooseCourseSearchAttribute();
  35. string chooseCourseSearchKey(string searchAttribute);
  36. Course* searchCourseDatabase(char * attribute, string searchItem, bool remove, int currentNumber,bool isThisAStudent);
  37. void makeCourse();
  38. int makeCourseMenu();
  39. void databaseRemove();
  40. void searchJobs(bool);
  41. int chooseJobSearchAttribute();
  42. string chooseJobSearchKey(string);
  43. Job* searchJobDatabase(char *, string, bool); // remove should be set to TRUE if you want to delete a user from the database
  44. Course* searchCourseDatabaseParticipants(char * attribute, string searchItem, bool remove, int currentNumber, bool isThisAStudent); // remove should be set to TRUE if you want to delete a user from the database
  45.  
  46.  
  47. void d2sDatabaseSystem()
  48. {
  49. bool exit = false;
  50. int choice = 0;
  51.  
  52. databaseWelcomeMessage();
  53.  
  54. while (!exit)
  55. {
  56. while (!(choice = databaseOptions()) || (choice > 5 || choice < 1))
  57. {
  58. Utilities::errorWarning("That Was Not One of the Options");
  59. }
  60. switch (choice)
  61. {
  62. case 1: databaseWrite();
  63. break;
  64. case 2: databaseRead();
  65. break;
  66. case 3: databaseSearch();
  67. break;
  68. case 4: databaseRemove();
  69. break;
  70. case 5: exit = true;
  71. break;
  72. default: // do something
  73. break;
  74. }
  75. }
  76. }
  77.  
  78. void databaseWelcomeMessage()
  79. {
  80. cout << "\n\n\t\tWelcome to the D2S Database Management System";
  81. }
  82.  
  83. int databaseOptions()
  84. {
  85. int x = 0;
  86. cout << "\n\n\tDatabase Options:"
  87. << "\n\t1. Write to Database"
  88. << "\n\t2. Read from Database"
  89. << "\n\t3. Search Database"
  90. << "\n\t4. Remove from Database"
  91. << "\n\t5. Exit"
  92. << "\n\t: ";
  93.  
  94. scanf_s("%d", &x);
  95.  
  96. getchar();
  97.  
  98. return x;
  99. }
  100.  
  101. void databaseWrite()
  102. {
  103. bool exit = false;
  104. int choice = 0;
  105. while (!exit)
  106. {
  107. while (!(choice = selectDatabase("to Write to")) || (choice > 5 || choice < 1))
  108. {
  109. Utilities::errorWarning("That Was Not One of the Options");
  110. }
  111. switch (choice)
  112. {
  113. case 1: makeUser();
  114. break;
  115. case 2: makeJob();
  116. break;
  117. case 3: makeExam();
  118. break;
  119. case 4: makeCourse();
  120. break;
  121. case 5: exit = true;
  122. break;
  123. default: // do something
  124. break;
  125. }
  126. }
  127. }
  128. void databaseRead()
  129. {
  130. bool exit = false;
  131. int choice = 0;
  132. while (!exit)
  133. {
  134. while (!(choice = selectDatabase("to Read from")) || (choice > 5 || choice < 1))
  135. {
  136. Utilities::errorWarning("That Was Not One of the Options");
  137. }
  138. switch (choice)
  139. {
  140. case 1: readUsers();
  141. break;
  142. case 2: readJobs();
  143. break;
  144. case 3: readExams();
  145. break;
  146. case 4: searchCourses(false);
  147. break;
  148. case 5: exit = true;
  149. break;
  150. default: // do something
  151. break;
  152. }
  153. }
  154. }
  155. void databaseSearch()
  156. {
  157. bool exit = false;
  158. int choice = 0;
  159. while (!exit)
  160. {
  161. while (!(choice = selectDatabase("to Search")) || (choice > 5 || choice < 1))
  162. {
  163. Utilities::errorWarning("That Was Not One of the Options");
  164. }
  165. switch (choice)
  166. {
  167. case 1: searchUsers(false);
  168. break;
  169. case 2: searchJobs(false);
  170. break;
  171. case 3: searchExams(false);
  172. break;
  173. case 4: searchCourses(false);
  174. break;
  175. case 5: exit = true;
  176. break;
  177. default: // do something
  178. break;
  179. }
  180. }
  181. }
  182. void databaseRemove()
  183. {
  184. bool exit = false;
  185. int choice = 0;
  186. while (!exit)
  187. {
  188. while (!(choice = selectDatabase("to Remove from")) || (choice > 5 || choice < 1))
  189. {
  190. Utilities::errorWarning("That Was Not One of the Options");
  191. }
  192. switch (choice)
  193. {
  194. case 1: searchUsers(true);
  195. break;
  196. case 2: searchJobs(true);
  197. break;
  198. case 3: searchExams(true);
  199. break;
  200. case 4: searchCourses(true);
  201. break;
  202. case 5: exit = true;
  203. break;
  204. default: // do something
  205. break;
  206. }
  207. }
  208. }
  209. int selectDatabase(string s)
  210. {
  211. int x = 0;
  212. cout << "\n\n\tSelect a Database " << s << ":"
  213. << "\n\t1. User Database"
  214. << "\n\t2. Job Listing Database"
  215. << "\n\t3. Exam Database"
  216. << "\n\t4. Course Database"
  217. << "\n\t5. Exit"
  218. << "\n\t: ";
  219.  
  220. scanf_s("%d", &x);
  221.  
  222. getchar();
  223.  
  224. return x;
  225. }
  226.  
  227. void makeUser()
  228. {
  229. Admin adm(" ", " ", " ", " ");
  230. User * newUser = new User;
  231. string id, name, username, password;
  232. bool exit = false,
  233. correct = false;
  234. int choice = 0;
  235. while (!exit)
  236. {
  237. cout << "\n\n\tEnter an id: ";
  238. getline(std::cin, id);
  239. cout << "\n\tEnter a name: ";
  240. getline(std::cin, name);
  241. cout << "\n\tEnter a username: ";
  242. getline(std::cin, username);
  243. cout << "\n\tEnter a password: ";
  244. getline(std::cin, password);
  245. while (!correct)
  246. {
  247. correct = false;
  248. cout << "\n\n\tYou Entered: "
  249. << "\n\t\tID: " << id
  250. << "\n\t\tName: " << name
  251. << "\n\t\tUsername: " << username
  252. << "\n\t\tPassword: " << password
  253. << "\n\n\tIs This Correct(1=T,0=F,2=EXIT)?";
  254. std::cin >> choice;
  255. std::cin.clear();
  256. std::cin.ignore();
  257. if (choice < 0 || choice > 2)
  258. Utilities::errorWarning("That was Not an Option");
  259. else
  260. correct = true;
  261. }
  262.  
  263. if (id.empty() || name.empty() || username.empty() || password.empty())
  264. choice = 0;
  265.  
  266. if (choice == 1)
  267. {
  268. char *cId = new char[id.length() + 1];
  269.  
  270. strcpy(cId, id.c_str());
  271.  
  272. if ((searchUserDatabase("id", cId, false)))//the bool means that we do not want to remove a user
  273. {
  274. Utilities::errorWarning("User Already in the Database");
  275. }
  276. else
  277. {
  278. adm.createUser(newUser, Utilities::toUpper(id), name, username, password);
  279. adm.storeToDatabase(newUser);
  280. exit = true;
  281. }
  282. delete[] cId;
  283. }
  284. else if (choice == 2)
  285. {
  286. exit = true;
  287. }
  288. else
  289. {
  290. Utilities::errorWarning("Admin Typed In User Incorrectly. Try Again.");
  291. correct = false;
  292. }
  293. }
  294.  
  295. delete newUser;
  296. newUser = 0;
  297.  
  298. /* there is not that much error checking going on here,
  299. maybe because we trust the admin to know what he is doing */
  300. }
  301. void makeExam()
  302. {
  303. Faculty fac;
  304. Admin adm;
  305. Exam * newExam = new Exam;
  306. Date day;
  307. string id, date, hour, course, description;
  308. PersonList participants;
  309. StudentView studView;
  310. bool exit = false,
  311. correct = false;
  312. int choice = 0;
  313. while (!exit)
  314. {
  315. cout << "\n\n\tEnter an exam id: ";
  316. getline(std::cin, id);
  317. cout << "\n\tEnter the exam date: ";
  318. getline(std::cin, date);
  319. cout << "\n\tEnter the exam hour: ";
  320. getline(std::cin, hour);
  321. cout << "\n\tEnter the course ID: ";
  322. getline(std::cin, course);
  323. cout << "\n\tEnter a description: ";
  324. getline(std::cin, description);
  325. while (!correct)
  326. {
  327. correct = false;
  328. cout << "\n\n\tYou Entered: "
  329. << "\n\t\tID: " << id
  330. << "\n\t\tExam Date: " << date
  331. << "\n\t\tExam Hour: " << hour
  332. << "\n\t\tCourse ID: " << course
  333. << "\n\t\tDescription: " << description
  334. << "\n\n\tIs This Correct(1=T,0=F,2=EXIT)?";
  335. std::cin >> choice;
  336. std::cin.clear();
  337. std::cin.ignore();
  338. if (choice < 0 || choice > 2)
  339. Utilities::errorWarning("That was Not an Option");
  340. else
  341. correct = true;
  342. }
  343.  
  344. if (id.empty() || date.empty() || hour.empty() || description.empty() || course.empty())
  345. choice = 0;
  346. if (choice == 1)
  347. {
  348. char *cId = new char[id.length() + 1];
  349. strcpy(cId, id.c_str());
  350.  
  351. if ((searchExamDatabase("id", cId, false)))
  352. {
  353. Utilities::errorWarning("Exam Already in the Database");
  354. }
  355. else
  356. {
  357. bool exit2 = false,
  358. correct2 = false;
  359. day.setDate(stoi(date));
  360.  
  361. fac.createExam(newExam, Utilities::toUpper(id), day, stoi(hour), Utilities::toUpper(course), description);
  362. adm.storeToDatabase(newExam);
  363. exit = true;
  364. }
  365. delete[] cId;
  366. }
  367. else if (choice == 2)
  368. {
  369. exit = true;
  370. }
  371. else
  372. {
  373. Utilities::errorWarning("Admin Typed In Exam Incorrectly. Try Again.");
  374. correct = false;
  375. }
  376. }
  377.  
  378. delete newExam;
  379. newExam = 0;
  380. }
  381. void makeCourse()
  382. {
  383. Admin adm;
  384. Course * newCourse = new Course;
  385. string id, name, instructor, description;
  386. PersonList participants;
  387. StudentView studView;
  388. int hour = 0;
  389. bool exit = false,
  390. correct = false;
  391. int choice = 0;
  392. while (!exit)
  393. {
  394. cout << "\n\n\tEnter a course id: ";
  395. getline(std::cin, id);
  396. cout << "\n\tEnter the course name: ";
  397. getline(std::cin, name);
  398. cout << "\n\tEnter a description: ";
  399. getline(std::cin, description);
  400. cout << "\n\tEnter the instructor ID: ";
  401. getline(std::cin, instructor);
  402. while (!correct)
  403. {
  404. correct = false;
  405. cout << "\n\n\tYou Entered: "
  406. << "\n\t\tID: " << id
  407. << "\n\t\tCourse Name: " << name
  408. << "\n\t\tDescription: " << description
  409. << "\n\t\tInstructor ID: " << instructor
  410. << "\n\n\tIs This Correct(1=T,0=F,2=EXIT)?";
  411. std::cin >> choice;
  412. std::cin.clear();
  413. std::cin.ignore();
  414. if (choice < 0 || choice > 2)
  415. Utilities::errorWarning("That was Not an Option");
  416. else
  417. correct = true;
  418. }
  419.  
  420. if (id.empty() || name.empty() || description.empty() || instructor.empty())
  421. choice = 0;
  422.  
  423. if (choice == 1)
  424. {
  425. char *cId = new char[id.length() + 1];
  426. strcpy(cId, id.c_str());
  427.  
  428. if ((searchUserDatabase("id", cId, false)))
  429. {
  430. Utilities::errorWarning("Course Already in the Database");
  431. }
  432. else
  433. {
  434. bool exit2 = false,
  435. correct2 = false;
  436. string numberOfParticipantsStr = "",
  437. studentID = "";
  438. cout << "\n\n\tEnter the Number Of Participants: ";
  439. getline(std::cin, numberOfParticipantsStr);
  440.  
  441. if (!numberOfParticipantsStr.empty())
  442. {
  443. if (stoi(numberOfParticipantsStr) > 0)
  444. {
  445. for (int participantCount = 0; participantCount < stoi(numberOfParticipantsStr); ++participantCount)
  446. {
  447. cout << "\n\tEnter Participant (" << participantCount + 1 <<"): ";
  448. getline(std::cin, studentID);
  449.  
  450. studView.setID(studentID);
  451. participants.addList(studView);
  452. }
  453. }
  454. }
  455.  
  456. adm.createCourse(newCourse, Utilities::toUpper(id), name, Utilities::toUpper(instructor), description, participants);
  457. adm.storeToDatabase(newCourse);
  458. exit = true;
  459. }
  460. delete[] cId;
  461. }
  462. else if (choice == 2)
  463. {
  464. exit = true;
  465. }
  466. else
  467. {
  468. Utilities::errorWarning("Admin Typed In Course Incorrectly. Try Again.");
  469. correct = false;
  470. }
  471. }
  472.  
  473. delete newCourse;
  474. newCourse = 0;
  475. }
  476. void makeJob()
  477. {
  478. Faculty fac;
  479. Admin adm;
  480. Job * newJob = new Job;
  481. string id, title, description, start, post, creator;
  482. bool exit = false,
  483. correct = false;
  484. int choice = 0;
  485. while (!exit)
  486. {
  487. cout << "\n\n\tEnter a Job id: ";
  488. getline(std::cin, id);
  489. cout << "\n\tEnter the Job title: ";
  490. getline(std::cin, title);
  491. cout << "\n\tEnter a description: ";
  492. getline(std::cin, description);
  493. cout << "\n\tEnter the start date: ";
  494. getline(std::cin, start);
  495. cout << "\n\tEnter the posting date: ";
  496. getline(std::cin, post);
  497. cout << "\n\tEnter the creator's ID: ";
  498. getline(std::cin, creator);
  499. while (!correct)
  500. {
  501. correct = false;
  502. cout << "\n\n\tYou Entered: "
  503. << "\n\t\tID: " << id
  504. << "\n\t\tJob Title: " << title
  505. << "\n\t\tDescription: " << description
  506. << "\n\t\tStart Date: " << start
  507. << "\n\t\tPosting Date: " << post
  508. << "\n\t\tCreator ID: " << creator
  509. << "\n\n\tIs This Correct(1=T,0=F,2=EXIT)?";
  510. std::cin >> choice;
  511. std::cin.clear();
  512. std::cin.ignore();
  513. if (choice < 0 || choice > 2)
  514. Utilities::errorWarning("That was Not an Option");
  515. else
  516. correct = true;
  517. }
  518.  
  519. if (id.empty() || title.empty() || description.empty() || start.empty() || post.empty() || creator.empty())
  520. choice = 0;
  521.  
  522. if (choice == 1)
  523. {
  524. char *cId = new char[id.length() + 1];
  525. strcpy(cId, id.c_str());
  526.  
  527. if ((searchUserDatabase("id", cId, false)))
  528. {
  529. Utilities::errorWarning("Job Already in the Database");
  530. }
  531. else
  532. {
  533. fac.createJob(newJob, Utilities::toUpper(id), title, description, start, post, Utilities::toUpper(creator));
  534. adm.storeToDatabase(newJob);
  535. exit = true;
  536. }
  537. delete[] cId;
  538. }
  539. else if (choice == 2)
  540. exit = true;
  541. else
  542. {
  543. Utilities::errorWarning("Admin Typed In Job Incorrectly. Try Again.");
  544. correct = false;
  545. }
  546. }
  547.  
  548. delete newJob;
  549. newJob = 0;
  550. }
  551.  
  552. void readUsers()
  553. {
  554. Admin adm;
  555. deque<User*> dqUserList;
  556. string id, name, username, password;
  557. int count = 0;
  558. tinyxml2::XMLDocument xmlDoc;
  559. xmlDoc.LoadFile("UserDatabase.xml");
  560. XMLNode * pRoot = xmlDoc.FirstChild();
  561. if (pRoot == nullptr)
  562. {
  563. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  564. getchar();
  565. exit(1);
  566. }
  567. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("User");
  568. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  569. {
  570. id = child->Attribute("id");
  571. name = child->Attribute("name");
  572. username = child->Attribute("username");
  573. password = child->Attribute("password");
  574.  
  575. User* newUser = new User;
  576. adm.createUser(newUser, id, name, username, password);
  577. dqUserList.push_back(newUser); // make sure to deallocate all of these when you are done
  578. }
  579. for (deque<User*>::iterator i = dqUserList.begin(); i != dqUserList.end(); ++i)
  580. {
  581. adm.displayUserData(dqUserList.at(count));
  582. cout << '\n';
  583. ++count;
  584. }
  585. count = 0;
  586. for (deque<User*>::iterator i = dqUserList.begin(); i != dqUserList.end(); ++i)
  587. {
  588. delete dqUserList.at(count);
  589. dqUserList.at(count) = 0;
  590. ++count;
  591. }
  592. dqUserList.clear();
  593.  
  594. cout << "\n\n\tTotal Users In Database: " << count;
  595. std::cin.clear();
  596. std::cin.ignore();
  597. }
  598. void readExams()
  599. {
  600. Admin adm;
  601. deque<Exam*> dqExamList;
  602. Exam dummy;
  603. string id, date, hour, course, description;
  604. int count = 0;
  605. tinyxml2::XMLDocument xmlDoc;
  606. xmlDoc.LoadFile("ExamDatabase.xml");
  607. XMLNode * pRoot = xmlDoc.FirstChild();
  608. if (pRoot == nullptr)
  609. {
  610. Utilities::errorWarning("Database Failed To Open");
  611. getchar();
  612. exit(1);
  613. }
  614. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Exam");
  615. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  616. {
  617. id = child->Attribute("id");
  618. date = child->Attribute("date");
  619. hour = child->Attribute("hour");
  620. course = child->Attribute("course");
  621. description = child->Attribute("description");
  622.  
  623. Exam* newExam = new Exam;
  624. adm.createExam(newExam, id, Date(stoi(date)), stoi(hour), course, description);
  625. dqExamList.push_back(newExam); // make sure to deallocate all of these when you are done
  626. }
  627. for (deque<Exam*>::iterator i = dqExamList.begin(); i != dqExamList.end(); ++i)
  628. {
  629. dummy.displayExamData(dqExamList.at(count));
  630. cout << '\n';
  631. ++count;
  632. }
  633. count = 0;
  634. for (deque<Exam*>::iterator i = dqExamList.begin(); i != dqExamList.end(); ++i)
  635. {
  636. delete dqExamList.at(count);
  637. dqExamList.at(count) = 0;
  638. ++count;
  639. }
  640. dqExamList.clear();
  641.  
  642. cout << "\n\n\tTotal Exams In Database: " << count;
  643. std::cin.clear();
  644. std::cin.ignore();
  645. }
  646. void readJobs()
  647. {
  648. Faculty fac;
  649. deque<Job> dqJobList;
  650. Job dummy;
  651. string id, title, desc, start, post, creator;
  652. int count = 0;
  653. tinyxml2::XMLDocument xmlDoc;
  654. xmlDoc.LoadFile("JobDatabase.xml");
  655. XMLNode * pRoot = xmlDoc.FirstChild();
  656. if (pRoot == nullptr)
  657. {
  658. Utilities::errorWarning("Database Failed To Open");
  659. getchar();
  660. exit(1);
  661. }
  662. int test = 0;
  663. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Job");
  664. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  665. {
  666. id = child->Attribute("id");
  667. title = child->Attribute("title");
  668. desc = child->Attribute("description");
  669. start = child->Attribute("startdate");
  670. post = child->Attribute("postdate");
  671. creator = child->Attribute("creator");
  672.  
  673. Job newJob;
  674. fac.createJob(&newJob, id, title, desc, start, post, creator);
  675.  
  676. dqJobList.push_back(newJob); // make sure to deallocate all of these when you are done
  677.  
  678. test++;
  679. }
  680. for (size_t countJobs = 0; countJobs < dqJobList.size(); ++countJobs)
  681. {
  682. dqJobList.at(countJobs).displayJobData();
  683. cout << '\n';
  684. count++;
  685. }
  686.  
  687. dqJobList.clear();
  688.  
  689. cout << "\n\n\tTotal Jobs In Database: " << count;
  690. std::cin.clear();
  691. std::cin.ignore();
  692. }
  693.  
  694. void searchCourses(bool remove)
  695. {
  696. int choice = 0;
  697. string searchKey = "";
  698. char * searchAttribute = "";
  699. Course* desiredCourse = NULL;
  700.  
  701. while (!(choice = chooseCourseSearchAttribute()) || (choice > 6 || choice < 1))
  702. {
  703. Utilities::errorWarning("That Was Not One of the Options");
  704. }
  705. if (choice == 1)
  706. searchAttribute = "id";
  707. else if (choice == 2)
  708. searchAttribute = "name";
  709. else if (choice == 3)
  710. searchAttribute = "description";
  711. else if (choice == 4)
  712. searchAttribute = "instructor";
  713.  
  714. searchKey = chooseCourseSearchKey(searchAttribute);
  715.  
  716. if (!searchKey.empty())
  717. {
  718. desiredCourse = searchCourseDatabase(searchAttribute, searchKey, remove, 1, false); // change
  719. Admin adm;
  720.  
  721.  
  722. if (desiredCourse == NULL)
  723. Utilities::errorWarning("Course Not Found");
  724. else if (desiredCourse->getCourseID() == "fail" || desiredCourse->getCourseID() == "FAIL")
  725. cout << "Course Deleted\n";
  726. else
  727. desiredCourse->printCourse();
  728. }
  729. }
  730. int chooseCourseSearchAttribute()
  731. {
  732. int x = 0;
  733. cout << "\n\n\tSelect the Key to Search For:"
  734. << "\n\t1. Id"
  735. << "\n\t2. Name"
  736. << "\n\t3. Description"
  737. << "\n\t4. Instructor"
  738. << "\n\t: ";
  739.  
  740. scanf_s("%d", &x);
  741.  
  742. getchar();
  743.  
  744. return x;
  745.  
  746. }
  747. string chooseCourseSearchKey(string searchAttribute)
  748. {
  749. string searchKey = "";
  750. bool exit = false;
  751. int choice = 0;
  752. while (!exit)
  753. {
  754. searchKey = "";
  755. choice = 0;
  756. cout << "\n\tEnter a " << searchAttribute << ": ";
  757. getline(std::cin, searchKey);
  758.  
  759. cout << "\n\n\tYou Entered: "
  760. << "\n\t\t" << searchAttribute << ": " << searchKey
  761. << "\n\n\tIs This Correct(1=T,0=F, 2=EXIT)?";
  762. std::cin >> choice;
  763. std::cin.clear();
  764. std::cin.ignore();
  765. if (choice == 2)
  766. {
  767. searchKey = "";
  768. exit = true;
  769. }
  770. else if (choice == 1)
  771. exit = true;
  772. else
  773. Utilities::errorWarning("You changed Your Mind. Try Again.");
  774. }
  775. return searchKey;
  776. }
  777. Course* searchCourseDatabase(char * attribute, string searchItem, bool remove, int currentNumber, bool isThisAStudent) // remove should be set to TRUE if you want to delete a user from the database
  778. { // call currentNumber as zero when calling for just one course
  779. Admin adm;
  780. int numberFound = 0;
  781. bool studentFound = false;
  782. Date * tmpDay = new Date;
  783. deque<StudentView> * dqTmpStudView = new deque<StudentView>;
  784. StudentView * tmpView = new StudentView;
  785. deque<Attendance> * dqTmpAtt = new deque<Attendance>;
  786. Attendance * tmpAttendance = new Attendance;
  787. Grade * tmpGrade = new Grade;
  788. string id, title, description, startdate, postdate, creator;
  789. tinyxml2::XMLDocument xmlDoc;
  790. xmlDoc.LoadFile("CourseDatabase.xml");
  791. XMLNode * pRoot = xmlDoc.FirstChild();
  792. if (pRoot == nullptr)
  793. {
  794. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  795. getchar();
  796. exit(1);
  797. }
  798. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Course");
  799.  
  800. if (!((attribute == "id") || (attribute == "name") || (attribute == "description") || (attribute == "instructor")))
  801. {
  802. Utilities::errorWarning("That Is Not a Searchable Item");
  803. return NULL;
  804. }
  805. int count = 0;
  806. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  807. {
  808. if (searchItem == child->Attribute(attribute))
  809. ++numberFound;
  810. if ((currentNumber == numberFound))
  811. {
  812. if (!remove)
  813. {
  814. if (searchItem == child->Attribute(attribute))
  815. {
  816. XMLElement* participantElement = child->FirstChildElement("Participant");
  817. if (participantElement != nullptr)
  818. {
  819. for (tinyxml2::XMLElement* childParticipant = participantElement; childParticipant != NULL; childParticipant = childParticipant->NextSiblingElement())
  820. {
  821. tmpView->setID(childParticipant->Attribute("id"));
  822.  
  823. XMLElement* gradeElement = childParticipant->FirstChildElement("Grade");
  824. if (gradeElement != nullptr)
  825. {
  826. for (tinyxml2::XMLElement* childGrade = gradeElement; childGrade != NULL; childGrade = childGrade->NextSiblingElement())
  827. {
  828. tmpGrade->setGrade(childGrade->Attribute("letter"));
  829. tmpView->setGrade(*tmpGrade);
  830.  
  831. XMLElement* attendanceElement = childGrade->FirstChildElement("Attendance");
  832. if (attendanceElement != nullptr)
  833. {
  834. for (tinyxml2::XMLElement* childAttendance = attendanceElement; childAttendance != NULL; childAttendance = childAttendance->NextSiblingElement())
  835. {
  836. tmpDay->setDate(atoi(childAttendance->Attribute("day")));
  837. tmpAttendance->setDate(*tmpDay);
  838. tmpAttendance->setAttendance(stoi(childAttendance->Attribute("didAttend")));
  839.  
  840. dqTmpAtt->push_back(*tmpAttendance);
  841. }
  842. }
  843. if (!dqTmpAtt->empty())
  844. tmpView->setAttendances(*dqTmpAtt);
  845.  
  846. }
  847. }
  848. dqTmpStudView->push_back(*tmpView);
  849. }
  850. }
  851.  
  852. Course * foundCourse = new Course;
  853.  
  854. adm.createCourse(foundCourse, child->Attribute("id"), child->Attribute("name"), child->Attribute("instructor"), child->Attribute("description"), *dqTmpStudView);
  855. return foundCourse;
  856. }
  857. }
  858. else if (remove)
  859. {
  860. if (searchItem == child->Attribute(attribute))
  861. {
  862. // User was found in the database, so: delete him
  863. Admin adm("", "", "", "");
  864. Course * foundCourse = new Course;
  865. foundCourse->setCourseID(child->Attribute("id"));
  866. foundCourse->setCourseDescription(child->Attribute("description"));
  867. foundCourse->setCourseInstructorID(child->Attribute("instructor"));
  868. foundCourse->setCourseName(child->Attribute("name"));
  869.  
  870. //adm.createCourse(foundCourse, child->Attribute("id"), child->Attribute("title"), child->Attribute("description"), child->Attribute("startdate"));
  871. cout << "\n\n\tCourse Being Deleted:";
  872. foundCourse->printCourse();
  873. xmlDoc.FirstChildElement()->DeleteChild(child);
  874.  
  875. adm.createCourse(foundCourse, "fail", "fail", "fail", "fail", *dqTmpStudView);
  876. xmlDoc.SaveFile("CourseDatabase.xml");
  877. return foundCourse;
  878. }
  879. }
  880. }
  881. }
  882.  
  883. cout << "\n";
  884.  
  885. std::cin.clear();
  886. std::cin.ignore();
  887. return NULL;
  888. }
  889. Course* searchCourseDatabaseParticipants(char * attribute, string searchItem, bool remove, int currentNumber, bool isThisAStudent) // remove should be set to TRUE if you want to delete a user from the database
  890. { // call currentNumber as zero when calling for just one course
  891. Admin adm;
  892. int numberFound = 0;
  893. bool studentFound = false;
  894. Date * tmpDay = new Date;
  895. deque<StudentView> * dqTmpStudView = new deque<StudentView>;
  896. StudentView * tmpView = new StudentView;
  897. deque<Attendance> * dqTmpAtt = new deque<Attendance>;
  898. Attendance * tmpAttendance = new Attendance;
  899. Grade * tmpGrade = new Grade;
  900. string id, title, description, startdate, postdate, creator;
  901. tinyxml2::XMLDocument xmlDoc;
  902. xmlDoc.LoadFile("CourseDatabase.xml");
  903. XMLNode * pRoot = xmlDoc.FirstChild();
  904. if (pRoot == nullptr)
  905. {
  906. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  907. getchar();
  908. exit(1);
  909. }
  910. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Course");
  911.  
  912. if (!((attribute == "id") || (attribute == "name") || (attribute == "description") || (attribute == "instructor")))
  913. {
  914. Utilities::errorWarning("That Is Not a Searchable Item");
  915. return NULL;
  916. }
  917. int count = 0;
  918. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  919. {
  920. dqTmpAtt->clear();
  921. dqTmpStudView->clear();
  922. if (!remove)
  923. {
  924.  
  925. XMLElement* participantElement = child->FirstChildElement("Participant");
  926. if (participantElement != nullptr)
  927. {
  928. for (tinyxml2::XMLElement* childParticipant = participantElement; childParticipant != NULL; childParticipant = childParticipant->NextSiblingElement())
  929. {
  930. dqTmpAtt->clear();
  931.  
  932. tmpView->setID(childParticipant->Attribute("id"));
  933.  
  934. if (searchItem == childParticipant->Attribute(attribute))
  935. {
  936. studentFound = true;
  937. ++numberFound;
  938. }
  939. XMLElement* gradeElement = childParticipant->FirstChildElement("Grade");
  940. if (gradeElement != nullptr && studentFound)
  941. {
  942. for (tinyxml2::XMLElement* childGrade = gradeElement; childGrade != NULL; childGrade = childGrade->NextSiblingElement())
  943. {
  944. tmpGrade->setGrade(childGrade->Attribute("letter"));
  945. tmpView->setGrade(*tmpGrade);
  946.  
  947. XMLElement* attendanceElement = childGrade->FirstChildElement("Attendance");
  948. if (attendanceElement != nullptr)
  949. {
  950. for (tinyxml2::XMLElement* childAttendance = attendanceElement; childAttendance != NULL; childAttendance = childAttendance->NextSiblingElement())
  951. {
  952. tmpDay->setDate(atoi(childAttendance->Attribute("day")));
  953. tmpAttendance->setDate(*tmpDay);
  954. tmpAttendance->setAttendance(stoi(childAttendance->Attribute("didAttend")));
  955.  
  956. dqTmpAtt->push_back(*tmpAttendance);
  957. }
  958. }
  959. if (!dqTmpAtt->empty() && searchItem == childParticipant->Attribute(attribute))
  960. tmpView->setAttendances(*dqTmpAtt);
  961.  
  962. }
  963. }
  964. if (searchItem == childParticipant->Attribute(attribute))
  965. dqTmpStudView->push_back(*tmpView);
  966. }
  967. }
  968. }
  969.  
  970. if (studentFound && (currentNumber == numberFound))
  971. {
  972. Course * foundCourse = new Course;
  973. adm.createCourse(foundCourse, child->Attribute("id"), child->Attribute("name"), child->Attribute("instructor"), child->Attribute("description"), *dqTmpStudView);
  974. return foundCourse;
  975. }
  976. else if (remove)
  977. {
  978. if (searchItem == child->Attribute(attribute))
  979. {
  980. // User was found in the database, so: delete him
  981. Admin adm("", "", "", "");
  982. Course * foundCourse = new Course;
  983. foundCourse->setCourseID(child->Attribute("id"));
  984. foundCourse->setCourseDescription(child->Attribute("description"));
  985. foundCourse->setCourseInstructorID(child->Attribute("instructor"));
  986. foundCourse->setCourseName(child->Attribute("name"));
  987.  
  988. //adm.createCourse(foundCourse, child->Attribute("id"), child->Attribute("title"), child->Attribute("description"), child->Attribute("startdate"));
  989. cout << "\n\n\tCourse Being Deleted:";
  990. foundCourse->printCourse();
  991. xmlDoc.FirstChildElement()->DeleteChild(child);
  992.  
  993. adm.createCourse(foundCourse, "fail", "fail", "fail", "fail", *dqTmpStudView);
  994. xmlDoc.SaveFile("CourseDatabase.xml");
  995. return foundCourse;
  996. }
  997. }
  998. }
  999.  
  1000. cout << "\n";
  1001.  
  1002. std::cin.clear();
  1003. std::cin.ignore();
  1004. return NULL;
  1005. }
  1006.  
  1007. void searchJobs(bool remove)
  1008. {
  1009. int choice = 0;
  1010. string searchKey = "";
  1011. char * searchAttribute = "";
  1012. Job* desiredJob = NULL;
  1013.  
  1014. while (!(choice = chooseJobSearchAttribute()) || (choice > 6 || choice < 1))
  1015. {
  1016. Utilities::errorWarning("That Was Not One of the Options");
  1017. }
  1018. if (choice == 1)
  1019. searchAttribute = "id";
  1020. else if (choice == 2)
  1021. searchAttribute = "title";
  1022. else if (choice == 3)
  1023. searchAttribute = "description";
  1024. else if (choice == 4)
  1025. searchAttribute = "startdate";
  1026. else if (choice == 5)
  1027. searchAttribute = "postdate";
  1028. else if (choice == 6)
  1029. searchAttribute = "creator";
  1030.  
  1031. searchKey = chooseJobSearchKey(searchAttribute);
  1032.  
  1033. if (!searchKey.empty())
  1034. {
  1035. desiredJob = searchJobDatabase(searchAttribute, searchKey, remove); // change
  1036. Admin adm("", "", "", "");
  1037.  
  1038.  
  1039. if (desiredJob == NULL)
  1040. Utilities::errorWarning("Job Not Found");
  1041. else if (desiredJob->getJobID() == "fail")
  1042. Utilities::errorWarning("Job Not Found");
  1043. else
  1044. desiredJob->displayJobData();
  1045. }
  1046. }
  1047. int chooseJobSearchAttribute()
  1048. {
  1049. int x = 0;
  1050. cout << "\n\n\tSelect the Key to Search For:"
  1051. << "\n\t1. Id"
  1052. << "\n\t2. Title"
  1053. << "\n\t3. Description"
  1054. << "\n\t4. Start Date"
  1055. << "\n\t5. Post Date"
  1056. << "\n\t6. Creator"
  1057. << "\n\t: ";
  1058.  
  1059. scanf_s("%d", &x);
  1060.  
  1061. getchar();
  1062.  
  1063. return x;
  1064.  
  1065. }
  1066. string chooseJobSearchKey(string searchAttribute)
  1067. {
  1068. string searchKey = "";
  1069. bool exit = false;
  1070. int choice = 0;
  1071. while (!exit)
  1072. {
  1073. searchKey = "";
  1074. choice = 0;
  1075. cout << "\n\tEnter a " << searchAttribute << ": ";
  1076. getline(std::cin, searchKey);
  1077.  
  1078. cout << "\n\n\tYou Entered: "
  1079. << "\n\t\t" << searchAttribute << ": " << searchKey
  1080. << "\n\n\tIs This Correct(1=T,0=F, 2=EXIT)?";
  1081. std::cin >> choice;
  1082. std::cin.clear();
  1083. std::cin.ignore();
  1084. if (choice == 2)
  1085. {
  1086. searchKey = "";
  1087. exit = true;
  1088. }
  1089. else if (choice == 1)
  1090. exit = true;
  1091. else
  1092. Utilities::errorWarning("You changed Your Mind. Try Again.");
  1093. }
  1094. return searchKey;
  1095. }
  1096. Job* searchJobDatabase(char * attribute, string searchItem, bool remove) // remove should be set to TRUE if you want to delete a user from the database
  1097. {
  1098. Admin adm(" ", " ", " ", " ");
  1099. string id, title, description, startdate, postdate, creator;
  1100. tinyxml2::XMLDocument xmlDoc;
  1101. xmlDoc.LoadFile("JobDatabase.xml");
  1102. XMLNode * pRoot = xmlDoc.FirstChild();
  1103. if (pRoot == nullptr)
  1104. {
  1105. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  1106. getchar();
  1107. exit(1);
  1108. }
  1109. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Job");
  1110.  
  1111. if (!((attribute == "id") || (attribute == "title") || (attribute == "description") || (attribute == "startdate") || (attribute == "postdate") || (attribute == "creator")))
  1112. {
  1113. Utilities::errorWarning("That Is Not a Searchable Item");
  1114. return NULL;
  1115. }
  1116. int count = 0;
  1117. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  1118. {
  1119. if (!remove)
  1120. {
  1121. if (searchItem == child->Attribute(attribute))
  1122. {
  1123. // Job was found in the database, so: make the job from the database and return him!
  1124. Admin adm("", "", "", "");
  1125. Job * foundJob = new Job;
  1126. adm.createJob(foundJob, child->Attribute("id"), child->Attribute("title"), child->Attribute("description"), child->Attribute("startdate"), child->Attribute("postdate"), child->Attribute("creator"));
  1127. return foundJob;
  1128. }
  1129. }
  1130. else if (remove)
  1131. {
  1132. if (searchItem == child->Attribute(attribute))
  1133. {
  1134. // User was found in the database, so: delete him
  1135. Admin adm("", "", "", "");
  1136. Job * foundJob = new Job; // might be a memory leak
  1137. adm.createJob(foundJob, child->Attribute("id"), child->Attribute("title"), child->Attribute("description"), child->Attribute("startdate"), child->Attribute("postdate"), child->Attribute("creator"));
  1138.  
  1139. cout << "\n\n\tJob Being Deleted:";
  1140. foundJob->displayJobData();
  1141. xmlDoc.FirstChildElement()->DeleteChild(child);
  1142. adm.createJob(foundJob, "fail", "fail", "fail", "fail", "fail", "fail");
  1143. xmlDoc.SaveFile("JobDatabase.xml");
  1144. return foundJob;
  1145. }
  1146. }
  1147. }
  1148.  
  1149. cout << "\n";
  1150.  
  1151. std::cin.clear();
  1152. std::cin.ignore();
  1153. return NULL;
  1154. }
  1155.  
  1156. void searchUsers(bool remove)
  1157. {
  1158. int choice = 0;
  1159. string searchKey = "";
  1160. char * searchAttribute = "";
  1161. User* desiredUser = NULL;
  1162.  
  1163. while (!(choice = chooseUserSearchAttribute()) || (choice > 5 || choice < 1))
  1164. {
  1165. Utilities::errorWarning("That Was Not One of the Options");
  1166. }
  1167. if (choice == 1)
  1168. searchAttribute = "id";
  1169. if (choice == 2)
  1170. searchAttribute = "name";
  1171. if (choice == 3)
  1172. searchAttribute = "username";
  1173. if (choice == 4)
  1174. searchAttribute = "password";
  1175.  
  1176. searchKey = chooseUserSearchKey(searchAttribute);
  1177.  
  1178. if (!searchKey.empty())
  1179. {
  1180. desiredUser = searchUserDatabase(searchAttribute, searchKey, remove);
  1181. Admin adm("", "", "", "");
  1182. if (desiredUser->getID() == "fail")
  1183. cout << "\n\n\t\tUser Deleted";
  1184. else if (desiredUser != NULL && desiredUser->getID() != "fail")
  1185. adm.displayUserData(desiredUser);
  1186. else if (desiredUser->getID() != "fail")
  1187. Utilities::errorWarning("User Not Found");
  1188. }
  1189. }
  1190. int chooseUserSearchAttribute()
  1191. {
  1192. int x = 0;
  1193. cout << "\n\n\tSelect the Key to Search For:"
  1194. << "\n\t1. Id"
  1195. << "\n\t2. Name"
  1196. << "\n\t3. Username"
  1197. << "\n\t4. Password"
  1198. << "\n\t5. Exit"
  1199. << "\n\t: ";
  1200.  
  1201. scanf_s("%d", &x);
  1202.  
  1203. getchar();
  1204.  
  1205. return x;
  1206.  
  1207. }
  1208. string chooseUserSearchKey(string searchAttribute)
  1209. {
  1210. string searchKey = "";
  1211. bool exit = false;
  1212. int choice = 0;
  1213. while (!exit)
  1214. {
  1215. searchKey = "";
  1216. choice = 0;
  1217. cout << "\n\tEnter a " << searchAttribute << ": ";
  1218. getline(std::cin, searchKey);
  1219.  
  1220. cout << "\n\n\tYou Entered: "
  1221. << "\n\t\t" << searchAttribute << ": " << searchKey
  1222. << "\n\n\tIs This Correct(1=T,0=F, 2=EXIT)?";
  1223. std::cin >> choice;
  1224. std::cin.clear();
  1225. std::cin.ignore();
  1226. if (choice == 2)
  1227. {
  1228. searchKey = "";
  1229. exit = true;
  1230. }
  1231. else if (choice == 1)
  1232. exit = true;
  1233. else
  1234. Utilities::errorWarning("You changed Your Mind. Try Again.");
  1235. }
  1236. return searchKey;
  1237. }
  1238. User* searchUserDatabase(char * attribute, string searchItem, bool remove) // remove should be set to TRUE if you want to delete a user from the database
  1239. {
  1240. Admin adm(" ", " ", " ", " ");
  1241. string id, name, username, password;
  1242. tinyxml2::XMLDocument xmlDoc;
  1243. xmlDoc.LoadFile("UserDatabase.xml");
  1244. XMLNode * pRoot = xmlDoc.FirstChild();
  1245. if (pRoot == nullptr)
  1246. {
  1247. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  1248. getchar();
  1249. exit(1);
  1250. }
  1251. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("User");
  1252.  
  1253. if (!((attribute == "id") || (attribute == "name") || (attribute == "username") || (attribute == "password")))
  1254. {
  1255. Utilities::errorWarning("That Is Not a Searchable Item");
  1256. return NULL;
  1257. }
  1258.  
  1259. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  1260. {
  1261. if (!remove)
  1262. {
  1263. if (searchItem == child->Attribute(attribute))
  1264. {
  1265. // User was found in the database, so: make the user from the database and return him!
  1266. Admin adm("", "", "", "");
  1267. User * foundUser = new User;
  1268. adm.createUser(foundUser, child->Attribute("id"), child->Attribute("name"), child->Attribute("username"), child->Attribute("password"));
  1269. return foundUser;
  1270. }
  1271. }
  1272. else if (remove)
  1273. {
  1274. if (searchItem == child->Attribute(attribute))
  1275. {
  1276. // User was found in the database, so: delete him
  1277. Admin adm("", "", "", "");
  1278. User * foundUser = new User;
  1279. adm.createUser(foundUser, child->Attribute("id"), child->Attribute("name"), child->Attribute("username"), child->Attribute("password"));
  1280.  
  1281. cout << "\n\n\tUser Being Deleted:";
  1282. adm.displayUserData(foundUser);
  1283. xmlDoc.FirstChildElement()->DeleteChild(child);
  1284. adm.createUser(foundUser, "fail", "fail", "fail", "fail");
  1285. xmlDoc.SaveFile("UserDatabase.xml");
  1286. return foundUser;
  1287. }
  1288. }
  1289. }
  1290.  
  1291. std::cin.clear();
  1292. std::cin.ignore();
  1293. return NULL;
  1294. }
  1295.  
  1296. void searchExams(bool remove)
  1297. {
  1298. int choice = 0;
  1299. string searchKey = "";
  1300. char * searchAttribute = "";
  1301. Exam* desiredExam = NULL;
  1302.  
  1303. while (!(choice = chooseExamSearchAttribute()) || (choice > 5 || choice < 1))
  1304. {
  1305. Utilities::errorWarning("That Was Not One of the Options");
  1306. }
  1307. if (choice == 1)
  1308. searchAttribute = "id";
  1309. if (choice == 2)
  1310. searchAttribute = "date";
  1311. if (choice == 3)
  1312. searchAttribute = "hour";
  1313. if (choice == 4)
  1314. searchAttribute = "course";
  1315.  
  1316. searchKey = chooseExamSearchKey(searchAttribute);
  1317.  
  1318. if (!searchKey.empty())
  1319. {
  1320. desiredExam = searchExamDatabase(searchAttribute, searchKey, remove);
  1321. Admin adm("", "", "", "");
  1322. if (desiredExam->getExamID() == "fail")
  1323. cout << "\n\n\t\tExam Deleted";
  1324. else if (desiredExam != NULL && desiredExam->getExamID() != "fail")
  1325. desiredExam->displayExamData(desiredExam);
  1326. else if (desiredExam->getExamID() != "fail")
  1327. Utilities::errorWarning("Exam Not Found");
  1328. }
  1329. }
  1330. Exam* searchExamDatabase(char * attribute, string searchItem, bool remove)
  1331. {
  1332. Date day;
  1333. Admin adm;
  1334. string id, name, username, password;
  1335. tinyxml2::XMLDocument xmlDoc;
  1336. xmlDoc.LoadFile("ExamDatabase.xml");
  1337. XMLNode * pRoot = xmlDoc.FirstChild();
  1338. if (pRoot == nullptr)
  1339. {
  1340. Utilities::errorWarning("Database Failed To Open");
  1341. getchar();
  1342. exit(1);
  1343. }
  1344. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("Exam");
  1345.  
  1346. if (!((attribute == "id") || (attribute == "date") || (attribute == "hour") || (attribute == "course")))
  1347. {
  1348. Utilities::errorWarning("That Is Not a Searchable Item");
  1349. return NULL;
  1350. }
  1351.  
  1352. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  1353. {
  1354. if (!remove)
  1355. {
  1356. if (searchItem == child->Attribute(attribute))
  1357. {
  1358. Admin adm2;
  1359. Exam * foundExam = new Exam;
  1360. adm2.createExam(foundExam, child->Attribute("id"), Date(stoi(child->Attribute("date"))), stoi(child->Attribute("hour")), child->Attribute("course"), child->Attribute("description"));
  1361. return foundExam;
  1362. }
  1363. }
  1364. else if (remove)
  1365. {
  1366. if (searchItem == child->Attribute(attribute))
  1367. {
  1368. Admin adm2;
  1369. Exam * foundExam = new Exam;
  1370. adm2.createExam(foundExam, child->Attribute("id"), Date(stoi(child->Attribute("date"))), stoi(child->Attribute("hour")), child->Attribute("course"), child->Attribute("description"));
  1371.  
  1372. cout << "\n\n\tExam Being Deleted:";
  1373. foundExam->displayExamData(foundExam);
  1374. xmlDoc.FirstChildElement()->DeleteChild(child);
  1375. adm2.createExam(foundExam, "fail", Date(0), 0, "fail", "fail");
  1376. xmlDoc.SaveFile("ExamDatabase.xml");
  1377. return foundExam;
  1378. }
  1379. }
  1380. }
  1381.  
  1382. std::cin.clear();
  1383. std::cin.ignore();
  1384. return NULL;
  1385. }
  1386. int chooseExamSearchAttribute()
  1387. {
  1388. int x = 0;
  1389. cout << "\n\n\tSelect the Key to Search For:"
  1390. << "\n\t1. ID"
  1391. << "\n\t2. Date"
  1392. << "\n\t3. Hour"
  1393. << "\n\t4. Course ID"
  1394. << "\n\t5. Exit"
  1395. << "\n\t: ";
  1396.  
  1397. scanf_s("%d", &x);
  1398.  
  1399. getchar();
  1400.  
  1401. return x;
  1402.  
  1403. }
  1404. string chooseExamSearchKey(string searchAttribute)
  1405. {
  1406. string searchKey = "";
  1407. bool exit = false;
  1408. int choice = 0;
  1409. while (!exit)
  1410. {
  1411. searchKey = "";
  1412. choice = 0;
  1413. cout << "\n\tEnter a " << searchAttribute << ": ";
  1414. getline(std::cin, searchKey);
  1415.  
  1416. cout << "\n\n\tYou Entered: "
  1417. << "\n\t\t" << searchAttribute << ": " << searchKey
  1418. << "\n\n\tIs This Correct(1=T,0=F, 2=EXIT)?";
  1419. std::cin >> choice;
  1420. std::cin.clear();
  1421. std::cin.ignore();
  1422. if (choice == 2)
  1423. {
  1424. searchKey = "";
  1425. exit = true;
  1426. }
  1427. else if (choice == 1)
  1428. exit = true;
  1429. else
  1430. Utilities::errorWarning("You changed Your Mind. Try Again.");
  1431. }
  1432. return searchKey;
  1433. }
  1434.  
  1435. User* verifyLogin(string username, string password)
  1436. {
  1437. Admin adm(" ", " ", " ", " ");
  1438. User * newUser = new User; // make sure to deallocate!!!!!
  1439. tinyxml2::XMLDocument xmlDoc;
  1440. xmlDoc.LoadFile("UserDatabase.xml");
  1441. XMLNode * pRoot = xmlDoc.FirstChild();
  1442. if (pRoot == nullptr)
  1443. {
  1444. Utilities::errorWarning("Database Failed To Open"); // Need to have a preinitialized database for this to work (use the xml file I included on github)
  1445. getchar();
  1446. exit(1);
  1447. }
  1448. XMLElement* userElement = xmlDoc.FirstChildElement()->FirstChildElement("User");
  1449.  
  1450. for (tinyxml2::XMLElement* child = userElement; child != NULL; child = child->NextSiblingElement())
  1451. {
  1452. if (username == child->Attribute("username"))
  1453. {
  1454. if (password == child->Attribute("password"))
  1455. {
  1456. adm.createUser(newUser, child->Attribute("id"), child->Attribute("name"), username, password);
  1457. return newUser;
  1458. }
  1459. }
  1460. }
  1461. return NULL;
  1462. std::cin.clear();
  1463. std::cin.ignore();
  1464. }
  1465. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement