private void WordDataGridView_SelectionChanged(object sender, EventArgs e) { var selectedWord = wordBindingSource.Current as Word; if (selectedWord != null) { lblSelectedWord.Text = selectedWord.WordText; lblSelectedWord.Visible = true; MeaningWordId = selectedWord.ID; meaningBindingSource.DataSource = _meaningRepository.List(x => x.WordId == selectedWord.ID); } }
public UIShowQuestion(int SetId, Action timer, IWordRepository wordRepository, IMeaningRepository meaningRepository, IMemorizationRepository memorizationRepository, ISettingRepository settingRepository) { _meaningRepository = meaningRepository; _wordRepository = wordRepository; _memorizationRepository = memorizationRepository; _settingRepository = settingRepository; if (_fistWordList == null) { _fistWordList = _wordRepository.List(SetId, SessionData.loginUserId) as List <Word>; } questionsAndAnswers = new QuestionsAndAnswers(); var word = _fistWordList.OrderBy(x => Guid.NewGuid()).FirstOrDefault(); _wordId = word.ID; _setId = SetId; _timer = timer; questionsAndAnswers.Question = word.WordText; var answer = _meaningRepository.Get(x => x.WordId == word.ID); questionsAndAnswers.AndAnswer = answer.MeaningWord; questionsAndAnswers.AndAnswers = _meaningRepository.List(x => x.ID != answer.ID).OrderBy(x => Guid.NewGuid()).Select(e => e.MeaningWord).Take(4).ToList(); questionsAndAnswers.AndAnswers.Add(questionsAndAnswers.AndAnswer); InitializeComponent(); Opacity = Convert.ToInt32(_settingRepository.Get("QuestionWindowOpacity").SettingValue) / 100D; var PlayAnswer = _settingRepository.Get("PlayAnswer").SettingValue; txtWord.Text = questionsAndAnswers.Question; Rectangle r = Screen.PrimaryScreen.WorkingArea; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); int i = 0; var pnlSize = pnlAnswers.Size; int btnYukseklik = pnlSize.Height / questionsAndAnswers.AndAnswers.Count(); foreach (var item in questionsAndAnswers.AndAnswers.OrderBy(x => Guid.NewGuid())) { Button button = new Button(); button.Text = item; button.Name = i.ToString() + "_Btn"; button.Size = new Size(pnlSize.Width - 2, btnYukseklik); button.Click += (object sender, EventArgs e) => { var clickButton = sender as Button; if (clickButton.Text == questionsAndAnswers.AndAnswer) { clickButton.BackColor = Color.Green; } if (PlayAnswer == "1") { SpeechSynthesizer ss = new SpeechSynthesizer(); ss.SpeakAsync(button.Text); } }; i++; button.Dock = DockStyle.Top; pnlAnswers.Controls.Add(button); } var playQuestion = _settingRepository.Get("PlayQuestion").SettingValue == "1" ? true : false; if (playQuestion) { SpeechSynthesizer ss = new SpeechSynthesizer(); ss.SpeakAsync(txtWord.Text); } }