private void buttonMatch_Click(object sender, EventArgs e) { List <Translation> translationForTestList = translationDBservice.getWordsForMatchTest(); if (translationForTestList.Count() < 4) { MessageBox.Show("You don't have words in your dictionary to exercise, please add some."); return; } ExerciseForm newForm = new ExerciseForm(wordService, dataContext, translationDBservice, applicationSettingsService); newForm.Show(); }
private void generateWords() { Random random = new Random(); List <Translation> translationForTestList = translationDBservice.getWordsForMatchTest(); if (translationForTestList.Count() < 4) { MessageBox.Show("You don't have words in your dictionary to exercise, please add some."); this.Close(); return; } IDictionary <String, String> wordsDictionary = new Dictionary <String, String>(); foreach (Translation t in translationForTestList) { String word1 = dataContext.Words.Where(word => word.Id == t.word_id_1).First().word1; String word2 = dataContext.Words.Where(word => word.Id == t.word_id_2).First().word1; wordsDictionary.Add(word1, word2); } Translation randomTranslation = translationForTestList.ElementAt(random.Next(0, 4)); while (rightTranslation != null && randomTranslation.word_id_1 == rightTranslation.word_id_1 && randomTranslation.word_id_2 == rightTranslation.word_id_2) { randomTranslation = translationForTestList.ElementAt(random.Next(0, 4)); } rightTranslation = randomTranslation; wordToTranslatePair = new KeyValuePair <String, String>(wordService.getWordById(rightTranslation.word_id_1), wordService.getWordById(rightTranslation.word_id_2)); labelWordToTranslate.Text = wordService.getWordById(rightTranslation.word_id_1); setWordsOnButtons(wordsDictionary); }