//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using DarkWynter.Engine.Init;
using DarkWynter.Engine.Globals;
using DarkWynter.Engine.Utilities;
namespace DarkWynter.App.Surveys
{
public class Survey
{
public int ID;
public static List questionList;
public static List SurveyList;
public static string surveyName;
public Survey(string xmlFile)
{
// Load the G2L PrePostSurvey
SurveyList = new List();
try
{
// Load Surveys
XmlDocument reader = new XmlDocument();
reader.Load(xmlFile);
XmlNodeList allNodes = reader.ChildNodes;
foreach (XmlNode settingsNode in allNodes)
{
if (settingsNode.Name == "QuestionSet")
{
if (settingsNode.Attributes["name"] != null)
{
surveyName = settingsNode.Attributes["name"].Value;
XmlNodeList settingsNodes = settingsNode.ChildNodes;
foreach (XmlNode node in settingsNodes)
{
if (node.Name == "ProblemSet")
{
SurveyList.Add(node);
}
}
}
}
}
}
catch
{
System.Diagnostics.Debug.WriteLine("Error reading xml");
throw new Exception("Error reading XML");
}
questionList = new List();
// Add all questions contained in this xml survey file
for (int i = 0; i < SurveyList.Count; i++)
{
questionList.Add(new Question(SurveyList[i]));
}
}
public string Validate()
{
string validationText = "";
for (int x = 0; x < questionList.Count; x++)
{
bool answered = false;
for (int i = 0; i < questionList[x].answers.Count; i++)
{
if (questionList[x].answers[i].Checked)
{
answered = true;
break;
}
}
if (!answered)
{
validationText += "Please answer question number: " + (x + 1) + "\n";
}
}
return validationText;
}
public void Save()
{
Logging.G2LSurveyLog.Clear();
for (int i = 0; i < questionList.Count; i++)
{
Logging.G2LSurveyLog.Add(questionList[i].problem.ToString());
questionList[i].Save();
}
}
}
}