Exemplo n.º 1
0
        //hàm cho phép chỉnh xoá thông tin sách theo mã sách
        //revised
        //need to check the relation with library ticket before deleting
        public static void delBookbyID(string bookID)
        {
            string        filePath = @"../../myLibrary.txt";
            List <string> listbook = new List <string>();

            listbook = File.ReadAllLines(filePath).ToList();

            Book input = Book.inqBookbyID(bookID);

            if (input.bookName != "")
            {
                //get lib index of the candidate book for modifying
                int lib_index = MyLibrary.find_lib_index(input.bookID);

                MyLibrary.mylib.Remove(MyLibrary.mylib[lib_index]);
                string book_record = listbook[lib_index];
                listbook.Remove(book_record);
                File.WriteAllLines(@"../../myLibrary.txt", listbook);

                Console.WriteLine("Da xoa thong tin sach voi Ma Sach {0} ", input.bookID);
                Console.WriteLine("Cap nhat Thu Vien Sach moi nhat\n");
                Book.print_header();
                MyLibrary.inquire_all_book();
            }
            else
            {
                Console.WriteLine("Khong co thong tin sach voi Ma Sach {0}", bookID);
            }
        }
Exemplo n.º 2
0
        //hàm cho phép chỉnh sửa thông tin sách theo mã sách
        //revised
        public static void editBookbyID(string bookID)
        {
            string        filePath = @"../../myLibrary.txt";
            List <string> listbook = new List <string>();

            listbook = File.ReadAllLines(filePath).ToList();

            Book input = Book.inqBookbyID(bookID);

            if (input.bookName != "")
            {
                //get lib index of the candidate book for modifying
                int lib_index = MyLibrary.find_lib_index(input.bookID);

                Console.WriteLine("Thuc hien viec sua thong tin sach co Ma Sach {0}", bookID);

                Console.Write("Nhap Ten Sach: "); MyLibrary.mylib[lib_index].bookName = Console.ReadLine();
                while (MyLibrary.mylib[lib_index].bookName.Length > 30)
                {
                    Console.Write("Vui long nhap Ten Sach toi da 30 ky tu: ");
                    MyLibrary.mylib[lib_index].bookName = Console.ReadLine();
                }

                Console.Write("Nhap Ten Tac Gia: "); MyLibrary.mylib[lib_index].bookAuthor = Console.ReadLine();
                while (MyLibrary.mylib[lib_index].bookAuthor.Length > 30)
                {
                    Console.Write("Vui long nhap ten tac gia toi da 30 ky tu: "); MyLibrary.mylib[lib_index].bookAuthor = Console.ReadLine();
                }

                Console.Write("Nhap Nha Xuat Ban: "); MyLibrary.mylib[lib_index].bookPublisher = Console.ReadLine();
                while (MyLibrary.mylib[lib_index].bookPublisher.Length > 20)
                {
                    Console.Write("Vui long nhap Nha Xuat Ban toi da 20 ky tu: "); MyLibrary.mylib[lib_index].bookPublisher = Console.ReadLine();
                }

                string inputprice;
                Console.Write("Nhap Gia Sach: "); inputprice = Console.ReadLine();
                while (!convertPrice(inputprice) || inputprice.Length > 13)
                {
                    inputprice = Console.ReadLine();
                }
                MyLibrary.mylib[lib_index].bookPriceTag = double.Parse(inputprice);

                listbook[lib_index] = $"{MyLibrary.mylib[lib_index].bookID},{MyLibrary.mylib[lib_index].bookName},{MyLibrary.mylib[lib_index].bookAuthor},{MyLibrary.mylib[lib_index].bookPublisher},{MyLibrary.mylib[lib_index].bookPriceTag},{MyLibrary.mylib[lib_index].isEN},{MyLibrary.mylib[lib_index].bookISBN}";
                File.WriteAllLines(@"../../myLibrary.txt", listbook);

                Console.WriteLine("\nCap nhat thong tin sach da hoan tat!\n");
                Console.WriteLine("Cap nhat Thu Vien Sach moi nhat\n");
                Book.print_header();
                MyLibrary.inquire_all_book();
            }
            else
            {
                Console.WriteLine("Khong co thong sach voi Ma Sach {0}", bookID);
            }
        }