Example #1
0
        public Subject getSubjectFromBD(int id)
        {
            string name = DataSetConverter.fromDsToSingle.toString.convert(SqlLiteSimpleExecute.
                                                                           execute(queryConfigurator.getObjectName(id)));

            return(subjectManipulator.load(name, true, true));
        }
Example #2
0
        public Question load(int id)
        {
            Question question = new Question();

            question.Id = id;
            question.QuestionsContent = EncryptWorker.getInstance().decrypt(
                DataSetConverter.fromDsToSingle.toString.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.loadQuestionContent(id))));
            int[] unswersIds = DataSetConverter.fromDsToBuf.toIntBuf.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.loadQuestionUnswersIds(id)));

            question.Unswers = new List <Unswer>();
            for (int i = 0; i < unswersIds.Count(); i++)
            {
                question.Unswers.Add(unswerManipalator.load(unswersIds[i]));
            }

            int questionTypeId = DataSetConverter.fromDsToSingle.toInt.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.loadQuestionTypeId(id)));
            string questionType = DataSetConverter.fromDsToSingle.toString.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.getObjectName(questionTypeId)));

            if (questionType.Equals(QuestionTypes.multiplyAnswer.getType()))
            {
                question.QuestionsType = QuestionTypes.multiplyAnswer;
                return(question);
            }
            if (questionType.Equals(QuestionTypes.singleAnswer.getType()))
            {
                question.QuestionsType = QuestionTypes.singleAnswer;
                return(question);
            }

            throw new ParamsTypesExceptions();
        }
Example #3
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));
 }
Example #4
0
        public Test load(int testId, bool loadAllQuestions, bool loadOnlyTestNames)
        {
            Test test = new Test();

            test.Id   = testId;
            test.Name = EncryptWorker.getInstance().decrypt(
                DataSetConverter.fromDsToSingle.toString.
                convert(SqlLiteSimpleExecute.execute(queryConfigurator.loadTestName(testId))));
            if (!loadOnlyTestNames)
            {
                test.QuestionsNumber = DataSetConverter.fromDsToSingle.toInt.
                                       convert(SqlLiteSimpleExecute.
                                               execute(queryConfigurator.loadTestQuestionCount(testId)));

                test.RequeredUnswersNumber = DataSetConverter.fromDsToSingle.toInt.
                                             convert(SqlLiteSimpleExecute.execute(queryConfigurator.
                                                                                  loadTestRequiredQuestionCount(testId)));

                int[] questionsIds = DataSetConverter.fromDsToBuf.toIntBuf.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.loadTestQuestionIds(testId)));
                if (loadAllQuestions)
                {
                    test.Questions = questionsGetter.get(questionsIds);
                }
                else
                {
                    test.Questions = questionsGetter.get(questionsIds,
                                                         test.QuestionsNumber);
                }
            }

            return(test);
        }
Example #5
0
 public void createTables()
 {
     //Previous delete all tables
     string[] querys = queryConfigurator.clearDataBase();
     for (int i = 0; i < querys.Count(); i++)
     {
         try
         {
             SqlLiteSimpleExecute.execute(querys[i]);
         }
         catch (Exception ex)
         {
             if (!ex.Message.Contains("SQL logic error\r\nno such table"))
             {
                 ExceptionHandler.getInstance().processing(ex);
             }
         }
     }
     //Create tables
     querys = queryConfigurator.createDataBase();
     for (int i = 0; i < querys.Count(); i++)
     {
         try
         {
             SqlLiteSimpleExecute.execute(querys[i]);
         }
         catch (Exception ex)
         {
             ExceptionHandler.getInstance().processing(ex);
         }
     }
 }
