Exemplo n.º 1
0
		public DeviceGuardZoneViewModel(GKDeviceGuardZone deviceGuardZone, GKDevice device)
		{
			DeviceGuardZone = deviceGuardZone;
			if (device != null)
				IsCodeReader = device.Driver.IsCardReaderOrCodeReader;
			No = deviceGuardZone.GuardZone.No;
			Name = deviceGuardZone.GuardZone.Name;
			Description = deviceGuardZone.GuardZone.Description;
			ActionTypes = new ObservableCollection<GKGuardZoneDeviceActionType>();
			if (device != null)
			switch (device.DriverType)
			{
				case GKDriverType.RSR2_GuardDetector:
				case GKDriverType.RSR2_GuardDetectorSound:
				case GKDriverType.RSR2_HandGuardDetector:
					ActionTypes.Add(GKGuardZoneDeviceActionType.SetAlarm);
					break;

				case GKDriverType.RSR2_AM_1:
				case GKDriverType.RSR2_MAP4:
					ActionTypes.Add(GKGuardZoneDeviceActionType.SetGuard);
					ActionTypes.Add(GKGuardZoneDeviceActionType.ResetGuard);
					ActionTypes.Add(GKGuardZoneDeviceActionType.ChangeGuard);
					ActionTypes.Add(GKGuardZoneDeviceActionType.SetAlarm);
					break;
			}
			if (deviceGuardZone.ActionType == null || !ActionTypes.Contains(deviceGuardZone.ActionType.Value))
				SelectedActionType = ActionTypes.FirstOrDefault();
			ShowPropertiesCommand = new RelayCommand(OnShowProperties);
		}
		public GuardZonesWithFuncSelectationViewModel(GKDevice device, bool canCreateNew = false)
		{
			Title = "Выбор охранных зон";
			AddCommand = new RelayCommand<object>(OnAdd, CanAdd);
			RemoveCommand = new RelayCommand<object>(OnRemove, CanRemove);
			AddAllCommand = new RelayCommand(OnAddAll, CanAddAll);
			RemoveAllCommand = new RelayCommand(OnRemoveAll, CanRemoveAll);
			CreateNewCommand = new RelayCommand(OnCreateNew);

			Device = device;
			DeviceGuardZones = new ObservableCollection<DeviceGuardZoneViewModel>();
			foreach (var zone in device.GuardZones)
			{
				var guardZoneDevice = zone.GuardZoneDevices.FirstOrDefault(x => x.Device == device);
				if (guardZoneDevice != null)
				{
					var deviceGuardZone = new GKDeviceGuardZone();
					deviceGuardZone.GuardZone = zone;
					deviceGuardZone.GuardZoneUID = zone.UID;
					deviceGuardZone.ActionType = guardZoneDevice.ActionType;
					deviceGuardZone.CodeReaderSettings = guardZoneDevice.CodeReaderSettings;
					DeviceGuardZones.Add(new DeviceGuardZoneViewModel(deviceGuardZone, device));
				}
			}

			CanCreateNew = canCreateNew;
			TargetZones = new SortableObservableCollection<DeviceGuardZoneViewModel>();
			SourceZones = new SortableObservableCollection<DeviceGuardZoneViewModel>();

			foreach (var guardZone in GKManager.GuardZones)
			{
				var deviceGuardZone = DeviceGuardZones.FirstOrDefault(x => x.DeviceGuardZone.GuardZone == guardZone);
				if (deviceGuardZone != null)
					TargetZones.Add(deviceGuardZone);
				else
				{
					var gkDeviceGuardZone = new GKDeviceGuardZone();
					gkDeviceGuardZone.GuardZone = guardZone;
					gkDeviceGuardZone.GuardZoneUID = guardZone.UID;
					SourceZones.Add(new DeviceGuardZoneViewModel(gkDeviceGuardZone, device));
				}
			}

			SelectedTargetZone = TargetZones.FirstOrDefault();
			SelectedSourceZone = SourceZones.FirstOrDefault();
		}
		void OnCreateNew()
		{
			var createZoneEventArg = new CreateGKGuardZoneEventArg();
			ServiceFactory.Events.GetEvent<CreateGKGuardZoneEvent>().Publish(createZoneEventArg);
			if (createZoneEventArg.Zone != null)
			{
				var deviceGuardZone = new GKDeviceGuardZone();
				deviceGuardZone.GuardZone = createZoneEventArg.Zone;
				TargetZones.Add(new DeviceGuardZoneViewModel(deviceGuardZone, Device));
				if (TargetZones.Count == 1)
				{
					SaveCommand.Execute();
				}
			}
		}