public TuningPropertyWrapViewModel(ControlSystemTuningProperty tuningProperty, ControlSystemTuningPropertyValue propertyValue) { mTuningProperty = tuningProperty; mType = (CommonUtils.PropertyType)Enum.Parse(typeof(CommonUtils.PropertyType),tuningProperty.Type, true); mName = tuningProperty.Name; mRequired = tuningProperty.Required; mPropertyValue = propertyValue; mErrorNumbericalValidationResult = new ValidationResult(string.Format("Field {0} is numerical", mName)); mErrorRequiredValidationResult = new ValidationResult(string.Format("Field {0} is required", mName)); AcceptCommand = new DelegateCommand<object>(AcceptCommandHandler, CanModifyHandler); }
private void AddDynamicProperties(TuningPropertiesDataAdapter adapter, ControlSystemComponent matchingComponent, int i) { foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties) { ControlSystemTuningProperty matchProperty = (from x in Cee.ControlSystemTuningProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (matchProperty == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemTuningProperty", dynamicProperty.PropertyName, i + 1))); continue; } ControlSystemComponentTypeTuningProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeTuningProperties where x.ControlSystemTuningPropertyId == matchProperty.Id && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId select x).FirstOrDefault(); if (matchCompTypeProperty == null) { var controlSystemPropertyName = (from x in Cee.ControlSystemTuningProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault(); var controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault(); string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, controlSystemTypeName, matchProperty.Id, controlSystemPropertyName, i); RaiseMessage(CommonUtils.MessageType.Error, message); continue; } //check for duplicates properties on this component (not allowed). var duplicateCount = (from x in Cee.ControlSystemTuningPropertyValues where x.ControlSystemComponentId == matchingComponent.ControlSystemComponentTypeId && x.ControlSystemTuningPropertyId == matchProperty.Id select x.Id).Count(); if (duplicateCount > 0) { var propertyName = matchProperty.Name; var componentName = matchingComponent.Name; string message = string.Format("An entry already exists in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentId = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, componentName, matchProperty.Id, propertyName, i); RaiseMessage(CommonUtils.MessageType.Error, message); continue; } if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1)) { continue; } ControlSystemTuningPropertyValue propertyValue = new ControlSystemTuningPropertyValue { ControlSystemTuningPropertyId = matchProperty.Id, ControlSystemComponentId = matchingComponent.Id, Value = dynamicProperty.PropertyValue, VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName) }; matchingComponent.ControlSystemTuningPropertyValues.Add(propertyValue); PropertyNameComponentNamePair pair = new PropertyNameComponentNamePair { ComponentName = matchingComponent.Name, PropertyName = matchProperty.Name, Value = dynamicProperty.PropertyValue }; mSavedResults.Add(pair); } }
private void UpdateDynamicProperties(TuningPropertiesDataAdapter adapter, ControlSystemComponent matchingComponent, int i) { foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties.Where(x => !string.IsNullOrEmpty(x.PropertyValue))) { ControlSystemTuningProperty matchProperty = (from x in Cee.ControlSystemTuningProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (matchProperty == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemTuningProperty", dynamicProperty.PropertyName, i + 1))); continue; } //is this property assocaited with the comp type? ControlSystemComponentTypeTuningProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeTuningProperties where x.ControlSystemTuningPropertyId == matchProperty.Id && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId select x).FirstOrDefault(); if (matchCompTypeProperty == null) { string controlSystemTuningPropertyName = (from x in Cee.ControlSystemTuningProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault(); var controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault(); string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, controlSystemTypeName, matchProperty.Id, controlSystemTuningPropertyName, i); RaiseMessage(CommonUtils.MessageType.Error, message); continue; } ControlSystemTuningPropertyValue matchSystemPropertyValue = (from x in Cee.ControlSystemTuningPropertyValues where (x.ControlSystemTuningPropertyId == matchProperty.Id) && (x.ControlSystemComponentId == matchingComponent.Id) select x).FirstOrDefault(); if (dynamicProperty.PropertyValue.ToLower().Trim() == NULLTEXT) { if (matchSystemPropertyValue == null) { //do nothing continue; } //delete Cee.ControlSystemTuningPropertyValues.Remove(matchSystemPropertyValue); } else { if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1)) { continue; } if (matchSystemPropertyValue == null) { //create matchSystemPropertyValue = new ControlSystemTuningPropertyValue { ControlSystemTuningPropertyId = matchProperty.Id, ControlSystemComponentId = matchingComponent.Id, Value = dynamicProperty.PropertyValue, VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName) }; Cee.ControlSystemTuningPropertyValues.Add(matchSystemPropertyValue); } else { //update matchSystemPropertyValue.Value = dynamicProperty.PropertyValue; matchSystemPropertyValue.VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName); } } PropertyNameComponentNamePair pair = new PropertyNameComponentNamePair { ComponentName = matchingComponent.Name, PropertyName = matchProperty.Name, Value = dynamicProperty.PropertyValue }; mSavedResults.Add(pair); } }
private ControlSystemTuningPropertyValue GetPropertyValue(ControlSystemComponent controlSystemComponent, ControlSystemComponentTypeTuningProperty controlSystemComponentTuningProperty) { var propertyValue = (from x in controlSystemComponent.ControlSystemTuningPropertyValues where x.ControlSystemTuningPropertyId == controlSystemComponentTuningProperty.ControlSystemTuningPropertyId && x.ControlSystemComponentId == controlSystemComponent.Id select x).FirstOrDefault(); if (propertyValue == null && controlSystemComponentTuningProperty.ControlSystemTuningPropertyId.HasValue) { propertyValue = new ControlSystemTuningPropertyValue { ControlSystemComponentId = controlSystemComponent.Id, ControlSystemTuningPropertyId = controlSystemComponentTuningProperty.ControlSystemTuningPropertyId.Value, Value = controlSystemComponentTuningProperty.ControlSystemTuningProperty.DefaultValue, Notes = controlSystemComponentTuningProperty.ControlSystemTuningProperty.Description }; controlSystemComponent.ControlSystemTuningPropertyValues.Add(propertyValue); } return propertyValue; }