Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace QCM
  12. {
  13.     public partial class QCM : Form
  14.     {
  15.         int[] indexquestion = new int[10]; //J'utilise un tableau pour retrouver l'index des differentes questions qui seront passées.
  16.         int position = 0; //J'utilise la position pour retrouver la bonne position d'index si dessus.
  17.         Points points = new Points(); //Je crée une instance de la classe points.
  18.         bool testFini=false;
  19.  
  20.         public QCM()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void QcmText() //Affichage de la question et des réponses.
  26.         {
  27.             LBL_question.Text = Global.ListeQuestion()[indexquestion[position]].Questions;
  28.             RADIO_rep1.Text = Global.ListeQuestion()[indexquestion[position]].Rep1;
  29.             RADIO_rep2.Text = Global.ListeQuestion()[indexquestion[position]].Rep2;
  30.             RADIO_rep3.Text = Global.ListeQuestion()[indexquestion[position]].Rep3;
  31.             RADIO_rep4.Text = Global.ListeQuestion()[indexquestion[position]].Rep4;
  32.             RADIO_rep1.Checked = false;
  33.             RADIO_rep2.Checked = false;
  34.             RADIO_rep3.Checked = false;
  35.             RADIO_rep4.Checked = false;
  36.         }
  37.  
  38.         private void QCM_Load(object sender, EventArgs e)//On remplis le tableau d'index à l'ouverture du formulaire et l'ont affiche la première question ainsi que les premières questions.
  39.         { //Le "Lotto" se fait ici pour remplir le tableau.
  40.             this.Text = "[" + (position + 1) + "/10] - " + Global.etudiantEnCour.Nom + " " + Global.etudiantEnCour.Prenom;
  41.             Random rnd1 = new Random();
  42.  
  43.             indexquestion[0] = rnd1.Next(0, 14);
  44.  
  45.             for (int i = 1; i < 10; i++)
  46.             {
  47.                 indexquestion[i] = rnd1.Next(0, 14);
  48.                 for (int j = i - 1; j >= 0; j--)
  49.                 {
  50.                     if (indexquestion[i] == indexquestion[j])
  51.                     {
  52.                         i--;
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.             QcmText();
  58.  
  59.         }
  60.  
  61.         private void BUT_OK_Click(object sender, EventArgs e) //Ajout des points via la fonctions addpoints si l'élève as bien répondu.
  62.         {
  63.             if (Global.ListeQuestion()[indexquestion[position]].BonneRep == 1 & RADIO_rep1.Checked == true)
  64.             {
  65.                 points.addpoint();
  66.             }
  67.             else if (Global.ListeQuestion()[indexquestion[position]].BonneRep == 2 & RADIO_rep2.Checked == true)
  68.             {
  69.                 points.addpoint();
  70.             }
  71.             else if (Global.ListeQuestion()[indexquestion[position]].BonneRep == 3 & RADIO_rep3.Checked == true)
  72.             {
  73.                 points.addpoint();
  74.             }
  75.             else if (Global.ListeQuestion()[indexquestion[position]].BonneRep == 4 & RADIO_rep4.Checked == true)
  76.             {
  77.                 points.addpoint();
  78.             }
  79.  
  80.             if (position == 9) //si l'étudiant arrive à la dernière question
  81.             {
  82.                 if (points.Pointstest == 0) { points.Appreciation = "Nul"; }
  83.                 else if (points.Pointstest >= 1 & points.Pointstest <= 4) { points.Appreciation = "Insuffisant"; }
  84.                 else if (points.Pointstest == 5) { points.Appreciation = "Suffisant"; }
  85.                 else if (points.Pointstest >= 6 & points.Pointstest <= 7) { points.Appreciation = "Bien"; }
  86.                 else if (points.Pointstest == 8 & points.Pointstest == 9) { points.Appreciation = "Très bien"; }
  87.                 else if (points.Pointstest == 10) { points.Appreciation = "Excellent"; }
  88.                 MessageBox.Show("Test terminé par " + Global.etudiantEnCour.Nom + " " + Global.etudiantEnCour.Prenom + "." + Environment.NewLine + Environment.NewLine + "Il as eu un résultât de " + points.Pointstest + "/10 ce qui est " + points.Appreciation + ".");
  89.                 testFini = true;
  90.                 Application.Exit();
  91.             }
  92.             else //Temps que l'élève n'est pas à la dernière question
  93.             {
  94.                 position++;
  95.                 this.Text = "[" + (position + 1) + "/10] - " + Global.etudiantEnCour.Nom + " " + Global.etudiantEnCour.Prenom;
  96.                 QcmText();
  97.             }
  98.         }
  99.  
  100.         private void QCM_FormClosing(object sender, FormClosingEventArgs e) //Si l'élève tente de fermer l'application avant d'avoir finis son test
  101.         {
  102.             if (testFini == false)
  103.             {
  104.                 DialogResult dialogResult = MessageBox.Show("Voulez vous vraiment abandonner se test", " Abandonner", MessageBoxButtons.YesNo);
  105.                 if (dialogResult == DialogResult.Yes)
  106.                 {
  107.                     if (points.Pointstest == 0) { points.Appreciation = "Nul"; }
  108.                     else if (points.Pointstest >= 1 & points.Pointstest <= 4) { points.Appreciation = "Insuffisant"; }
  109.                     else if (points.Pointstest == 5) { points.Appreciation = "Suffisant"; }
  110.                     else if (points.Pointstest >= 6 & points.Pointstest <= 7) { points.Appreciation = "Bien"; }
  111.                     else if (points.Pointstest == 8 & points.Pointstest == 9) { points.Appreciation = "Très bien"; }
  112.                     else if (points.Pointstest == 10) { points.Appreciation = "Excellent"; }
  113.                     MessageBox.Show("Test abandonné par " + Global.etudiantEnCour.Nom + " " + Global.etudiantEnCour.Prenom + "." + Environment.NewLine + Environment.NewLine + "Il as eu un résultât de " + points.Pointstest + "/10 ce qui est " + points.Appreciation + ".");
  114.                 }
  115.                 else if (dialogResult == DialogResult.No)
  116.                 {
  117.                     e.Cancel = true;
  118.                 }
  119.             }
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement