Пример #1
0
        //METHOD THAT DESERIALIZES USING OUR METHOD
        public DataRepository Deserialize(IFormatter formatter, FileStream FS)
        {
            //Recreating all Klient and Ksiazka objects from the file.
            for (int i = 0; i < ClientAmount; i++)
            {
                DataRepository.AddClient((Klient)formatter.Deserialize(FS));
            }
            for (int i = 0; i < BookAmount; i++)
            {
                Ksiazka K = (Ksiazka)formatter.Deserialize(FS);
                DataRepository.AddBook(K);
            }
            //Recreating all Egzemplarz objects from the file and setting their references at the same time.
            for (int i = 0; i < CopyAmount; i++)
            {
                Egzemplarz E = (Egzemplarz)formatter.Deserialize(FS);
                E.Book = DataRepository.GetBook((Guid)formatter.Deserialize(FS));
                DataRepository.AddCopy(E);
            }
            //Recreating all Faktura objects from the file and setting their references at the same time.
            for (int i = 0; i < InvoiceAmount; i++)
            {
                Faktura F = (Faktura)formatter.Deserialize(FS);
                F.Client = DataRepository.GetClient((Guid)formatter.Deserialize(FS));
                F.Copy   = DataRepository.GetCopy((Guid)formatter.Deserialize(FS));

                DataRepository.AddInvoice(F);
            }
            //Closing file from which we deserialized data.
            FS.Close();
            //Returning the recreated DataRepository object.
            return(DataRepository);
        }
        // METHOD THAT FILLS DATA REPOSITORY
        public void Fill(DataContext DC)
        {
            // ADDING CLIENTS TO THE DATA REPOSITORY;
            Klient K1 = new Klient("Dorian", "Grzybiarczyk", 20);
            Klient K2 = new Klient("Przemyslaw", "Sosnka", 10);
            Klient K3 = new Klient("Gracjan", "Graala", 44);
            Klient K4 = new Klient("Edyta", "Piotrkarczyk", 0);
            Klient K5 = new Klient("Dominik", "Nieciesielski", 0);

            DC.Client.Add(K1);
            DC.Client.Add(K2);
            DC.Client.Add(K3);
            DC.Client.Add(K4);
            DC.Client.Add(K5);

            // ADDING NEW BOOKS TO THE BOOKSTORE
            Ksiazka KS1 = new Ksiazka(System.Guid.NewGuid(), "Pan Tadeusz", "Mickiewicz");
            Ksiazka KS2 = new Ksiazka(System.Guid.NewGuid(), "Dziady", "Mickiewicz");
            Ksiazka KS3 = new Ksiazka(System.Guid.NewGuid(), "Harry Potter", "Rolling");
            Ksiazka KS4 = new Ksiazka(System.Guid.NewGuid(), "Ludzie bezdomni", "Żeromski");
            Ksiazka KS5 = new Ksiazka(System.Guid.NewGuid(), "Zbrodnia i Kara", "Dostojewski");

            DC.Book.Add(KS1.Index, KS1);
            DC.Book.Add(KS2.Index, KS2);
            DC.Book.Add(KS3.Index, KS3);
            DC.Book.Add(KS4.Index, KS4);
            DC.Book.Add(KS5.Index, KS5);

            // ADDING THE COPIES AVAIABLE
            Egzemplarz E1 = new Egzemplarz(20, "Helium", new DateTime(2009), KS1);
            Egzemplarz E2 = new Egzemplarz(15.5, "WSIP", new DateTime(1997), KS2);
            Egzemplarz E3 = new Egzemplarz(9.99, "Znak", new DateTime(2001), KS3);
            Egzemplarz E4 = new Egzemplarz(2.99, "Helium", new DateTime(2005), KS4);
            Egzemplarz E5 = new Egzemplarz(99.95, "WSIP", new DateTime(1990), KS5);

            DC.Copy.Add(E1);
            DC.Copy.Add(E2);
            DC.Copy.Add(E3);
            DC.Copy.Add(E4);
            DC.Copy.Add(E5);

            // ADDING INVOICES
            Faktura F1 = new Faktura(new DateTime(2018, 11, 3), E5, K5);
            Faktura F2 = new Faktura(new DateTime(2018, 11, 3), E4, K1);
            Faktura F3 = new Faktura(new DateTime(2018, 11, 5), E3, K4);

            DC.Invoice.Add(F1);
            DC.Invoice.Add(F2);
            DC.Invoice.Add(F3);
        }
        public void Fill(DataContext DC)
        {
            Random rand = new Random();

            for (int i = 0; i < amount; i++)
            {
                Klient     _client  = new Klient(clientNameBase[rand.Next(8)], clientSurnameBase[rand.Next(6)], rand.Next(90));
                Ksiazka    _book    = new Ksiazka(System.Guid.NewGuid(), bookNameBase[rand.Next(5)], bookAuthorBase[rand.Next(7)]);
                Egzemplarz _copy    = new Egzemplarz(rand.NextDouble() * 100, copyProviderBase[rand.Next(4)], new DateTime(rand.Next(1900, 2018), rand.Next(1, 12), rand.Next(1, 28)), _book);
                Faktura    _invoice = new Faktura(new DateTime(rand.Next(1900, 2018), rand.Next(1, 12), rand.Next(1, 28)), _copy, _client);

                DC.Client.Add(_client);
                DC.Book.Add(_book.Index, _book);
                DC.Copy.Add(_copy);
                DC.Invoice.Add(_invoice);
            }
        }
        //CONSTRUCTOR
        public Faktura(DateTime _purchaseDate, Egzemplarz _copy, Klient _klient)
        {
            PurchaseDate = _purchaseDate;
            Copy         = _copy;
            Client       = _klient;

            if (Client != null && Copy != null)
            {
                PurchasePrice = Copy.Price * Client.Discount / 100;
            }
            else
            {
                PurchasePrice = 0;
            }

            Index = System.Guid.NewGuid();
        }
Пример #5
0
 //METHOD TO ADD NEW INVOICE TO THE COLLECTION
 public void AddInvoice(Klient _client, Egzemplarz _copy)
 {
     DataRepository.AddInvoice(new Faktura(DateTime.Now, _copy, _client));
 }