Esempio n. 1
0
        public static void printInvDetail(string invNo)
        {
            //tim kiem
            List <int> indexmatched = new List <int>();

            for (int i = 0; i < MyInvoice.myinvdt.Count; i++)
            {
                if (MyInvoice.myinvdt[i].invNo.ToUpper() == invNo.ToUpper())
                {
                    indexmatched.Add(i);
                }
                else
                {
                }
            }
            //in ket qua
            Console.WriteLine("\nChi Tiet Hoa Don");
            //in thong tin chi tiet hoa don
            // phai xu ly cach tim index phu hop voi thong tin invoice no
            InvoiceDetail.print_header();
            //foreach (InvoiceDetail invdt in MyInvoice.myinvdt)
            for (int x = 0; x < indexmatched.Count; x++)
            {
                Console.WriteLine("{0,-5}{1,-35}{2,-15}{3,-15}{4,-15}",
                                  x + 1,
                                  Book.inqBookbyID(MyInvoice.myinvdt[indexmatched[x]].invUnit).bookName,
                                  MyInvoice.myinvdt[indexmatched[x]].invUnitQty,
                                  GeneralCode.converPricetag(MyInvoice.myinvdt[indexmatched[x]].invUnitPrice),
                                  GeneralCode.converPricetag(MyInvoice.myinvdt[indexmatched[x]].invUnitAmount));
            }
        }
Esempio n. 2
0
        }                                               //5. Thành Tiền - auto

        public static double calculateAmount(int qty, double pricetag)
        {
            double result;

            result = qty * pricetag;
            Console.WriteLine("\ntong cong: " + GeneralCode.converPricetag(result));//
            return(result);
        }
Esempio n. 3
0
        public static void printInv(string invNo)
        {
            int index = 0;

            index = find_InvIndex(invNo);
            // MyInvoice.myinvdt[indexmatched[x]].invUnitQty
            Console.WriteLine("\nHoa Don {0} \n", GeneralCode.convertinvType(MyInvoice.myinv[index].invType));
            Console.WriteLine("So Hoa Don : {0,-10} ", MyInvoice.myinv[index].invNo);
            Console.WriteLine("Trang Thai : {0,-15}", GeneralCode.convertinvStatus(MyInvoice.myinv[index].invStatus));
            Console.WriteLine("Ngay Phat Hanh : {0,-20} ", MyInvoice.myinv[index].issueDate);
            Console.WriteLine("Nguoi lap Hoa Don : {0,-20}", MyInvoice.myinv[index].Issuer);
            printInvDetail(invNo);
            Console.WriteLine("Tong Cong : {0,-15}", GeneralCode.converPricetag(MyInvoice.myinv[index].invTotalAmount));
        }
Esempio n. 4
0
        //print a specific book
        public static void printBook(int index)
        {
            int i = index;

            // (mã, tên sách, nxb, giá, năm xuất bản, thể loại, số lượng)
            Console.WriteLine("{0,-8}{1,-35}{2,-20}{3,-15}{4,-15}{5,-20}{6,-15}",
                              MyBookStore.mybs[i].bookID,
                              MyBookStore.mybs[i].bookName,
                              MyBookStore.mybs[i].bookPublisher,
                              GeneralCode.converPricetag(MyBookStore.mybs[i].bookPriceTag),
                              MyBookStore.mybs[i].bookYear,
                              Category.inqCategorybyID(MyBookStore.mybs[i].bookCat).catName,
                              MyBookStore.mybs[i].bookQty
                              );
        }
Esempio n. 5
0
        //tim sach da xuat ban tren 3 nam
        public static void inqBookbybookYear(int bookYear)
        {
            List <int> indexmatched = new List <int>();

            for (int i = 0; i < MyBookStore.mybs.Count; i++)
            {
                if (Book.calculatebookYear(MyBookStore.mybs[i].bookYear) > 3)
                {
                    indexmatched.Add(i);
                }
                else
                {
                }
            }
            //nếu không có kết quả sách nào khớp với từ khoá tìm kiếm, in ra dòng kết quả như sau
            if (indexmatched.Count == 0)
            {
                Console.WriteLine("\nKhong co thong tin sach cu da xuat ban tren 3 nam\n");
            }
            //nếu có kết quả sách khớp với từ khoá tìm kiếm, lần lượt in thông tin sách ra
            else
            {
                //nếu có kết quả thì in ra thông tin sách có thứ tự như sau
                Console.WriteLine("\nDanh sach ket qua sach cu da xuat ban tren 3 nam:");
                Book.print_header();
                //chạy một vòng lặp, lấy các thông tin sách theo list các index khớp với điều kiện và đã được lưu vào indexmatched
                for (int x = 0; x < indexmatched.Count; x++)
                {
                    Console.WriteLine("{0,-8}{1,-35}{2,-20}{3,-15}{4,-15}{5,-20}{6,-15}",
                                      MyBookStore.mybs[indexmatched[x]].bookID,
                                      MyBookStore.mybs[indexmatched[x]].bookName,
                                      MyBookStore.mybs[indexmatched[x]].bookPublisher,
                                      GeneralCode.converPricetag(MyBookStore.mybs[indexmatched[x]].bookPriceTag),
                                      MyBookStore.mybs[indexmatched[x]].bookYear,
                                      Category.inqCategorybyID(MyBookStore.mybs[x].bookCat).catName,
                                      MyBookStore.mybs[x].bookQty
                                      );
                }
            }
        }
Esempio n. 6
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);
        }