private void WindowGame_Loaded(object sender, RoutedEventArgs e) { List <Question> allQuestions; using (QuestionContex db = new QuestionContex()) { db.Themes.Load(); db.Timers.Load(); allQuestions = db.Questions.ToList(); } foreach (var question in allQuestions) { if (question.Theme.Name == ThemeL.Text) { questions.Add(question); } } enQ = questions.GetEnumerator(); if (enQ.MoveNext()) { currentTime = enQ.Current.Timer.Time; SetQuestion(enQ.Current); } else { this.Hide(); var windowGame = new WindowsRightAnswer(); windowGame.ShowDialog(); this.Show(); this.Close(); } }
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (currentTime > 0) { --currentTime; Dispatcher.Invoke(() => TimeTB.Text = TimeSpan.FromSeconds(currentTime).ToString(@"mm\:ss")); } else { if (enQ.MoveNext()) { Dispatcher.Invoke(() => SetQuestion(enQ.Current)); } else { timer.Stop(); Dispatcher.Invoke(() => { this.Hide(); var windowsRightAnswer = new WindowsRightAnswer(); string currentTheme = string.Empty; int numberQuestion = 1; foreach (var answer in rightAnswer) { if (answer.Question.Name == currentTheme) { windowsRightAnswer.AnswerTB.Text += answer.Name + ", "; } else { ++numberQuestion; windowsRightAnswer.AnswerTB.Text += "\n"; windowsRightAnswer.AnswerTB.Text += answer.Question.Name + ": "; windowsRightAnswer.AnswerTB.Text += answer.Name; } currentTheme = answer.Question.Name; } windowsRightAnswer.ShowDialog(); //this.Show(); this.Close(); }); } } }