Exemplo 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);
            }
        }
Exemplo n.º 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();
 }
Exemplo n.º 3
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
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public static void issueSalesInvoice()
        {
            string fPathInv       = @"../../myInvoice.txt";
            string fPathInvDetail = @"../../myInvoiceDetail.txt";
            //tam luu tat ca du lieu trong txt file vao List<string>
            List <string> all_inv_records       = File.ReadAllLines(fPathInv).ToList();
            List <string> all_invDetail_records = File.ReadAllLines(fPathInvDetail).ToList();

            Invoice newInv = new Invoice();
            string  invNo = string.Empty;
            string  bookID = string.Empty;
            string  Issuer = string.Empty;
            int     bookQty; double bookPriceTag;

            Console.Write("Nhap So Hoa Don "); invNo = Console.ReadLine();
            while (chkinvNo(invNo) || invNo.Length > 8)
            {
                Console.Write("\n So Hoa Don {0} da ton tai. Vui long nhap So Hoa Don khac: ", invNo);
                invNo = Console.ReadLine();
            }

            newInv.invNo          = invNo;
            newInv.invType        = 1;                                //Ban
            newInv.issueDate      = DateTime.Now.ToShortDateString(); // chi don gian la lay thoi gian hien hanh
            newInv.invTotalAmount = 0;                                // init
            newInv.invStatus      = 1;
            Console.Write("Nhap Ten Nguoi Lap Hoa Don: ");
            Issuer = Console.ReadLine();
            while (Issuer.Length > 20)
            {
                Console.Write("\nVui long nhap ten duoi 20 ky tu");
                Issuer = Console.ReadLine();
            }
            newInv.Issuer = Issuer;

            //nhap thong tin chi tiet hoa don
            int selection = 1;

            while (selection == 1)
            {
                InvoiceDetail newInvDetails = new InvoiceDetail();
                newInvDetails.invNo = newInv.invNo;
                Console.Write("Nhap thong tin Chi Tiet Hoa Don ");
                MyBookStore.printAllBook();

                //kiem tra ma sach can ban can phai co trong book store
                Console.Write("Nhap Ma Sach can ban ");
                bookID = Console.ReadLine();
                Book rs = Book.inqBookbyID(bookID);
                while (rs.bookName == "")
                {
                    Console.Write("Nhap Ma Sach can ban ");
                    bookID = Console.ReadLine();
                    rs     = Book.inqBookbyID(bookID);
                }

                bookQty                    = Book.inqBookbyID(bookID).bookQty;
                bookPriceTag               = Book.inqBookbyID(bookID).bookPriceTag;
                newInvDetails.invUnit      = bookID;
                newInvDetails.invUnitPrice = bookPriceTag;
                Console.Write("\nGia 1 cuon sach la " + GeneralCode.converPricetag(newInvDetails.invUnitPrice));
                string invUnitQty = string.Empty;
                Console.Write("\nNhap So Luong ");
                invUnitQty = Console.ReadLine();
                while (!InvoiceDetail.chkQty(invUnitQty))
                {
                    invUnitQty = Console.ReadLine();
                }

                //cap nhat so luong ban ra so luong sach hien co
                int newQty = bookQty;

                // validate so luong sach & - so luong sach
                if (bookQty < int.Parse(invUnitQty))
                {
                    Console.Write("\nVuot qua so luong sach hien co : {0}", bookQty);
                    Console.Write("\nBan chi duoc ban toi da : {0} cuon sach", bookQty);
                    newInvDetails.invUnitQty = bookQty;
                    Book.updateBookQty(Book.inqBookbyID(bookID).bookID, 0);
                }
                else
                {
                    newInvDetails.invUnitQty = int.Parse(invUnitQty);
                    newQty -= int.Parse(invUnitQty);
                    Book.updateBookQty(Book.inqBookbyID(bookID).bookID, newQty);
                }


                newInvDetails.invUnitAmount = InvoiceDetail.calculateAmount(newInvDetails.invUnitQty, newInvDetails.invUnitPrice);
                newInv.invTotalAmount      += newInvDetails.invUnitAmount;

                // luu vao MyInvoice
                MyInvoice.myinvdt.Add(newInvDetails);
                //luu vao file
                string invDetailrecord = $"{newInvDetails.invNo}#{newInvDetails.invUnit}#{newInvDetails.invUnitQty}#{newInvDetails.invUnitPrice}#{newInvDetails.invUnitAmount}";
                all_invDetail_records.Add(invDetailrecord);
                File.WriteAllLines(fPathInvDetail, all_invDetail_records);

                Console.Write("De tiep tuc - Nhap 1 | De hoan tat Hoa Don - Nhap 0 : ");
                selection = int.Parse(Console.ReadLine());
            }

            MyInvoice.myinv.Add(newInv);

            //tao ban ghi
            string invrecord = $"{newInv.invNo}#{newInv.invType}#{newInv.invTotalAmount}#{newInv.issueDate}#{newInv.invStatus}#{newInv.Issuer}";

            all_inv_records.Add(invrecord);
            File.WriteAllLines(fPathInv, all_inv_records);

            Console.WriteLine("\nHaon tat them thong tin Hoa Don Ban Sach");
            //in ket qua
            MyInvoice.printInv(newInv.invNo);
        }
