Google Search

Google
 

Thursday, May 29, 2008

Video: Building a Quiz Engine 3 C#

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will continue the work on the Quiz Engine, adding the ability to save test results and other functionality. This will allow you to exercise the skills developed in the earlier videos.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

This video to your discussion oh the ASP net 2 0 quiz engine that we ve been working on one single look at snapshot number four and we had two basic goals for the snapshot the first goal was to tackle the saving of the test results into the database so to set up a scenario again the usual come in selected tasks to take to wind up on the questions aspx page or recall from there the bookkeeping the next button effort to make the selection for the correct answer and as a gift to the end of the questions Bill Clinton as results aspx page which will display each of their selections and weather was correct or incorrect by selecting the little link to the left hand side will be able to then view to the particulars for that given question posted a question text all the possible answers and in which the
Minute 1

The correct answer and finally a textual explanation as to why that particular answer was a right or wrong about this one time only been displaying the results we haven t saved the results back into our quiz i database so that s one of the things that we needed to for this snapshot and after we said the results to the database will need to display them you recall from our discussion in the previous two videos were going to test the display those here in on the default aspx page under test results history so will display what the quiz name was whether when it was completed to date and time of the correct answer count and a number of questions and ideally we would want to display the percentage corrected softener mockup however we ll talk with us in just a moment Iran is in problems in terms of
Minute 2

How did you get that information displayed out let s step back and look at our results aspx page particularly the code that will save our test results into our database single look at the results aspx CS file ends at the fuels take a look at our page load were to make sure first of all to only review the code from 121 to approximately 35 where were checking to make sure that were not posting back so this is should only run the very first time that the page is displayed to the user in case not any subsequent times the user may click on the little links next to individual questions that so basically here will want to do is create a new SQL data source as a look at this is an example of creating a data source purely through code at this point we ll then dragging and dropping the data source either from a toolbox or
Minute 3

Going to our own art data menu item to create a new SQL data source in this case with his accrued from scratch Remus set the connection string and the insert command and then set the insert parameters are using the insert parameters add method to insert up first of all the name of the parameter the value of the parameter and if each one and notice that these parameters these four primers we ve listed are contained in our insert command through the simple use of an ad symbol before the name of the parameter that we want to identify and so the quiz ID daytime complete correct answer counting username all correspond to these input parameters that we have specified here within the value section of our insert SQL commands and then we simply call
Minute 4

The insert command of our SQL data store s now unfortunately I chose a bad name will correct this in the next snapshot I just want to see this work and I kind of got stuck in using it will remain will respect for it so that it is a given a more appropriate name however after testing this it was very simple to use this this SQL data source to set insert command set the parameters and then insert the record in the database improves versions of video net it would not have been quite as simple so this is a welcome improvement to the other data access model so now that we successfully save the data in the database were going to need to display the results to the user back on our default aspx page of the first low stock started to talk the page you can see here that I had
Minute 5

Data bound the available tests I set the SQL data source to basically just full all of the does the title from the quiz because now the first challenge that IE came to was that I realized I might want to display some additional information about each of us has that I wanted to make available so right now I simply have a title but perhaps many more information for example a description on so this really forced me to first of all reconsider my quiz tables designed so we may need to come back to that but as a first pass I was able these bind the title to a listing hearing will notice that I also need to then Chris insert a hyperlink that when you click it will send the user to the start page so we haven t done that yet and the reason we haven t done that because I ran the little bit of a problem that caused me to rethink a lot of things
Minute 6

Grid on the default aspx page the test results history my biggest challenge in this snapshot was performing the calculation of the percentage correct in the test results history as once you have the final two columns correct answer count the number of questions displayed for performing a third calculation world actually get a percentage grew to be a little bit challenging now if I m only storing the total number of correct answers I have to pare that up with the total number of questions on a given test an estimate of probably require pretty hairy query on my part and I went down that path also what came up with but I think it can be a eye thing to be done and but then I still had to figure out a way to perform the percentage calculation you in the SQL query or the control itself after spinning off 15 minutes 30 minutes looking at it and thinking of solutions for ads decided that made any disgruntled that an brief think
Minute 7

