ProgramModel.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. namespace MuchInfo.Chart.Data.Models
  5. {
  6. /// <summary>
  7. /// 公式内容设置
  8. /// </summary>
  9. public class ProgramModel
  10. {
  11. //用户设置周期参数
  12. private Dictionary<string, CustomParamModel> _customParams = new Dictionary<string, CustomParamModel>();
  13. /// <summary>
  14. /// 用户设置周期参数
  15. /// </summary>
  16. public Dictionary<string, CustomParamModel> CustomParams
  17. {
  18. get { return _customParams; }
  19. }
  20. private Dictionary<string, string> _defaultParams = new Dictionary<string, string>();
  21. /// <summary>
  22. /// 默认周期参数
  23. /// </summary>
  24. public Dictionary<string, string> DefaultParams
  25. {
  26. get { return _defaultParams; }
  27. }
  28. /// <summary>
  29. /// 是否为主图指标
  30. /// </summary>
  31. public bool IsMainView { get; set; }
  32. /// <summary>
  33. /// 公式名称
  34. /// </summary>
  35. public string Name { get; set; }
  36. /// <summary>
  37. /// 转换成可计算的公式
  38. /// </summary>
  39. /// <returns></returns>
  40. public FormulaModel CovertToFormulaModel()
  41. {
  42. var formulaModel = new FormulaModel();
  43. //formulaModel.FormulaName = this.Name;
  44. string paramsStr = "(";
  45. foreach (var paramsName in DefaultParams.Keys)
  46. {
  47. if (!DefaultParams.ContainsKey(paramsName)) throw new Exception("公式默认参数获取异常!");
  48. if (string.IsNullOrEmpty(CustomParams[paramsName].Value))
  49. {
  50. CustomParams[paramsName].Value = DefaultParams[paramsName];
  51. }
  52. paramsStr += CustomParams[paramsName].Value + ",";
  53. }
  54. paramsStr = paramsStr.TrimEnd(',') + ")";
  55. formulaModel.FormulaName = this.Name + (paramsStr.Equals("()") ? string.Empty : paramsStr);
  56. formulaModel.IsMainIndicator = this.IsMainView;
  57. formulaModel.EditProgram = this;
  58. return formulaModel;
  59. }
  60. }
  61. /// <summary>
  62. /// 处理无法编辑字典值问题
  63. /// </summary>
  64. public class CustomParamModel
  65. {
  66. private string _value;
  67. /// <summary>
  68. /// 用户设置默认值
  69. /// </summary>
  70. public string Value
  71. {
  72. get { return _value; }
  73. set { _value = value; }
  74. }
  75. }
  76. }