Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //cho phép hiển thị UTF-8 string (Tiếng Việt) trong Console Application
            //Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.SetWindowSize(180, 30);

            //khoi gan thong tin thu vien: sach / doc gia / phieu muon sach tu file txt file
            MyLibrary.init_library();
            MyReader.init_lib_reader();
            MyTicket.init_lib_ticket();

            //testing new function

            // chương trình bắt đầu
            menuScreen();
        }
Beispiel #4
0
        //hàm thêm thông tin sách
        public static void addBook()
        {
            Book   newbook = new Book();
            string inputprice;

            Console.Write("Nhap Ma Sach: "); newbook.bookID = Console.ReadLine();
            //validation
            while (checkexistedbookID(newbook.bookID) || newbook.bookID.Length > 8)
            {
                //Console.Write("Vui lòng nhập mã sách tối đa 08 ký tự hoặc mã sách đã tồn tại ");
                Console.Write("Vui long nhap Ma Sach khac toi da 08 ky tu: ");
                newbook.bookID = Console.ReadLine();
            }

            Console.Write("Nhap Ten Sach: "); newbook.bookName = Console.ReadLine();
            //validation
            while (newbook.bookName.Length > 30)
            {
                Console.Write("Vui long nhap Ten Sach toi da 30 ky tu: "); newbook.bookName = Console.ReadLine();
            }

            Console.Write("Nhap Ten Tac Gia: "); newbook.bookAuthor = Console.ReadLine();
            //validation
            while (newbook.bookAuthor.Length > 30)
            {
                Console.Write("Vui long nhap Ten Tac Gia toi da 30 ky tu: ");
                newbook.bookAuthor = Console.ReadLine();
            }

            Console.Write("Nhap Nha Xuat Ban: "); newbook.bookPublisher = Console.ReadLine();
            // validation
            while (newbook.bookPublisher.Length > 20)
            {
                Console.Write("Vui long nhap Nha Xuat Ban toi da 20 ky t"); newbook.bookPublisher = Console.ReadLine();
            }

            Console.Write("Nhap Gia Sach: "); inputprice = Console.ReadLine();
            //validation
            // kiểm tra giá trị nhập phải là giá trị số
            while (!convertPrice(inputprice) || inputprice.Length > 13)
            {
                //nếu không phải là số thì yêu cầu nhập lại giá trị hợp lệ
                inputprice = Console.ReadLine();
            }
            newbook.bookPriceTag = double.Parse(inputprice);

            Console.WriteLine("Nhap Loai Sach: ");
            Console.Write("Sach Tieng Viet - nhap (0) | Sach Ngoai Van - nhap (1): "); newbook.isEN = Console.ReadLine();
            // kiểm tra giá trị nhập phải là 0 hoặc 1
            //validation
            while (newbook.isEN != "0" && newbook.isEN != "1")
            {
                Console.WriteLine("Khong hop le");
                Console.Write("Sach Tieng Viet - nhap (0) | Sach Ngoai Van - nhap (1): "); newbook.isEN = Console.ReadLine();
            }
            //Nếu là sách Tiếng Việt sẽ không có ISBN - Nếu là sách Ngoại Văn, yêu cầu nhập ISBN
            if (newbook.isEN == "1")
            {
                Console.Write("Nhap Ma ISBN: "); newbook.bookISBN = Console.ReadLine();
                while (newbook.bookISBN.Length > 13)
                {
                    Console.Write("Vui long nhap ma ISBN toi da 13 ky tu: "); newbook.bookISBN = Console.ReadLine();
                }
            }
            else
            {
                newbook.bookISBN = "NA";
            }                                 //gia tri mac dinh la NA - not available

            //newbook.isOccupied = false; //init
            //thêm một bản ghi thông tin chi tiết một cuốn sách hoàn chỉnh vào thư viện sách mylib
            //lưu vào một biến string newrecord với dạng $ format thay thế cho gọn thay vì phải + từng chuỗi giá trị
            string newrecord = $"{newbook.bookID},{newbook.bookName},{newbook.bookAuthor},{newbook.bookPublisher},{newbook.bookPriceTag},{newbook.isEN},{newbook.bookISBN}";//,{newbook.isOccupied}";

            //mở file txt và lưu các bản ghi hiện có vào một List<string> tên lines
            List <string> allrecords = System.IO.File.ReadAllLines(@"../../myLibrary.txt").ToList();

            //thêm bản ghi mới nhất vào lines
            allrecords.Add(newrecord);
            //tới đây biến lines sẽ
            //bao gồm các bản ghi thể hiện các sách đã có trong thư viện
            //và một bản ghi mới của sách ta mới tạo ra
            //lưu thông tin hiện lại vào file myLibrary.txt
            File.WriteAllLines(@"../../myLibrary.txt", allrecords);
            //lưu thông tin sách mới vào thư viện MyLibrary
            MyLibrary.mylib.Add(newbook);

            Console.WriteLine("\nThem sach da hoan tat!\n");
            Book.print_header();
            MyLibrary.inquire_a_book(MyLibrary.mylib.Count - 1);
        }
Beispiel #5
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);
        }
Beispiel #6
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;
            }
        }