The user quiz tables design with a look at the data source for sure the direction I was heading down before I came to this conclusion Solana click configure data source were going to then here take a look at the select statement I actually use according older to help design is however you can see it so convoluted this point accord builder can help me out essentially what wanted to do was attempt to join the user quiz table to the quiz table on the quiz ID field for that s what this one the sequel does many as you can see I tried to on to account of the number of questions for a given quiz and in all the rest of the information from user quiz like the daytime complete the correct answer count of this title and so on and then needed to group buying is a having statement as well and so this was again fairly complex is
Minute 8

A lot of time and in one of schema wills it never quite the me the results that I really needed as a vested tip whenever you find yourself really fighting the tool you may want to think that am I doing the right thing here maybe there s more simple solution only to rethink how going about this that would make life a lot easier so I decided that I needed a fundamental step back and rethink the database design and think how I want to save data into the database so that I can display it a little more simply than having to jump through so many hoops in order to add or if the data into this test results history so I stopped what I was doing on snapshot number four to the snapshot will probably not work completely if you were loaded up and try to execute yourself or Cartwright so I put her menopause decided go back to the drawing board and work on snapshot five where we think the database structure and the underlying code to suck
Minute 9

That so will snapshot number five this snapshot started with me working on the database layout so if you look at the database Explorer and look it out first of all the quiz tabled to notice that I simply added a new description field believe that some public bar charm acts or something along those lines as little as opened up the table definition i see yes indeed it s far from acts and it s also noble and I say that I did was I I made a change to the user quiz table you ll notice that essentially is exactly the same tide change though from the number of correct question
Minute 10

Is to the concept of the score s was going to look at the definition for this table and can see it s a tiny and so this will be of value that will equate to basically zero to a hundred a simple percentage so if there were for example on the 20 questions in quiz and the user answered 15 of those correctly their score would be 75 and that s more in line with how we think about tests in terms of percentages corrects instead of a looking at in no 15 questions correct out a possible 20 and have you do the math in Rome had so that is what I decided to do to take that route again if this is something that is a suit your needs and plenty uses the future is simply added a few more fields to to record the number of phone correct answers versus the number of
Minute 11

Total questions on a given quiz okay so there were several things that needed a change from the previous snapshot or accommodate this will starts first of all and how we re displaying information now notice that I really upgraded the available tests on a data list that I was using from the previous snapshot I essentially a selected the edit template of selection in order to change the item template so you ll see here that I used a hyperlink and a label and although it doesn t really show up as we re working in this item template mode on I set the cascading stylesheet classes so that they ll be displayed in such a way that has that attractive on a formatting that my graphic artist friend of great form
Minute 12

Inc and then basically bound these two are data source and I expanded the data source to include not only the title from our quiz table but also the description which will now display in the description label head Inc and just end to split editing can see to see here that what look like when it s finished as we will run it and then we move onto the test results history you can see now is a much more simplified grid were not have the title of the quiz when it was completed to date timestamp and then finally the score of the twists and to contradict this stick a look at the data source and we have a much more simplified SQL statement now that we work with
Minute 13

We are still going to create a joint in between user quiz and the quiz table but the data that we needed to a select from happening aggregations and so that greatly simple five things Cisco and Castle lists now I d be remiss if I didn t also go before we run this application show you the other changes that were made as well in fact the change that we made affected pre much every page in the site for sample I went ahead and link job the available tests to the start page so that when a user selects one of the available tests it will pull up the start page guide and how to we do this we need to not only sends a request as such Little League
Minute 14

To the start page but we need to send a witch test that the user is interested in taking Solis revisits what we ve done here go back to the edit templates select our hyperlink and to go to the properties and you will notice that the text is a bound property also the navigate your allies about properties as well and I don t really want to to change anything about it if we look at the edit data bindings you can see that the navigate your hell I was able to do a custom binding code expression sews the Senate to start aspx So we ever query string test IDC equals and then we re going to add a eval quiz IDE does he tell statement will grasp the current data item basically whatever values
Minute 15

