|
First, let me to thank Mr. Steve Stchur for the great XML control, and I will try in this article to express how to build a complete survey engine based on sstchur.web.survey.dll version 2.6.
You may expect that I will build this solution based on XML files, but I can’t resist my love to SQL Server, so in this article I will construct the survey engine to use SQL Server Database and XML files for just display. At the beginning, we need to build our database which contains 3 tables as the following:

If you look at the database design you will discover that I’m storing the XML into database fields! And I recall it back to XML files if the selected survey is active.
Second step is to build VS.NET project and writing our code; obviously you will notice that my code here is not commented well, so please forgive me for that, but I promise I will do my best to get some time to comment my code.
 As Websurvey designed to read from XML files, I’ve created 4 XML files to handle this job, two files as temporary and the others to display questions and collect responses from people.
As expected the most complicated part of this project is how to build and Edit a survey through parsing and modify and save XML, also to be presented in Back-end survey page. I think you may feel with this complication if you look at this part of code:
|
DataTable dt = db.GetSurveyXML(id); string surveyXML = ""; foreach(DataRow dr in dt.Rows) { surveyXML += dr["SurveyXML"].ToString(); } DataTable Sur = db.GetSurveyByID(id); lblSurveyName.Text = Sur.Rows[0]["SurveyName"].ToString(); chkActive.Checked =Convert.ToBoolean(Sur.Rows[0]["Active"].ToString()); DataTable result = GetQuestionTable(); if(surveyXML.Trim()!="") { XmlDataDocument xmlDoc =new XmlDataDocument(); xmlDoc.LoadXml(surveyXML); foreach(XmlNode nd in xmlDoc.ChildNodes[1].ChildNodes) { DataRow gdr = result.NewRow(); if(nd.Name=="Group") { gdr["id"] = nd.Attributes["id"].Value; gdr["type"] = "New Page"; result.Rows.Add(gdr); } foreach(XmlNode ind in nd.ChildNodes) { DataRow dr = result.NewRow(); switch(ind.Name) { case "Question": if(ind.Attributes["id"]!= null) { dr["id"] = ind.Attributes["id"].Value; } switch(ind.Attributes["type"].Value) { case "shortans": dr["type"] = "Text Box"; break; case "mcss": dr["type"] = "Radio Buttons"; break; case "mcms": dr["type"] = "Check Boxes"; break; case "essay": dr["type"] = "Text Area"; break; } if(ind.Attributes["required"]!= null) { dr["required"] = ind.Attributes["required"].Value; } if(ind.Attributes["layout"]!=null) { dr["Layout"] = ind.Attributes["layout"].Value; } if(ind.Attributes["cols"]!= null)
............................................................ |
Anyway, this part is just a sample, and I‘ve put all source code for download in the bottom.
You will find 4 aspx forms:
Default.aspx which will be presented to people
Result.aspx which you can see result of the survey, but I remove the survey result from front-end. I see it is better to be represented in back-end
SurveyList.aspx which list surveys in back-end
Survey.aspx which display and build and edit surveys.
The following figure showing survey list page:

And when you select a survey you will get the following page which will let you to build and edit surveys

There is an important notice here: to save survey and get it active you should press "save survey data" then press "set active"
Even if you just modify active survey items, you should set it active again after saving to get information from database to files.
now you can build your survey with questions according to the following types:

I believe that this simple web survey can be enhanced form other interested guys if they like and republish it again, just contact me if you like.
Download source code here
|