Ejemplo n.º 1
0
		public TariffSelectionViewModel(DeviceDetailsViewModel parentViewModel)
		{
			Tariffs = new ObservableCollection<Tariff>(DbCache.Tariffs.Where(x => 
				x.TariffType == parentViewModel.TariffType && 
				x.TariffParts.Count <= parentViewModel.Device.MaxTatiffParts));
			_emptyTariff = new Tariff { Name = "Открепить от тарифа" };
			Tariffs.Insert(0, _emptyTariff);
			if(parentViewModel.Tariff != null)
				SelectedTariff = Tariffs.FirstOrDefault(x => x.UID == parentViewModel.Tariff.UID);
		}
Ejemplo n.º 2
0
		public DetailsParameterViewModel(Parameter model, DeviceDetailsViewModel parent)
		{
			Model = model;
			Name = model.DriverParameter.Description;
			_parent = parent;
			IsNotReadOnly = !model.DriverParameter.IsReadOnly && (model.DriverParameter.CanWriteInActive || !parent.IsActive);

			if (IsNotReadOnly)
				switch (Model.DriverParameter.ParameterType)
				{
					case ParameterType.Enum:
						IsEnum = true;
						ParameterEnum = new ObservableCollection<ParameterEnumItem>(Model.DriverParameter.ParameterEnumItems);
						SelectedEnumItem = ParameterEnum.FirstOrDefault(x => x.Value == model.IntValue);
						if (SelectedEnumItem == null)
							SelectedEnumItem = ParameterEnum.FirstOrDefault();
						break;
					case ParameterType.String:
						IsString = true;
						StringValue = Model.StringValue;
						break;
					case ParameterType.Int:
						IsInt = true;
						IntValue = Model.IntValue ?? Model.DriverParameter.IntDefaultValue;
						if (Model.DriverParameter.IsReadOnly)
							StringValue = IntValue.ToString();
						break;
					case ParameterType.Double:
						IsDouble = true;
						var doubleValue = Model.DoubleValue ?? Model.DriverParameter.DoubleDefaultValue;
						StringValue = doubleValue.ToString();
						break;
					case ParameterType.Bool:
						IsBool = true;
						BoolValue = Model.BoolValue ?? Model.DriverParameter.BoolDefaultValue;
						break;
					case ParameterType.DateTime:
						IsDateTime = true;
						var dateTime = Model.DateTimeValue ?? DateTime.Now;
						DateTimeValue = new DateTimePairViewModel(dateTime);
						TimeSpan = dateTime.TimeOfDay;
						break;
					default:
						break;
				}
			else
				ReadOnlyValue = model.GetStringValue();
		}
Ejemplo n.º 3
0
		void OnEdit()
		{
			var oldConsumer = SelectedDevice.Device.Consumer;
			var deviceDetailsViewModel = new DeviceDetailsViewModel(SelectedDevice.Device);
			if (DialogService.ShowModalWindow(deviceDetailsViewModel))
			{
				SelectedDevice.Update(deviceDetailsViewModel.Device);
				foreach (var child in SelectedDevice.Children)
					child.Update();
				UpdateConsumerDetailsViewModels(SelectedDevice.Device, oldConsumer);
			}
		}
Ejemplo n.º 4
0
		void OnAdd()
		{
			var parent = SelectedDevice;
			if (parent.Device.Driver.Children.Count == 0)
				parent = SelectedDevice.Parent;
			bool isCreateDevice = true;
			var driverType = new DriverType();
			if (parent.Device.Driver.Children.Count > 1)
			{
				var driverTypesViewModel = new DriverTypesViewModel(parent.Device.DriverType);
				if (DialogService.ShowModalWindow(driverTypesViewModel))
				{
					driverType = driverTypesViewModel.SelectedDriverType;
				}
				else
					isCreateDevice = false;
			}
			else
				driverType = parent.Device.Driver.Children.FirstOrDefault();
			if(isCreateDevice)
			{
				var deviceDetailsViewModel = new DeviceDetailsViewModel(driverType, parent.Device);
				if (DialogService.ShowModalWindow(deviceDetailsViewModel))
				{
					var deviceViewModel = new DeviceViewModel(deviceDetailsViewModel.Device);
					parent.AddChild(deviceViewModel);
					parent.IsExpanded = true;
					AllDevices.Add(deviceViewModel);
					SelectedDevice = deviceViewModel;
					DeviceProcessor.Instance.AddToMonitoring(deviceViewModel.Device);
					UpdateConsumerDetailsViewModels(SelectedDevice.Device);
				}
			}
		}