Example #6
0
        public void changeUserPassword(string oldPassword, string newPassword)
        {
            if (currentUser.isEnterIntoSystem())
            {
                string currentPassword = hashWorker.getHash(oldPassword, getSultForCurrentUser());

                if (DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(queryConfigurator.checkUser(
                                                         currentUser.getLogin(), currentPassword))) == 1)
                {
                    SqlLiteSimpleExecute.execute(
                        queryConfigurator.changePassword(currentUser.getLogin(),
                                                         hashWorker.getHash(newPassword, getSultForCurrentUser())));

                    currentUser.setPassword(newPassword);

                    InformationPopupWindow       view   = new InformationPopupWindow();
                    InformationPopupWindowConfig config = new InformationPopupWindowConfig(
                        "Пароль успешно изменен");
                    view.setConfig(config);
                    view.show();
                }
                else
                {
                    throw new IncorrectOldPassword("Exception: old password is not a right");
                }
            }
            else
            {
                throw new InsufficientPermissionsException("This user does not"
                                                           + "have sufficient rights to perform the specified operation");
            }
        }
Example #7
0
        private void deleteSelf()
        {
            GoTestQueryConfiguratorI queryConfigurator = new GoTestQueryConfigurator();

            SqlLiteSimpleExecute.execute(queryConfigurator.deleteObjectReferences(id));
            SqlLiteSimpleExecute.execute(queryConfigurator.deleteObjectParameters(id));
            SqlLiteSimpleExecute.execute(queryConfigurator.deleteObjectFromObjectsTable(id));
        }
Example #8
0
        private string getSultForCurrentUser()
        {
            int id = DataSetConverter.fromDsToSingle.toInt.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.getUserId(
                                                 currentUser.getLogin())));
            string currentSult = DataSetConverter.fromDsToSingle.toString.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.getSult(id)));

            return(currentSult);
        }
        public void create(Subject subject)
        {
            SqlLiteSimpleExecute.execute(queryConfigurator.createSubject(
                                             EncryptWorker.getInstance().encrypt(subject.Name)));
            for (int i = 0; i < subject.Tests.Count; i++)
            {
                testManipulator.create(subject.Tests.ElementAt(i), subject.Id);
            }

            SqlLiteSimpleExecute.execute(queryConfigurator.setApproveStatusToObject(
                                             DbTypes.subject));
        }
Example #10
0
        public void loadTestForTesting(int testId)
        {
            Subject newSubject = new Subject();

            newSubject.Id = DataSetConverter.fromDsToSingle.toInt.
                            convert(SqlLiteSimpleExecute.execute(queryConfigurator.loadSubjectId(testId)));
            Test loadTest = testManipulator.load(testId, false, false);

            loadTest.IsSelected = true;

            bool testAlreadyPreLoad = false;
            int  subjectPosition    = -1;

            for (int i = 0; i < store.Count; i++)
            {
                if (store.ElementAt(i).Id == newSubject.Id)
                {
                    testAlreadyPreLoad = true;
                    subjectPosition    = i;
                    break;
                }
            }

            if (!testAlreadyPreLoad)
            {
                List <Subject> newConfig = new List <Subject>();
                newSubject.Tests.Add(loadTest);
                newSubject.Name = DataSetConverter.fromDsToSingle.toString.
                                  convert(SqlLiteSimpleExecute.execute(queryConfigurator.
                                                                       loadSubjectName(newSubject.Id)));
                newConfig.Add(newSubject);
                setConfig(newConfig);
            }
            else
            {
                for (int i = 0; i < config.ElementAt(subjectPosition).Tests.Count; i++)
                {
                    if (config.ElementAt(subjectPosition).Tests.ElementAt(i).Id == testId)
                    {
                        config.ElementAt(subjectPosition).Tests.RemoveAt(i);
                        config.ElementAt(subjectPosition).Tests.Insert(i, loadTest);
                        setConfig(config);
                        break;
                    }
                }
            }
            currentQuestionIndex = 0;
            loadStore();
            teacher = new GoTestTeacher(loadTest);
        }
