Esempio n. 1
0
        public static void UpdateDepartament(Library libarary, int depID, string Filename)
        {
            Departament departament = libarary.FindDepartamentById(depID);

            Console.WriteLine("------current departament--------");
            Console.WriteLine(departament.ToString());
            Console.WriteLine("Enter new name of departament");
            string NewDepName = Console.ReadLine();

            departament.DepName = NewDepName;
            Console.WriteLine("Save all departaments books?(Yes/No)");
            string choice = Console.ReadLine();

            if (choice.ToLower().Trim().Equals("no"))
            {
                departament.books.Clear();
            }
            XmlSerializer serilaizer = new XmlSerializer(typeof(Library));
            StreamWriter  sw         = new StreamWriter(Filename);

            serilaizer.Serialize(sw, libarary);
            sw.Close();
            Console.WriteLine("Succesfull updeate");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string FileName = "library.xml";
            bool   b        = true;

            while (b)
            {
                switch (Menu())
                {
                case 1:
                    Console.Clear();
                    ShowDepartaments(loadLibraryFromXml(FileName));
                    break;

                case 2:
                    Console.Clear();
                    InsertDepartament(loadLibraryFromXml(FileName), FileName);
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Type departament id:");
                    int depId;
                    int.TryParse(Console.ReadLine(), out depId);
                    UpdateDepartament(loadLibraryFromXml(FileName), depId, FileName);
                    break;

                case 4:
                    Console.Clear();
                    ShowDepartaments(loadLibraryFromXml(FileName));
                    Console.WriteLine("Select departament id");
                    int departamentId;
                    int.TryParse(Console.ReadLine(), out departamentId);
                    DeleteDepartament(loadLibraryFromXml(FileName), departamentId, FileName);
                    break;

                case 5:
                    Console.Clear();
                    loadLibraryFromXml(FileName).SortDepartamentsByBooks();
                    break;

                case 6:
                    Console.Clear();
                    Library l = loadLibraryFromXml(FileName);
                    l.ShowAuthors();
                    l.ShowAllBooksSortedByPages();
                    break;

                case 7:
                    Console.WriteLine("Library have: " + loadLibraryFromXml(FileName).countBooks() + " books");
                    break;

                case 8:
                    createBook();
                    break;

                case 9:
                    Console.Clear();
                    Departament d = loadLibraryFromXml(FileName).Departaments.ToArray().OrderByDescending(x => x.books.Count).FirstOrDefault();
                    Console.WriteLine(d.DepName);
                    Console.WriteLine("max book is " + d.books.Count);
                    break;

                case 10:
                    Book book = loadLibraryFromXml(FileName).showBooksThereHaveLessPages();
                    Console.WriteLine(book.ToString());
                    break;

                case 11:
                    Console.Clear();
                    b = false;
                    break;
                }
            }
        }