1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Xml;
using System.ComponentModel;
namespace WindowsFormsApplication1
{
[Serializable]
public class Question
{
//ATTRIBUTS:
private int nb_choix;
private String ennonce;
private BindingList <Choix> liste_choix = new BindingList<Choix>();
//METHODES:
public Question()
{
}
public Question(int val)
{
XmlDocument doc = new XmlDocument();
doc.Load("qcm.xml");
XmlNodeList nodQuestion = doc.GetElementsByTagName("Question");
XmlNodeList node = nodQuestion[val].ChildNodes;
//initialisation de nb choix
this.ennonce = node.Item(0).InnerText;
//initialisation de nb choix
this.nb_choix = int.Parse(node.Item(1).InnerText);
//initialisation de liste choix
for (int i = 1; i <= nb_choix; i++)
{
this.liste_choix.Add(new Choix(val, i));
}
}//fin
// Accesseur ennonce Question
public String Ennonce
{
get { return this.ennonce; }
set
{
if (value.Trim().Length > 0)
this.ennonce = value;
else
throw new Exception("Ennoner question invalide!!!");
}
}//fin
// Accesseur Nombre Question
public int NbChoix
{
get { return this.nb_choix; }
set
{
if (value > 0)
this.nb_choix = value;
else
throw new Exception("Nombre question invalide!!!");
}
}//fin
//Accesseur Liste des choix
public BindingList <Choix> ListeChoix
{
get { return this.liste_choix; }
set { this.liste_choix = value; }
}//fin
// Ajouter un choix
public void AjouterChoix(Choix c)
{
if (c != null)
this.liste_choix.Add(c);
else
throw new ArgumentNullException("Ajout d'une choix non initialisée.");
}//fin
// Suppression d'une choix
public void SupprimerChoix(Choix c)
{
if (c != null)
this.liste_choix.Remove(c);
else
throw new ArgumentNullException("Suppression d'une choix non initialisée.");
}//fin
// Trouver une choix
public Choix TrouverChoix(String choix)
{
foreach (Choix c in this.liste_choix)
{
if (c.Ch_choix.Equals(choix) )
return c;
}
return null;
}//fin
// Affichage question
public override string ToString()
{
return this.ennonce;
}//fin
}
} |