Esempio n. 1
0
        //hàm chi cho phép update so luong sach = 0
        //vi thong tin sach con duoc dung trong thong tin hoa don
        public static void deleteBook(string bookID)
        {
            string        filePath = @"../../myBookstore.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 = MyBookStore.findIndex(input.bookID);
                MyBookStore.mybs[lib_index].bookQty = 0;

                listbook[lib_index] = $"{MyBookStore.mybs[lib_index].bookID}#{MyBookStore.mybs[lib_index].bookName}#{MyBookStore.mybs[lib_index].bookPublisher}#{MyBookStore.mybs[lib_index].bookPriceTag}#{MyBookStore.mybs[lib_index].bookYear}#{ MyBookStore.mybs[lib_index].bookCat}#{MyBookStore.mybs[lib_index].bookQty}";
                File.WriteAllLines(filePath, listbook);
                //MyBookStore.mybs.Remove(MyBookStore.mybs[lib_index]);
                //string book_record = listbook[lib_index];
                //listbook.Remove(book_record);
                //File.WriteAllLines(filePath, listbook);

                Console.WriteLine("Da xoa thong tin sach voi Ma Sach {0} ", input.bookID);
                Console.WriteLine("Cap nhat Thu Vien Sach moi nhat\n");

                MyBookStore.printAllBook();
            }
            else
            {
                Console.WriteLine("Khong co thong tin sach voi Ma Sach {0}", bookID);
            }
        }
Esempio n. 2
0
        //test
        public static void updateBookQty(string bookID, int newQty)
        {
            string        filePath = @"../../myBookstore.txt";
            List <string> listbook = new List <string>();

            listbook = File.ReadAllLines(filePath).ToList();
            Book input = Book.inqBookbyID(bookID);
            //get lib index of the candidate book for modifying
            int lib_index = MyBookStore.findIndex(input.bookID);

            //chi cho phep sua: so luong
            MyBookStore.mybs[lib_index].bookQty = newQty;
            listbook[lib_index] = $"{MyBookStore.mybs[lib_index].bookID}#{MyBookStore.mybs[lib_index].bookName}#{MyBookStore.mybs[lib_index].bookPublisher}#{MyBookStore.mybs[lib_index].bookPriceTag}#{MyBookStore.mybs[lib_index].bookYear}#{ MyBookStore.mybs[lib_index].bookCat}#{MyBookStore.mybs[lib_index].bookQty}";
            File.WriteAllLines(filePath, listbook);
            //Console.WriteLine("Cap nhat so luong sach thanh cong"); // test
        }
Esempio n. 3
0
        //hàm cho phép chỉnh sửa thông tin sách theo mã sách
        public static void updateBook(string bookID)
        {
            string        filePath = @"../../myBookstore.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 = MyBookStore.findIndex(input.bookID);
                //chi cho phep sua: gia sach / so luong
                Console.WriteLine("Thuc hien viec sua thong tin sach co Ma Sach {0}", bookID);

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

                Console.Write("Nhap So Luong: "); string bookQty = Console.ReadLine();
                while (!Book.chkbookQty(bookQty))
                {
                    bookQty = Console.ReadLine();
                }
                MyBookStore.mybs[lib_index].bookQty = int.Parse(bookQty);

                listbook[lib_index] = $"{MyBookStore.mybs[lib_index].bookID}#{MyBookStore.mybs[lib_index].bookName}#{MyBookStore.mybs[lib_index].bookPublisher}#{MyBookStore.mybs[lib_index].bookPriceTag}#{MyBookStore.mybs[lib_index].bookYear}#{ MyBookStore.mybs[lib_index].bookCat}#{MyBookStore.mybs[lib_index].bookQty}";
                File.WriteAllLines(filePath, listbook);

                Console.WriteLine("\nCap nhat thong tin sach da hoan tat!\n");
                Console.WriteLine("Cap nhat Thu Vien Sach moi nhat\n");

                MyBookStore.printAllBook();
            }
            else
            {
                Console.WriteLine("Khong co thong tin sach voi Ma Sach {0}", bookID);
            }
        }
Esempio n. 4
0
        public static void addBook()
        {
            string filePath = @"../../myBookstore.txt";
            Book   newbook  = new Book();
            string inputprice;

            Console.Write("Nhap Ma Sach: "); newbook.bookID = Console.ReadLine();
            //validation
            while (chkbookID(newbook.bookID) || newbook.bookID.Length > 8)
            {
                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 35 ky tu: "); newbook.bookName = 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 tu"); 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ố
            // 2019-05-22 nho kiem tra lai truong hop nhap 0
            while (!chkbookPriceTag(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);

            //2019-05-22 them moi nam xuat ban + gia sach + so luong
            // nho kiem tra lai truong hop nhap 0
            Console.Write("Nhap Nam Xuat Ban: "); string inputyear = Console.ReadLine();

            while (!chkbookYear(inputyear))
            {
                //Console.WriteLine("Gia tri Nam Xuat Ban khong hop le");
                inputyear = Console.ReadLine();
            }
            newbook.bookYear = int.Parse(inputyear);
            MyCategory.printAllCategory();
            Console.Write("Nhap Ma The Loai Sach tuong ung: "); int inputcatID = int.Parse(Console.ReadLine());

            while (Category.inqCategorybyID(inputcatID).catName == "")
            {
                //  Console.WriteLine("Nhap Ma Sach tuong ung: ");
                inputcatID = int.Parse(Console.ReadLine());
            }
            newbook.bookCat = inputcatID;

            Console.Write("Nhap So Luong: "); string bookQty = Console.ReadLine();
            while (!Book.chkbookQty(bookQty))
            {
                bookQty = Console.ReadLine();
            }
            newbook.bookQty = int.Parse(bookQty);
            //(mã, tên sách, nxb, giá, năm xuất bản, thể loại, số lượng)
            string newrecord = $"{newbook.bookID}#{newbook.bookName}#{newbook.bookPublisher}#{newbook.bookPriceTag}#{newbook.bookYear}#{newbook.bookCat}#{newbook.bookQty}";

            List <string> allrecords = File.ReadAllLines(filePath).ToList();

            //thêm bản ghi mới nhất vào lines
            allrecords.Add(newrecord);
            File.WriteAllLines(filePath, allrecords);
            //lưu thông tin sách mới vào nha sach MyBookStore
            MyBookStore.mybs.Add(newbook);

            Console.WriteLine("\nThem thong tin sach da hoan tat!\n");
            //Book.print_header();
            //MyBookStore.printBook(MyBookStore.mybs.Count - 1);
            MyBookStore.printBook(MyBookStore.findIndex(newbook.bookID));
        }