public DirectionDetailsViewModel(XDirection direction = null)
        {
            if (direction == null)
            {
                Title = "Создание новоого направления";

                XDirection = new XDirection()
                {
                    Name = "Новое направление",
                    No = 1
                };
                if (XManager.DeviceConfiguration.Directions.Count != 0)
                    XDirection.No = (ushort)(XManager.DeviceConfiguration.Directions.Select(x => x.No).Max() + 1);
            }
            else
            {
                Title = string.Format("Свойства направления: {0}", direction.PresentationName);
                XDirection = direction;
            }
            if (XDirection.DirectionDevices.Count == 0)
            {
                var directionDevice = new DirectionDevice();
                XDirection.DirectionDevices.Add(directionDevice);
            }
            CopyProperties();
            DirectionDevicesViewModel = new DirectionDevicesViewModel(XDirection);
        }
 public void Save()
 {
     Direction.DirectionDevices = new List<DirectionDevice>();
     foreach (var directionDeviceViewModel in DirectionDevices)
     {
         if (directionDeviceViewModel.Device != null)
         {
             var directionDevice = new DirectionDevice()
             {
                 DeviceUID = directionDeviceViewModel.Device.UID,
                 StateType = directionDeviceViewModel.SelectedStateType
             };
             Direction.DirectionDevices.Add(directionDevice);
         }
     }
 }
示例#3
0
        public DirectionDeviceViewModel(DirectionDevice directionDevice = null)
        {
            ChooseDeviceCommand = new RelayCommand(OnChooseDevice);

            StateTypes = new List<XStateType>();
            StateTypes.Add(XStateType.TurnOn);
            StateTypes.Add(XStateType.CancelDelay);
            StateTypes.Add(XStateType.TurnOff);
            StateTypes.Add(XStateType.Stop);
            StateTypes.Add(XStateType.ForbidStart);
            StateTypes.Add(XStateType.TurnOnNow);
            StateTypes.Add(XStateType.TurnOffNow);
            SelectedStateType = StateTypes.FirstOrDefault();

            if (directionDevice != null)
            {
                SelectedStateType = directionDevice.StateType;
                if (directionDevice.DeviceUID != null)
                    Device = XManager.DeviceConfiguration.Devices.FirstOrDefault(x => x.UID == directionDevice.DeviceUID);
            }
        }