/// <summary> /// Initializes a new instance of the MovieExemplaCollection class that is /// owned by a database. For remarks explaining 'ownership' of exemplars /// <see cref="MovieExemplarCollection.MovieExemplarCollection(Movie movie)"/> /// constructor. /// </summary> /// public MovieExemplarCollection(VideoRentalOutlet database) : base(database, "Movie Exemplars", "Movie Exemplar") { this.Movie = null; this.lastExemplarID = 0; ForwardChangedEventsToDatabase = false; }
///////////////////////////////////////////////////////////////////////////////// #region [ Constructors ] /// <summary> /// Initializes a new instance of the price list class containing a default base /// price specification. (See <see cref="MinQuantityprice.IsBasePrice"/>.) /// </summary> /// public PriceList(VideoRentalOutlet database) : base(database, "Price List", "Price Specification") { ForwardChangedEventsToDatabase = true; // Add a default 'base' price specification. // UpdatePrice(Membership.NotMember, PriceClass.SwedishNew, 1, 100m); }
///////////////////////////////////////////////////////////////////////////////// #region [ Constructors ] /// <summary> /// Creates a new instance of price specification. Note that constructor is /// marked as internal, so the user cannot directly create instances -- /// it must use <see cref="PriceList.UpdatePrice"/> method instead. /// </summary> /// internal MinQuantityPrice(VideoRentalOutlet database, Membership membership, PriceClass priceClass) : base(database, "Price Specification") { // Mandatory values // this.ID = database.NextPriceSpecID; this.Membership = membership; this.PriceClass = priceClass; // Default properties: // this.MinimumQuantity = 0; this.Price = 0; }
///////////////////////////////////////////////////////////////////////////////// #region [ Public Methods ] /// <summary> /// Inserts newly created instance into database. /// </summary> /// public Movie AddTo(VideoRentalOutlet database) { VerifyAddTo(database); Database = database; ID = Database.NextMovieID; this.MovieExemplars = new MovieExemplarCollection(this); LockProperties(); // make record immutable Database.Movies.Add(this); return(this); }
///////////////////////////////////////////////////////////////////////////////////// #region [ Constructor ] /// <summary> /// Initializes a new main form of the Video Rentl Outlet application. /// </summary> /// public MainForm() : base() { FormBase.MainForm = this; ///////////////////////////////////////////////////////////////////////////////// InitializeComponents(); InitializeMainMenu(); ///////////////////////////////////////////////////////////////////////////////// VideoStore = new VideoRentalOutlet("No Name", "(No VAT)"); VideoStore.Changed += VideoStore_Changed; UpdateTitle(); }
///////////////////////////////////////////////////////////////////////////////// public void LoadFromFile(string filename) { Out.Begin(); ///////////////////////////////////////////////////////////////////////////// Out.Title("Deserializing video store data..."); VideoStore = null; try { // Open the file containing the data that we want to deserialize. // using (FileStream fs = new FileStream(filename, FileMode.Create)) { VideoStore = VideoRentalOutlet.Deserialize(fs); } } catch (Exception ex) { Out.WriteLine(ex); } if (VideoStore == null) { return; } Out.WriteLine(VideoStore.FullInfo()); Out.WriteLine(VideoStore.MovieExemplars.FullInfo()); Out.WriteLine(VideoStore.Movies.FullInfo()); Out.WriteLine(VideoStore.Customers.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.End(); }
///////////////////////////////////////////////////////////////////////////////// #region [ Public Methods ] /// <summary> /// Inserts newly created instance into database. /// </summary> /// public Customer AddTo(VideoRentalOutlet database) { VerifyAddTo(database); Database = database; Customer customerWithPID = Database.Customers.FindByPersID(PersonID); if (customerWithPID != null && customerWithPID != this) { throw new ArgumentException("Customer with the same Person-ID " + "already exists in database."); } ID = Database.NextCustomerID; this.RentedItems = new RentedItems(this); LockProperties(); // make record immutable Database.Customers.Add(this); return(this); }
///////////////////////////////////////////////////////////////////////////////////// #region [ Load/Save Database Methods ] /// <summary> /// Loads database from file. /// </summary> /// private void LoadDatabase(string filename, string caption, bool silent = false) { string progressInfo = "Loading database from '" + filename + "'..."; // Remove children from client area (probably referring to the contents // of the current database) // UnloadAllMdiChildForms(); // Create progress bar // MyProgressBar progress = new MyProgressBar(this, progressInfo); Exception lastException = null; VideoRentalOutlet loadedStore = null; string elapsedTime = string.Empty; // Deserialize database using our file stream with progress info. // try { FileInfo fileInfo = new FileInfo(filename); long fileLength = fileInfo.Exists ? fileInfo.Length : 0; using (FileStreamWithProgressBar fs = new FileStreamWithProgressBar( filename, FileMode.Open, progress, fileLength) ) { loadedStore = VideoRentalOutlet.Deserialize(fs); fs.StopTimer(); elapsedTime = " in " + fs.VerboseElapsedTime; } } catch (Exception ex) { lastException = ex; } progress.Quit(); if (loadedStore != null) { VideoStore = loadedStore; VideoStore.Changed += VideoStore_Changed; string info = VideoStore.TotalRecordsCount.ToString() + " records loaded from '" + filename + "'" + elapsedTime; if (silent) { this.InfoMessage = info; } else { info += "\n\n\n" + VideoStore.StatisticsInfo(info.Length) + "\n"; MessageBox.Show(info, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } UpdateTitle(); } else if (lastException != null) { MessageBox.Show( "There was an error while loading database.\n\n" + "Filename: " + filename + "\n\n" + "System Message:\n\n" + lastException.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
///////////////////////////////////////////////////////////////////////////////////// #region [ Initialize Test Database and Add Test Records to Database Methods ] /// <summary> /// Initializes sample database using VRO_TestSuite (from ID132V Lab3a). /// </summary> /// private void InitializeTestDatabase() { DialogResult answer = MessageBox.Show( "You are about to delete all current data!\n\nAre you sure?", "Initialize Sample Database", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (answer != DialogResult.Yes) { return; } UnloadAllMdiChildForms(); // Create progress bar // MyProgressBar progress = new MyProgressBar(this, "Initializing database..."); progress.Minimum = 0; progress.Maximum = 100; string report = null; try { VRO_TestSuite.StringWriter sb = new VRO_TestSuite.StringWriter(); VRO_TestSuite.TestClient_VRO test = new VRO_TestSuite.TestClient_VRO(sb); sb.WriteLine(); sb.WriteLine("Initializing Sample Database..."); test.CreateSampleDatabase(); progress.Value = 100; progress.Refresh(); report = sb.ToString(); if (test.VideoStore != null) { VideoStore = test.VideoStore; VideoStore.Changed += VideoStore_Changed; UpdateTitle(); } } catch (Exception ex) { report = ex.ToString(); } progress.Quit(); try { System.IO.File.WriteAllText("VRO-test.txt", report); report += "Report saved to to 'VRO-Test.txt'"; } catch {} ShowReport("Video Rental Outlet - Test Suite Report", report); }
///////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes Database menu sub-item. /// </summary> /// private void InitializeMenu_Database(MenuItem parentItem) { MenuItem miDatabase = new MenuItem("&Database"); SetToolTip(miDatabase, "Load, save and initialize database..."); parentItem.MenuItems.Add(miDatabase); //------------------------------------------------------------------------------- MenuItem miDatabaseDump = new MenuItem("&Dump Database..."); SetToolTip(miDatabaseDump, "Dump database contents to file 'VRO-dump.txt'..."); miDatabase.MenuItems.Add(miDatabaseDump); miDatabaseDump.Click += delegate { DumpDatabase(); }; //------------------------------------------------------------------------------- miDatabase.MenuItems.Add(new MenuItem("-")); //------------------------------------------------------------------------------- MenuItem miDatabaseLoad = new MenuItem("Re&load"); SetToolTip(miDatabaseLoad, "Reload database from file..."); miDatabase.MenuItems.Add(miDatabaseLoad); miDatabaseLoad.Click += delegate { DialogResult answer = MessageBox.Show( "You are about to reload database from file.\r\n\r\n" + "All changes to data will be lost!", "Loading Database", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (answer != DialogResult.OK) { return; } LoadDatabase(this.databaseFilename, "Video Rental Outlet Database"); }; //------------------------------------------------------------------------------- MenuItem miDatabaseSave = new MenuItem("&Save"); SetToolTip(miDatabaseSave, "Save current database into file..."); miDatabase.MenuItems.Add(miDatabaseSave); miDatabaseSave.Click += delegate { SaveDatabase(this.databaseFilename, "Video Rental Outlet Database"); }; //------------------------------------------------------------------------------- miDatabase.MenuItems.Add(new MenuItem("-")); //------------------------------------------------------------------------------- MenuItem miDatabaseClear = new MenuItem("&Clear All Data"); SetToolTip(miDatabaseClear, "Initialize an empty database..."); miDatabase.MenuItems.Add(miDatabaseClear); miDatabaseClear.Click += delegate { DialogResult answer = MessageBox.Show( "You are about to delete all current data!\r\n\r\n" + "Are you sure?", "Clear Database", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (answer != DialogResult.Yes) { return; } UnloadAllMdiChildForms(); VideoStore = new VideoRentalOutlet("No Name", "(No VAT)"); VideoStore.Changed += VideoStore_Changed; UpdateTitle(); }; //------------------------------------------------------------------------------- MenuItem miDatabaseInitialize = new MenuItem("&Initialize Sample Database"); SetToolTip(miDatabaseInitialize, "Initialize database with sample data..."); miDatabase.MenuItems.Add(miDatabaseInitialize); miDatabaseInitialize.Click += delegate { try { InitializeTestDatabase(); } catch (Exception ex) { // As InitializeTestDatabase method uses external DLL, we cannot catch // "could not load dll error" inside the method, so we do it here. // Note that the method handles itself its own exceptions. // MessageBox.Show(ex.Message, "Error Loading DLL", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }; //------------------------------------------------------------------------------- miDatabase.MenuItems.Add(new MenuItem("-")); //------------------------------------------------------------------------------- MenuItem miFileTestAddRandomData = new MenuItem("Add &Random Data"); SetToolTip(miFileTestAddRandomData, "Add random data to current database..."); miDatabase.MenuItems.Add(miFileTestAddRandomData); miFileTestAddRandomData.Click += delegate { try { AddTestRecordsToDatabase(); } catch (Exception ex) { // As AddTestRecordsToDatabase method uses external DLL, we cannot catch // "could not load dll error" inside the method, so we do it here // Note that the method handles itself its own exceptions. // MessageBox.Show(ex.Message, "Error Loading DLL", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }; }
///////////////////////////////////////////////////////////////////////////////// #region [ Constructors ] /// <summary> /// Initializes a new instance of the Library class with an empty item store. /// </summary> /// public MovieCollection(VideoRentalOutlet database) : base(database, "Movies", "Movie") { ForwardChangedEventsToDatabase = true; }
///////////////////////////////////////////////////////////////////////////////// #region [ Test Suite ] /// <summary> /// Creates a sample VRO database and runs various tests according ID132V /// Lab3a specification. /// </summary> /// <remarks> /// Final contents of the sample database: /// <pre> /// 3 customers /// 3 price specifications /// 4 movies /// 9 movie exemplars /// 3 rented items /// </pre> /// </remarks> /// public void CreateSampleDatabase() { ///////////////////////////////////////////////////////////////////////////// // Create default instance of VideoRentalOutlet class and hook // our event handler that will trace changes. VideoStore = new VideoRentalOutlet("Blurry Bluray", "SE554078214101") { Address = "Tulegatan 50", PostCode = "112 54", City = "Solna", Country = "Sweden", Phone = "+46(8)90510", EMail = "*****@*****.**", HomePage = "http://www.blurrybluray.com" }; VideoStore.Changed += VideoStore_Changed; Out.Begin(); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping contents of initial empty store..."); Out.WriteLine(VideoStore.FullInfo()); Out.WriteLine(VideoStore.PriceList.FullInfo()); Out.WriteLine(VideoStore.Customers.FullInfo()); Out.WriteLine(VideoStore.MovieExemplars.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Changing price list..."); VideoStore.PriceList.UpdatePrice(Membership.Member, PriceClass.OlderMovie, 1, 10m); VideoStore.PriceList.UpdatePrice(Membership.GoldMember, PriceClass.OlderMovie, 1, 5m); VideoStore.PriceList.UpdatePrice(Membership.GoldMember, PriceClass.NewHotMovie, 1, 10m); VideoStore.PriceList.UpdatePrice(Membership.NotMember, PriceClass.OlderMovie, 3, 15m); VideoStore.PriceList.UpdatePrice(Membership.NotMember, PriceClass.SwedishNew, 1, 20m); Out.WriteLine(VideoStore.PriceList.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Getting fees for misc Membership/PriceClass combinations..."); Enum[] membershipsDesc = { Membership.GoldMember, Membership.Member, Membership.NotMember }; Enum[] priceClassesAsc = { PriceClass.OlderMovie, PriceClass.NewMovie, PriceClass.NewHotMovie, PriceClass.SwedishNew, }; int[] quantitiesDesc = { 5, 1 }; foreach (Enum membership in membershipsDesc) { foreach (Enum priceClass in priceClassesAsc) { foreach (int quantity in quantitiesDesc) { decimal fee = VideoStore.GetPrice( (Membership)membership, (PriceClass)priceClass, quantity); Out.WriteLine(string.Format("{0,-12} {1,-15} {2,3} {3,8:0.00}", membership.Verbose(), priceClass.Verbose(), quantity, fee)); } } } ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Andrew Wiles as a customer..."); Customer customer = new Customer() { PersonID = "US 1953-05-14", FirstName = "Andrew", LastName = "Wiles", Address = "Princeton University", PostCode = "08544", City = "Princeton, NJ", Country = "USA", Phone = "+1(609)789-44-44", CreditCard = new CreditCard(CreditCardType.VISA, "4000-0012-3456-7899", 14, 12), Membership = Membership.Member }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding John Poe as a customer..."); customer = new Customer() { PersonID = "820315-1035", FirstName = "John", LastName = "Poe", Address = "aaa", PostCode = "ppp", City = "ccc", EMail = "*****@*****.**", Membership = Membership.GoldMember }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Linnéa Andersson as a customer..."); customer = new Customer() { PersonID = "830415-2034", FirstName = "Linnéa", LastName = "Andersson", Address = "Ostmästargatan 12", PostCode = "128 87", City = "Stockholm", CellPhone = "+46(73)45342225", Membership = Membership.GoldMember }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding Richard Liboff as a customer..."); customer = new Customer() { PersonID = "193405143415", FirstName = "Richard", LastName = "Liboff", Address = "Oxvägen 44", PostCode = "141 40", City = "Huddinge", Phone = "+46(8)7798881", EMail = "*****@*****.**" }; customer.AddTo(VideoStore); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing non-existing customer..."); VideoStore.RemoveCustomer(cust => cust.FirstName == "(*&*($@"); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Changing customer's last name 'Poe' to 'Doe'..."); customer = VideoStore.FindCustomer(cust => cust.LastName == "Poe"); customer = new Customer(customer); customer.LastName = "Doe"; customer.Update(); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing customer with name 'John Doe'..."); VideoStore.RemoveCustomer(cust => cust.FullName == "John Doe"); Out.WriteLine(VideoStore.Customers); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping contents of the customer database..."); Out.WriteLine(VideoStore.Customers.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 1 VHS and 3 BluRay copies of '2001 A Space Odyssey'..."); Movie movie = new Movie() { Title = "2001: A Space Odyssey", IMDB = "http://www.imdb.com/title/tt0062622/", Genre = Genre.ScienceFiction | Genre.Adventure | Genre.Mystery, FirstRelease = new DateTime(1968, 4, 2), Duration = new TimeSpan(0, 141, 0), Country = "UK | US", Language = "English | Russian (only few words)", PgRate = "11 (Sweden)", Directors = new List <string> () { "Stanley Kubrick" }, Writers = new List <string> () { "Stanley Kubrick", "Arthur C Clarke" }, Actors = new List <MovieActor> () { new MovieActor("Keir Dullea", "Dr Dave Bowman"), new MovieActor("Gary Lockwood", "Dr Frank Poole "), new MovieActor("William Sylves", "Dr Heywood R Floyd"), new MovieActor("Douglas Rain", "HAL 9000 (voice)"), } }; movie.AddTo(VideoStore); MovieExemplar exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1999, 6, 29), ImageFormat = "NTSC 4:3", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00000J2KZ", Features = "Turner Home Ent" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2007, 10, 23), ImageFormat = "2.20:1", Subtitles = "English | Spanish | French", PriceClass = PriceClass.NewMovie, ISAN = "ASIN:B000Q66J1M", Features = "All Regions" }; exemplar.AddTo(movie).CreateCopies(2); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 2 DVD copies of 'Platoon'..."); movie = new Movie() { Title = "Platoon", IMDB = "http://www.imdb.com/title/tt0091763/", Genre = Genre.Action | Genre.Drama | Genre.War, FirstRelease = new DateTime(1986, 12, 19), Duration = new TimeSpan(0, 120, 0), Country = "UK | US", Language = "English | Vietnamese", PgRate = "15 (Sweden)", Directors = new List <string> () { "Oliver Stone" }, Writers = new List <string> () { "Oliver Stone" }, Actors = new List <MovieActor> () { new MovieActor("Charlie Sheen", "Chris"), new MovieActor("Tom Berenger", "Sgt. Barnes"), new MovieActor("Willem Dafoe", "Sgt. Elias"), } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(2001, 6, 5), ImageFormat = "Anamorphic, 1.85:1", Subtitles = "Spanish | French", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00005AUJQ", Features = "Special Edition | MGM" }; exemplar.AddTo(movie).CreateCopies(1); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding one exemplar of 'Sällskapsresan'..."); movie = new Movie() { Title = "Sällskapsresan", IMDB = "http://www.imdb.com/title/tt0081590/", FirstRelease = new DateTime(1980, 8, 22), Duration = new TimeSpan(0, 107, 0), Country = "Sweden", Language = "Swedish | Norwegian | Spanish", Directors = new List <string> () { "Lasse Åberg", "Peter Hald" }, Writers = new List <string> () { "Bo Jönsson", "Lasse Åberg" }, Actors = new List <MovieActor> () { new MovieActor("Lasse Åberg", "Stig-Helmer Olsson"), new MovieActor("Lottie Ejebrant", "Maj-Britt Lindberg"), new MovieActor("Jon Skolmen", "Ole Bramserud") } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.BluRay, Released = new DateTime(2001, 6, 5), ImageFormat = "Widescreen (1.78:1)", Subtitles = "Swedish | Norwegian", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B003TLJY1I", Features = "SF(Fox) | Region 2" }; exemplar.AddTo(movie); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Adding 2 DVD, 1 VHS and 1 BluRay copies of 'Citizen Kane'..."); movie = new Movie() { Title = "Citizen Kane", IMDB = "http://www.imdb.com/title/tt0033467/", Genre = Genre.Drama | Genre.Mystery, FirstRelease = new DateTime(1941, 5, 1), Duration = new TimeSpan(0, 119, 0), Country = "USA", Language = "English", PgRate = "15 (Sweden)", Directors = new List <string> () { "Orson Welles" }, Writers = new List <string> () { "Herman J. Mankiewicz", "Orson Welles" }, Actors = new List <MovieActor> () { new MovieActor("Orson Welles", "Kane"), new MovieActor("Joseph Cotten", "Jedediah Leland"), new MovieActor("Dorothy Comingore", "Susan A Kane"), } }; movie.AddTo(VideoStore); exemplar = new MovieExemplar() { Media = Media.DVD, Released = new DateTime(2001, 9, 25), ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B00003CX9E", Features = "Turner Home Ent | 2 discs" }; exemplar.AddTo(movie).CreateCopies(1); exemplar = new MovieExemplar() { Media = Media.VHS, Released = new DateTime(1996, 8, 13), ImageFormat = "B&W, 1.33:1, NTSC", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:6304119046", Features = "RKO Radio Pictures | Special Edition" }; exemplar.AddTo(movie); exemplar = new MovieExemplar() { Media = Media.BluRay, ImageFormat = "B&W, 1.33:1, NTSC", Subtitles = "English | French | Portuguese | Spanish ", PriceClass = PriceClass.OlderMovie, ISAN = "ASIN:B001PIHH5M", Features = "Warner" }; exemplar.AddTo(movie); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing exemplar with ID #3 from library..."); VideoStore.RemoveMovieExemplar(ex => ex.ID == 3); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Removing exemplar with ID #8 from library..."); VideoStore.RemoveMovieExemplar(ex => ex.ID == 8); Out.WriteLine(VideoStore.Movies); Out.WriteLine(); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #4 to user with PID 830415-2034"); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 4), VideoStore.FindCustomer(cust => cust.PersonID == "830415-2034"), /* rent days: */ 2, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie ex #6 to user with first name Andrew..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 6), VideoStore.FindCustomer(cust => cust.FirstName == "Andrew"), /* rent days: */ 3, /* rental fee: */ 20 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Returning exemplar #4 from renting..."); VideoStore.ReturnItem( VideoStore.FindMovieExemplar(ex => ex.ID == 4) ); Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #2 to user with ID #1..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 2), VideoStore.FindCustomer(cust => cust.ID == 1), /* rent days: */ 1, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("Renting out movie exemplar #9 to user with ID #3..."); try { VideoStore.RentItem( VideoStore.FindMovieExemplar(ex => ex.ID == 9), VideoStore.FindCustomer(cust => cust.ID == 3), /* rent days: */ 1, /* rental fee: */ 15 ); } catch (Exception ex) { Out.WriteLine(ex.Message); } Out.WriteLine(VideoStore.MovieExemplars); ///////////////////////////////////////////////////////////////////////////// Out.Title("LINQ: Listing all rented items using LINQ and yield return..."); var rented = from p in VideoStore.RentedItems select p; Out.WriteLine("Total {0} rented items:", rented.Count <RentedItem> ()); foreach (var item in rented) { Out.WriteLine(); Out.WriteLine(item); Out.WriteLine(); Out.WriteLine(" " + item.Exemplar); Out.WriteLine(" " + item.RentedTo); } ///////////////////////////////////////////////////////////////////////////// Out.Title("LINQ: Querying movies having 'odys' in title..."); var queryMovies = from p in VideoStore.Movies where p.FullTitle.ToLower().Contains("odys") select p; Out.WriteLine("Selected {0} movies:", queryMovies.Count <Movie> ()); foreach (var item in queryMovies) { Out.WriteLine(item.FullTitle); } ////////////////////////////////////////////////////////////////////////////// Out.Title("Dumping final movie collection..."); Out.WriteLine(VideoStore.Movies.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping final movie exemplar collection..."); Out.WriteLine(VideoStore.MovieExemplars.FullInfo()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping all customers with rented items..."); Out.WriteLine(VideoStore.QueryAllCustomersWithRentals()); ///////////////////////////////////////////////////////////////////////////// Out.Title("Dumping all rented items..."); Out.WriteLine(VideoStore.QueryAllRentedItems()); ///////////////////////////////////////////////////////////////////////////// // Don't forget to remove hooked event handlers and mark end of test. // VideoStore.Changed -= VideoStore_Changed; Out.End(); ///////////////////////////////////////////////////////////////////////////// // Our sample database is now ready to be used. }
///////////////////////////////////////////////////////////////////////////////// #region [ Constructors ] /// <summary> /// Initializes a new instance of the CustomerDB class with an empty database. /// </summary> /// public CustomerCollection(VideoRentalOutlet database) : base(database, "Customers", "Customer") { ForwardChangedEventsToDatabase = true; }