Exemplo n.º 1
0
 public void create(Unswer unswer, int questionId)
 {
     if (unswer.IsRight)
     {
         SqlLiteSimpleExecute.execute(queryConfigurator.createUnswer(questionId));
         unswer.Id = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                   execute(queryConfigurator.getObjectIdInDevelopStatus(DbTypes.unswer)));
         SqlLiteSimpleExecute.execute(queryConfigurator.setUnswerContent(unswer.Id,
                                                                         EncryptWorker.getInstance().encrypt(unswer.Content)));
         SqlLiteSimpleExecute.execute(queryConfigurator.setUnswerType(unswer.Id,
                                                                      UnswerTypes.rightUnswer));
     }
     else
     {
         SqlLiteSimpleExecute.execute(queryConfigurator.createUnswer(questionId));
         unswer.Id = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                   execute(queryConfigurator.getObjectIdInDevelopStatus(DbTypes.unswer)));
         SqlLiteSimpleExecute.execute(queryConfigurator.setUnswerContent(unswer.Id,
                                                                         EncryptWorker.getInstance().encrypt(unswer.Content)));
         SqlLiteSimpleExecute.execute(queryConfigurator.setUnswerType(unswer.Id,
                                                                      UnswerTypes.unswer));
     }
     SqlLiteSimpleExecute.execute(queryConfigurator.setApproveStatusToObject(
                                      DbTypes.unswer));
 }
Exemplo n.º 2
0
        private bool isRightUnswers(int[] unswerIds, Question question)
        {
            int requiredCount = 0;
            int rightCount    = 0;

            for (int i = 0; i < unswerIds.Length; i++)
            {
                if (isRightUnswer(unswerIds[i], question))
                {
                    rightCount++;
                }
            }
            for (int i = 0; i < question.Unswers.Count; i++)
            {
                Unswer unswer = question.Unswers.ElementAt(i);
                if (unswer.IsRight)
                {
                    requiredCount++;
                }
            }
            if (rightCount == requiredCount)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public Unswer unRestore()
        {
            Unswer unswer = new Unswer();

            unswer.Content = Content;
            unswer.Id      = Id;
            unswer.IsRight = IsRight;

            return(unswer);
        }
Exemplo n.º 4
0
 public void update(int unswerId, Unswer newVersion)
 {
     try
     {
         model.update(unswerId, newVersion);
     }
     catch (Exception ex)
     {
         ExceptionHandler.getInstance().processing(ex);
     }
 }
Exemplo n.º 5
0
        public void update(int id, Unswer newVersion)
        {
            IntHierarchy hi            = searcher.getQuestionPosition(store, id);
            int          questionIndex = -1;
            int          unswerIndex   = -1;

            if (!hi.getLastListType().Equals(new Unswer().GetType()))
            {
                throw new GoTestObjectNotFound();
            }
            else
            {
                questionIndex = hi.getChild().getChild().value;
                unswerIndex   = hi.getChild().getChild().getChild().value;
            }

            int      rightUnswersCount = 1;
            Question question          = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                                         Questions.ElementAt(questionIndex);

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                if (question.Unswers.ElementAt(i).IsRight)
                {
                    rightUnswersCount++;
                }
            }
            if (rightUnswersCount > 1)
            {
                question.QuestionsType = QuestionTypes.multiplyAnswer;
            }
            else
            {
                question.QuestionsType = QuestionTypes.singleAnswer;
            }
            newVersion.Id = store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
                            Questions.ElementAt(questionIndex).Unswers.ElementAt(unswerIndex).Id;
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.ElementAt(questionIndex).Unswers.
            RemoveAt(unswerIndex);
            store.ElementAt(hi.value).Tests.ElementAt(hi.getChild().value).
            Questions.ElementAt(questionIndex).Unswers.
            Insert(unswerIndex, newVersion);


            notifyObservers();
        }
Exemplo n.º 6
0
        public void addEmptyUnswer(int questionId)
        {
            Test test = getCurrentTest();

            for (int i = 0; i < test.Questions.Count; i++)
            {
                if (test.Questions.ElementAt(i).Id == questionId)
                {
                    Unswer newUnswer = new Unswer();
                    newUnswer.Id = currentNewObjectIndex;
                    test.Questions.ElementAt(i).Unswers.Add(newUnswer);
                    currentNewObjectIndex--;
                    notifyObservers();
                    return;
                }
            }
            throw new GoTestObjectNotFound();
        }
Exemplo n.º 7
0
 private bool isRightUnswer(int unswerId, Question question)
 {
     for (int i = 0; i < question.Unswers.Count; i++)
     {
         Unswer unswer = question.Unswers.ElementAt(i);
         if (unswer.Id == unswerId)
         {
             if (unswer.IsRight)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     throw new GoTestObjectNotFound();
 }
Exemplo n.º 8
0
 public void update(Unswer unswer)
 {
     if (DataSetConverter.fromDsToSingle.toInt.convert(
             SqlLiteSimpleExecute.execute(queryConfigurator.countOfObject(unswer.Id))) == 0)
     {
         throw new ObjectIsNotExistYet();
     }
     if (unswer.IsRight)
     {
         SqlLiteSimpleExecute.execute(queryConfigurator.updateUnswerContent(
                                          unswer.Id, EncryptWorker.getInstance().encrypt(unswer.Content)));
         SqlLiteSimpleExecute.execute(queryConfigurator.updateUnswerType(
                                          unswer.Id, DbObjects.rightUnswer));
     }
     else
     {
         SqlLiteSimpleExecute.execute(queryConfigurator.updateUnswerContent(
                                          unswer.Id, EncryptWorker.getInstance().encrypt(unswer.Content)));
         SqlLiteSimpleExecute.execute(queryConfigurator.updateUnswerType(
                                          unswer.Id, DbObjects.unswer));
     }
 }
Exemplo n.º 9
0
        public Unswer load(int id)
        {
            Unswer unswer = new Unswer();

            unswer.Id = id;
            string lastQuery = "";

            try
            {
                lastQuery      = queryConfigurator.loadUnswerContent(id);
                unswer.Content = EncryptWorker.getInstance().decrypt(
                    DataSetConverter.fromDsToSingle.toString.convert(SqlLiteSimpleExecute.
                                                                     execute(queryConfigurator.loadUnswerContent(id))));
                lastQuery = queryConfigurator.loadUnswerTypeId(id);
                int typeId = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                           execute(queryConfigurator.loadUnswerTypeId(id)));
                lastQuery = queryConfigurator.getObjectName(typeId);
                string type = DataSetConverter.fromDsToSingle.toString.convert(SqlLiteSimpleExecute.
                                                                               execute(queryConfigurator.getObjectName(typeId)));
                if (type.Equals(DbObjects.rightUnswer.getName()))
                {
                    unswer.IsRight = true;
                    return(unswer);
                }
                if (type.Equals(DbObjects.unswer.getName()))
                {
                    unswer.IsRight = false;
                    return(unswer);
                }
            }
            catch (СonversionError err)
            {
                throw new СonversionError("Ошибка при обработке запроса:" + lastQuery +
                                          ". Обратитесь к администратору");
            }
            throw new ParamsTypesExceptions();
        }
Exemplo n.º 10
0
 public void restore(Unswer unswer)
 {
     Content = unswer.Content;
     Id      = unswer.Id;
     IsRight = unswer.IsRight;
 }
Exemplo n.º 11
0
 public VUnswer(int position, Unswer unswer)
 {
     this.position = position;
     restore(unswer);
 }