Example #11
0
        public void addNewUser(SecurityUserInterface user)
        {
            string sult = hashWorker.getSult(user);
            int    id   = DataSetConverter.fromDsToSingle.toInt.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.getUserId(user.getLogin())));

            SqlLiteSimpleExecute.execute(queryConfigurator.setSult(id, sult));
            SqlLiteSimpleExecute.execute(queryConfigurator.setPassword(id,
                                                                       hashWorker.getHash(user.getPassword(), sult)));
            InformationPopupWindow       view   = new InformationPopupWindow();
            InformationPopupWindowConfig config = new InformationPopupWindowConfig(
                "Пользователь: " + user.getLogin() + " успешно добавлен!");

            view.setConfig(config);
            view.show();
        }
Example #12
0
        public bool check(SqlLiteCheckerConfig config)
        {
            string[] dbTables = DataSetConverter.fromDsToBuf.toStringBuf.convert(
                SqlLiteSimpleExecute.execute(executer.checkDbTables()));
            //Create checking tables
            List <string[]> checkingTables = new List <string[]>();

            for (int i = 0; i < 6; i++)
            {
                checkingTables.Add(new string[2]);
                checkingTables.ElementAt(i)[1] = "no";
            }
            checkingTables.ElementAt(0)[0] = "Types";
            checkingTables.ElementAt(1)[0] = "Objects";
            checkingTables.ElementAt(2)[0] = "Attributes";
            checkingTables.ElementAt(3)[0] = "Schemas";
            checkingTables.ElementAt(4)[0] = "Parameters";
            checkingTables.ElementAt(5)[0] = "Objects_references";
            //Check tables
            if (checkingTables.Count > dbTables.Count())
            {
                throw new NotEnoughTablesExeption();
            }
            else
            {
                for (int i = 0; i < dbTables.Count(); i++)
                {
                    for (int n = 0; n < checkingTables.Count(); n++)
                    {
                        if (dbTables[i].Equals(checkingTables.ElementAt(n)[0]))
                        {
                            checkingTables.ElementAt(i)[1] = "yes";
                        }
                    }
                }

                for (int i = 0; i < checkingTables.Count(); i++)
                {
                    if (checkingTables.ElementAt(i)[1].Equals("no"))
                    {
                        throw new NotEnoughTablesExeption();
                    }
                }

                return(true);
            }
        }
        public void update(Subject subject)
        {
            SqlLiteSimpleExecute.execute(queryConfigurator.updateSubjectName(
                                             subject.Id, EncryptWorker.getInstance().encrypt(subject.Name)));

            for (int i = 0; i < subject.Tests.Count; i++)
            {
                try
                {
                    testManipulator.update(subject.Tests.ElementAt(i), subject.Id);
                }
                catch (ObjectIsNotExistYet ex)
                {
                    testManipulator.create(subject.Tests.ElementAt(i), subject.Id);
                }
            }
        }
        public Subject load(string name, bool loadOnlySubjectAndTestNamesWithoutChilds,
                            bool loadAllQuestions)
        {
            Subject sub = new Subject();

            sub.Id = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                   execute(queryConfigurator.getSubjectId(name)));
            sub.Name = EncryptWorker.getInstance().decrypt(name);
            int[] testIds = DataSetConverter.fromDsToBuf.toIntBuf.convert(SqlLiteSimpleExecute.
                                                                          execute(queryConfigurator.loadSubjectTestIds(sub.Id)));
            for (int i = 0; i < testIds.Length; i++)
            {
                sub.Tests.Add(testManipulator.load(testIds[i], loadAllQuestions,
                                                   loadOnlySubjectAndTestNamesWithoutChilds));
            }

            return(sub);
        }
