void SetTargetValueEdit(TargetValueEdit targetValueEdit, TargetValue targetValue) { double multiplier = 1; if (targetValueEdit.Units == "%") { multiplier = 100.0; } targetValueEdit.Value = (targetValue.value * multiplier).ToString(); if (targetValue.absoluteVariance != 0) { targetValueEdit.Variance = targetValue.absoluteVariance.ToString(); } else { targetValueEdit.Variance = (100 * targetValue.relativeVariance).ToString() + "%"; } targetValueEdit.Binding = targetValue.targetBinding.ToString(); targetValueEdit.Drift = targetValue.drift.ToString(); targetValueEdit.Min = targetValue.min.ToString(); targetValueEdit.Max = targetValue.max.ToString(); }
TargetValue ToTargetValue(TargetValueEdit tve) { double relativeVariance = 0; double absoluteVariance = 0; string varianceStr = tve.Variance.Trim(); if (varianceStr.EndsWith("%")) // "0%" <- relative { relativeVariance = varianceStr.Substring(0, varianceStr.Length - 1).ToDouble() / 100.0; } else // "1" <- absolute { absoluteVariance = varianceStr.ToDouble(); } double divisor = 1; if (tve.Units == "%") { divisor = 100.0; } return(new TargetValue(tve.Value.ToDouble() / divisor, relativeVariance, absoluteVariance, tve.Min.ToDouble(), tve.Max.ToDouble(), tve.Drift.ToDouble(), tve.GetTargetBinding())); }