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