Files
BasicsOfComputerSoftwareEng…/大作业/StudentInfoManager.hpp
2023-06-23 22:13:32 +08:00

96 lines
2.3 KiB
C++

#pragma once
#include "ListDisplay.hpp"
#include "ListE.hpp"
#include "Record.hpp"
#include <ctime>
#include <filesystem>
#include <string>
namespace infoManagerCommand {
namespace home {
enum cmd {
newRecord,
removeRecord,
modifyRecord,
setFilter,
unsetFilter,
setSortBy,
flipSortOrder,
nextPage,
prevPage,
help,
saveFile,
closeFile,
quit,
unknown
};
}
namespace promptFileName {
enum cmd { openFile, newFile, unknown };
}
namespace promptSaveBeforeClose {
enum cmd { save, noSave };
}
namespace promptNewRecord {
enum cmd { lateRecord, absentRecord, PersonalLeaveRecord, unknown };
}
namespace promptNewInfo {
enum cmd { date, courseName, studentInfo, unknown };
}
namespace filterSettings {
enum cmd {
fromDate = 1,
toDate,
courseName,
studentID,
studentName,
recordType,
};
}
namespace sortbySettings {
enum cmd { recordID = 1, date, courseName, studentID, studentName, recordType };
}
} // namespace infoManagerCommand
class StudentInfoManager {
private:
List<BaseRecord *> recordPtrList;
std::filesystem::directory_entry file;
ListDisplay displayer;
bool hasChangePendingSave;
// Open the file in this->file. Assumes that the file exists.
void readFile();
// Save the file to this->file. If the file does not exists, create one; if
// such exists, overwrite.
void saveFile();
// Reset this->file, and reset BaseRecord::nextRecordID
void closeFile();
// Prompt for "open file name" or "new file name". Returns true if user
// selected open file and needs to call readFile(); returns false if user
// selects new file and no call to readFile() is needed.
bool promptForFileName();
// The following functions are for handling commands user typed in. Returns
// true when user goes deeper and finally selected a command. Returns false
// if user typed 'esc' to quit.
// The base for listening command.
bool cmdNew();
bool cmdRemove();
bool cmdModify();
bool cmdSetFilter();
bool cmdSetSortby();
void displayHelp();
public:
// Use when no command line argument exists
StudentInfoManager();
// Use when has command line argument
StudentInfoManager(const std::string _fileName);
void mainloop();
~StudentInfoManager();
};