Exemplo n.º 8
0
        public static void issuePurchaseInvoice()
        {
            string fPathInv       = @"../../myInvoice.txt";
            string fPathInvDetail = @"../../myInvoiceDetail.txt";
            //tam luu tat ca du lieu trong txt file vao List<string>
            List <string> all_inv_records       = File.ReadAllLines(fPathInv).ToList();
            List <string> all_invDetail_records = File.ReadAllLines(fPathInvDetail).ToList();
            Invoice       newInv = new Invoice();
            //InvoiceDetail newInvDetails = new InvoiceDetail();
            string invNo  = string.Empty;
            string Issuer = string.Empty;

            Console.Write("Nhap So Hoa Don ");
            invNo = Console.ReadLine();
            while (chkinvNo(invNo) || invNo.Length > 8)
            {
                Console.Write("\n So Hoa Don {0} da ton tai. Vui long nhap So Hoa Don khac: ", invNo);
                invNo = Console.ReadLine();
            }
            newInv.invNo          = invNo;
            newInv.invType        = 2;                                // Nhap
            newInv.issueDate      = DateTime.Now.ToShortDateString(); // chi don gian la lay thoi gian hien hanh
            newInv.invTotalAmount = 0;
            newInv.invStatus      = 1;
            Console.Write("Nhap Ten Nguoi Lap Hoa Don: ");
            Issuer = Console.ReadLine();
            while (Issuer.Length > 20)
            {
                Console.Write("\nVui long nhap ten duoi 20 ky tu");
                Issuer = Console.ReadLine();
            }
            newInv.Issuer = Issuer;
            int    selection = 1;
            string bookID    = string.Empty;

            // int bookQty; double bookPriceTag;
            while (selection == 1)
            {
                InvoiceDetail newInvDetails = new InvoiceDetail();
                newInvDetails.invNo = newInv.invNo;
                Console.WriteLine("Nhap thong tin Chi Tiet Hoa Don ");
                MyBookStore.printAllBook();

                Console.WriteLine("Nhap Ma Sach can nhap");
                // bookID = Console.ReadLine();
                Book rs = new Book();
                Console.WriteLine("Nhap Ma Sach");
                string input = Console.ReadLine();
                // tien hanh tim ma sach nay
                if (Book.chkbookID(input))
                {
                    rs = Book.inqBookbyID(input);
                    // neu ma sach da ton tai - tien hanh lay thong tin cua sach nay
                    newInvDetails.invUnit      = rs.bookID;
                    newInvDetails.invUnitPrice = rs.bookPriceTag;
                }
                else
                {
                    //neu ma sach moi, thuc hien them sach nay vao bookstore luon
                    Book.addBook(input);
                    rs = Book.inqBookbyID(input);
                    newInvDetails.invUnit      = rs.bookID;
                    newInvDetails.invUnitPrice = rs.bookPriceTag;
                    //we both know rs.bookQty = 0
                }

                string invUnitQty = string.Empty;
                //Console.WriteLine("\nNhap So Luong sach can nhap");
                invUnitQty = Console.ReadLine();
                while (!InvoiceDetail.chkQty(invUnitQty))
                {
                    invUnitQty = Console.ReadLine();
                }

                //cap nhat so luong mua vao va cap nhat so luong cho thong tin sach lien quan
                // + so luong sach mua vao MyBookstore
                rs.bookQty += int.Parse(invUnitQty);
                Book.updateBookQty(input, rs.bookQty);
                //hoan thanh viec cap nhat so luong mua vao va cap nhat so luong cho thong tin sach lien quan

                newInvDetails.invUnitQty    = int.Parse(invUnitQty);
                newInvDetails.invUnitAmount = InvoiceDetail.calculateAmount(newInvDetails.invUnitQty, newInvDetails.invUnitPrice);
                newInv.invTotalAmount      += newInvDetails.invUnitAmount;

                // luu vao MyInvoice
                MyInvoice.myinvdt.Add(newInvDetails);
                //luu vao file
                string invDetailrecord = $"{newInvDetails.invNo}#{newInvDetails.invUnit}#{newInvDetails.invUnitQty}#{newInvDetails.invUnitPrice}#{newInvDetails.invUnitAmount}";
                all_invDetail_records.Add(invDetailrecord);
                File.WriteAllLines(@"../../myInvoiceDetail.txt", all_invDetail_records);

                Console.Write("Tiep tuc - Nhap 1 | Hoan tat Hoa Don - Nhap 0 ");
                selection = int.Parse(Console.ReadLine());
            }
            // newInv.invTotalAmount = Invoices.calculateTotalAmount(newInv.invDetail);
            MyInvoice.myinv.Add(newInv);

            //tao ban ghi
            string invrecord = $"{newInv.invNo}#{newInv.invType}#{newInv.invTotalAmount}#{newInv.issueDate}#{newInv.invStatus}#{newInv.Issuer}";

            all_inv_records.Add(invrecord);
            File.WriteAllLines(@"../../myInvoice.txt", all_inv_records);

            Console.WriteLine("\nHoan tat them thong tin Hoa Don Nhap Sach");
            MyInvoice.printInv(newInv.invNo);
        }