About Me

My photo
Hello, I'm a technology geek looking to upgrade my programming skills. These are some of the things I'm learning along my journey.

Monday, July 23, 2012

Create a Basic Quiz Engine (part 3)

This is a continuation of "Create a Basic Quiz Engine (part2)".

Let's add some more functionality to this quiz engine.

Example:

Quiz Engine Requirements
User is greeted is required to log into the program before entering.
The user ID from the Splash page is passed to the Question page.
The quiz displays percentage correct.









Add the pages, controls, files and databases necessary to complete the project.

    Example:

    -Splash Page 
    --text box to enter user name
    --text box to enter user password
    -Question page
    --total percentage correct label
    -Quiz Database 
    --User Profile Table
    ---user id
    ---user name
    ---user password


Use the code from "Create a Basic Quiz Engine (part2)" to create a new project. Add a "UserProfile" table to the Quiz database.

Create a new table to hold the user profile with 3 columns:
user id
user name
user password

Create two text boxes on the Splash page and add logic to the button to check the user name and password before going on to the Question page.

Example:
if (strUserName.ToString() == txtUserName.Text && strUserPassword == txtPassword.Text)
  {
   bolMatch = true;
   intUserID = (int)reader[0];
   QuestionPage qp = new QuestionPage(intUserID);
   qp.Visible = true;
   this.Hide();
  }
if (!bolMatch)
  {
   MessageBox.Show("The User Name and/or Passord Does Not Match" + "\n" + "Try Again");
   txtPassword.Text = "";
   txtUserName.Text = "";
   txtUserName.Focus();
  }
Pass the User ID from the Splash page to the Question page for display.

Example:
//QuestionPage.cs
public QuestionPage(int _intUserID)
//SplashPage.cs
QuestionPage qp = new QuestionPage(intUserID);


Create a label and logic in the Question page to display the average user score.

Example:
dblAverageScore = (double)intTotalScore / QuestionRowList.Count;
                dblAverageScore = dblAverageScore * 100;
                lblAverageScore.Text = "Your average score is: " + (int)dblAverageScore + "%";
                lblAverageScore.Visible = true;



Click here for the project code. Just create a SQL Server database with test data, edit the connection string and run it.

No comments:

Post a Comment