コード例 #1
0
void EducationSystemDataModel::addInstructor(int id, string password, string firstName, string lastName)
{
    // Check for duplicate id
    if(isUserExists(id)){
        cout << "This user already exists" << endl;
        return;
    }

    // Add new student
    users.push_back(UserModel(id, password, firstName, lastName, 2));
}
コード例 #2
0
UserModel EducationSystemDataModel::getUserByCredentials(int id, string password, bool &exist)
{
    // Assume we don't have such user
    exist = false;

    // Iterate through users list and check for match
    list<UserModel>::iterator userItem;
    for(userItem = users.begin(); userItem != users.end(); userItem++){
        UserModel user = *userItem;
        if(user.getId() == id && user.getPassword() == password){
            // Match found
            exist = true;
            return user;
        }
    }
    return UserModel();
}
コード例 #3
0
ファイル: ModelUpdater.cpp プロジェクト: gunner14/old_rr_code
// GetStepOverall {{{
int ModelUpdater::GetStepOverall(long WORKER, long WORKERNUM, long STEP,
		int stepno, map<USERID,UserModel>& models)
{
	char* fname = "/data/xce/friendranknew/data/passport.list";
	
	long filesize = get_filesize(fname);
	assert(filesize % sizeof(int) == 0);
	long usersize = filesize / sizeof(int);
	long stepsize = (long)ceil((double)usersize / WORKERNUM);  // by user
	
	long worker_begin = (WORKER * stepsize) * sizeof(int);
	long worker_end = worker_begin + stepsize * sizeof(int);  // [worker_begin,worker_end)
	if (worker_end>filesize)
		worker_end = filesize;
	assert((worker_end-worker_begin) % sizeof(int) == 0);

	long begin = worker_begin + (stepno * STEP) * sizeof(int);
	if (begin>=worker_end)
		return -1;
	long end = begin + STEP * sizeof(int);
	if (end>=worker_end)
		end = worker_end;
	assert((end-begin) % sizeof(int) == 0);

	int* idlist = new int[STEP];
	FILE* fp = fopen(fname, "rb");
	assert(fp!=NULL);
	fseek(fp, begin, SEEK_SET);
	int idnum = fread(idlist, sizeof(int), /*STEP*/(end-begin)/sizeof(int), fp);
	fclose(fp);

	for (int i=0; i<idnum; ++i)
	{
		models.insert(make_pair<USERID,UserModel>(idlist[i], UserModel(idlist[i])));
	}
	delete[] idlist;
	return 0;
}// }}}
コード例 #4
0
ファイル: ModelUpdater.cpp プロジェクト: gunner14/old_rr_code
// GetStepInterval {{{
int ModelUpdater::GetStepInterval(long WORKER, long WORKERNUM, long STEP,
		int stepno, map<USERID,UserModel>& models)
{
	long begin = ((stepno * WORKERNUM + WORKER) * STEP) * sizeof(int);
	char* fname = "/data/xce/friendranknew/data/passport.list";
	long filesize = get_filesize(fname);
	if (begin>filesize)
		return -1;

	int* idlist = new int[STEP];
	FILE* fp = fopen(fname, "rb");
	assert(fp!=NULL);
	fseek(fp, begin, SEEK_SET);
	int idnum = fread(idlist, sizeof(int), STEP, fp);
	fclose(fp);

	for (int i=0; i<idnum; ++i)
	{
		models.insert(make_pair<USERID,UserModel>(idlist[i], UserModel(idlist[i])));
	}
	delete[] idlist;
	return 0;
}// }}}
コード例 #5
0
void MainWindow::login()
{
    Login login;
    bool loggedIn = false;
    while (!loggedIn)
    {
        if (login.exec() == QDialog::Accepted)
        {
            loggedIn = login.createUserOrLogin();
            if (!loggedIn)
            {
                QMessageBox::critical(NULL, "Could not log in", "Error logging in, please try again");
            }
        }
        else
        {
            exit(0);
        }
    }
    mUser = UserModel(login.userName());
    ui->lblUsername->setText(mUser.username());
    updateShoppingCart();
}
コード例 #6
0
void EducationSystemDataModel::loadFromFiles()
{
    // =======================================
    //       Reading users from file
    // =======================================
    ifstream usersFile(USERS_FILE);
    string userItem;
    while(getline(usersFile, userItem)){
        vector<string> fields = Utils::split(userItem, FIELD_DELIM);

        // User ID
        int id = stoi(fields[0]);
        // Password
        string password = fields[1];
        // First Name
        string firstName = fields[2];
        // Last Name
        string lastName = fields[3];
        // status (type of user)
        int status = stoi(fields[4]);

        // Add to list
        users.push_back(UserModel(id, password, firstName, lastName, status));
    }
    usersFile.close();

    // =======================================
    //       Reading courses from file
    // =======================================
    ifstream coursesFile(COURSES_FILE);
    string courseItem;
    while(getline(coursesFile, courseItem)){
        vector<string> fields = Utils::split(courseItem, FIELD_DELIM);

        // Course ID
        int id = stoi(fields[0]);
        // Name
        string name = fields[1];
        // Instructor ID
        int instructorId = stoi(fields[2]);

        // Add to list
        courses.push_back(CourseModel(id, name, instructorId));
    }
    coursesFile.close();

    // =======================================
    //       Reading takes from file
    // =======================================
    ifstream takesFile(TAKES_FILE);
    string takeItem;
    while(getline(takesFile, takeItem)){
        vector<string> fields = Utils::split(takeItem, FIELD_DELIM);

        // Course ID
        int courseId = stoi(fields[0]);
        // Instructor ID
        int instructorId = stoi(fields[1]);
        // Student ID
        int studentId = stoi(fields[2]);
        // Grade
        float grade = stof(fields[3]);

        // Add to list
        takes.push_back(TakeModel(courseId, instructorId, studentId, grade));
    }
    takesFile.close();
}