Example #15
0
        public void create(Question question, int testId)
        {
            SqlLiteSimpleExecute.execute(queryConfigurator.createQuestion(testId));
            question.Id = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                        execute(queryConfigurator.getObjectIdInDevelopStatus(DbTypes.question)));
            SqlLiteSimpleExecute.execute(queryConfigurator.setQuestionContent(question.Id,
                                                                              EncryptWorker.getInstance().encrypt(question.QuestionsContent)));
            SqlLiteSimpleExecute.execute(queryConfigurator.setQuestionType(question.Id,
                                                                           question.QuestionsType));


            for (int i = 0; i < question.Unswers.Count; i++)
            {
                unswerManipalator.create(question.Unswers.ElementAt(i), question.Id);
            }
            SqlLiteSimpleExecute.execute(queryConfigurator.setApproveStatusToObject(
                                             DbTypes.question));
        }
Example #16
0
        public void create(Test test, int subjectId)
        {
            SqlLiteSimpleExecute.execute(queryConfigurator.createTest(
                                             EncryptWorker.getInstance().encrypt(test.Name), subjectId));

            int id = DataSetConverter.fromDsToSingle.toInt.convert(SqlLiteSimpleExecute.
                                                                   execute(queryConfigurator.getObjectIdInDevelopStatus(DbTypes.test)));

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         setTestsQuestionsNumber(id, test.QuestionsNumber));

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         setTestsRequeredUnswersNumber(id, test.RequeredUnswersNumber));

            for (int i = 0; i < test.Questions.Count; i++)
            {
                questionManipulator.create(test.Questions.ElementAt(i), id);
            }
            SqlLiteSimpleExecute.execute(queryConfigurator.setApproveStatusToObject(
                                             DbTypes.test));
        }
Example #17
0
        public void update(Test test, int subjectId)
        {
            if (DataSetConverter.fromDsToSingle.toInt.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.countOfObject(test.Id))) == 0)
            {
                throw new ObjectIsNotExistYet();
            }

            SqlLiteSimpleExecute.execute(queryConfigurator.updateTestsSubject(
                                             test.Id, subjectId));

            SqlLiteSimpleExecute.execute(queryConfigurator.updateTestName(
                                             test.Id, EncryptWorker.getInstance().encrypt(test.Name)));
            int id = test.Id;

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         updateTestsQuestionsNumber(id, test.QuestionsNumber));

            SqlLiteSimpleExecute.execute(queryConfigurator.
                                         updateTestsRequeredUnswersNumber(id, test.RequeredUnswersNumber));

            for (int i = 0; i < test.Questions.Count; i++)
            {
                try
                {
                    if (test.Questions.ElementAt(i).IsDeleted)
                    {
                        test.Questions.ElementAt(i).delete();
                    }
                    else
                    {
                        questionManipulator.update(test.Questions.ElementAt(i));
                    }
                }
                catch (ObjectIsNotExistYet ex)
                {
                    questionManipulator.create(test.Questions.ElementAt(i), test.Id);
                }
            }
        }
Example #18
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));
     }
 }
Example #19
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();
        }
