Exemplo n.º 1
0
        /// <summary>
        /// Biến đổi một List của Laptop thành LaptopList
        /// </summary>
        /// <param name="list">List của Laptop</param>
        /// <returns>LaptopList tương ứng</returns>
        public LaptopList ToList(List <Laptop> list)
        {
            LaptopList laptopList = new LaptopList();

            foreach (Laptop lap in list)
            {
                laptopList.Add(lap);
            }
            return(laptopList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tìm kiếm Laptop dựa trên tiêu chí của key
        /// </summary>
        /// <param name="key">Laptop mẫu dùng để so sánh</param>
        /// <returns>Kết quả các laptop tìm được</returns>
        public LaptopList Search(Laptop key)
        {
            LaptopList result = new LaptopList();
            string     expr   = key.ToRegExpression();

            foreach (Laptop lap in this)
            {
                string input = lap.ToString();
                input = input.Replace("/", "\\/");
                if (Regex.IsMatch(lap.ToString(), expr))
                {
                    result.Add(lap);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            listLaptop              = new LaptopList();
            Transaction.LaptopList  = listLaptop;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            Menu.PrintHeader();
            int choise = 0;

            do
            {
                Menu.Output();
                switch (Menu.GetChoice())
                {
                case 1:
                    //Thêm một laptop
                    listLaptop.AddNewLaptop();
                    break;

                case 2:
                    //Lưu danh sách ra file
                    Console.WriteLine("Enter file's directory:");
                    string dir = Console.ReadLine();
                    listLaptop.AddFromFile(dir);
                    Laptop.PrintHeader();
                    Console.BackgroundColor = ConsoleColor.Blue;
                    listLaptop.Output();
                    Console.BackgroundColor = ConsoleColor.Black;
                    break;

                case 3:
                    //Chế độ mở rộng nhiều chức năng
                    AdvanceMode();
                    break;

                case 4:
                    return;
                }
            } while (choise != 4);


            Console.ReadLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Hiển thị chế độ mở rộng
        /// </summary>
        public static void AdvanceMode()
        {
            Console.Clear();
            bool           isExit = false;
            FileListViewer viewer = new FileListViewer(AppDomain.CurrentDomain.BaseDirectory);

            while (!isExit)
            {
                switch (Menu.printMenu("Function Menu", new List <string> {
                    "Add new Laptop", "Show List", "Save to file", "Load from file", "Delete a laptop", "Edit data", "Search", "Sell", "Exit"
                }, ConsoleColor.White, ConsoleColor.Black, ConsoleColor.Blue, ConsoleColor.Yellow))
                {
                case 0:     //Thêm laptop
                    Laptop laptop = new Laptop();
                    laptop.Input();
                    listLaptop.Add(laptop);
                    break;

                case 1:     //Hiển thị danh sách
                    Laptop.PrintHeader();
                    Console.BackgroundColor = ConsoleColor.Blue;
                    listLaptop.Output();
                    Console.BackgroundColor = ConsoleColor.Black;
                    break;

                case 2:     //Lưu ra file
                    Console.WriteLine("Enter directory: ");
                    listLaptop.WriteToFile(AppDomain.CurrentDomain.BaseDirectory + Console.ReadLine());
                    break;

                case 3:     //Đọc dữ liệu từ file
                    Console.WriteLine("Enter directory: ");
                    viewer = new FileListViewer(AppDomain.CurrentDomain.BaseDirectory);
                    listLaptop.AddFromFile(viewer.Open());
                    break;

                case 4:     //Xóa dữ liệu
                    List <string> listLaptopStr = new List <string>();
                    foreach (Laptop lap in listLaptop)
                    {
                        listLaptopStr.Add(lap.GetOutput());
                    }
                    listLaptopStr.Add("CANCEL DELETE FUNCTION !!!");
                    int ind = Menu.printMenu("Deletion list", listLaptopStr, ConsoleColor.White, ConsoleColor.Black, ConsoleColor.Blue, ConsoleColor.Yellow);
                    if (ind == listLaptopStr.Count - 1)
                    {
                        break;
                    }
                    listLaptop.RemoveAt(ind);
                    break;

                case 5:     //Chỉnh sửa dữ liệu
                    listLaptopStr = new List <string>();
                    foreach (Laptop lap in listLaptop)
                    {
                        listLaptopStr.Add(lap.GetOutput());
                    }
                    listLaptopStr.Add("CANCEL EDIT FUNCTION !!!");
                    Laptop.PrintHeader();
                    ind = Menu.printMenu("Edit list", listLaptopStr, ConsoleColor.White, ConsoleColor.Black, ConsoleColor.Blue, ConsoleColor.Yellow);
                    if (ind == listLaptopStr.Count - 1)
                    {
                        break;
                    }
                    Console.Write("SKU: Replace " + listLaptop[ind].Sku + " to: ");
                    listLaptop[ind].Sku = Console.ReadLine();
                    Console.Write("Name: Replace " + listLaptop[ind].Name + " to: ");
                    listLaptop[ind].Name = Console.ReadLine();
                    Console.Write("MFG: Replace " + listLaptop[ind].MFG + " to: ");
                    listLaptop[ind].MFG = DateTime.Parse(Console.ReadLine());
                    Console.Write("Price: Replace " + listLaptop[ind].Price + " to: ");
                    listLaptop[ind].Price = double.Parse(Console.ReadLine());
                    Console.Write("Quantity on hand: Replace " + listLaptop[ind].QuantityOnHand + " to: ");
                    listLaptop[ind].QuantityOnHand = int.Parse(Console.ReadLine());
                    Console.Write("Made in: Replace " + listLaptop[ind].MadeIn + " to: ");
                    listLaptop[ind].MadeIn = Console.ReadLine();
                    break;

                case 6:     //Tìm kiếm dữ liệu
                    Console.WriteLine("Enter search pattern: ");
                    Laptop key = new Laptop();
                    key.Input();
                    Console.WriteLine("Search result:");
                    Laptop.PrintHeader();
                    Console.BackgroundColor = ConsoleColor.Blue;
                    LaptopList result = listLaptop.Search(key);
                    foreach (Laptop lap in result)
                    {
                        lap.Output();
                    }
                    Console.BackgroundColor = ConsoleColor.Black;

                    break;

                case 7:     //Bán laptop
                    Transaction transaction = new Transaction();
                    transaction.StartTransaction();
                    transaction.EndTransaction();
                    transaction.PrintReceipt();
                    break;

                case 8:
                    return;
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Tạo đối tượng mới
 /// </summary>
 /// <param name="laptopList">Danh sách laptop cần giao dịch</param>
 public Transaction(LaptopList laptopList)
 {
     Transaction.laptopList = laptopList;
 }