private void CreateButton_Click(object sender, EventArgs e) { if (CheckingFields()) { var books = (BookLibrary)BookComboBox.SelectedItem; int year; int.TryParse(YeartextBox.Text, out year); var author = new AuthorLibrary { Name = AuthortextBox.Text, Gender = GendertextBox.Text, YearOfBirth = year, BookLibrary = books }; dataAccess.CreateAuthor(author); Close(); } }
public UpdateAuthor(AuthorLibrary author) { InitializeComponent(); authorLibrary = author; AuthortextBox.Text = author.Name; GendertextBox.Text = author.Gender; YeartextBox.Text = author.YearOfBirth.ToString(); var books = dataAccess.GetBooks(); var index = books.Select(x => x.UniqueID).ToList().IndexOf(author.BookLibrary.UniqueID); BookComboBox.BackColor = Color.Black; BookComboBox.ForeColor = Color.White; BookComboBox.DataSource = books; BookComboBox.SelectedIndex = index; BookComboBox.DisplayMember = "Book"; BookComboBox.DropDownStyle = ComboBoxStyle.DropDownList; }