/// <summary> /// Loads user record data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void LoadRecord(object sender, EventArgs e) { UserRecords record = new UserRecords(textBoxFirstName.Text, textBoxLastName.Text); //Creates an object with the first and last name entered. record.LoadUserRecord(record); //Retrives the record associated with the username and passes the created object to retrieve the record data. if (!record.Exists) //Checks if user record exists. { Label[] labels = { lblName, lblPreviousPhoneticScore, lblTopPhoneticScore, lblPhoneticAssessmentsAttempted, lblPreviousSyllabaryScore, lblTopSyllabaryScore, lblSyllabaryAssessmentsAttempted, lblPreviousEnglishScore, lblTopEnglishScore, lblEnglishAssessmentsAttempted, lblLearnerLevel }; foreach (Label label in labels) { label.Visible = false; //Hides all labels since no information is available to display. } lblName.Text = "Record does not exist"; //Changes label to show that the record does not exist. lblName.Visible = true; //Makes the label visible. } else //If the user record exists all data displayed. { Label[] labels = { lblName, lblPreviousPhoneticScore, lblTopPhoneticScore, lblPhoneticAssessmentsAttempted, lblPreviousSyllabaryScore, lblTopSyllabaryScore, lblSyllabaryAssessmentsAttempted, lblPreviousEnglishScore, lblTopEnglishScore, lblEnglishAssessmentsAttempted, lblLearnerLevel }; foreach (Label label in labels) { label.Visible = true; //Makes the labels visible so the retrieved records can be displayed. } lblName.Text = record.Firstname + " " + record.Lastname; lblPreviousPhoneticScore.Text = "Previous Score: " + record.PreviousPhoneticScore; lblTopPhoneticScore.Text = "Top Score: " + record.TopPhoneticScore; lblPhoneticAssessmentsAttempted.Text = "Assessments Attempted: " + record.AttemptedPhoneticAssessments; lblPreviousSyllabaryScore.Text = "Previous Score: " + record.PreviousSyllabaryScore; lblTopSyllabaryScore.Text = "Top Score: " + record.TopSyllabaryScore; lblSyllabaryAssessmentsAttempted.Text = "Assessments Attempted: " + record.AttemptedSyllabaryAssessments; lblPreviousEnglishScore.Text = "Previous Score: " + record.PreviousEnglishScore; lblTopEnglishScore.Text = "Top Score: " + record.TopEnglishScore; lblEnglishAssessmentsAttempted.Text = "Assessments Attempted: " + record.AttemptedEnglishAssessments; lblLearnerLevel.Text = "Level: " + record.LearnerLevel; } }
/// <summary> /// Loads and deserializes the user record. /// </summary> public void LoadUserRecord(UserRecords _record) { IFormatter formatter = new BinaryFormatter(); string path; if (Program.recordsFoldersFound) { path = Program.portableVersion ? Program.recordsFolderLocationPortable + Firstname + Lastname + "Record.txt" : Program.recordsFolderLocation + Firstname + Lastname + "Record.txt"; } else { path = Properties.Settings.Default.customRecordsPath + Firstname + Lastname + "Record.txt"; } if (File.Exists(path)) { Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read); _record = (UserRecords)formatter.Deserialize(stream); Firstname = _record.Firstname; Lastname = _record.Lastname; PreviousPhoneticScore = _record.PreviousPhoneticScore; TopPhoneticScore = _record.TopPhoneticScore; AttemptedPhoneticAssessments = _record.AttemptedPhoneticAssessments; PreviousEnglishScore = _record.PreviousEnglishScore; TopEnglishScore = _record.PreviousEnglishScore; AttemptedEnglishAssessments = _record.AttemptedEnglishAssessments; PreviousSyllabaryScore = _record.PreviousSyllabaryScore; TopSyllabaryScore = _record.TopSyllabaryScore; AttemptedSyllabaryAssessments = _record.AttemptedSyllabaryAssessments; LearnerLevel = _record.LearnerLevel; Exists = true; stream.Close(); } else { Exists = false; } }
/// <summary> /// Saves the user record in a serialized file to reduce ease of data manipulation. /// </summary> public void SaveUserRecord(UserRecords _record) { IFormatter formatter = new BinaryFormatter(); //Create a method to store the record to a file. string username = Firstname + Lastname; if (username != "") { string path; if (Program.recordsFoldersFound) { path = Program.portableVersion ? Program.recordsFolderLocationPortable + username + "Record.txt" : Program.recordsFolderLocation + username + "Record.txt"; } else { path = Properties.Settings.Default.customRecordsPath; } Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write); formatter.Serialize(stream, _record); stream.Close(); } }