public CreateBookForm(MainForm mainForm) { this.mainForm = mainForm; InitializeComponent(); foreach (var item in this.mainForm.LibraryDropdown.Items) { this.LibrarySelectionDropdown.Items.Add(item); } if (this.LibrarySelectionDropdown.SelectedItem != null) { string SelectedName = this.LibrarySelectionDropdown.SelectedItem.ToString().Substring(this.LibrarySelectionDropdown.SelectedItem.ToString().IndexOf(':') + 2); foreach (Core.Library library in this.mainForm.LibraryList) { Console.WriteLine(library.Name); if (SelectedName == library.Name) { activeLibrary = library; } } } else { activeLibrary = this.mainForm.LibraryList[0]; } }
private void AddBtn_Click(object sender, EventArgs e) { if (this.TitleInput.Text != "" && this.AuthorInput.Text != "" && this.LibrarySelectionDropdown.SelectedItem != null) { string SelectedName = this.LibrarySelectionDropdown.SelectedItem.ToString().Substring(this.LibrarySelectionDropdown.SelectedItem.ToString().IndexOf(':') + 2); foreach (Core.Library library in this.mainForm.LibraryList) { Console.WriteLine(library.Name); if (SelectedName == library.Name) { try { activeLibrary = library; activeLibrary.AddBook(this.TitleInput.Text.ToString(), this.AuthorInput.Text.ToString()); MessageBox.Show("Book added!"); Core.Book Book; if (activeLibrary.BookList.Count != 0) { Book = activeLibrary.BookList[activeLibrary.BookList.Count - 1]; } else { Book = activeLibrary.BookList[0]; } var row = new string[] { Book.Id.ToString(), Book.Titel, Book.Author, Book.Loaned.ToString() }; var lvi = new ListViewItem(row); lvi.Tag = "Book"; lvi.ToolTipText = "Doubble click to open or edit book!"; this.mainForm.BookListView.Items.Add(lvi); mainForm.BookListView.Update(); this.Close(); return; } catch (Exception error) { Console.WriteLine(error); } } else { MessageBox.Show("Library not found!"); } } } else { if (this.TitleInput.Text == "") { MessageBox.Show("Title can not be empty!"); } else if (this.AuthorInput.Text == "") { MessageBox.Show("Author can not be empty!"); } else if (this.LibrarySelectionDropdown.SelectedItem == null) { MessageBox.Show("Please select a library!"); } else { MessageBox.Show("Unknown error!"); } } }
public MainForm() { InitializeComponent(); BookListView.MouseDoubleClick += new MouseEventHandler(BookListView_MouseDoubleClick); BookListView.View = View.Details; this.LibraryList = new List <Core.Library>(); LibraryList.Add(new Core.Library(0, "Oscars Bibliotek")); foreach (var library in LibraryList) { LibraryDropdown.Items.Add($"{library.Id} : {library.Name}"); } //var row = new string[] { "0", "Hello", "World!", "Yes" }; this.activeLibrary = LibraryList[0]; if (LibraryDropdown.SelectedItem != null) { foreach (var library in LibraryList) { if (LibraryDropdown.SelectedItem.ToString() == library.Name) { this.activeLibrary = library; break; } } } else { LibraryDropdown.SelectedItem = LibraryDropdown.Items[0]; } if (this.activeLibrary == null) { this.activeLibrary = LibraryList[0]; } for (int i = 0; i < 5; i++) { this.activeLibrary.AvailibleGenreList.Add("Genre: " + i); } foreach (string Genere in this.activeLibrary.AvailibleGenreList) { this.GenreSelectionBox.Items.Add(Genere); } for (int i = 0; i < 2; i++) { this.activeLibrary.AddBook("Hello World Volume." + i, "God"); } foreach (var Book in this.activeLibrary.BookList) { var row = new string[] { Book.Id.ToString(), Book.Titel, Book.Author, Book.Loaned.ToString() }; var lvi = new ListViewItem(row); lvi.Tag = "Book"; lvi.ToolTipText = "Doubble click to open or edit book!"; BookListView.Items.Add(lvi); } }