private FileStream input; //Stream for reading from a file // Precondition: None // Postcondition: The form's GUI is prepared for display. A few test items and patrons // are added to the library public Prog2Form() { InitializeComponent(); _lib = new Library(); // Create the library // Insert test data - Magic numbers allowed here _lib.AddLibraryBook("The Wright Guide to C#", "UofL Press", 2010, 14, "ZZ25 3G", "Andrew Wright"); _lib.AddLibraryBook("Harriet Pooter", "Stealer Books", 2000, 21, "AB73 ZF", "IP Thief"); _lib.AddLibraryMovie("Andrew's Super-Duper Movie", "UofL Movies", 2011, 7, "MM33 2D", 92.5, "Andrew L. Wright", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG); _lib.AddLibraryMovie("Pirates of the Carribean: The Curse of C#", "Disney Programming", 2012, 10, "MO93 4S", 122.5, "Steven Stealberg", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.G); _lib.AddLibraryMusic("C# - The Album", "UofL Music", 2014, 14, "CD44 4Z", 84.3, "Dr. A", LibraryMediaItem.MediaType.CD, 10); _lib.AddLibraryMusic("The Sounds of Programming", "Soundproof Music", 1996, 21, "VI64 1Z", 65.0, "Cee Sharpe", LibraryMediaItem.MediaType.VINYL, 12); _lib.AddLibraryJournal("Journal of C# Goodness", "UofL Journals", 2017, 14, "JJ12 7M", 1, 2, "Information Systems", "Andrew Wright"); _lib.AddLibraryJournal("Journal of VB Goodness", "UofL Journals", 2008, 14, "JJ34 3F", 8, 4, "Information Systems", "Alexander Williams"); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2019, 14, "MA53 9A", 16, 7); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2019, 14, "MA53 9B", 16, 8); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2019, 14, "MA53 9C", 16, 9); _lib.AddLibraryMagazine(" VB Magazine ", " UofL Mags ", 2018, 14, "MA21 5V", 1, 1); // Add 5 Patrons _lib.AddPatron("Ima Reader", "12345"); _lib.AddPatron("Jane Doe", "11223"); _lib.AddPatron(" John Smith ", " 654321 "); _lib.AddPatron("James T. Kirk", "98765"); _lib.AddPatron("Jean-Luc Picard", "33456"); }
DialogResult result; // Holds the results of the dialog box // Precondition: None // Postcondition: GUI is initialized and items are added public Program2Form() { InitializeComponent(); _lib = new Library(); //Creates Library //Adds Test Data _lib.AddLibraryBook("How to Read", "Book Inc.", 1990, 14, "000015683", "John Fisher"); _lib.AddLibraryBook("How to do Things", "Publisher Inc.", 1995, 14, "000015615", "Bill Bo Baggings"); _lib.AddLibraryJournal("New Math Theories", "Publisher Inc.", 1500, 18, "000012348", 1, 1, "Math Stuff", "Dukey"); _lib.AddLibraryJournal("Revolutionary Sciencey Stuff", "Publisher Corp", 1904, 21, "000015846", 1, 3, "Science Stuff", "Dr. Grizzwald"); _lib.AddLibraryMagazine("The Subscription", "Magazines Corp", 2050, 7, "000098761", 1, 2); _lib.AddLibraryMagazine("The Subscription", "Magazines Corp", 2051, 7, "000098762", 2, 9); _lib.AddLibraryMovie("The Revenge of Count Walter", "Koon Pictures Inc", 2024, 4, "000012845", 240, "Moose Meat the Third", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG13); _lib.AddLibraryMovie("Black Wasp", "Cynical Juice Box Inc", 2019, 5, "000098514", 180, "Mouse Fish, the Second", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.R); _lib.AddLibraryMusic("Squash Those Mushrooms", "Music Inc", 2020, 6, "000063541", 51, "Stephan Smith", LibraryMediaItem.MediaType.VINYL, 15); _lib.AddLibraryMusic("Seven In and 4 out", "Loud & Right Company", 2025, 5, "000065482", 60, "7 Snails", LibraryMediaItem.MediaType.SACD, 16); _lib.AddPatron("Billy Bo", "12345"); _lib.AddPatron("Milly Bo", "12346"); _lib.AddPatron("Sally Bo", "12347"); _lib.AddPatron("Silly Bo", "12348"); _lib.AddPatron("Gilly Bo", "12349"); }
private Library _lib; //The Library Object //Precondition: None //Postcondition: Books and Patrons will be displayed in the GUI public Program2() { //Precondition: none //Postcondition: The Program2 Form GUI is initialized InitializeComponent(); _lib = new Library(); //Insert Test Data _lib.AddLibraryBook("The Hills Have Eyes", "UofL Press", 2010, 20, "44RTW", "Dr.Wright"); _lib.AddLibraryBook("To Kill a Mockingbird", "NY Press", 1998, 20, "46RYW", "Moll Happerns"); _lib.AddLibraryMovie("The Color Purple", "Movies Press", 1987, 21, "TT432", 1.23, "Logan Jones", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.PG13); _lib.AddLibraryMovie("101 Dalmations", "Kids Movies Press", 1956, 21, "HE321", 2.15, "Jessie James", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.G); _lib.AddLibraryJournal("Journal of Teen Fashion", "Teen Press", 2019, 14, "PPO98", 4, 6, "Fashion", "Jimmy Richards"); _lib.AddLibraryJournal("Journal of Calculus", "Math Press", 2001, 14, "DEO48", 10, 7, "Math", "Caroline Henderson"); _lib.AddLibraryMagazine("Vogue", "Fashion Press", 2013, 20, "IU74W", 3, 12); _lib.AddLibraryMagazine("NascarRaces", "Cars Press", 2004, 20, "FG487", 5, 7); _lib.AddLibraryMusic("The Sound of Music", "Broadway Classics", 1996, 14, "890TR", 4.67, "Various Artists", LibraryMediaItem.MediaType.CD, 4); _lib.AddLibraryMusic("The Story of My Life", "Music Producers Inc.", 2007, 14, "CCS23", 1.55, "One Direction", LibraryMediaItem.MediaType.CD, 12); //Add 5 Patrons _lib.AddPatron("Emily Robertson", "987EE"); _lib.AddPatron("Molly Baldock", "PP901"); _lib.AddPatron("Jessie Hehn", "87TRE"); _lib.AddPatron("Akansha Gupta", "3WQ12"); _lib.AddPatron("Maddie Bloemer", "54RFC1"); }
private void bookToolStripMenuItem_Click(object sender, EventArgs e) { //creates the book subform and opens it. BookForm bookForm = new BookForm(); DialogResult result; //Holds the dialog result string title; //holds the title of the book string publisher; //holds the publisher of the book int copyRightYear; //holds the copyRightYear of the book int loanPeriod; //holds the loanPeriod of the book string callNum; //holds the callNum of the book string author; //holds the author of the book result = bookForm.ShowDialog(); if (result == DialogResult.OK) // Update when user clicks OK { title = bookForm.Title; publisher = bookForm.Publisher; copyRightYear = int.Parse(bookForm.CopyRightYear); loanPeriod = int.Parse(bookForm.LoanPeriod); callNum = bookForm.CallNumber; author = bookForm.Author; newLibrary.AddLibraryBook(title, publisher, copyRightYear, loanPeriod, callNum, author); } }
private void addBookToolStripMenuItem_Click(object sender, EventArgs e) {//precondition:result must be OK //postcondition: book is added BookInputForm bookInputBox = new BookInputForm();//form instance DialogResult result; result = bookInputBox.ShowDialog(); if (result == DialogResult.OK) { item.AddLibraryBook(bookInputBox.bookTitle, bookInputBox.bookPublisher, int.Parse(bookInputBox.bookCopyRightYear), int.Parse(bookInputBox.bookLoanPeriod), bookInputBox.bookCallNumber, bookInputBox.bookAuthor); //add book } }
DialogResult result; // holds dialog result public MainForm() { InitializeComponent(); _lib = new Library(); // creates the library //Adding library items _lib.AddLibraryBook("The Wright Guide to C#", "UofL Press", 2010, 14, "ZZ25 3G", "Andrew Wright"); _lib.AddLibraryBook("Harry Potter", " Bloomsbury Publishing ", 1997, 14, "ZZ25 3G", " J. K. Rowling"); //Adding 2 two LibraryMovie objects to the list _lib.AddLibraryMovie(" Andrew's Super-Duper Movie ", " UofL Movies ", 2019, 7, "MM33 2D", 92.5, " Andrew L. Wright ", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG); // Trims? _lib.AddLibraryMovie(" Frozen 2 ", " Disney ", 2019, 7, "MM33 2D", 92.5, " Jennifer Lee ", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG); //Adding 2 two LibraryMusic objects to the list _lib.AddLibraryMusic("C# - The Album", "UofL Music", 2020, 14, "CD44 4Z", 84.3, "Dr. A", LibraryMediaItem.MediaType.CD, 10); _lib.AddLibraryMusic("Lover", "Jack Antonoff", 2019, 14, "CD44 4Z", 84.3, "Dr. A", LibraryMediaItem.MediaType.CD, 10); //Adding 2 two LibraryJournal objects to the list _lib.AddLibraryJournal("Journal of C# Goodness", "UofL Journals", 2018, 14, "JJ12 7M", 1, 2, "Information Systems", "Andrew Wright"); _lib.AddLibraryJournal("Physics", "UofL Journals", 2018, 14, "JJ12 7M", 1, 2, "Science", "XYZ"); //Adding 2 two LibraryMagazine objects to the list _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2017, 14, "MA53 9A", 16, 7); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2017, 14, "MA53 9A", 9, 10); // Adding patrons to the patrons list _lib.AddPatron("Ima Reader", "12345"); _lib.AddPatron("Jane Doe", "11223"); _lib.AddPatron(" John Smith ", " 654321 "); // Trims? _lib.AddPatron("Joe John", "12003"); _lib.AddPatron("Jake", "60890"); _lib.AddPatron(" Steve ", " 70623 "); }
private void bookToolStripMenuItem_Click(object sender, EventArgs e) { BookForm bookform = new BookForm(); // Bookform is created DialogResult result; // Dialog result is created result = bookform.ShowDialog(); if (result == DialogResult.OK) { string title = bookform.Title; // Title is set using the form property string publisher = bookform.Publisher; // Publisher is set using the form property int copyrightyear = int.Parse(bookform.CopyrightYear); // Copyrightyear is set using the form property int loanperiod = int.Parse(bookform.LoanPeriod); // Loanperiod is set using the form property string callnumber = bookform.CallNumber; // Callnumber is set using the form property string author = bookform.Author; // Author is set using the form property // A new library book is added to the library newLibrary.AddLibraryBook(title, publisher, copyrightyear, loanperiod, callnumber, author); } }
//Precondition: Insert -> book item is activated //Postcondition: New book is inserted private void bookToolStripMenuItem_Click(object sender, EventArgs e) { BookForm bookForm = new BookForm(); DialogResult result = bookForm.ShowDialog(); if (result == DialogResult.OK) { library.AddLibraryBook(bookForm.BookTitle, bookForm.BookPublisher, int.Parse(bookForm.BookCopyright), int.Parse(bookForm.BookLoanPeriod), bookForm.BookCallNumber, bookForm.BookAuthor); } }
private Library lib; // The library #endregion Fields #region Constructors // Precondition: None // Postcondition: The form's GUI is prepared for display. A few test items and patrons // are added to the library public Prog2Form() { InitializeComponent(); lib = new Library(); // Create the library // Insert test data - Magic numbers allowed here lib.AddLibraryBook("The Wright Guide to C#", "UofL Press", 2010, 14, "ZZ225 3G", "Andrew Wright"); lib.AddLibraryBook("Harriet Pooter", "Stealer Books", 2000, 21, "AG773 ZF", "IP Thief"); lib.AddLibraryMovie("Andrew's Super-Duper Movie", "UofL Movies", 2011, 7, "MM33 2D", 92.5, "Andrew L. Wright", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG); lib.AddLibraryMovie("Pirates of the Carribean: The Curse of C#", "Disney Programming", 2011, 10, "MO93 4S", 122.5, "Steven Stealberg", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.G); lib.AddLibraryMusic("C# - The Album", "UofL Music", 2011, 14, "CD44 4Z", 84.3, "Dr. A", LibraryMediaItem.MediaType.CD, 10); lib.AddLibraryMusic("The Sounds of Programming", "Soundproof Music", 1996, 21, "VI64 1Z", 65.0, "Cee Sharpe", LibraryMediaItem.MediaType.VINYL, 12); lib.AddLibraryJournal("Journal of C# Goodness", "UofL Journals", 2011, 14, "JJ12 7M", 1, 2, "Information Systems", "Andrew Wright"); lib.AddLibraryJournal("Journal of VB Goodness", "UofL Journals", 2007, 14, "JJ34 3F", 8, 4, "Information Systems", "Alexander Williams"); lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2010, 14, "MA53 9A", 16, 7); lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2010, 14, "MA53 9B", 16, 8); lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2010, 14, "MA53 9C", 16, 9); lib.AddLibraryMagazine("VB Magazine", "UofL Mags", 2011, 14, "MA21 5V", 1, 1); // Add 5 Patrons lib.AddPatron("Ima Reader", "12345"); lib.AddPatron("Jane Doe", "11223"); lib.AddPatron("John Smith", "54321"); lib.AddPatron("James T. Kirk", "98765"); lib.AddPatron("Jean-Luc Picard", "33456"); }
// Precondition: Insert, Book menu item activated // Postcondition: The Book dialog box is displayed. If data entered // are OK, a LibraryBook is created and added to the library private void bookToolStripMenuItem_Click(object sender, EventArgs e) { BookForm bookForm = new BookForm(); // The book dialog box form DialogResult result = bookForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { try { // Use form's properties to get book info to send to library _lib.AddLibraryBook(bookForm.ItemTitle, bookForm.ItemPublisher, int.Parse(bookForm.ItemCopyrightYear), int.Parse(bookForm.ItemLoanPeriod), bookForm.ItemCallNumber, bookForm.BookAuthor); } catch (FormatException) // This should never happen if form validation works! { MessageBox.Show("Problem with Book Validation!", "Validation Error"); } } bookForm.Dispose(); // Good .NET practice - will get garbage collected anyway }
Library LibraryData = new Library(); // gives access to Library class public LibraryForm() { InitializeComponent(); // hard coded list of patrons and items LibraryData.AddPatron("James Hunt", "001"); LibraryData.AddPatron("Jessica Jones", "002"); LibraryData.AddPatron("James Bond", "003"); LibraryData.AddLibraryBook("Sample B0ok", "Sample Publisher", 2017, 31, "Q111", "Sample Auth0r"); LibraryData.AddLibraryBook("Samp1e Book", "Sample Publisher", 2017, 31, "Q121", "Samp1e Author"); LibraryData.AddLibraryBook("2ample Book", "Sample Publisher", 2017, 31, "Q126", "2ample Author"); LibraryData.AddLibraryBook("Sampl3 Book", "Sample Publisher", 2017, 31, "Q129", "Sampl3 Author"); LibraryData.AddLibraryBook("S4mple Book", "Sample Publisher", 2017, 31, "Q122", "Sample 4uthor"); LibraryData.AddLibraryBook("5ample Book", "Sample Publisher", 2017, 31, "Q023", "5ample Author"); }
// Precondition: Book menuItem activated // Postcondition: The book dialog box is displayed. If data entered // are OK, a book is created and added to the list // of books private void bookToolStripMenuItem_Click(object sender, EventArgs e) { BookForm Book = new BookForm(); // The dialog box form, variable that interacts with book form result = Book.ShowDialog(); string Title; // holds book's title string Publisher; // holds book's author int LoanPeriod; // holds loan period int Copyright; // holds copyright year string CallNumber; // holds call number string Author; // holds author of the book if (result == DialogResult.OK) // Only update if user chose OK from dialog box { Title = Book.TitleValue; Publisher = Book.PublisherValue; Copyright = int.Parse(Book.CopyrightValue); //Retrieve value from dialog box LoanPeriod = int.Parse(Book.LoanPeriodValue); //Retrieve value from dialog box CallNumber = Book.CallNumberValue; Author = Book.AuthorValue; _lib.AddLibraryBook(Title, Publisher, Copyright, LoanPeriod, CallNumber, Author); } }
// Precondition: None // Postcondition: Opens a dialog box that will add a book to the library private void bookToolStripMenuItem_Click(object sender, EventArgs e) { BookForm Book = new BookForm(); // variable that interacts with book form result = Book.ShowDialog(); string Title; // the book's title string Publisher; // the book's author int LoanPeriod; // the loan period int Copyright; // the copyright year string CallNumber; // the call number in the library's system string Author; // the writer of the book if (result == DialogResult.OK) { Title = Book.titleTextbox.Text; Publisher = Book.publisherTextbox.Text; Copyright = int.Parse(Book.copyrightTextbox.Text); LoanPeriod = int.Parse(Book.loanPeriodTextbox.Text); CallNumber = Book.callNumberTextBox.Text; Author = Book.authorTextbox.Text; _lib.AddLibraryBook(Title, Publisher, Copyright, LoanPeriod, CallNumber, Author); } }
private Library _lib; // The library // Precondition: None // Postcondition: The form's GUI is prepared for display. A few test items and patrons // are added to the library public Prog2Form() { InitializeComponent(); _lib = new Library(); // Create the library // Insert test data - Magic numbers allowed here _lib.AddLibraryBook("The Wright Guide to C#", "UofL Press", 2010, 14, "ZZ25 3G", "Andrew Wright"); _lib.AddLibraryBook("Harriet Pooter", "Stealer Books", 2000, 21, "AB73 ZF", "IP Thief"); _lib.AddLibraryMovie("Andrew's Super-Duper Movie", "UofL Movies", 2011, 7, "MM33 2D", 92.5, "Andrew L. Wright", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.PG); _lib.AddLibraryMovie("Pirates of the Carribean: The Curse of C#", "Disney Programming", 2012, 10, "MO93 4S", 122.5, "Steven Stealberg", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.G); _lib.AddLibraryMusic("C# - The Album", "UofL Music", 2014, 14, "CD44 4Z", 84.3, "Dr. A", LibraryMediaItem.MediaType.CD, 10); _lib.AddLibraryMusic("The Sounds of Programming", "Soundproof Music", 1996, 21, "VI64 1Z", 65.0, "Cee Sharpe", LibraryMediaItem.MediaType.VINYL, 12); _lib.AddLibraryJournal("Journal of C# Goodness", "UofL Journals", 2000, 14, "JJ12 7M", 1, 2, "Information Systems", "Andrew Wright"); _lib.AddLibraryJournal("Journal of VB Goodness", "UofL Journals", 2008, 14, "JJ34 3F", 8, 4, "Information Systems", "Alexander Williams"); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2016, 14, "MA53 9A", 16, 7); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2016, 14, "MA53 9B", 16, 8); _lib.AddLibraryMagazine("C# Monthly", "UofL Mags", 2016, 14, "MA53 9C", 16, 9); _lib.AddLibraryMagazine("VB Magazine", "UofL Mags", 2017, 14, "MA21 5V", 1, 1); // Add 5 Patrons _lib.AddPatron("Ima Reader", "12345"); _lib.AddPatron("Jane Doe", "11223"); _lib.AddPatron("John Smith", "54321"); _lib.AddPatron("James T. Kirk", "98765"); _lib.AddPatron("Jean-Luc Picard", "33456"); string NEW = Environment.NewLine; // Constant string holder for new lines Console.WriteLine("Original List" + NEW); foreach (LibraryItem i in _lib.GetItemsList()) // walking thru library { Console.WriteLine(i + NEW); // print } Console.WriteLine("Please press a key to continue..."); Console.ReadLine(); // Sorting by title _lib.GetItemsList().Sort(); Console.WriteLine("Sorted Items" + NEW); foreach (LibraryItem i in _lib.GetItemsList()) { Console.WriteLine(i + NEW); } Console.WriteLine("Please press a key to continue..."); Console.ReadLine(); // Sorting in desc order by copyright year _lib.GetItemsList().Sort(new DescendingCopyRightYear()); Console.WriteLine("Descending Order by Copyright Year" + NEW); foreach (LibraryItem i in _lib.GetItemsList()) { Console.WriteLine(i + NEW); } Console.WriteLine("Please press a key to continue..."); Console.ReadLine(); }