コード例 #1
0
 private void AdminWindowLoaded(object sender, RoutedEventArgs e)
 {
     CRUDManager cm = new CRUDManager();
     Questions = cm.GetAllQuestions();
 }
コード例 #2
0
        private void UserWindowLoaded(object sender, RoutedEventArgs e)
        {
            NameTB.Text = this.UserName;
            IDNumbrTB.Text = this.IDCardNo;

            CRUDManager cm = new CRUDManager();
            //ttbCountDown.TimeSpan = cm.GetTimeSpan();
            int number = cm.GetNumberOfQuestions();
            List<QuestionModel> qm = cm.GetAllQuestions();
            int[] temp = { };
            if (qm.Count > 0)
            {
                Random rnd = new Random();
                temp = Enumerable.Range(0, qm.Count).OrderBy(i => rnd.Next()).ToArray();
            }

            int[] count = { number, temp.Length };

            for (int i = 0; i < count.Min(); i++)
            {
                int qIndex = temp[i];
                QuestionVM qvModel = new QuestionVM();
                qvModel.Answers = new ObservableCollection<AnswersVM>();
                qvModel.Images = new ObservableCollection<ImageModel>();
                qvModel.QNumber = i+1;
                qvModel.QBody = qm[qIndex].QBody;
                for (int j = 0; j < qm[qIndex].Answers.Count; j++)
                {
                    AnswersVM a = new AnswersVM();
                    a.AnswerBody = qm[qIndex].Answers[j].AnswerBody;
                    a.IsCorrectAnswer = qm[qIndex].Answers[j].IsCorrectAnswer;
                    a.TagNumber = j.ToString();

                    qvModel.Answers.Add(a);
                }
                for (int j = 0; j < qm[qIndex].Images.Count; j++)
                {
                    qvModel.Images.Add(qm[qIndex].Images[j]);
                }

                Question qView = new Question();
                qView.DataContext = qvModel;
                QuestionListSP.Children.Add(qView);
                QuestionList.Add(qView);
            }
        }