Example #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);
            }
        }
Example #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);
            }
        }
Example #3
0
        //register a new library ticket with reader info, book info and start date (issue date)
        //revised
        public static void addTicket()
        {
            LibraryTicket newticket = new LibraryTicket();
            string        readerID = "", bookID = "";
            Reader        input_rd = new Reader();
            Book          input_bk = new Book();

            MyReader.inquire_all_reader();
            Console.Write("Hay nhap Ma Doc Gia tuong ung: ");

            while (input_rd.readerName == "")
            {
                readerID = Console.ReadLine();
                input_rd = Reader.inqReaderbyID(readerID);
            }
            newticket.readerID = input_rd.readerID;

            //thông tin sách
            Book.print_header();
            MyLibrary.inquire_all_book();

            Console.Write("Hay nhap Ma Sach tuong ung: ");
            while (input_bk.bookName == "")
            {
                bookID   = Console.ReadLine();
                input_bk = Book.inqBookbyID(bookID);
            }
            newticket.bookID = input_bk.bookName;
            newticket.isEN   = input_bk.bookISBN;
            newticket.status = "1";//init

            Console.Write("Nhap ngay bat dau muon (vi du: 10/22/2018): ");
            string inputtedDate = Console.ReadLine();

            while (!checkDatetime(inputtedDate))
            {
                inputtedDate = Console.ReadLine();
            }
            newticket.fromDate = DateTime.Parse(inputtedDate).ToShortDateString().ToString();
            newticket.toDate   = "";//init

            // Cấu hình thiết lập thông tin quá hạn mượn sách
            // Mỗi quyển sách được mượn tối đa 7 ngày (kể cả Thứ Bảy, Chủ Nhật):
            // Sách tiếng Việt sẽ bị phạt 10000d đồng/ngày trễ hạn
            // Sách Ngoại văn sẽ bị phạt 20000d đồng/ngày trễ hạn

            GeneralCode iniTicket = new GeneralCode(7, 10000d, 20000d);

            if (newticket.isEN == "1")
            {
                newticket.standardRate = iniTicket.StandardRateEN;
            }
            else
            {
                newticket.standardRate = iniTicket.StandardRateVN;
            }

            newticket.overDays = "0"; //init
            newticket.amount   = 0;   //init

            //lưu thông tin đồng thời vào txt file và MyTicket
            string        newrecord = $"{newticket.readerID},{newticket.bookID},{newticket.isEN},{newticket.status},{newticket.fromDate},{newticket.toDate},{newticket.overDays},{newticket.standardRate},{newticket.amount}";
            List <string> lines     = System.IO.File.ReadAllLines(@"../../myTicket.txt").ToList();

            lines.Add(newrecord);
            File.WriteAllLines(@"../../myTicket.txt", lines);
            MyTicket.mytk.Add(newticket);

            Console.WriteLine("\nTao Phieu Muon Sach thanh cong!\n");
            //in ket qua phieu muon sach
            MyTicket.inquire_a_ticket(MyTicket.mytk.Count - 1);
        }
Example #4
0
        //hàm gọi 11 chức năng của console
        static void begins(int slt)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            switch (slt)
            {
            case 1:
            {
                Console.WriteLine("\nChuc nang them sach");
                Book.addBook();
                break;
            }

            case 2:
            {
                Console.WriteLine("\nChuc nang xoa sach");
                MyLibrary.inquire_all_book();
                Console.Write("\nNhap Ma sach tuong ung voi Ten Sach can xoa: ");

                string inputvar = Console.ReadLine();
                Book.delBookbyID(inputvar);
                break;
            }

            case 3:
            {
                Console.WriteLine("\nChuc nang sua sach");
                MyLibrary.inquire_all_book();
                Console.Write("\nNhap Ma Sach tuong ung voi ten sach can sua: ");
                string inputvar = Console.ReadLine();
                Book.editBookbyID(inputvar);
                break;
            }

            case 4:
            {
                Console.WriteLine("\nChuc nang tim kiem Sach");
                MyLibrary.inquire_all_book();
                Console.Write("\nNhap Ten Sach can tim: ");
                string inputvar = Console.ReadLine();
                Book.inqBookbyName(inputvar);
                break;
            }

            case 5:
            {
                Console.WriteLine("\nChuc nang them Doc Gia");
                Reader.addReader();
                break;
            }

            case 6:
            {
                Console.WriteLine("\nChuc nang xoa Doc Gia");
                MyReader.inquire_all_reader();
                Console.Write("Nhap Ma Doc Gia can xoa: ");
                string inputvar = Console.ReadLine();
                Reader.delReaderbyID(inputvar);
                break;
            }

            case 7:
            {
                Console.WriteLine("\nChuc nang sua Doc Gia");
                MyReader.inquire_all_reader();
                Console.Write("Nhap Ma Doc Gia can sua: ");
                string inputvar = Console.ReadLine();
                Reader.editReaderbyID(inputvar);
                break;
            }

            case 8:
            {
                Console.WriteLine("\nChuc nang tim kiem Doc Gia");
                Console.Write("Nhap Ten Doc Gia can tim: ");
                string inputvar = Console.ReadLine();
                Reader.inqReaderbyName(inputvar);
                break;
            }

            case 9:
            {
                Console.WriteLine("\nChuc nang lap Phieu Muon Sach");
                LibraryTicket.addTicket();
                break;
            }

            case 10:
            {
                Console.WriteLine("\nChuc nang lap Phieu Tra Sach");
                Console.Write("Nhap Ma Phieu Muon Sach can tra: ");
                string inputvar = Console.ReadLine();
                LibraryTicket.returnTicket(inputvar);
                break;
            }

            case 11:
            {
                Console.WriteLine("\nChuc nang liet ke danh sach muon sach tre han");
                LibraryTicket.overdayslistLibraryTicket();
                break;
            }

            case 12:
            {
                Console.WriteLine("\nDanh muc sach co trong thu vien");
                MyLibrary.inquire_all_book();
                break;
            }
                // default: break;
            }
        }