예제 #1
0
        private List <string> GetQuestionDataFromDialog(CreateQuestion window)
        {
            List <string> result = new List <string>();

            // 0 - content, 1 - answer1, 2 - answer2 .. 5 - answer5, 6 - points, 7 - id
            //string correct;
            result.Add(window.content.Text);
            result.Add(window.answer1.Text + ((bool)(window.answer1.Text.Length > 0) ? ((bool)window.correct1.IsChecked ? "_1" : "_0") : ""));
            result.Add(window.answer2.Text + ((bool)(window.answer2.Text.Length > 0) ? ((bool)window.correct2.IsChecked ? "_1" : "_0") : ""));
            result.Add(window.answer3.Text + ((bool)(window.answer3.Text.Length > 0) ? ((bool)window.correct3.IsChecked ? "_1" : "_0") : ""));
            result.Add(window.answer4.Text + ((bool)(window.answer4.Text.Length > 0) ? ((bool)window.correct4.IsChecked ? "_1" : "_0") : ""));
            result.Add(window.answer5.Text + ((bool)(window.answer5.Text.Length > 0) ? ((bool)window.correct5.IsChecked ? "_1" : "_0") : ""));
            result.Add(window.points.Content.ToString());

            return(result);
        }
예제 #2
0
        public CreateTest()
        {
            InitializeComponent();
            //Closing += (s, e) => ViewModelLocator.Cleanup();
            //Closing += (sender, args) => DialogResult = chkBox.IsChecked;


            Messenger.Default.Register <OpenWindowMessage>(
                this,
                message =>
            {
                switch (message.Type)
                {
                    #region new question
                case WindowType.kNewQuestion:

                    var modalWindowVM = SimpleIoc.Default.GetInstance <CreateQuestionViewModel>();

                    var modalWindow = new CreateQuestion()
                    {
                        DataContext = modalWindowVM
                    };
                    modalWindowVM.ClearWindow();
                    bool?result = modalWindow.ShowDialog();     // ?? false;

                    if (result.HasValue && result.Value)
                    {
                        List <string> resultList = GetQuestionDataFromDialog(modalWindow);
                        Messenger.Default.Send(resultList, "question");
                    }

                    string resultString;
                    if (result == true)
                    {
                        resultString = "Accepted";
                    }
                    else
                    {
                        resultString = "Rejected";
                    }

                    Messenger.Default.Send(resultString);
                    break;
                    #endregion

                    #region new single question
                case WindowType.kNewSingleQuestion:
                    //var modalWindowVM = SimpleIoc.Default.GetInstance<CreateTestViewModel>();
                    var createSingleQuestionWindowVM = SimpleIoc.Default.GetInstance <CreateQuestionViewModel>();
                    //modalWindowVM.MyText = message.Argument;
                    var createSingleQuestionlWindow = new CreateSingleQuestion()
                    {
                        DataContext = createSingleQuestionWindowVM
                    };
                    createSingleQuestionWindowVM.ClearWindow();
                    result = createSingleQuestionlWindow.ShowDialog();     // ?? false;

                    if (result.HasValue && result.Value)
                    {
                        List <string> resultList = GetQuestionDataFromDialog(createSingleQuestionlWindow);
                        Messenger.Default.Send(resultList, "question");
                    }

                    //string resultString;
                    if (result == true)
                    {
                        resultString = "Accepted";
                    }
                    else
                    {
                        resultString = "Rejected";
                    }

                    Messenger.Default.Send(resultString);
                    break;
                    #endregion

                    #region edit question
                case WindowType.kEditQuestion:

                    var EditQuestionWindowVM = SimpleIoc.Default.GetInstance <CreateQuestionViewModel>();
                    List <string> unparsed   = UnParseQuestionString(message.Argument);

                    EditQuestionWindowVM.QuestionString = new List <string>();
                    foreach (var item in unparsed)
                    {
                        EditQuestionWindowVM.QuestionString.Add(item);
                    }
                    //EditQuestionWindowVM.QuestionString = unparsed; //questionString

                    var EditQuestionWindow = new CreateQuestion()
                    {
                        DataContext = EditQuestionWindowVM
                    };

                    EditQuestionWindowVM.FillDialog();     //fill dialog with questionString
                    result = EditQuestionWindow.ShowDialog();

                    if (result.HasValue && result.Value)
                    {
                        List <string> resultList = GetQuestionDataFromDialog(EditQuestionWindow);
                        Messenger.Default.Send(resultList, "question");
                    }

                    if (result == true)
                    {
                        resultString = "Accepted";
                    }
                    else
                    {
                        resultString = "Rejected";
                    }

                    Messenger.Default.Send(resultString, "result");

                    break;
                    #endregion

                    #region edit single question
                case WindowType.kEditSingleQuestion:

                    var EditSingleQuestionWindowVM = SimpleIoc.Default.GetInstance <CreateQuestionViewModel>();
                    unparsed = UnParseQuestionString(message.Argument);

                    EditSingleQuestionWindowVM.QuestionString = new List <string>();
                    foreach (var item in unparsed)
                    {
                        EditSingleQuestionWindowVM.QuestionString.Add(item);
                    }


                    var EditSingleQuestionWindow = new CreateSingleQuestion()
                    {
                        DataContext = EditSingleQuestionWindowVM
                    };

                    EditSingleQuestionWindowVM.FillDialog();     //fill dialog with questionString
                    result = EditSingleQuestionWindow.ShowDialog();

                    if (result.HasValue && result.Value)
                    {
                        List <string> resultList = GetQuestionDataFromDialog(EditSingleQuestionWindow);
                        Messenger.Default.Send(resultList, "question");
                    }

                    if (result == true)
                    {
                        resultString = "Accepted";
                    }
                    else
                    {
                        resultString = "Rejected";
                    }

                    Messenger.Default.Send(resultString, "result");

                    break;
                    #endregion
                }
            });
        }