static void Main(string[] args) { // [1] 그냥 호출 Driver.Right(); Driver.Left(); Driver.Boost(); Console.WriteLine(); // [2] 대리자 선언 할당 같이 //Driver driver = new Driver(); // static으로 만들면 인스턴트 만들지 X // 집가는 대리자 생성 GoHome goHome = new GoHome(Driver.Left); goHome += Driver.Right; goHome += Driver.Boost; goHome.Invoke(); Console.WriteLine(); //[3] 대리자 선언, 할당 따로 Meeting meeting; meeting = new Meeting(Hi); meeting += LTNS; meeting(); Console.WriteLine(); //[4] 스태틱 메서드 아닐때 Insa insa = new Insa(); Meeting meeting2 = new Meeting(insa.Bye); // 다른 대리자는 인스턴트 이름 다르게 생성 meeting2(); }
private void GoHomeButton_Click(object sender, EventArgs e) { this.Dismiss(); GoHome?.Invoke(this, new EventArgs()); }
private void buttonAddQuestion_Click(object sender, RoutedEventArgs e) { if (question.Id == 0) { bool dateCheck = true; foreach (var item in questionsRepo.Data) { if ((DateTime)datePicker.SelectedDate == item.Date) { dateCheck = false; break; } } if (dateCheck && (DateTime)datePicker.SelectedDate >= DateTime.Now.Date) { List <Answer> newAnswers = new List <Answer>(); if (!String.IsNullOrEmpty(textBoxQuestionText.Text)) { var newDate = (DateTime)datePicker.SelectedDate; var newQuestion = new Question { Date = newDate.Date, Text = textBoxQuestionText.Text, Explanation = textBoxExplanation.Text, }; int textCount = 0; int checkCount = 0; int checkNull = 0; List <Answer> answers = new List <Answer> { new Answer { Text = textBox1.Text, IsCorrect = (bool)checkBox1.IsChecked }, new Answer { Text = textBox2.Text, IsCorrect = (bool)checkBox2.IsChecked }, new Answer { Text = textBox3.Text, IsCorrect = (bool)checkBox3.IsChecked }, new Answer { Text = textBox4.Text, IsCorrect = (bool)checkBox4.IsChecked } }; foreach (var item in answers) { if (!String.IsNullOrEmpty(item.Text)) { textCount++; } if (item.IsCorrect) { checkCount++; } if (String.IsNullOrEmpty(item.Text) && item.IsCorrect) { checkNull++; } } if (textCount > 0) { if (checkCount > 0) { if (checkNull == 0) { foreach (var item in answers) { if (!String.IsNullOrEmpty(item.Text)) { newAnswers.Add(item); } } newQuestion.Answers = newAnswers; questionsRepo.AddItem(newQuestion); MessageBox.Show("Your question was successefully added", "Success", MessageBoxButton.OK, MessageBoxImage.Information); GoHome?.Invoke(); } else { MessageBox.Show("You can't pick empty answer as a correct one", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question without choosing at least one correct answer", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question without answers", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question without text", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question for this date", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } //редактирование вопроса и ответов к нему else { bool dateCheck = true; if (question.Date != (DateTime)datePicker.SelectedDate) { foreach (var item in questionsRepo.Data) { if ((DateTime)datePicker.SelectedDate == item.Date) { dateCheck = false; break; } } } if (dateCheck && (DateTime)datePicker.SelectedDate >= DateTime.Now.Date) { List <Answer> answers = new List <Answer>(); question.Date = (DateTime)datePicker.SelectedDate; question.Explanation = textBoxExplanation.Text; question.Text = textBoxQuestionText.Text; if (!String.IsNullOrEmpty(question.Text)) { var checkBoxes = GetCheckBoxes(); bool res = true; int checkNull = 0; int textCount = 0; var removeAnswers = new List <Answer>(); foreach (var answer in question.Answers) { CheckBox cb = checkBoxes.FirstOrDefault(c => chbAnswerDict[c.Name] == answer.Id); var tb = cb.Content as TextBox; if (!String.IsNullOrEmpty(tb.Text)) { textCount++; answer.Text = tb.Text; answer.IsCorrect = (bool)cb.IsChecked; if ((bool)cb.IsChecked) { checkNull++; } //answerRepo.EditItem(answer, answer.Id); } else if ((bool)cb.IsChecked) { MessageBox.Show("You can't pick empty answer as a correct one", "Error", MessageBoxButton.OK, MessageBoxImage.Error); res = false; } else { removeAnswers.Add(answer); } checkBoxes.Remove(cb); } if (checkBoxes.Count() > 0) { foreach (var cb in checkBoxes) { var tb = cb.Content as TextBox; if (!String.IsNullOrEmpty(tb.Text)) { var newAnswer = new Answer { Text = tb.Text, IsCorrect = (bool)cb.IsChecked }; if ((bool)cb.IsChecked) { checkNull++; } textCount++; question.Answers.Add(newAnswer); } else if ((bool)cb.IsChecked) { MessageBox.Show("You can't pick empty answer as a correct one", "Error", MessageBoxButton.OK, MessageBoxImage.Error); res = false; } } } if (textCount > 0) { if (checkNull > 0) { if (res) { foreach (var item in removeAnswers) { question.Answers.Remove(item); answerRepo.RemoveItem(item); } questionsRepo.EditItem(question, question.Id); MessageBox.Show("Your question was successefully edited", "Success", MessageBoxButton.OK, MessageBoxImage.Information); GoHome?.Invoke(); } } else { MessageBox.Show("You can't create question without choosing at least one correct answer", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question without answers", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question without text", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("You can't create question for this date", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }