MesDataChangedEvent.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. namespace LocalhostMES.Core
  3. {
  4. [Flags]
  5. public enum MesDataScope
  6. {
  7. None = 0,
  8. WorkOrder = 1 << 0,
  9. Sn = 1 << 1,
  10. KeyPart = 1 << 2,
  11. ParkingLot = 1 << 3,
  12. BindRecord = 1 << 4,
  13. ProcessRecord = 1 << 5
  14. }
  15. public sealed class MesDataChangedEventArgs : EventArgs
  16. {
  17. public MesDataChangedEventArgs(MesDataScope scope)
  18. {
  19. Scope = scope;
  20. }
  21. public MesDataScope Scope { get; }
  22. public bool Has(MesDataScope target) => (Scope & target) == target;
  23. }
  24. /// <summary>
  25. /// 统一的数据变更通知入口,供各业务写库后广播,界面按需订阅刷新。
  26. /// </summary>
  27. public static class MesDataChangedNotifier
  28. {
  29. public static event EventHandler<MesDataChangedEventArgs> Changed;
  30. public static void Raise(MesDataScope scope)
  31. {
  32. if (scope == MesDataScope.None)
  33. {
  34. return;
  35. }
  36. Changed?.Invoke(null, new MesDataChangedEventArgs(scope));
  37. }
  38. }
  39. }