Пример #1
0
        public static void addBookCategories()
        {
            Category newCat  = new Category();
            string   bookCat = string.Empty;

            Console.Write("Nhap Ma The Loai Sach: ");
            bookCat = Console.ReadLine();
            //validation
            while (!chkcatID(bookCat))
            {
                //Console.Write("Vui long nhap Ma Sach khac bang chu so: ");
                bookCat = Console.ReadLine();
            }
            newCat.catID = int.Parse(bookCat);

            string bookCatName = string.Empty;

            Console.Write("Nhap Ten The Loai Sach: ");
            newCat.catName = Console.ReadLine();
            //validation
            while (newCat.catName == String.Empty || newCat.catName.Length > 30)
            {
                Console.Write("Vui long nhap Ten The Loai Sach toi da 30 ky tu: ");
                newCat.catName = Console.ReadLine();
            }
            string        newrecord  = $"{newCat.catID}#{newCat.catName}";
            List <string> allrecords = File.ReadAllLines(@"../../myBookCategories.txt").ToList();

            allrecords.Add(newrecord);
            File.WriteAllLines(@"../../myBookCategories.txt", allrecords);
            MyCategory.mybctgr.Add(newCat);
            Console.WriteLine("\nThem The Loai Sach da hoan tat!\n");
            Category.print_header();
            MyCategory.printCategory(MyCategory.mybctgr.Count - 1);
        }
Пример #2
0
 static void initial()
 {
     Console.SetWindowSize(180, 30);
     //khoi gan thong tin nha sach: sach / the loai sach / hoa don ban sach / hoa don nhap sach tu file txt file
     MyBookStore.init_MyBookstore();
     MyCategory.init_MyCategory();
     MyInvoice.init_invoice();
     MyInvoice.init_invDetail();
 }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        //hàm gọi 18 chức năng của console
        static void begins(int slt)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            switch (slt)
            {
            // 2019-05-24: done
            case 1:
            {
                Console.WriteLine("\nChuc nang them sach");
                Book.addBook();
                break;
            }

            // 2019-05-24: done
            case 2:
            {
                Console.WriteLine("\nChuc nang xoa sach");
                MyBookStore.printAllBook();
                Console.Write("\nNhap Ma sach tuong ung voi Ten Sach can xoa: ");
                string inputvar = Console.ReadLine();
                Book.deleteBook(inputvar);
                break;
            }

            // 2019-05-24: done
            case 3:
            {
                Console.WriteLine("\nChuc nang sua sach");
                MyBookStore.printAllBook();
                Console.Write("\nNhap Ma Sach tuong ung voi Ten Sach can sua: ");
                string inputvar = Console.ReadLine();
                Book.updateBook(inputvar);
                break;
            }

            // 2019-05-24: done
            case 4:
            {
                Console.WriteLine("\nChuc nang tim kiem Sach");
                //MyBookStore.inquire_all_book(); // in ra truoc de test, remove truoc khi commit
                Console.Write("\nNhap Ten Sach can tim: ");
                string inputvar = Console.ReadLine();
                Book.inqBookbyName(inputvar);
                break;
            }

            case 5:
            {
                Console.WriteLine("\nChuc nang them The Loai Sach");
                Category.addBookCategories();
                break;
            }

            case 6:
            {
                Console.WriteLine("\nChuc nang xoa The Loai Sach");
                MyCategory.printAllCategory();
                Console.Write("Nhap Ma The Loai Sach can xoa: ");
                int inputvar = int.Parse(Console.ReadLine());
                Category.deleteCategory(inputvar);
                break;
            }

            case 7:
            {
                Console.WriteLine("\nChuc nang sua The Loai Sach");
                MyCategory.printAllCategory();
                Console.Write("Nhap Ma The Loai Sach can sua: ");
                int inputvar = int.Parse(Console.ReadLine());
                Category.updateCategory(inputvar);
                break;
            }

            case 8:
            {
                Console.WriteLine("\nChuc nang tim kiem The Loai Sach");
                Console.Write("Nhap The Loai Sach can tim: ");
                string inputvar = Console.ReadLine();
                Category.inqCategorybyName(inputvar);
                break;
            }

            case 9:
            {
                Console.WriteLine("\nChuc nang them Hoa Don Ban Sach");
                Invoice.issueSalesInvoice();
                break;
            }

            case 10:
            {
                Console.WriteLine("\nChuc nang xoa Hoa Don Ban Sach");
                Console.Write("Nhap Hoa Don Ban Sach can xoa: ");
                string inputvar = Console.ReadLine();
                Invoice.deleteInvoice(inputvar);
                break;
            }

            case 11:
            {
                Console.WriteLine("\nChuc nang sua Hoa Don Ban Sach");
                Console.Write("Nhap Hoa Don Ban Sach can sua: ");
                string inputvar = Console.ReadLine();
                Invoice.updateInvoice(inputvar);
                break;
            }

            case 12:
            {
                Console.WriteLine("\nChuc nang tim kiem Hoa Don Ban Sach");
                Console.Write("Nhap Hoa Don Ban Sach can tim: ");
                string inputvar = Console.ReadLine();
                Invoice.inqInvoice(inputvar, 1);
                break;
            }

            case 13:
            {
                Console.WriteLine("\nChuc nang them Hoa Don Nhap Sach");
                Invoice.issuePurchaseInvoice();
                break;
            }

            case 14:
            {
                Console.WriteLine("\nChuc nang xoa Hoa Don Nhap Sach");
                Console.Write("Nhap Hoa Don Nhap Sach can xoa: ");
                string inputvar = Console.ReadLine();
                Invoice.deleteInvoice(inputvar);
                break;
            }

            case 15:
            {
                Console.WriteLine("\nChuc nang sua Hoa Don Nhap Sach");
                Console.Write("Nhap Hoa Don Nhap Sach can sua: ");
                string inputvar = Console.ReadLine();
                Invoice.updateInvoice(inputvar);
                break;
            }

            case 16:
            {
                Console.WriteLine("\nChuc nang tim kiem Hoa Don Nhap Sach");
                Console.Write("Nhap Hoa Don Nhap Sach can tim: ");
                string inputvar = Console.ReadLine();
                Invoice.inqInvoice(inputvar, 2);
                break;
            }

            case 17:
            {
                Console.WriteLine("\nChuc nang thong ke so sach con lai trong nha sach theo the loai");
                MyBookStore.printRemainBook();
                break;
            }

            case 18:
            {
                Console.WriteLine("\nChuc nang thong ke so sach cu da xuat ban tren 3 nam");
                Book.inqBookbybookYear(3);
                break;
            }
                // default: break;
            }
        }
Пример #6
0
        //ham them sach tu hoa don nhap hang
        public static void addBook(string bookID)
        {
            string filePath = @"../../myBookstore.txt";
            Book   newbook  = new Book();
            string inputprice;

            while (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 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;

            newbook.bookQty = 0;
            //(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);
            //return newbook;
        }