|
- using BPA.Helper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Collections.ObjectModel;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using BPASmartClient.Model;
- using System.Windows.Media;
- using BPASmartClient.CustomResource.Pages.View;
- using BPASmartClient.CustomResource.UserControls;
-
- namespace BPASmartClient.CustomResource.Pages.Model
- {
- public class MessageNotify
- {
- private volatile static MessageNotify _Instance;
- public static MessageNotify GetInstance => _Instance ??= new MessageNotify();
-
- public static readonly object runLock = new object();
- public static readonly object userlock = new object();
- public static readonly object alarmlock = new object();
- public static readonly object recipeLogslock = new object();
- private MessageNotify() { }
-
- public Action<string> UserLog { get; set; }
-
- public Action<string> RunLog { get; set; }
-
- public Action<string> AlarmLog { get; set; }
-
- public Action<string> RecipeCompleteLogs { get; set; }
-
- public ObservableCollection<RunLog> runLogs { get; set; } = new();
-
- public ObservableCollection<UserLog> userLogs { get; set; } = new();
-
- public ObservableCollection<BPASmartClient.Model.Alarm> alarmLogs { get; set; } = new();
-
- public ObservableCollection<RecipeCompleteLog> recipeLogs { get; set; } = new();
-
- public void LogSave()
- {
- try
- {
- Sqlite<UserLog>.GetInstance.Save();
- Sqlite<RunLog>.GetInstance.Save();
- //Sqlite<BPASmartClient.Model.Alarm>.GetInstance.Save();
- Sqlite<RecipeCompleteLog>.GetInstance.Save();
- }
- catch (Exception)
- {
-
- // throw;
- }
- }
-
- public void ShowRecipeLog(string info)
- {
- lock (recipeLogslock)
- {
- try
- {
- RecipeCompleteLog runLog = new RecipeCompleteLog()
- {
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- RecipeName = info
- };
- Sqlite<RecipeCompleteLog>.GetInstance.Base.Add(runLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { recipeLogs.Insert(0, runLog); }));
- RecipeCompleteLogs?.Invoke(info);
- }
- catch (Exception)
- {
-
- // throw;
- }
- }
- }
-
- public void ShowUserLog(string info)
- {
- lock (userlock)
- {
- if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString()) && !string.IsNullOrEmpty(info))
- {
- UserLog userLog = new UserLog()
- {
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- Permission = Global.userInfo.permission.ToString(),
- UserName = Global.userInfo.UserName,
- LogInfo = info
- };
- Sqlite<UserLog>.GetInstance.Base.Add(userLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { userLogs.Insert(0, userLog); }));
- UserLog?.Invoke(info);
- }
- }
- }
-
- public void ShowRunLog(string info)
- {
- lock (runLock)
- {
- try
- {
- RunLog runLog = new RunLog()
- {
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- RunLogInfo = info
- };
- Sqlite<RunLog>.GetInstance.Base.Add(runLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { runLogs.Insert(0, runLog); }));
- RunLog?.Invoke(info);
- }
- catch (Exception)
- {
-
- // throw;
- }
- }
- }
-
- int AlarmID;
- public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
- {
- lock (alarmlock)
- {
-
- LogHelper.GetInstance.AddAlarm(info, AlarmNumber);
-
- //AlarmID++;
- // BPASmartClient.Model.Alarm alarmLog = new BPASmartClient.Model.Alarm()
- // {
- // NumId = AlarmID,
- // Date = DateTime.Now.ToString("yyyy-MM-dd"),
- // Time = DateTime.Now.ToString("HH:mm:ss"),
- // Info = info,
- // Value = AlarmNumber,
- // Grade = (level) + ""
- // };
- // Sqlite<BPASmartClient.Model.Alarm>.GetInstance.Base.Add(alarmLog);
- // Application.Current.Dispatcher.Invoke(new Action(() => { alarmLogs.Insert(0, alarmLog); }));
- // AlarmLog?.Invoke(info);
- }
- }
-
- public bool ShowDialog(string info, DialogType dialogType = DialogType.Information)
- {
- bool result = false;
- Application.Current.Dispatcher.Invoke(() =>
- {
- PromptView PV = new PromptView();
- PV.TextBlockInfo = info;
- switch (dialogType)
- {
- case DialogType.Warning:
- PV.TextBlockIcon = "";
- PV.TextBlockForeground = Brushes.Yellow;
- PV.infoType.Text = "警告:";
- //PV.Cancel.Visibility = Visibility.Collapsed;
- break;
- case DialogType.Error:
- PV.TextBlockIcon = "";
- PV.TextBlockForeground = Brushes.Red;
- PV.infoType.Text = "错误:";
- //PV.Cancel.Visibility = Visibility.Collapsed;
- break;
- case DialogType.Information:
- PV.TextBlockIcon = "";
- PV.TextBlockForeground = Brushes.DeepSkyBlue;
- PV.infoType.Text = "提示:";
- //PV.Cancel.Visibility = Visibility.Visible;
- break;
- default:
- break;
- }
- PV.infoType.Foreground = PV.TextBlockForeground;
-
- //要设置弹框和主窗体跟随,需要设置弹框的打开位置为默认
- PV.Width = MainView.CurrentWidth;
- PV.Height = MainView.CurrentHeight;
- PV.Left = MainView.LeftLoc;
- PV.Top = MainView.TopLoc;
- var res = PV.ShowDialog();
- result = res == null ? false : (bool)res;
- });
- return result;
- }
-
-
- #region 弹框提示信息
-
- public Notifiaction NotifiactionShow { get; set; } = new Notifiaction();
-
- #region 右侧弹框
-
- /// <summary>
- /// 手动关闭
- /// </summary>
- public void OnExit(string e)
- {
- switch (e)
- {
- case "Error":
- NotifiactionShow.Clear(EnumPromptType.Error);
- return;
- case "Success":
- NotifiactionShow.Clear(EnumPromptType.Success);
- return;
- case "Warm":
- NotifiactionShow.Clear(EnumPromptType.Warn);
- return;
- case "Info":
- NotifiactionShow.Clear(EnumPromptType.Info);
- return;
- default:
- break;
- }
- //NoticeManager.ExitNotifiaction();
-
- }
-
- /// <summary>
- /// 屏幕右下角信息提示弹窗
- /// </summary>
- /// <param name="content">弹窗消息内容</param>
- /// <param name="type">弹窗类型:Error、Success、Warm、Info,分别对应不同颜色</param>
- /// <param name="title">弹窗消息类型:属性判证、XX告警...</param>
- public void OpenMsg(string content, EnumPromptType type = EnumPromptType.Info, string title = "提示")
- {
- //if (window == null) return;
- string text = string.Empty;
- if (content != null)
- {
- if (content.Length < 40)
- {
- int count = 40 - content.Length;
- for (int i = 0; i < count * 2; i++)
- {
- content += " ";
- }
-
- }
- text = content;
- }
- Application.Current.Dispatcher.Invoke(() =>
- {
- NotifiactionShow.AddNotifiaction(new NotifiactionModel()
- {
- Title = title,//"这是Error通知标题",
- Content = text,//"这条通知不会自动关闭,需要点击关闭按钮",
- ContentToolTip = content,
- NotifiactionType = type,
- window = Application.Current.MainWindow
- });
- });
- }
-
- #endregion
- public void OpenMsg(EnumPromptType type, string title, string content, byte viewcount, int viewtime)
- {
- //if (window == null) return;
- string text = string.Empty;
- if (content != null)
- {
- if (content.Length < 40)
- {
- int count = 40 - content.Length;
- for (int i = 0; i < count * 2; i++)
- {
- content += " ";
- }
- }
- text = content;
- }
- Application.Current.Dispatcher.Invoke(() =>
- {
- NotifiactionShow.MAX_NOTIFICATIONS = viewcount;
- NotifiactionShow.AddNotifiaction(new NotifiactionModel()
- {
- Title = title,//"这是Error通知标题",
- Content = text,//"这条通知不会自动关闭,需要点击关闭按钮",
- ContentToolTip = content,
- NotifiactionType = type,
- time = viewtime,
- window = Application.Current.MainWindow
- });
- });
- }
-
- #endregion
-
-
-
-
- }
-
- public enum DialogType
- {
- Warning,
- Error,
- Information,
- }
- }
|