Are in quiz IDE according to our SQL data source or currently bound to thank Anna will insert that value into this expression signature for the text property were sadly doing and even all titled nothing special tangent here and do the same sort of thing were for the text was doing and even out description that so let s go then rushes to see what they ll look like now priceless login remembers admin and mint tea kettle PAS says fact of your key number one and click login okay so we ll see how this manifests itself you see here that I ve taken several quizzes and here s the results and you can see with the available tests are hearing when I harbor my mouse cursor over a given Quiznos at the very bottom
Minute 16

Will have the is distilled the link displayed right and appear them about to click on and notice that the test ID equals one or the test ID so are our evaluation expression of work just great that s all that work just fine so while we re going to look at next the start page home in just a moment but also won t here take a look at the test result history this was the most recent testify to to notice the score 75 some of these were scores that were saved in the database in previous runs where I ve at essentially you just change the name of the field and so it was still see the number of questions correct not the percentage so you getting nor symbols earlier tests okay so lets stop regular and then take a look at our stark agency will you do to change that
Minute 17

For small think I changed a little bit of the text you re not included but romantic happens in the stark aspx CSS file and this is where I grab the request query strain test ID issue that is not null if it is null to direct you back to the default that is the XML they got here without sending us a test ID but assuming they did give us a test ID them should wind up in lines 28 and 29 here where resistance to grab off the test ID from our per string test ID parameter save it into integer called test ID and then add that to our session so we basically removed are hardcoded number one quiz ID and replaced it with a dynamic value from the default aspx page so that s the major change we made their a single of the questions page in the sure that we made any changes here is his review of brief
Minute 18

Okay primus looks exactly the same incorrect a little problem that we had here in 135 in order make sure we hit the end of the quiz correctly than biggest change came in the results page soul single look at results of its pics LCS essentially school hadn t moved things over here the biggest change was accommodating this new concept of of a percentage instead of an absolute number of questions right a wrong answer was back at her couple lines of code and is walk through this okay social start in line approximately 27 UC first of all we need to calculate the score so we re going to grab the number of questions for the current quiz and got to keep track of the number that are correct
Minute 19

Were going to perform balloon to determine how many are correct and incorrect answer with a loop through each of the items within our answer lists which is essentially an array list cast those too tight answer and then check the value of the results and you ll notice here that you may have expected a literal string corrector ran correct full salute dad about that didn t want to use a magic strings instead chose to change to enumeration we jump over here to the answer CS file go to the very bottom and you can see that I have created a new result value enumeration that I use in my read only result value of rather result property of type result value soar you to return result value correct or result value incorrect or so evaluate that back over here in line 30
Minute 20

E738 if it s correct in all increment correct by one and then we all calculate the score by dividing the correct answers by the number of total questions and multiply that number by 100 so then the next piece of this should look similar to what we did in the previous shot I changed the name from this nebulous idea of test to a user quiz data source and so I set the connection string and the insert command for our user quiz data source changing up on our new score column and accepting use or input parameter set the input parameters of the insert parameters rather just before launch 47 to 50 and then finally to form the insert and the Summit at a small check your
Minute 21

To see and make sure that we have indeed insert rows in a database if not then I have a basically put something on our form that says there was problems saving your quiz results in your database therefore the results from the squid log displayed on the list on the Main menu and where is this error label was to go look at the results aspx page and see a design agency here that we conservative and error label which will only be displayed if there indeed is a problem solos go through the entire sequence of events now auto had run the application will loss in
Minute 22

Test and Tucker would pay attention of slowing to a quick answers to the next one and the next one in conceived acts in the stickler case I went out one correct out of a possible love for a console I also have the sole return to main menu lets see if this particular test is recorded it is and you can see my scores only 25 so that s about it for this particular video shot five at this point we does have some cleanup to do will need to reviews some of some of our code and see if there s opportunities for some exception handling will want to look into what it takes to make our applications in a bowl so that it can be customized for a column of individual users and
Minute 23

Look at what will take to deploy this application and will cover those in the next snap shots in the next video thank you

No comments: