using 货架标准上位机.ViewModel; using System; using System.Collections.Generic; using System.Linq; using System.Media; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using WCS.Model.WebSocketModel; using HandyControl.Controls; using WCS.Model; using 货架标准上位机.Api; using TouchSocket.Core; using Window = HandyControl.Controls.Window; namespace 货架标准上位机 { /// /// 提示框 /// public partial class WarningWindow : HandyControl.Controls.Window { public WebSocketMessageModel warning { get; set; } public WarningWindow(WebSocketMessageModel _warning) { InitializeComponent(); this.Topmost = true; // 设置窗口始终在最上方 this.WindowStyle = WindowStyle.None; // 可选,移除窗口的标准边框 warning = _warning; } private void closeClick(object sender, RoutedEventArgs e) { //this.Close(); WarningManager.RemoveWarning(warning.Guid); } /// /// 显示提示框 /// /// 内容 /// 界面右上角是否显示关闭按钮 /// 点击的按钮文本 public static WarningWindow Show(string content, WebSocketMessageModel _warning, bool isVisCloseBut = true, Window owner = null) { return Show(content, string.Empty, _warning, isVisCloseBut); } /// /// 显示提示框 /// /// 内容 /// 标题 /// 界面右上角是否显示关闭按钮 /// 点击的按钮文本 public static WarningWindow Show(string content, string title, WebSocketMessageModel _warning, bool isVisCloseBut = true, Window owner = null) { return Show(content, title, new string[] { "确认", "忽略" }, _warning, isVisCloseBut); } /// /// 显示提示框 /// /// 内容 /// 按钮内容 /// 界面右上角是否显示关闭按钮 /// 点击的按钮文本 public static WarningWindow Show(string content, IEnumerable buttons, WebSocketMessageModel _warning, bool isVisCloseBut = true, Window owner = null) { return Show(content, string.Empty, buttons, _warning, isVisCloseBut); } /// /// 显示提示框 /// /// 内容 /// 标题 /// 按钮内容 /// 界面右上角是否显示关闭按钮 /// 点击的按钮文本 public static WarningWindow Show(string content, string title, IEnumerable buttons, WebSocketMessageModel _warning, bool isVisCloseBut = true, Window owner = null) { WarningWindow WaningWindow; string clikename = string.Empty; WaningWindow = new WarningWindow(_warning); Application.Current.Dispatcher.Invoke(new Action(() => { WaningWindow = new WarningWindow(_warning); WaningWindow.DataContext = new { Title = title, Content = content, IsClose = isVisCloseBut }; WaningWindow.spacingPanel.Children.Clear(); foreach (var item in buttons) { Button button = new Button() { Content = item, }; button.Click += (s, e) => { clikename = ((Button)s).Content.ToString(); Logs.Write($"用户{LocalStatic.CurrentUser}在处理异常报警{_warning.Guid}时点击了" + clikename); #region 调用接口处理异常/消除报警 try { var body = new SolveWarningRequest() { Guid = _warning.Guid, SolveType = clikename == "确认" ? SolveTypeEnum.处理 : SolveTypeEnum.忽略, UserName = LocalStatic.CurrentUser, DeviceType = "WCS前端", }; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "warning/solveWarning", body, "POST"); if (Result != null && Result.Code == 200) { //消除异常或已不存在该异常 WaningWindow.Close(); } else if (Result != null && !string.IsNullOrEmpty(Result.Message)) { Growl.Warning(Result.Message); } else if (Result == null) { Growl.Warning("调用后台接口失败!"); } } catch (Exception ex) { Growl.Warning(ex.Message); } #endregion }; WaningWindow.spacingPanel.Children.Add(button); } WaningWindow.Owner = owner == null ? System.Windows.Application.Current.MainWindow : owner; WaningWindow.Show(); })); return WaningWindow; } private void previewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } } }