예제 #1
0
 /// <summary>
 /// Ajoute un QCM
 /// </summary>
 /// <param name="titreQCM">Titre du QCM</param>
 /// <param name="levelQCM">Niveau du QCM</param>
 public void InsertQCM(string titreQCM, int levelQCM)
 {
     Qcm = new QCMDatas(GetNextIdQCM(), titreQCM, levelQCM, Modes.Create);
     Qcm.NextIdMotCle   = 1;
     Qcm.NextIdQuestion = 1;
     Qcm.NextIdReponse  = 1;
 }
예제 #2
0
파일: DAO.cs 프로젝트: cedricdrrnm/TPI_QCM
        /// <summary>
        /// Sélectionne un QCM par son id
        /// </summary>
        /// <param name="idQCM">Id du QCM</param>
        /// <returns>QCM</returns>
        public QCMDatas SelectQCMById(int idQCM)
        {
            //Open connection
            try
            {
                OpenConnection();
                string query = "SELECT `idQCM`, `nomQCM`, `level` FROM `qcm` WHERE `idQCM` = @idQCM;";

                //Create a QCMModele to store the result
                QCMDatas qcmModele = null;

                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, Conn);

                //Parameters
                cmd.Parameters.AddWithValue("@idQCM", idQCM);

                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    qcmModele = new QCMDatas(dataReader.GetInt32("idQCM"), dataReader.GetString("nomQCM"), dataReader.GetInt32("level"), Modes.AddedInBase);
                }
                dataReader.Close();
                CloseConnection();

                if (qcmModele != null)
                {
                    qcmModele.DictMotCle         = SelectAllMotCleByIdQCM(idQCM);
                    qcmModele.DictQuestionModele = SelectAllQuestionByIdQCM(idQCM);
                    foreach (KeyValuePair <int, QuestionDatas> item in qcmModele.DictQuestionModele)
                    {
                        item.Value.DictReponseModele = SelectAllReponseByIdQuestion(item.Key);
                    }

                    Dictionary <string, int> auto_increment_value = SelectAutoIncrement();
                    int _nextID;

                    if (auto_increment_value.TryGetValue("motcle", out _nextID))
                    {
                        qcmModele.NextIdMotCle = _nextID;
                    }
                    if (auto_increment_value.TryGetValue("question", out _nextID))
                    {
                        qcmModele.NextIdQuestion = _nextID;
                    }
                    if (auto_increment_value.TryGetValue("reponse", out _nextID))
                    {
                        qcmModele.NextIdReponse = _nextID;
                    }
                    if (auto_increment_value.TryGetValue("qcm", out _nextID))
                    {
                        NextIdQCM = _nextID;
                    }
                    //return list to be displayed
                    return(qcmModele);
                }
                return(qcmModele);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }