using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace WingCloudServer.GeneralDocTools.Model.Parameters { /// /// Enum parameter base type /// /// [DataContract] public abstract class EnumParameterBase : IParameter { private T _initialValue; private T _value; /// /// parameter value /// [DataMember] public IList Source { get; set; } public T SavedValue { get; protected set; } public T InitialValue => _initialValue; /// /// parameter value /// [DataMember] public T Value { get => _value; set { if (!Equals(_value, value)) { _value = value; OnValueChanged(); } } } /// /// parameter name /// public string Name { get; set; } /// /// parameter section /// public string Section { get; set; } /// /// parameter value changed state /// public bool IsChanged => !Equals(_initialValue, Value); /// /// value changed event /// public event EventHandler ValueChanged; /// /// notify value changed /// private void OnValueChanged() { ValueChanged?.Invoke(this, EventArgs.Empty); } /// /// change initial value /// public void ChangeInitialValue() { _initialValue = Value; SavedValue = Value; } public void ChangeSavedValue() { SavedValue = Value; } /// /// Set user value; /// /// User setting value. public abstract void ChangeParameterValue(object value); } /// /// string enum parameter /// [DataContract] public class EnumStringParameter : EnumParameterBase { public override void ChangeParameterValue(object value) { var stringParameter = value as StringParameter; if (stringParameter != null) { Value = stringParameter.Value; SavedValue = Value; } } public void ChangeSource(IEnumerable newSource, string defaultValue) { Source = new List(newSource); Value = defaultValue; } } /// /// Default exam record search time range /// public enum SearchInterval { OneDay, OneWeek, OneMonth, OneYear, ThreeYears } }