public AddEditCalibrationPropertyViewModel() { mCalibrationProperty = new CalibrationProperty(); LoadTypes(); InitialiseCommandButtons(); }
public AddEditCalibrationPropertyViewModel(int calibrationPropertyId) { CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); LoadTypes(); cmsWebServiceClient.GetCalibrationPropertyCompleted += (s, e) => { mCalibrationProperty = e.Result; DataLoaded(); }; cmsWebServiceClient.GetCalibrationPropertyAsync(calibrationPropertyId); InitialiseCommandButtons(); }
set => SetValue(CalibrationProperty, value);
private void BuildPropertyValues(CalibrationComponent componentIn, CalibrationComponentDataAdapter adapter) { foreach (CalibrationPropertyDto dto in adapter.PropertyValues) { CalibrationProperty property = (from x in mExistingProperties where x.Name.ToLower() == dto.PropertyName.ToLower() select x).FirstOrDefault(); if (property == null) { if (CanCreateProperties) { property = new CalibrationProperty { Name = dto.PropertyName, Type = "not used", Description = "(created by importer.)" }; mExistingProperties.Add(property); //JOIN TABLE - joins the Property with the Type CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty(); typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType; //EngineeringUnit if (dto.NewUnit != null) { CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault(); if (unit == null) { typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit; } else { typePropertyJoin.CalibrationEngineeringUnit = unit; } } property.CalibrationComponentTypeProperties.Add(typePropertyJoin); mExistingProperties.Add(property); } else { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1} Tag {2} Component Name {3}' : The property does not exist.", WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.CalibrationName)); continue; } } else { //do we have a record in the join table for this property and comp type? CalibrationComponentTypeProperty equipmentComponentTypeProperty = (from x in Cee.CalibrationComponentTypeProperties where x.CalibrationComponentType.Name.ToLower() == componentIn.CalibrationComponentType.Name.ToLower() && x.CalibrationProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); if (equipmentComponentTypeProperty == null) { ////no row in join table - so create one. CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty(); if (dto.NewUnit != null) { CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault(); if (unit == null) { typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit; } else { typePropertyJoin.CalibrationEngineeringUnit = unit; } } typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType; property.CalibrationComponentTypeProperties.Add(typePropertyJoin); } } CalibrationComponentPropertyValue propertyValue = (from x in Cee.CalibrationComponentPropertyValues where x.CalibrationComponentId == componentIn.Id && x.CalibrationPropertyId == property.Id select x).FirstOrDefault(); if (propertyValue == null) { propertyValue = new CalibrationComponentPropertyValue {CalibrationComponent = componentIn, CalibrationProperty = property}; property.Type = "Text";//not used but not nullable property.EnableAsFound = false; //not used but not nullable } //Set AsFoundValue if (!string.IsNullOrEmpty(dto.AsFoundValue)) { propertyValue.Value = dto.AsFoundValue; } //Set AsLeftValue if (!string.IsNullOrEmpty(dto.AsLeftValue)) { propertyValue.Value2 = dto.AsLeftValue; } componentIn.CalibrationComponentPropertyValues.Add(propertyValue); } }
public CalibrationProperty SaveCalibrationProperty(CalibrationProperty calibrationProperty) { using (CmsEntities cee = new CmsEntities()) { CalibrationProperty original = (from x in cee.CalibrationProperties where x.Id == calibrationProperty.Id select x).FirstOrDefault(); if (original == null) { cee.CalibrationProperties.Add(calibrationProperty); } else { cee.Entry(original).CurrentValues.SetValues(calibrationProperty); } cee.SaveChanges(); } return calibrationProperty; }