public CheckViewModel() { _CargoCollection = WebApiOperate.StatiCargoInfoModels; _GroupNameCollection = WebApiOperate.StatiCargosGroups; SelectGropuChangedCommand = new RelayCommand <CargosGroup>(g => { var result = WebApiOperate.StatiCargoInfoModels.Where(i => i.PDGroup == g.PDGroup).ToList(); CargoCollection = new ObservableCollection <CargoInfoModel>(result); }); EditRelayCommand = new RelayCommand(() => { var Win = AddNewCargo.GetInstance(); (Win.DataContext as CargoEditViewModel).NewDetialMoedl = SelectInfoModel; (Win.DataContext as CargoEditViewModel).SelectedGroupName = SelectInfoModel.PDGroup; (Win.DataContext as CargoEditViewModel).EditModel = "修改"; Win.Show(); Win.Closed += UpdateList; }); AddNewRelayCommand = new RelayCommand(() => { SelectInfoModel = new CargoInfoModel(); var Win = AddNewCargo.GetInstance(); (Win.DataContext as CargoEditViewModel).NewDetialMoedl = SelectInfoModel; (Win.DataContext as CargoEditViewModel).SelectedGroupName = SelectInfoModel.PDGroup; (Win.DataContext as CargoEditViewModel).EditModel = "保存"; Win.Show(); Win.Closed += UpdateList; }); DeleRelayCommand = new RelayCommand(() => { CargoCollection = WebApiOperate.DeleCargo(SelectInfoModel.PDCode).Result; }); }
public MainViewModel() { WebApiOperate.StatiCargoInfoModels = WebApiOperate.GetAllCargoInfoModels(); WebApiOperate.StatiCargosGroups = WebApiOperate.GetAllGroup(); _CargosCollection = WebApiOperate.StatiCargoInfoModels; _GroupsCollection = WebApiOperate.StatiCargosGroups; _CartItemsCollection = new ObservableCollection <CartItem>(); SelectByGroupName = new RelayCommand <string>(s => { var result = WebApiOperate.StatiCargoInfoModels.Where(i => i.PDGroup == s).ToList(); CargosCollection = new ObservableCollection <CargoInfoModel>(result); }); SelectBystring = new RelayCommand <string>(s => { var reslut = WebApiOperate.StatiCargoInfoModels.Where(i => i.PDGroup == s || i.PDCode.Contains(s) || i.PDName.Contains(s) || i.PDSubName.Contains(s)).ToList(); CargosCollection = new ObservableCollection <CargoInfoModel>(reslut); }); AddToCart = new RelayCommand <CargoInfoModel>(i => { double Pdcnt = 1; if (i.IsWeighedNeeded) { Thread.Sleep(500); Pdcnt = 2; } CartItemsCollection.Add(new CartItem { Count = Pdcnt, PDName = i.PDName, PDSn = i.PDCode, UnitPrice = i.PDSellPrice, PDTotalPrice = Pdcnt * i.PDSellPrice }); CartCost = CartItemsCollection.Sum(a => a.PDTotalPrice); CartCount = CartItemsCollection.Count; }); DeleCargoBycode = new RelayCommand <string>(s => { WebApiOperate.StatiCargoInfoModels = WebApiOperate.DeleCargo(s); CargosCollection = WebApiOperate.StatiCargoInfoModels; }); RefreshCommand = new RelayCommand <RefreshView>(rv => { rv.IsRefreshing = true; WebApiOperate.StatiCargoInfoModels = WebApiOperate.GetAllCargoInfoModels(); WebApiOperate.StatiCargosGroups = WebApiOperate.GetAllGroup(); CargosCollection = WebApiOperate.StatiCargoInfoModels; GroupsCollection = WebApiOperate.StatiCargosGroups; rv.IsRefreshing = false; }); }