示例#1
0
        /// <summary>
        /// outputs info about a libraryRegister and the most common publication in all three publication types
        /// </summary>
        /// <param name="reg">the libraryRegister as input</param>
        public static void OutputCommonInfo(LibraryRegister reg)
        {
            Publication commonBook    = reg.GetMostReleasedBook();
            Publication commonJournal = reg.GetMostReleasedJournal();
            Publication commonPaper   = reg.GetMostReleasedPaper();

            Console.WriteLine("{0} (-os) informacija:", reg.LibraryName);
            Console.WriteLine("Numeris: {0}", reg.LibraryPhone);
            Console.WriteLine("Adresas: {0}", reg.LibraryAddr);

            Console.WriteLine("Didžiausio tiražo:");
            Console.WriteLine(commonBook.ToString());
            Console.WriteLine(commonJournal.ToString());
            Console.WriteLine(commonPaper.ToString());
            Console.WriteLine("-----------------------------");
        }
示例#2
0
        /// <summary>
        /// creates a libraryRegister from an input file
        /// </summary>
        /// <param name="fileName">the input filename</param>
        /// <returns>a libraryRegister</returns>
        public static LibraryRegister readLibraryRegister(string fileName)
        {
            LibraryRegister output = new LibraryRegister();

            if (File.Exists(fileName) == false)
            {
                throw new Exception(String.Format("Failas {0} neegzistuoja.", fileName));
            }

            int linecount = TotalLines(fileName);

            if (linecount < 4)
            {
                throw new Exception(String.Format("Failas {0} nėra tinkamai formatuotas.", fileName));
            }

            StreamReader sr = new StreamReader(fileName);

            output.LibraryName  = sr.ReadLine();
            output.LibraryAddr  = sr.ReadLine();
            output.LibraryPhone = sr.ReadLine();

            string line;

            while ((line = sr.ReadLine()) != null)
            {
                string[] split = line.Split(';');

                if (split[0] == "book")
                {
                    output.AddPublication(new Book(
                                              split[1],
                                              split[2],
                                              int.Parse(split[3]),
                                              int.Parse(split[4]),
                                              int.Parse(split[5]),
                                              int.Parse(split[6]),
                                              split[7]
                                              ));
                }
                else if (split[0] == "journal")
                {
                    output.AddPublication(new Journal(
                                              split[1],
                                              split[2],
                                              int.Parse(split[3]),
                                              int.Parse(split[4]),
                                              int.Parse(split[5]),
                                              int.Parse(split[6]),
                                              int.Parse(split[7])
                                              ));
                }
                else if (split[0] == "paper")
                {
                    output.AddPublication(new Paper(
                                              split[1],
                                              split[2],
                                              int.Parse(split[3]),
                                              int.Parse(split[4]),
                                              int.Parse(split[5]),
                                              DateTime.Parse(split[6]),
                                              int.Parse(split[7])
                                              ));
                }
                else
                {
                    throw new Exception(String.Format("Nežinomas leidinio tipas \"{0}\"", split[0]));
                }
            }

            return(output);
        }
