public static T_Shaft ConvertToDB(ShaftClass shaft) { T_Shaft t_shaft = new T_Shaft(); t_shaft.id = shaft.id; t_shaft.Name = shaft.Name; t_shaft.Guid = shaft.Guid; t_shaft.IsSlidingBearing = shaft.IsSlidingBearing; t_shaft.DeltaRPM = shaft.DeltaRPM; t_shaft.DefaultRPM = shaft.DefaultRPM; t_shaft.RPMCoeff = shaft.RPMCoeff; if (shaft.BearingComponents != null) { t_shaft.BearingComponentsJson = JsonConvert.SerializeObject(shaft.BearingComponents); } else { t_shaft.BearingComponentsJson = null; } if (shaft.BeltComponents != null) { t_shaft.BeltComponentsJson = JsonConvert.SerializeObject(shaft.BeltComponents); } else { t_shaft.BeltComponentsJson = null; } if (shaft.GearComponents != null) { t_shaft.GearComponentsJson = JsonConvert.SerializeObject(shaft.GearComponents); } else { t_shaft.GearComponentsJson = null; } if (shaft.MotorComponents != null) { t_shaft.MotorComponentsJson = JsonConvert.SerializeObject(shaft.MotorComponents); } else { t_shaft.MotorComponentsJson = null; } if (shaft.ImpellerComponents != null) { t_shaft.ImpellerComponentsJson = JsonConvert.SerializeObject(shaft.ImpellerComponents); } else { t_shaft.ImpellerComponentsJson = null; } if (shaft.AllotItems != null) { t_shaft.AllotItemsJson = JsonConvert.SerializeObject(shaft.AllotItems); } else { t_shaft.AllotItemsJson = null; } if (shaft.NegationDivFreStrategies != null) { t_shaft.NegationDivFreStrategiesJson = JsonConvert.SerializeObject(shaft.NegationDivFreStrategies); } else { t_shaft.NegationDivFreStrategiesJson = null; } if (shaft.NaturalFres != null) { t_shaft.NaturalFresJson = JsonConvert.SerializeObject(shaft.NaturalFres); } else { t_shaft.NaturalFresJson = null; } if (shaft.NaturalFres != null) { t_shaft.DivFreThresholdProportionesJson = JsonConvert.SerializeObject(shaft.DivFreThresholdProportiones); } else { t_shaft.DivFreThresholdProportionesJson = null; } t_shaft.FilterType = (int)(shaft.FilterType); t_shaft.BindRPMForFilter = shaft.BindRPMForFilter; if (shaft.DgBandPassFilter != null) { t_shaft.DgBandPassFilterJson = JsonConvert.SerializeObject(shaft.DgBandPassFilter); } else { t_shaft.DgBandPassFilterJson = null; } if (shaft.DgHighPassFilter != null) { t_shaft.DgHighPassFilterJson = JsonConvert.SerializeObject(shaft.DgHighPassFilter); } else { t_shaft.DgHighPassFilterJson = null; } if (shaft.DgLowPassFilter != null) { t_shaft.DgLowPassFilterJson = JsonConvert.SerializeObject(shaft.DgLowPassFilter); } else { t_shaft.DgLowPassFilterJson = null; } return(t_shaft); }
public static ShaftClass ConvertFromDB(T_Shaft t_shaft) { ShaftClass shaft = new ShaftClass(); shaft.id = t_shaft.id; shaft.Name = t_shaft.Name; shaft.Guid = t_shaft.Guid ?? new Guid(); shaft.IsSlidingBearing = t_shaft.IsSlidingBearing ?? false; shaft.DeltaRPM = t_shaft.DeltaRPM ?? 0; shaft.DefaultRPM = t_shaft.DefaultRPM ?? 0; shaft.RPMCoeff = t_shaft.RPMCoeff ?? 0; if (!string.IsNullOrWhiteSpace(t_shaft.BearingComponentsJson)) { var components = JsonConvert.DeserializeObject <List <BearingComponent> >(t_shaft.BearingComponentsJson); if (components != null) { shaft.BearingComponents.AddRange(components); } } if (!string.IsNullOrWhiteSpace(t_shaft.BeltComponentsJson)) { var components = JsonConvert.DeserializeObject <List <BeltComponent> >(t_shaft.BeltComponentsJson); if (components != null) { shaft.BeltComponents.AddRange(components); } } if (!string.IsNullOrWhiteSpace(t_shaft.GearComponentsJson)) { var components = JsonConvert.DeserializeObject <List <GearComponent> >(t_shaft.GearComponentsJson); if (components != null) { shaft.GearComponents.AddRange(components); } } if (!string.IsNullOrWhiteSpace(t_shaft.MotorComponentsJson)) { var components = JsonConvert.DeserializeObject <List <MotorComponent> >(t_shaft.MotorComponentsJson); if (components != null) { shaft.MotorComponents.AddRange(components); } } if (!string.IsNullOrWhiteSpace(t_shaft.ImpellerComponentsJson)) { var components = JsonConvert.DeserializeObject <List <ImpellerComponent> >(t_shaft.ImpellerComponentsJson); if (components != null) { shaft.ImpellerComponents.AddRange(components); } } if (!string.IsNullOrWhiteSpace(t_shaft.AllotItemsJson)) { shaft.AllotItems = JsonConvert.DeserializeObject <ObservableCollection <ItemInfo> >(t_shaft.AllotItemsJson); } if (!string.IsNullOrWhiteSpace(t_shaft.NegationDivFreStrategiesJson)) { shaft.NegationDivFreStrategies = JsonConvert.DeserializeObject <ObservableCollection <NegationDivFreStrategy> >(t_shaft.NegationDivFreStrategiesJson); } if (!string.IsNullOrWhiteSpace(t_shaft.NaturalFresJson)) { shaft.NaturalFres = JsonConvert.DeserializeObject <ObservableCollection <NaturalFre> >(t_shaft.NaturalFresJson); } if (!string.IsNullOrWhiteSpace(t_shaft.NaturalFresJson)) { shaft.DivFreThresholdProportiones = JsonConvert.DeserializeObject <ObservableCollection <DivFreThresholdProportion> >(t_shaft.DivFreThresholdProportionesJson); } shaft.FilterType = (FilterType)(t_shaft.FilterType ?? 0); shaft.BindRPMForFilter = t_shaft.BindRPMForFilter ?? false; if (!string.IsNullOrWhiteSpace(t_shaft.DgBandPassFilterJson)) { shaft.DgBandPassFilter = JsonConvert.DeserializeObject <DgBandPassFilter>(t_shaft.DgBandPassFilterJson); } if (!string.IsNullOrWhiteSpace(t_shaft.DgHighPassFilterJson)) { shaft.DgHighPassFilter = JsonConvert.DeserializeObject <DgHighPassFilter>(t_shaft.DgHighPassFilterJson); } if (!string.IsNullOrWhiteSpace(t_shaft.DgLowPassFilterJson)) { shaft.DgLowPassFilter = JsonConvert.DeserializeObject <DgLowPassFilter>(t_shaft.DgLowPassFilterJson); } //修复一些不进行json的字段 shaft.InitMachComponents(); return(shaft); }