예제 #1
0
        public void LoadFoodDataToListView()
        {
            //Gọi đối tượng FoodBL từ tầng BusinessLogic
            FoodBL foodBL = new FoodBL();

            listfood = foodBL.GetAll();

            int count = 1; // Biến số thứ tự

            lvFood.Items.Clear();

            foreach (var item in listfood)
            {
                ListViewItem lvitem = new ListViewItem(count.ToString());

                // Đưa dữ liệu Name, Unit, price vào cột tiếp theo
                lvitem.SubItems.Add(item.Name);
                lvitem.SubItems.Add(item.Unit);
                lvitem.SubItems.Add(item.Price.ToString());

                // Theo dữ liệu của bảng Category ID, lấy Name để hiển thị
                string foodname = listcategory.Find(x => x.ID == item.FoodCategoryID).Name;

                lvitem.SubItems.Add(foodname);
                lvitem.SubItems.Add(item.Notes);

                lvFood.Items.Add(lvitem);
                count++;
            }
        }
예제 #2
0
        public void LoadFoodDataToListView()
        {
            //Gọi đối tượng FoodBL từ tầng BusinessLogic
            FoodBL foodBL = new FoodBL();

            // Lấy dữ liệu
            listFood = foodBL.GetAll();
            int count = 1; // Biến số thứ tự

            // Xoá dữ liệu trong ListView
            lsvFood.Items.Clear();
            // Duyệt mảng dữ liệu để đưa vào ListView
            foreach (var food in listFood)
            {
                // Số thứ tự
                ListViewItem item = lsvFood.Items.Add(count.ToString());
                // Đưa dữ liệu Name, Unit, price vào cột tiếp theo
                item.SubItems.Add(food.Name);
                item.SubItems.Add(food.Unit);
                item.SubItems.Add(food.Price.ToString());
                // Theo dữ liệu của bảng Category ID, lấy Name để hiển thị
                string foodName = listCategory

                                  .Find(x => x.ID == food.FoodCategoryID).Name;

                item.SubItems.Add(foodName);
                // Đưa dữ liệu Notes vào cột cuối
                item.SubItems.Add(food.Notes);
                count++;
            }
        }
예제 #3
0
        private void LoadFoodDataToListView()
        {
            FoodBL foodBL = new FoodBL();

            listFood = foodBL.GetAll();
            int count = 1;

            lvfood.Items.Clear();
            foreach (var food in listFood)
            {
                ListViewItem item = lvfood.Items.Add(count.ToString());
                item.SubItems.Add(food.Name);
                item.SubItems.Add(food.Unit);
                item.SubItems.Add(food.Price.ToString());
                string foodname = listCategory.Find(x => x.ID == food.FoodCategoryID).Name;
                item.SubItems.Add(foodname);
                item.SubItems.Add(food.Notes);
                count++;
            }
        }