示例#1
0
        public StationMachinesVM(StationVM station, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentStation = station;
            StationDataService = new StationDataService(UnitOfWork);
            StationDataService.MachineAdded += OnMachineAdded;
            StationDataService.MachineRemoved += OnMachineRemoved;
            MachineDataService = new MachineDataService(UnitOfWork);
            StationMachineDataService = new StationMachineDataService(UnitOfWork);
            MachineFamilyDataService = new MachineFamilyDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<StationMachineVM>();
            foreach (var stationMachine in StationDataService.GetMachines(station.Id))
            {
                selectedVms.Add(new StationMachineVM(stationMachine, Access, StationMachineDataService, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<MachineVM>();
            foreach (var machine in MachineDataService.GetActives()
				.Where(machine => !selectedVms.Any(stationMachine => stationMachine.MachineId == machine.Id)))
            {
                allVms.Add(new MachineVM(machine, Access, MachineDataService, MachineFamilyDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
			IncludeAllCommand = new Command(o =>
			{
				foreach (var vm in allVms.ToArray())
				{
					StationDataService.AddMachine(CurrentStation.Id, ((IEntityItem)vm).Id);
				}
			}, () => allVms.Any());
        }
示例#2
0
 private void OnStationRemoved(object sender, ModelRemovedEventArgs e)
 {
     foreach (StationMachineVM item in SelectedItems)
     {
         if (item.Id == e.Id)
         {
             var model = StationDataService.GetSingle(item.StationId);
             var returnedVm = new StationVM(model, Access, StationDataService);
             AllItems.AddNewItem(returnedVm);
             AllItems.CommitNew();
             SelectedItems.Remove(item);
             break;
         }
     }
 }
示例#3
0
 private void OnStationAdded(object sender, ModelAddedEventArgs<Station> e)
 {
     var newStationVm = new StationVM(e.NewModel, Access, StationDataService);
     Items.AddNewItem(newStationVm);
     Items.CommitNew();
     CurrentContent = newStationVm;
     CurrentContent.IsSelected = true;
 }