终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

150 lines
5.3 KiB

  1. using BPASmartClient.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Collections.ObjectModel;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using BPASmartClient.Model;
  10. using System.Windows.Media;
  11. using BPASmartClient.CustomResource.Pages.View;
  12. namespace BPASmartClient.CustomResource.Pages.Model
  13. {
  14. public class MessageNotify
  15. {
  16. private volatile static MessageNotify _Instance;
  17. public static MessageNotify GetInstance => _Instance ??= new MessageNotify();
  18. public static readonly object runLock = new object();
  19. public static readonly object userlock = new object();
  20. public static readonly object alarmlock = new object();
  21. private MessageNotify() { }
  22. public Action<string> UserLog { get; set; }
  23. public Action<string> RunLog { get; set; }
  24. public Action<string> AlarmLog { get; set; }
  25. public ObservableCollection<RunLog> runLogs { get; set; } = new ObservableCollection<RunLog>();
  26. public ObservableCollection<UserLog> userLogs { get; set; } = new ObservableCollection<UserLog>();
  27. public ObservableCollection<Alarm> alarmLogs { get; set; } = new ObservableCollection<Alarm>();
  28. public void LogSave()
  29. {
  30. Sqlite<UserLog>.GetInstance.Save();
  31. Sqlite<RunLog>.GetInstance.Save();
  32. Sqlite<Alarm>.GetInstance.Save();
  33. }
  34. public void ShowUserLog(string info)
  35. {
  36. lock (userlock)
  37. {
  38. if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString()) && !string.IsNullOrEmpty(info))
  39. {
  40. UserLog userLog = new UserLog()
  41. {
  42. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  43. Time = DateTime.Now.ToString("HH:mm:ss"),
  44. Permission = Global.userInfo.permission.ToString(),
  45. UserName = Global.userInfo.UserName,
  46. LogInfo = info
  47. };
  48. Sqlite<UserLog>.GetInstance.Base.Add(userLog);
  49. Application.Current.Dispatcher.Invoke(new Action(() => { userLogs.Insert(0, userLog); }));
  50. UserLog?.Invoke(info);
  51. }
  52. }
  53. }
  54. public void ShowRunLog(string info)
  55. {
  56. lock (runLock)
  57. {
  58. try
  59. {
  60. RunLog runLog = new RunLog()
  61. {
  62. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  63. Time = DateTime.Now.ToString("HH:mm:ss"),
  64. RunLogInfo = info
  65. };
  66. Sqlite<RunLog>.GetInstance.Base.Add(runLog);
  67. Application.Current.Dispatcher.Invoke(new Action(() => { runLogs.Insert(0, runLog); }));
  68. RunLog?.Invoke(info);
  69. }
  70. catch (Exception)
  71. {
  72. // throw;
  73. }
  74. }
  75. }
  76. int AlarmID;
  77. public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
  78. {
  79. lock (alarmlock)
  80. {
  81. AlarmID++;
  82. Alarm alarmLog = new Alarm()
  83. {
  84. NumId = AlarmID,
  85. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  86. Time = DateTime.Now.ToString("HH:mm:ss"),
  87. Info = info,
  88. Value = AlarmNumber,
  89. Grade = (level) + ""
  90. };
  91. Sqlite<Alarm>.GetInstance.Base.Add(alarmLog);
  92. Application.Current.Dispatcher.Invoke(new Action(() => { alarmLogs.Insert(0, alarmLog); }));
  93. AlarmLog?.Invoke(info);
  94. }
  95. }
  96. public bool ShowDialog(string info, DialogType dialogType = DialogType.Information)
  97. {
  98. PromptView PV = new PromptView();
  99. PV.TextBlockInfo = info;
  100. switch (dialogType)
  101. {
  102. case DialogType.Warning:
  103. PV.TextBlockIcon = "&#xe61f;";
  104. PV.TextBlockForeground = Brushes.Yellow;
  105. PV.infoType.Text = "警告:";
  106. //PV.Cancel.Visibility = Visibility.Collapsed;
  107. break;
  108. case DialogType.Error:
  109. PV.TextBlockIcon = "&#xed1a;";
  110. PV.TextBlockForeground = Brushes.Red;
  111. PV.infoType.Text = "错误:";
  112. //PV.Cancel.Visibility = Visibility.Collapsed;
  113. break;
  114. case DialogType.Information:
  115. PV.TextBlockIcon = "&#xe657;";
  116. PV.TextBlockForeground = Brushes.DeepSkyBlue;
  117. PV.infoType.Text = "提示:";
  118. //PV.Cancel.Visibility = Visibility.Visible;
  119. break;
  120. default:
  121. break;
  122. }
  123. PV.infoType.Foreground = PV.TextBlockForeground;
  124. var res = PV.ShowDialog();
  125. return res == null ? false : (bool)res;
  126. }
  127. }
  128. public enum DialogType
  129. {
  130. Warning,
  131. Error,
  132. Information,
  133. }
  134. }