EnumParameterBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. namespace WingCloudServer.GeneralDocTools.Model.Parameters
  5. {
  6. /// <summary>
  7. /// Enum parameter base type
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. [DataContract]
  11. public abstract class EnumParameterBase<T> : IParameter
  12. {
  13. private T _initialValue;
  14. private T _value;
  15. /// <summary>
  16. /// parameter value
  17. /// </summary>
  18. [DataMember]
  19. public IList<T> Source { get; set; }
  20. public T SavedValue { get; protected set; }
  21. public T InitialValue => _initialValue;
  22. /// <summary>
  23. /// parameter value
  24. /// </summary>
  25. [DataMember]
  26. public T Value
  27. {
  28. get => _value;
  29. set
  30. {
  31. if (!Equals(_value, value))
  32. {
  33. _value = value;
  34. OnValueChanged();
  35. }
  36. }
  37. }
  38. /// <summary>
  39. /// parameter name
  40. /// </summary>
  41. public string Name { get; set; }
  42. /// <summary>
  43. /// parameter section
  44. /// </summary>
  45. public string Section { get; set; }
  46. /// <summary>
  47. /// parameter value changed state
  48. /// </summary>
  49. public bool IsChanged => !Equals(_initialValue, Value);
  50. /// <summary>
  51. /// value changed event
  52. /// </summary>
  53. public event EventHandler ValueChanged;
  54. /// <summary>
  55. /// notify value changed
  56. /// </summary>
  57. private void OnValueChanged()
  58. {
  59. ValueChanged?.Invoke(this, EventArgs.Empty);
  60. }
  61. /// <summary>
  62. /// change initial value
  63. /// </summary>
  64. public void ChangeInitialValue()
  65. {
  66. _initialValue = Value;
  67. SavedValue = Value;
  68. }
  69. public void ChangeSavedValue()
  70. {
  71. SavedValue = Value;
  72. }
  73. /// <summary>
  74. /// Set user value;
  75. /// </summary>
  76. /// <param name="value">User setting value.</param>
  77. public abstract void ChangeParameterValue(object value);
  78. }
  79. /// <summary>
  80. /// string enum parameter
  81. /// </summary>
  82. [DataContract]
  83. public class EnumStringParameter : EnumParameterBase<string>
  84. {
  85. public override void ChangeParameterValue(object value)
  86. {
  87. var stringParameter = value as StringParameter;
  88. if (stringParameter != null)
  89. {
  90. Value = stringParameter.Value;
  91. SavedValue = Value;
  92. }
  93. }
  94. public void ChangeSource(IEnumerable<string> newSource, string defaultValue)
  95. {
  96. Source = new List<string>(newSource);
  97. Value = defaultValue;
  98. }
  99. }
  100. /// <summary>
  101. /// Default exam record search time range
  102. /// </summary>
  103. public enum SearchInterval
  104. {
  105. OneDay,
  106. OneWeek,
  107. OneMonth, OneYear,
  108. ThreeYears
  109. }
  110. }