Пример #1
0
        public static void updateCategory(int catID)
        {
            string        filePath       = @"../../myBookCategories.txt";
            List <string> listcategories = new List <string>();

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

            Category input = Category.inqCategorybyID(catID);

            if (input.catName != "")
            {
                //get lib index of the candidate book for modifying
                int cat_index = MyCategory.findIndex(catID);
                //chi cho phep sua: ten the loai sach
                Console.WriteLine("Thuc hien viec sua thong tin The Loai Sach co Ma {0}", catID);

                string newbookCat;
                Console.Write("Nhap Ten The Loai Sach moi: "); newbookCat = Console.ReadLine();
                while (newbookCat == String.Empty || newbookCat.Length > 30)
                {
                    Console.Write("Vui long nhap Ten The Loai Sach toi da 30 ky tu: ");
                    newbookCat = Console.ReadLine();
                }
                MyCategory.mybctgr[cat_index].catName = newbookCat;


                listcategories[cat_index] = $"{MyCategory.mybctgr[cat_index].catID}#{MyCategory.mybctgr[cat_index].catName}";
                File.WriteAllLines(filePath, listcategories);

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

                MyCategory.printAllCategory();
            }
            else
            {
                // Console.WriteLine("Khong co thong tin The Loai Sach voi Ma {0}", catID);
            }
        }
Пример #2
0
        public static void deleteCategory(int catID)
        {
            string        filePath       = @"../../myBookCategories.txt";
            List <string> listcategories = new List <string>();

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

            Category input = Category.inqCategorybyID(catID);

            if (input.catName != "")
            {
                //get lib index of the candidate book for modifying
                int cat_index = MyCategory.findIndex(catID);
                //tien hanh tim sach theo thong tin The Loai Sach
                //neu co thi khong cho xoa
                //neu ko co thi tien hanh xoa
                if (Book.inqBookbybookCat(catID) == true)
                {
                    Console.WriteLine("\nKhong the xoa The Loai Sach Nay. Co ton tai thong tin sach voi The Loai Sach nay");
                }
                else
                {
                    MyCategory.mybctgr.Remove(MyCategory.mybctgr[cat_index]);
                    string cat_record = listcategories[cat_index];
                    listcategories.Remove(cat_record);
                    File.WriteAllLines(filePath, listcategories);
                    Console.WriteLine("Cap nhat The Loai Sach moi nhat\n");

                    MyCategory.printAllCategory();
                    Console.WriteLine("Da xoa xong");
                }
            }
            else
            {
                //  Console.WriteLine("Khong co thong tin The Loai Sach voi Ma {0}", catID);
            }
        }