Example #20
0
        public bool checkUser()
        {
            if (currentUser.isEnterIntoSystem())
            {
                return(true);
            }
            else
            {
                try
                {
                    int id = DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(queryConfigurator.getUserId(
                                                         currentUser.getLogin())));
                    DataSetConverter.fromDsToSingle.toString.convert(
                        SqlLiteSimpleExecute.execute(queryConfigurator.getSult(id)));
                }
                catch (СonversionError ex)
                {
                    return(false);
                }

                string currentPassword = hashWorker.getHash(currentUser.getPassword(),
                                                            getSultForCurrentUser());


                if (DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(queryConfigurator.checkUser(
                                                         currentUser.getLogin(), currentPassword))) == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #21
0
 public int[] getAllSubjectIds()
 {
     return(DataSetConverter.fromDsToBuf.toIntBuf.convert(SqlLiteSimpleExecute.
                                                          execute(queryConfigurator.getAllSubjectIds())));
 }
Example #22
0
        public void update(Question question)
        {
            if (DataSetConverter.fromDsToSingle.toInt.convert(
                    SqlLiteSimpleExecute.execute(queryConfigurator.countOfObject(question.Id))) == 0)
            {
                throw new ObjectIsNotExistYet();
            }
            SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionContent(question.Id,
                                                                                 EncryptWorker.getInstance().encrypt(question.QuestionsContent)));


            int rightUnswersCount = 0;

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                if (question.Unswers.ElementAt(i).IsRight)
                {
                    rightUnswersCount++;
                }
            }
            if ((question.QuestionsType.getType().Equals(QuestionTypes.singleAnswer)) &
                (rightUnswersCount == 0 | rightUnswersCount > 1))
            {
                throw new QuestionTypeException();
            }
            if (question.QuestionsType.getType().Equals(QuestionTypes.multiplyAnswer) &
                rightUnswersCount < 2)
            {
                throw new QuestionTypeException();
            }

            if (question.QuestionsType.getType().Equals(DbObjects.multiplyAnswer.getName()))
            {
                SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionType(question.Id,
                                                                                  DbObjects.multiplyAnswer));
            }
            else
            {
                SqlLiteSimpleExecute.execute(queryConfigurator.updateQuestionType(question.Id,
                                                                                  DbObjects.singleAnswer));
            }

            for (int i = 0; i < question.Unswers.Count; i++)
            {
                try
                {
                    if (question.Unswers.ElementAt(i).IsDeleted)
                    {
                        question.Unswers.ElementAt(i).delete();
                    }
                    else
                    {
                        unswerManipalator.update(question.Unswers.ElementAt(i));
                    }
                }
                catch (ObjectIsNotExistYet ex)
                {
                    unswerManipalator.create(question.Unswers.ElementAt(i), question.Id);
                }
            }
        }
        public void check()
        {
            List <string> result = new List <string>();

            for (int i = 0; i < attrs.Count; i++)
            {
                try
                {
                    int id = DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(getQueryForGettingAttrId(
                                                         attrs.ElementAt(i).getName())));
                }
                catch (СonversionError ex)
                {
                    throw new NotEnoughBasicObjects(attrs.ElementAt(i).getName());
                }
            }
            for (int i = 0; i < objects.Count; i++)
            {
                try
                {
                    int id = DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(getQueryForGettingObjectId(
                                                         objects.ElementAt(i)[0], objects.ElementAt(i)[1])));
                }
                catch (СonversionError ex)
                {
                    throw new NotEnoughBasicObjects(objects.ElementAt(i)[0].getName() + " " +
                                                    objects.ElementAt(i)[0].getName());
                }
            }
            for (int i = 0; i < types.Count; i++)
            {
                try
                {
                    int id = DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(getQueryForGettingTypeId(
                                                         types.ElementAt(i).getName())));
                }
                catch (СonversionError ex)
                {
                    throw new NotEnoughBasicObjects(types.ElementAt(i).getName());
                }
            }
            for (int i = 0; i < schemas.Count; i++)
            {
                try
                {
                    int count = DataSetConverter.fromDsToSingle.toInt.convert(
                        SqlLiteSimpleExecute.execute(getCountStringFromSchemas(
                                                         schemas.ElementAt(i)[0], schemas.ElementAt(i)[1], schemas.ElementAt(i)[2])));
                    if (count == 0)
                    {
                        throw new СonversionError();
                    }
                }
                catch (СonversionError ex)
                {
                    throw new NotEnoughBasicObjects(schemas.ElementAt(i)[0].getName() + " " +
                                                    schemas.ElementAt(i)[1].getName() + " " + schemas.ElementAt(i)[2].getName());
                }
            }
            //Check admin
            int adminCount = DataSetConverter.fromDsToSingle.toInt.convert(
                SqlLiteSimpleExecute.execute(queryConfigurator.checkExistAdmin()));

            if (adminCount == 0)
            {
                throw new AdminIsNotExist();
            }
        }