终端一体化运控平台
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.
 
 
 

186 rivejä
6.5 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. public static readonly object recipeLogslock = new object();
  22. private MessageNotify() { }
  23. public Action<string> UserLog { get; set; }
  24. public Action<string> RunLog { get; set; }
  25. public Action<string> AlarmLog { get; set; }
  26. public Action<string> RecipeCompleteLogs { get; set; }
  27. public ObservableCollection<RunLog> runLogs { get; set; } = new();
  28. public ObservableCollection<UserLog> userLogs { get; set; } = new();
  29. public ObservableCollection<Alarm> alarmLogs { get; set; } = new();
  30. public ObservableCollection<RecipeCompleteLog> recipeLogs { get; set; } = new();
  31. public void LogSave()
  32. {
  33. Sqlite<UserLog>.GetInstance.Save();
  34. Sqlite<RunLog>.GetInstance.Save();
  35. Sqlite<Alarm>.GetInstance.Save();
  36. Sqlite<RecipeCompleteLog>.GetInstance.Save();
  37. }
  38. public void ShowRecipeLog(string info)
  39. {
  40. lock (recipeLogslock)
  41. {
  42. try
  43. {
  44. RecipeCompleteLog runLog = new RecipeCompleteLog()
  45. {
  46. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  47. Time = DateTime.Now.ToString("HH:mm:ss"),
  48. RecipeName = info
  49. };
  50. Sqlite<RecipeCompleteLog>.GetInstance.Base.Add(runLog);
  51. Application.Current.Dispatcher.Invoke(new Action(() => { recipeLogs.Insert(0, runLog); }));
  52. RecipeCompleteLogs?.Invoke(info);
  53. }
  54. catch (Exception)
  55. {
  56. // throw;
  57. }
  58. }
  59. }
  60. public void ShowUserLog(string info)
  61. {
  62. lock (userlock)
  63. {
  64. if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString()) && !string.IsNullOrEmpty(info))
  65. {
  66. UserLog userLog = new UserLog()
  67. {
  68. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  69. Time = DateTime.Now.ToString("HH:mm:ss"),
  70. Permission = Global.userInfo.permission.ToString(),
  71. UserName = Global.userInfo.UserName,
  72. LogInfo = info
  73. };
  74. Sqlite<UserLog>.GetInstance.Base.Add(userLog);
  75. Application.Current.Dispatcher.Invoke(new Action(() => { userLogs.Insert(0, userLog); }));
  76. UserLog?.Invoke(info);
  77. }
  78. }
  79. }
  80. public void ShowRunLog(string info)
  81. {
  82. lock (runLock)
  83. {
  84. try
  85. {
  86. RunLog runLog = new RunLog()
  87. {
  88. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  89. Time = DateTime.Now.ToString("HH:mm:ss"),
  90. RunLogInfo = info
  91. };
  92. Sqlite<RunLog>.GetInstance.Base.Add(runLog);
  93. Application.Current.Dispatcher.Invoke(new Action(() => { runLogs.Insert(0, runLog); }));
  94. RunLog?.Invoke(info);
  95. }
  96. catch (Exception)
  97. {
  98. // throw;
  99. }
  100. }
  101. }
  102. int AlarmID;
  103. public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
  104. {
  105. lock (alarmlock)
  106. {
  107. AlarmID++;
  108. Alarm alarmLog = new Alarm()
  109. {
  110. NumId = AlarmID,
  111. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  112. Time = DateTime.Now.ToString("HH:mm:ss"),
  113. Info = info,
  114. Value = AlarmNumber,
  115. Grade = (level) + ""
  116. };
  117. Sqlite<Alarm>.GetInstance.Base.Add(alarmLog);
  118. Application.Current.Dispatcher.Invoke(new Action(() => { alarmLogs.Insert(0, alarmLog); }));
  119. AlarmLog?.Invoke(info);
  120. }
  121. }
  122. public bool ShowDialog(string info, DialogType dialogType = DialogType.Information)
  123. {
  124. bool result = false;
  125. Application.Current.Dispatcher.Invoke(() =>
  126. {
  127. PromptView PV = new PromptView();
  128. PV.TextBlockInfo = info;
  129. switch (dialogType)
  130. {
  131. case DialogType.Warning:
  132. PV.TextBlockIcon = "&#xe61f;";
  133. PV.TextBlockForeground = Brushes.Yellow;
  134. PV.infoType.Text = "警告:";
  135. //PV.Cancel.Visibility = Visibility.Collapsed;
  136. break;
  137. case DialogType.Error:
  138. PV.TextBlockIcon = "&#xed1a;";
  139. PV.TextBlockForeground = Brushes.Red;
  140. PV.infoType.Text = "错误:";
  141. //PV.Cancel.Visibility = Visibility.Collapsed;
  142. break;
  143. case DialogType.Information:
  144. PV.TextBlockIcon = "&#xe657;";
  145. PV.TextBlockForeground = Brushes.DeepSkyBlue;
  146. PV.infoType.Text = "提示:";
  147. //PV.Cancel.Visibility = Visibility.Visible;
  148. break;
  149. default:
  150. break;
  151. }
  152. PV.infoType.Foreground = PV.TextBlockForeground;
  153. var res = PV.ShowDialog();
  154. result = res == null ? false : (bool)res;
  155. });
  156. return result;
  157. }
  158. }
  159. public enum DialogType
  160. {
  161. Warning,
  162. Error,
  163. Information,
  164. }
  165. }