private void UpdateDynamicProperties(EngineeringPropertyDataAdapter adapter, ControlSystemComponent matchingComponent, int i) { foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties.Where(x => !string.IsNullOrEmpty(x.PropertyValue))) { ControlSystemProperty matchProperty = (from x in Cee.ControlSystemProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (matchProperty == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemProperty", dynamicProperty.PropertyName, i + 1))); continue; } //is this property assocaited with the comp type? ControlSystemComponentTypeProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeProperties where x.ControlSystemPropertyId == matchProperty.Id && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId select x).FirstOrDefault(); if (matchCompTypeProperty == null) { string controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault(); string controlSystemPropertyName = (from x in Cee.ControlSystemProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault(); string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, controlSystemTypeName, matchProperty.Id, controlSystemPropertyName, i); RaiseMessage(CommonUtils.MessageType.Error, message); continue; } ControlSystemPropertyValue matchSystemPropertyValue = (from x in Cee.ControlSystemPropertyValues where (x.ControlSystemPropertyId == matchProperty.Id) && (x.ControlSystemComponentId == matchingComponent.Id) select x).FirstOrDefault(); if (dynamicProperty.PropertyValue.ToLower().Trim() == NULLTEXT) { if (matchSystemPropertyValue == null) { //do nothing continue; } //delete Cee.ControlSystemPropertyValues.Remove(matchSystemPropertyValue); } else { if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1)) { continue; } if (matchSystemPropertyValue == null) { //create matchSystemPropertyValue = new ControlSystemPropertyValue { ControlSystemPropertyId = 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.ControlSystemPropertyValues.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); } } var pair = new PropertyNameComponentNamePair { ComponentName = matchingComponent.Name, PropertyName = matchProperty.Name, Value = dynamicProperty.PropertyValue }; mSavedResults.Add(pair); } }
private ControlSystemPropertyValue GetPropertyValue(ControlSystemComponent controlSystemComponent, ControlSystemComponentTypeProperty controlSystemComponentProperty) { var propertyValue = (from x in controlSystemComponent.ControlSystemPropertyValues where x.ControlSystemPropertyId == controlSystemComponentProperty.ControlSystemPropertyId && x.ControlSystemComponentId == controlSystemComponent.Id select x).FirstOrDefault(); if (propertyValue == null && controlSystemComponentProperty.ControlSystemPropertyId.HasValue) { propertyValue = new ControlSystemPropertyValue { ControlSystemComponentId = controlSystemComponent.Id, ControlSystemPropertyId = controlSystemComponentProperty.ControlSystemPropertyId.Value, Value = controlSystemComponentProperty.ControlSystemProperty.DefaultValue }; controlSystemComponent.ControlSystemPropertyValues.Add(propertyValue); } return propertyValue; }
private void AddDynamicProperties(EngineeringPropertyDataAdapter adapter, ControlSystemComponent matchingComponent, int i) { foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties) { ControlSystemProperty matchProperty = (from x in Cee.ControlSystemProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (matchProperty == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemProperty", dynamicProperty.PropertyName, i + 1))); continue; } ControlSystemComponentTypeProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeProperties where x.ControlSystemPropertyId == matchProperty.Id && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId select x).FirstOrDefault(); if (matchCompTypeProperty == null) { string controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault(); string controlSystemPropertyName = (from x in Cee.ControlSystemProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault(); string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemPropertyId = '{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). int duplicateCount = (from x in Cee.ControlSystemPropertyValues where x.ControlSystemComponentId == matchingComponent.ControlSystemComponentTypeId && x.ControlSystemPropertyId == matchProperty.Id select x.Id).Count(); if (duplicateCount > 0) { string propertyName = matchProperty.Name; string componentName = matchingComponent.Name; string message = string.Format("An entry already exists in Database for the Table 'ControlSystemPropertyValue' Where ControlSystemComponentId = '{0}'({1}) And ControlSystemPropertyId = '{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; } var propertyValue = new ControlSystemPropertyValue { ControlSystemPropertyId = matchProperty.Id, Value = dynamicProperty.PropertyValue, VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName) }; matchingComponent.ControlSystemPropertyValues.Add(propertyValue); var pair = new PropertyNameComponentNamePair { ComponentName = matchingComponent.Name, PropertyName = matchProperty.Name, Value = dynamicProperty.PropertyValue }; mSavedResults.Add(pair); } }