示例#3
0
        static void Main(string[] args)
        {
            // variables
            string SpecificPubName = "Technologija";

            LibraryRegister reg1 = IOUtils.readLibraryRegister("kaunas.txt");
            LibraryRegister reg2 = IOUtils.readLibraryRegister("kaunas2.txt");
            LibraryRegister reg3 = IOUtils.readLibraryRegister("vilnius.txt");

            // output the most common book in each library
            IOUtils.OutputCommonInfo(reg1);
            IOUtils.OutputCommonInfo(reg2);
            IOUtils.OutputCommonInfo(reg3);

            // output the rarest book from all libraries
            List <Publication> GlobalPublications = new List <Publication>();

            GlobalPublications.AddRange(reg1.AllPublications);
            GlobalPublications.AddRange(reg2.AllPublications);
            GlobalPublications.AddRange(reg3.AllPublications);

            List <Publication> UniquePublications = new List <Publication>();

            for (int i = 0; i < GlobalPublications.Count; i++)
            {
                bool IsUnique = true;
                for (int j = 0; j < GlobalPublications.Count; j++)
                {
                    if (GlobalPublications[i].Title == GlobalPublications[j].Title && i != j)
                    {
                        IsUnique = false;
                    }
                }

                if (IsUnique)
                {
                    UniquePublications.Add(GlobalPublications[i]);
                }
            }

            IOUtils.OutputPublicationsToCSV("RetiLeidiniai.csv", "Reti leidiniai:", UniquePublications);


            // output all books from a specific publisher, sort before outputting
            List <Publication> SpecificPublisherPubs = new List <Publication>();

            SpecificPublisherPubs.AddRange(reg1.GetPubsFromSpecificPublisher(SpecificPubName));
            SpecificPublisherPubs.AddRange(reg2.GetPubsFromSpecificPublisher(SpecificPubName));
            SpecificPublisherPubs.AddRange(reg3.GetPubsFromSpecificPublisher(SpecificPubName));


            // bubble sort
            for (int i = 0; i < SpecificPublisherPubs.Count; i++)
            {
                for (int j = 0; j < SpecificPublisherPubs.Count - i - 1; j++)
                {
                    if (SpecificPublisherPubs[j] > SpecificPublisherPubs[j + 1])
                    {
                        Publication buf = SpecificPublisherPubs[j];
                        SpecificPublisherPubs[j]     = SpecificPublisherPubs[j + 1];
                        SpecificPublisherPubs[j + 1] = buf;
                    }
                }
            }

            IOUtils.OutputPublicationsToCSV(
                "Technologija.csv",
                "Visi leidiniai iš leidyklos \"Technologjia\":",
                SpecificPublisherPubs
                );


            // get all publications that can be found in all three libraries, output them
            List <Publication> CommonPublications = new List <Publication>();

            for (int i = 0; i < GlobalPublications.Count; i++)
            {
                int count = 0;
                for (int j = 0; j < GlobalPublications.Count; j++)
                {
                    if (GlobalPublications[i].Title == GlobalPublications[j].Title && i != j)
                    {
                        count++;
                    }
                }

                if (count == 2)
                {
                    bool        contains   = false;
                    Publication itemToTest = GlobalPublications[i];

                    // testing is needed for all specific types ofpublication
                    // which is why there is a lot of code below.
                    if (itemToTest.Type == "book")
                    {
                        foreach (Publication t in CommonPublications)
                        {
                            if (t.Type == "book")
                            {
                                Book tBook    = t as Book;
                                Book itemBook = itemToTest as Book;

                                if (tBook.ISBN == itemBook.ISBN)
                                {
                                    contains = true;
                                }
                            }
                        }
                    }
                    else if (itemToTest.Type == "journal")
                    {
                        foreach (Publication t in CommonPublications)
                        {
                            if (t.Type == "journal")
                            {
                                Journal tJournal    = t as Journal;
                                Journal itemJournal = itemToTest as Journal;

                                if (tJournal.JournalNumber == itemJournal.JournalNumber)
                                {
                                    contains = true;
                                }
                            }
                        }
                    }
                    else if (itemToTest.Type == "paper")
                    {
                        foreach (Publication t in CommonPublications)
                        {
                            if (t.Type == "paper")
                            {
                                Paper tPaper    = t as Paper;
                                Paper itemPaper = itemToTest as Paper;

                                if (tPaper.PaperNumber == itemPaper.PaperNumber)
                                {
                                    contains = true;
                                }
                            }
                        }
                    }
                    if (!contains)
                    {
                        CommonPublications.Add(GlobalPublications[i]);
                    }
                }
            }

            IOUtils.OutputPublicationsToCSV(
                "BendriLeidiniai.csv",
                "Bendri leidiniai tarp trijų bibliotekų:",
                CommonPublications
                );
        }