예제 #1
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);
        }
예제 #2
0
 public void CreateFail()
 {
     Assert.False(inn.Create_Invoice(new Invoice()));
 }