Beispiel #1
0
 public IActionResult Details(int?id)
 {
     ViewData["Item"] = ibl.GetItemById(id ?? 0);
     if (ViewData["Item"] == null)
     {
         TempData["msg"] = "Can't find Item with id = " + id;
     }
     return(View());
 }
        static void Main(string[] args)
        {
            short mainChoose = 0, imChoose;

            string[]    mainMenu = { "Item Management", "Add Customer (using stored procedure)", "Create Order (using Transaction)", "Exit" };
            string[]    imMenu   = { "Get By Item Id", "Get All Items", "Search By Item Name", "Exit" };
            ItemBL      ibl      = new ItemBL();
            CustomerBL  cbl      = new CustomerBL();
            OrderBL     obl      = new OrderBL();
            List <Item> lst;

            do
            {
                mainChoose = Menu(" Order Management System - OMS", mainMenu);
                switch (mainChoose)
                {
                case 1:
                    do
                    {
                        // if (ibl == null) ibl = new ItemBL();
                        imChoose = Menu("Item Management", imMenu);
                        switch (imChoose)
                        {
                        case 1:
                            Console.Write("\nInput Item Id: ");
                            int itemId;
                            if (Int32.TryParse(Console.ReadLine(), out itemId))
                            {
                                Item i = ibl.GetItemById(itemId);
                                if (i != null)
                                {
                                    //Console.WriteLine("Item ID: " + i.ItemId);
                                    Console.WriteLine("Item Name: " + i.ItemName);
                                    Console.WriteLine("Item Price: " + i.ItemPrice);
                                    Console.WriteLine("Amount: " + i.Amount);
                                    Console.WriteLine("Item Status: " + i.Status);
                                    Console.WriteLine("Item Description: " + i.Description);
                                }
                                else
                                {
                                    Console.WriteLine("There is no item with id " + itemId);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Your Choose is wrong!");
                            }
                            Console.WriteLine("\n    Press Enter key to back menu...");
                            Console.ReadLine();
                            break;

                        case 2:
                            lst = ibl.GetAll();
                            Console.WriteLine("\nItem Count: " + lst.Count);
                            break;

                        case 3:
                            lst = ibl.GetByName("I");
                            Console.WriteLine("\nItem Count By Name: " + lst.Count);
                            break;
                        }
                    } while (imChoose != imMenu.Length);
                    break;

                case 2:
                    Customer c = new Customer {
                        CustomerName = "Nguyen Thi Nhi", CustomerAddress = "Ha Tay"
                    };
                    Console.WriteLine("Customer ID: " + cbl.AddCustomer(c));
                    break;

                case 3:
                    Order order = new Order();
                    //new customer
                    //order.OrderCustomer = new Customer { CustmerId = null, CustomerName = "Nguyen Xuan Sinh", CustomerAddress = "Hanoi" };

                    //exists customer
                    order.OrderCustomer = new Customer {
                        CustmerId = 1, CustomerName = "Nguyen Xuan Sinh", CustomerAddress = "Hanoi"
                    };

                    order.ItemsList.Add(ibl.GetItemById(2));
                    order.ItemsList[0].Amount = 1;
                    order.ItemsList.Add(ibl.GetItemById(3));
                    order.ItemsList[1].Amount = 2;
                    Console.WriteLine("Create Order: " + (obl.CreateOrder(order) ? "completed!" : "not complete!"));
                    break;
                }
            } while (mainChoose != mainMenu.Length);
        }
Beispiel #3
0
 public void Test_ItemBL()
 {
     Assert.NotNull(itembl.GetItemById("GT1"));
 }
Beispiel #4
0
        public static bool CreateOrders()
        {
            System.Console.Clear();
            invoicebl        = new InvoiceBL();
            invoice          = new Invoice();
            itembl           = new ItemBL();
            item             = new Item();
            invoice.ItemList = new List <Item>();
            int count1 = 0;

            invoice.staff         = new Staff();
            invoice.staff.StaffID = u;
            List <Item> result = itembl.GetAllItem();
            int         index  = 0;

            if (result != null)
            {
                while (true)
                {
                    while (true)
                    {
                        int count = 0;
                        System.Console.WriteLine("Nhập Mã Sản Phẩm: ");
                        try
                        {
                            string item_id = System.Console.ReadLine();
                            for (int i = 0; i < result.Count; i++)
                            {
                                if (item_id == result[i].itemID)
                                {
                                    invoice.ItemList.Add(itembl.GetItemById(item_id));
                                    foreach (var item in invoice.ItemList)
                                    {
                                        System.Console.Clear();
                                        System.Console.WriteLine(item.itemName);
                                    }
                                    index = i;
                                    count++;
                                }
                            }
                            if (count == 0)
                            {
                                throw new System.Exception("Không tìm thấy ID");
                            }
                        }
                        catch (System.Exception e)
                        {
                            System.Console.WriteLine(e.Message);
                            continue;
                        }
                        // catch{
                        //     continue;
                        // }
                        break;
                    }

                    while (true)
                    {
                        try
                        {
                            System.Console.WriteLine("----------------");
                            System.Console.Write("Nhập Vào Số Lượng: ");
                            do
                            {
                                // System.Console.Write("Nhập Vào Số Lượng: ");
                                amount = Convert.ToInt32(System.Console.ReadLine());
                                if (amount <= 0)
                                {
                                    System.Console.WriteLine("Số lương không hợp lệ - Nhập lại");
                                }
                            } while (amount <= 0);

                            if ((amount > result[index].amount && result[index].amount == 0) || (amount == result[index].amount && result[index].amount == 0))
                            {
                                System.Console.WriteLine("Số Lượng Sản Phẩm Không Còn!");
                                System.Console.ReadKey();
                                List_Item();
                            }
                            if (amount > result[index].amount && result[index].amount > 0)
                            {
                                System.Console.WriteLine("Số Lượng Còn : {0}", result[index].amount);
                                throw (new System.Exception("Mời Khách Hàng Giảm Số Lượng Hoặc Chọn Sản Phẩm Khác !"));
                            }
                            else if (0 < amount || amount <= result[index].amount)
                            {
                                invoice.ItemList[count1].amount = amount;
                                count1++;
                                break;
                            }
                        }
                        catch (System.Exception e)
                        {
                            System.Console.Write(e.Message);
                            continue;
                        }
                        break;
                    }
                    System.Console.Write("Bạn Muốn Mua Thêm  ?(y/n) ");
                    char choice = Convert.ToChar(System.Console.ReadLine());
                    if (choice == 'n')
                    {
                        break;
                    }
                }
                System.Console.WriteLine("Bạn Có Muốn Tạo Hóa Đơn Này Không ? Y/N");
                char ch = Convert.ToChar(System.Console.ReadLine());
                switch (ch)
                {
                case 'n':
                    System.Console.WriteLine("Hóa Đơn Đã Bị Hủy - Đang Trở Lại Menu Nhân Viên ");
                    System.Console.ReadLine();
                    MenuStaff();
                    break;

                case 'y':
                    System.Console.WriteLine("Tạo Hóa Đơn " + (invoicebl.Create_Invoice(invoice) ? "Thành Công!" : "Không Thành Công!"));
                    System.Console.WriteLine("Nhập Bất Kì Để Xuất Hóa Đơn Chó Khách Hàng ");
                    break;
                }
                GetInvoiceDetails();
                System.Console.ReadLine();
            }
            else if (result == null)
            {
                System.Console.Write("Sản Phẩm Không Tồn Tại!");
                System.Console.ReadLine();
                List_Item();
                return(false);
            }
            return(true);
        }
        static void Main(string[] args)
        {
            short mainChoose = 0, imChoose;

            string[]    mainMenu = { "Dang Nhap", "Xem thong tin va dat hang", "Quan li gio hang", "Exit" };
            string[]    imMenu   = { "Get By Item Id", "Get All Items", "Search By Item Name", "Exit" };
            ItemBL      ibl      = new ItemBL();
            CustomerBL  cbl      = new CustomerBL();
            OrderBL     obl      = new OrderBL();
            List <Item> lst;

            do
            {
                mainChoose = Menu(" Nguoi Mua Hang Online", mainMenu);
                switch (mainChoose)
                {
                case 1:
                    do
                    {
                        // if (ibl == null) ibl = new ItemBL();
                        imChoose = Menu("Login", imMenu);
                        switch (imChoose)
                        {
                        case 1:
                            Console.Write("\nInput Item Id: ");
                            int itemId;
                            if (Int32.TryParse(Console.ReadLine(), out itemId))
                            {
                                Item i = ibl.GetItemById(itemId);
                                if (i != null)
                                {
                                    //Console.WriteLine("Item ID: " + i.ItemId);
                                    Console.WriteLine("Item Name: " + i.ItemName);
                                    Console.WriteLine("Item Price: " + i.ItemPrice);
                                    Console.WriteLine("Amount: " + i.Amount);
                                    Console.WriteLine("Item Status: " + i.Status);
                                    Console.WriteLine("Item Description: " + i.Description);
                                }
                                else
                                {
                                    Console.WriteLine("There is no item with id " + itemId);
                                }
                            }
                            else
                            {
                                Console.WriteLine("Your Choose is wrong!");
                            }
                            Console.WriteLine("\n    Press Enter key to back menu...");
                            Console.ReadLine();
                            break;

                        case 2:
                            lst = ibl.GetAll();
                            Console.WriteLine("\nItem Count: " + lst.Count);
                            break;

                        case 3:
                            lst = ibl.GetByName("I");
                            Console.WriteLine("\nItem Count By Name: " + lst.Count);
                            break;
                        }
                    } while (imChoose != imMenu.Length);
                    break;

                case 2:
                    Customer c = new Customer {
                        CustomerName = "Nguyen Thi Nhi", CustomerAddress = "Ha Tay"
                    };
                    Console.WriteLine("Customer ID: " + cbl.AddCustomer(c));
                    break;

                case 3:
                    Order order = new Order();
                    order.OrderCustomer = new Customer {
                        CustmerId = null, CustomerName = "Dao Van Duc", CustomerAddress = "Thai Binh"
                    };
                    order.ItemsList.Add(ibl.GetItemById(2));
                    order.ItemsList[0].Amount = 1;
                    order.ItemsList.Add(ibl.GetItemById(3));
                    order.ItemsList[1].Amount = 2;

                    Console.WriteLine("Create Order: " + (obl.CreateOrder(order) ? "completed!" : "not complete!"));
                    break;
                }
            } while (mainChoose != mainMenu.Length);
        }