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(); } }
public bool CheckForRepetition() { bool themeNormal = true; List <Theme> themes; using (QuestionContex db = new QuestionContex()) { themes = db.Themes.ToList(); } foreach (var theme in themes) { theme.Name = theme.Name.Trim(); if (theme.Name.Equals(NameThemeTB.Text, StringComparison.OrdinalIgnoreCase)) { WarmingThemeL.Opacity = 1; themeNormal = false; break; } else { WarmingThemeL.Opacity = 0; } } return(themeNormal); }
private void ConectionDataBase() { List <Theme> themes; using (QuestionContex db = new QuestionContex()) { themes = db.Themes.ToList(); } SelectTehmeCB.ItemsSource = themes.Select(t => t.Name); SelectTehmeCB.SelectedIndex = 0; }
public void AddInDataBase() { using var db = new QuestionContex(); string themeName = NameThemeTB.Text; var theme = db.Themes.FirstOrDefault(theme => theme.Name.Equals(themeName)); if (theme is null) { theme = new Theme() { Name = themeName }; } Timer timer = new Timer { Time = Convert.ToInt32(TimeTB.Text) }; Question question = new Question { Name = NameQuestionTB.Text, Theme = theme, Timer = timer }; Answer answer1 = new Answer { Name = AnswerTB_1.Text, Condition = ConditionAnswer_1.IsChecked ?? false, Question = question }; Answer answer2 = new Answer { Name = AnswerTB_2.Text, Condition = ConditionAnswer_2.IsChecked ?? false, Question = question }; Answer answer3 = new Answer { Name = AnswerTB_3.Text, Condition = ConditionAnswer_3.IsChecked ?? false, Question = question }; Answer answer4 = new Answer { Name = AnswerTB_4.Text, Condition = ConditionAnswer_4.IsChecked ?? false, Question = question }; db.Answers.AddRange(new[] { answer1, answer2, answer3, answer4 }); db.SaveChanges(); }
private void SetQuestion(Question question) { currentTime = question.Timer.Time; Dispatcher.Invoke(() => TimeTB.Text = TimeSpan.FromSeconds(currentTime).ToString(@"mm\:ss")); QuestionTB.Text = question.Name; List <Answer> allAnswers; using (QuestionContex db = new QuestionContex()) { db.Questions.Load(); allAnswers = db.Answers.ToList(); } List <string> answers = new List <string>(); foreach (var answer in allAnswers) { if (answer.Question.Name == question.Name) { answers.Add(answer.Name); if (answer.Condition == true) { rightAnswer.Add(answer); } } } Options.Text = null; int i = 1; foreach (var answer in answers) { Options.Text += "\u25CF" + answer; if (i % 2 != 0) { Options.Text += "\t"; } else { Options.Text += "\n"; } ++i; } }