//主窗体初始化 public DishPackagesViewModel(IChooseDishesDataService dataService) { _DataService = dataService; //查询套菜绑定grid DishV = new ObservableCollection <DishBean>(); DishDaoV = new ObservableCollection <DishDaoBean>(); DishDetailV = new ObservableCollection <DishDetailBean>(); Dish dish = new Dish(); List <Dish> loooo = _DataService.queryByDish(dish); bool a = loooo != null; if (a) { foreach (var loca in loooo) { DishBean bean = new DishBean(); bean = bean.CreateDishBean(loca); bean.InjectBeanPrice(); DishV.Add(new DishBean { DishId = bean.DishId, Code = bean.Code, DishName = bean.DishName, DishFormatName = bean.DishFormatName, Price1 = bean.Price1 }); } } }
//加载所有的 菜品 大类 小类 public void LoadDishObject() { //加载所有小类 _DishTypeSmail = new ObservableCollection <DishType>(); List <DishType> listsmail = _DataService.FindDishTypeByType(-1); _DishTypeSmail.Clear(); foreach (var element in listsmail) { _DishTypeSmail.Add(element); } //加载所有的菜品 List <Dish> list = _DataService.FindDishPackages(0); _DishesMenusSelected.Clear(); foreach (var element in list) { DishBean dishBean = new DishBean(); dishBean = dishBean.CreateDishBean(element); dishBean.InjectBeanPrice(); //注入大类,小类 for (int i = 0; i < _DishTypeSmail.Count; i++) { if (element.DishTypeId == _DishTypeSmail[i].DishTypeId) { dishBean.DishTypeName = _DishTypeSmail[i].Name; bool flag = false; for (int j = 0; j < _DishTypeBig.Count; j++) { if (_DishTypeSmail[i].ParentId == _DishTypeBig[j].DishTypeId) { dishBean.DishTypeBigName = _DishTypeBig[j].Name; flag = true; break; } } if (flag) { break; } } } DishesMenusSelected.Add(dishBean); } }