using System; using System.Collections.Generic; namespace MuchInfo.Chart.Data.Models { /// /// 公式内容设置 /// public class ProgramModel { //用户设置周期参数 private Dictionary _customParams = new Dictionary(); /// /// 用户设置周期参数 /// public Dictionary CustomParams { get { return _customParams; } } private Dictionary _defaultParams = new Dictionary(); /// /// 默认周期参数 /// public Dictionary DefaultParams { get { return _defaultParams; } } /// /// 是否为主图指标 /// public bool IsMainView { get; set; } /// /// 公式名称 /// public string Name { get; set; } /// /// 转换成可计算的公式 /// /// public FormulaModel CovertToFormulaModel() { var formulaModel = new FormulaModel(); //formulaModel.FormulaName = this.Name; string paramsStr = "("; foreach (var paramsName in DefaultParams.Keys) { if (!DefaultParams.ContainsKey(paramsName)) throw new Exception("公式默认参数获取异常!"); if (string.IsNullOrEmpty(CustomParams[paramsName].Value)) { CustomParams[paramsName].Value = DefaultParams[paramsName]; } paramsStr += CustomParams[paramsName].Value + ","; } paramsStr = paramsStr.TrimEnd(',') + ")"; formulaModel.FormulaName = this.Name + (paramsStr.Equals("()") ? string.Empty : paramsStr); formulaModel.IsMainIndicator = this.IsMainView; formulaModel.EditProgram = this; return formulaModel; } } /// /// 处理无法编辑字典值问题 /// public class CustomParamModel { private string _value; /// /// 用户设置默认值 /// public string Value { get { return _value; } set { _value = value; } } } }