コード例 #1
0
ファイル: SurveyPage.xaml.cs プロジェクト: naf73/Survey
 private void QuestionAdd_Click(object sender, RoutedEventArgs e)
 {
     if (CheckFillingQuestionFields())
     {
         if (CheckAnswersCount())
         {
             if (CheckExistRightAnswer())
             {
                 questionController.Add(new Question()
                 {
                     SurveyId = _survey.Id,
                     Text     = !string.IsNullOrEmpty(QuestionText.Text) ? QuestionText.Text : string.Empty,
                     Foto     = QuestionPicture.Source != null ? ConvertPicture.BitmapImageToByteArray((BitmapImage)QuestionPicture.Source) : null
                 }, _answers);
                 _answers.Clear();
                 UpdateQuestionTable();
             }
             else
             {
                 MessageBox.Show(LangPages.MBox.MissingCorrectAnswer);
             }
         }
         else
         {
             MessageBox.Show(LangPages.MBox.NeedToAddQuestionAnswers);
         }
     }
     else
     {
         MessageBox.Show(LangPages.MBox.NotAllFieldsInTheQuestionAreFilled);
     }
 }
コード例 #2
0
        private void ShowQuestion(int number)
        {
            string text = _survey.Question.ToList()[number].Text;

            byte[] picture = _survey.Question.ToList()[number].Foto;
            if (!(text is null))
            {
                Question.Content = text;
            }
            if (!(picture is null))
            {
                Foto.Source = ConvertPicture.ByteArrayToImage(picture);
            }
            ShowAnswer(_survey.Question.ToList()[number].Answer.ToList());
        }
コード例 #3
0
ファイル: SurveyPage.xaml.cs プロジェクト: naf73/Survey
        private void QuestionEdit_Click(object sender, RoutedEventArgs e)
        {
            Question question = (Question)QuestionsDataGrid.SelectedItem;

            if (!(question is null))
            {
                if (CheckFillingQuestionFields())
                {
                    if (CheckAnswersCount())
                    {
                        if (CheckExistRightAnswer())
                        {
                            question.SurveyId = _survey.Id;
                            question.Text     = !string.IsNullOrEmpty(QuestionText.Text) ? QuestionText.Text : string.Empty;
                            question.Foto     = QuestionPicture.Source != null?ConvertPicture.BitmapImageToByteArray((BitmapImage)QuestionPicture.Source) : null;

                            questionController.Edit(question, _answers);
                            _answers.Clear();
                            UpdateQuestionTable();
                        }
                        else
                        {
                            MessageBox.Show(LangPages.MBox.MissingCorrectAnswer);
                        }
                    }
                    else
                    {
                        MessageBox.Show(LangPages.MBox.NeedToAddQuestionAnswers);
                    }
                }
                else
                {
                    MessageBox.Show(LangPages.MBox.NotAllFieldsInTheQuestionAreFilled);
                }
            }
        }
コード例 #4
0
ファイル: UnitTestDB.cs プロジェクト: naf73/Survey
        public void InitDB()
        {
            if (userController.Get().Count == 0)
            {
                userController.AddAdmin();
                categoryController.Add(new Category()
                {
                    Name = "Техника безопасности"
                });
                categoryController.Add(new Category()
                {
                    Name = "Техника пожарной безопасности"
                });

                Category category = categoryController.Get()[0];

                for (int k = 0; k < 3; k++)
                {
                    List <Question> questions = new List <Question>();

                    for (int i = 0; i < 10; i++)
                    {
                        List <Answer> answers = new List <Answer>();
                        for (int j = 0; j < 3; j++)
                        {
                            if (j == 0)
                            {
                                answers.Add(new Answer()
                                {
                                    Text      = string.Format("{0} {1}", j, RandomString(23)),
                                    IsTrue    = true,
                                    IsDeleted = false
                                });
                            }
                            else
                            {
                                answers.Add(new Answer()
                                {
                                    Text      = string.Format("{0} {1}", j, RandomString(23)),
                                    IsTrue    = false,
                                    IsDeleted = false
                                });
                            }
                        }
                        questions.Add(new Question()
                        {
                            Text      = string.Format("{0} {1} ", i, RandomString(34)),
                            Answer    = answers,
                            IsDeleted = false,
                            Foto      = ConvertPicture.BitmapImageToByteArray(new BitmapImage(new Uri(@"C:\Users\Alex\source\repos\Survey\Survey\Pictures\Hamster.jpg", UriKind.Relative)))
                        });
                    }

                    surveyController.Add(new Survey.Model.Survey()
                    {
                        Name       = string.Format("{0} {1}", k, RandomString(25)),
                        CategoryId = category.Id,
                        Time       = 1,
                        Question   = questions
                    });
                }
            }
        }