Software Development Technologies and Solutions
SharePoint | .NET | MCMS | MS SQL | Office

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:

db.JPG


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.

xml.jpg
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:

 

list.jpg

 

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

 

sur.jpg

 

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:

 

types.jpg

 

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

 

Trackbacks :
http://www.devexpert.net/blog/pt/blog/track.aspx?id=6
Building a Complete ASP.NET Survey Engine Based on XML WebSurvey
Comment By Tony M. At 5/4/2007 6:31 PM
it is great.
Comment By Iqbal Raheem At 5/5/2007 2:14 PM
Hi,

I was looking for a survey system long time s go
and -thanks god - finally I found it here, however I still facing one issue that this code has written on VS 2003 and I try to convert it to VS 2005 with no success there was some errors specially on the XML controls.
Do you have any tips on how to convert it or any other solution to make it work on VS 2005?
That will be helpful for me.

Finally I am really happy to see a Saudi gay like you how have all of this information and professionally as well.
Comment By Mansour At 6/9/2007 3:09 AM
:) thanks for your nice word, Actually I'm Egyptian GUY not Saudi GAY ;)but working in Saudi, I'm planning to release ASP.NET 2.0 version in the near future ISA

Regards...
Comment By Mahdi Abdulhamid At 6/9/2007 1:06 PM
Hi
Saudis and Egyptians are just partners with no different :P, I still pride of you.
I am waiting the 2.0 release

Best Regards,
Mansour
Comment By Mansour At 6/17/2007 2:46 AM
Comments :
Name :
Email :
URL :
       
Comments :
Allowed Tags : <A>, <B>, <I>, <BLOCKQUOTE>