Browse Source

增加日志筛选

样式分支
fyf 2 years ago
parent
commit
526f3fc7dd
6 changed files with 195 additions and 18 deletions
  1. +1
    -1
      BPASmartClient.ViewModel/LogOrAlarmViewModel.cs
  2. +139
    -7
      BPASmartClient.ViewModel/LogViewModel.cs
  3. +16
    -0
      BPASmartClient/Control/IOTView.xaml
  4. +29
    -0
      BPASmartClient/Control/IOTView.xaml.cs
  5. +9
    -3
      BPASmartClient/Control/LogView.xaml
  6. +1
    -7
      BPASmartClient/MainWindow.xaml

+ 1
- 1
BPASmartClient.ViewModel/LogOrAlarmViewModel.cs View File

@@ -132,7 +132,7 @@ namespace BPASmartClient.ViewModel
BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" }) { IsChecked = true }); BookExs.Add(new BookEx(new Book() { Name = "错误日志条件", Tag = "Error" }) { IsChecked = true });
BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" }) { IsChecked = true }); BookExs.Add(new BookEx(new Book() { Name = "设备告警条件", Tag = "DeviceAlarm" }) { IsChecked = true });
SelectBookExs = new ObservableCollection<BookEx>(); SelectBookExs = new ObservableCollection<BookEx>();
ItemPropertyChanged(new BookEx(new Book() { Name = "一般日志条件", Tag = "Info" }) { IsChecked = true },new PropertyChangedEventArgs("IsChecked"));
ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true },new PropertyChangedEventArgs("IsChecked"));
//查询 //查询
QueryCommand = new RelayCommand(() => QueryCommand = new RelayCommand(() =>
{ {


+ 139
- 7
BPASmartClient.ViewModel/LogViewModel.cs View File

@@ -1,12 +1,14 @@
using BPASmartClient.Helper; using BPASmartClient.Helper;
using BPASmartClient.IoT; using BPASmartClient.IoT;
using BPASmartClient.Message; using BPASmartClient.Message;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input; using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -26,6 +28,7 @@ namespace BPASmartClient.ViewModel
#region 变量 #region 变量
public DispatcherTimer dispatcherTimer; public DispatcherTimer dispatcherTimer;
public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
public ObservableCollection<LogModel> LogDataGridData { get; set; }
private ObservableCollection<LogModel> _LogModels;public ObservableCollection<LogModel> LogDataGrid private ObservableCollection<LogModel> _LogModels;public ObservableCollection<LogModel> LogDataGrid
{ {
get get
@@ -68,6 +71,54 @@ namespace BPASmartClient.ViewModel
OnPropertyChanged("TimedClear"); OnPropertyChanged("TimedClear");
} }
} }
private string _SelectedText = "";
public string SelectedText
{
get
{
return _SelectedText;
}
set
{
if (_SelectedText == value)
return;
_SelectedText = value;
OnPropertyChanged("SelectedText");
}
}
public ObservableCollection<BookEx> SelectBookExs { set; get; }
private ObservableCollection<BookEx> _books;
public ObservableCollection<BookEx> BookExs
{
get
{
if (_books == null)
{
_books = new ObservableCollection<BookEx>();

_books.CollectionChanged += (sender, e) =>
{
if (e.OldItems != null)
{
foreach (BookEx bookEx in e.OldItems)
{
bookEx.PropertyChanged -= ItemPropertyChanged;
}
}

if (e.NewItems != null)
{
foreach (BookEx bookEx in e.NewItems)
{
bookEx.PropertyChanged += ItemPropertyChanged;
}
}
};
}

return _books;
}
}
#endregion #endregion


#region 单一 #region 单一
@@ -85,14 +136,23 @@ namespace BPASmartClient.ViewModel
/// </summary> /// </summary>
public void Init() public void Init()
{ {
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>();
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory);
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>();
if (LogDataGridData == null) LogDataGridData = new ObservableCollection<LogModel>();
BookExs.Add(new BookEx(new Book() { Name = "一般日志", Tag = "Info" }) { IsChecked = true });
BookExs.Add(new BookEx(new Book() { Name = "设备日志", Tag = "DeviceLog" }) { IsChecked = true });
BookExs.Add(new BookEx(new Book() { Name = "错误日志", Tag = "Error" }) { IsChecked = true });
BookExs.Add(new BookEx(new Book() { Name = "设备告警", Tag = "DeviceAlarm" }) { IsChecked = true });
SelectBookExs = new ObservableCollection<BookEx>();
ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true }, new PropertyChangedEventArgs("IsChecked"));
//一般日志 //一般日志
MessageLog.GetInstance.InfoNotify = new Action<string>((s) => MessageLog.GetInstance.InfoNotify = new Action<string>((s) =>
{ {
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{ {
LogDataGrid.Insert(0, new LogModel { message = s, type = "Info" });
LogModel logModel = new LogModel { message = s, type = "Info" };
LogDataGridData.Insert(0, logModel);
AddLog(logModel);
logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s);
})); }));
}); });
@@ -101,7 +161,9 @@ namespace BPASmartClient.ViewModel
{ {
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{ {
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" });
LogModel logModel = new LogModel { message = s, type = "DeviceLog" };
LogDataGridData.Insert(0, logModel);
AddLog(logModel);
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s); logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s);
})); }));
}); });
@@ -110,7 +172,9 @@ namespace BPASmartClient.ViewModel
{ {
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{ {
LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" });
LogModel logModel = new LogModel { message = id, type = "DeviceAlarm" };
LogDataGridData.Insert(0, logModel);
AddLog(logModel);
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id);
})); }));
}); });
@@ -119,7 +183,9 @@ namespace BPASmartClient.ViewModel
{ {
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{ {
LogDataGrid.Insert(0, new LogModel { message = s, type = "Error" });
LogModel logModel = new LogModel { message = s, type = "Error" };
LogDataGridData.Insert(0, logModel);
AddLog(logModel);
logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s); logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s);
DataVClient.GetInstance().HttpAddLog(new LogTable DataVClient.GetInstance().HttpAddLog(new LogTable
{ {
@@ -154,9 +220,11 @@ namespace BPASmartClient.ViewModel
{ {
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{ {
if (LogDataGrid.Count > 100)
if (LogDataGridData.Count > 200)
{ {
LogDataGrid.RemoveAt(LogDataGrid.Count - 1);
LogModel logModel= LogDataGridData.Last();
DeleteLog(logModel);
LogDataGridData.Remove(logModel);
} }
})); }));


@@ -164,6 +232,43 @@ namespace BPASmartClient.ViewModel
dispatcherTimer.Interval = TimeSpan.FromSeconds(10); dispatcherTimer.Interval = TimeSpan.FromSeconds(10);
dispatcherTimer.Start(); dispatcherTimer.Start();
} }
/// <summary>
/// 增加日志
/// </summary>
public void AddLog(LogModel logModel)
{
BookEx book= SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == logModel.type);
if (book != null)
{
LogDataGrid.Insert(0, logModel);
}
}
/// <summary>
/// 刷新日志
/// </summary>
/// <param name="logModel"></param>
public void RefreshLog()
{
LogDataGrid.Clear();
LogDataGridData?.ToList().ForEach(b => {

BookEx book = SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == b.type);
if (book != null)
{
LogDataGrid.Add(b);
}
});
}
/// <summary>
/// 删除日志
/// </summary>
public void DeleteLog(LogModel logModel)
{
LogModel log= LogDataGrid?.ToList().Find(par => par == logModel);
if(log!=null) LogDataGrid.Remove(log);
}

/// <summary> /// <summary>
/// 导出数据 /// 导出数据
/// </summary> /// </summary>
@@ -210,6 +315,33 @@ namespace BPASmartClient.ViewModel
System.Windows.MessageBox.Show("无数据!"); System.Windows.MessageBox.Show("无数据!");


} }
/// <summary>
/// 选中改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsChecked")
{
BookEx bookEx = sender as BookEx;

if (bookEx != null)
{
IEnumerable<BookEx> bookExs = BookExs.Where(b => b.IsChecked == true);

StringBuilder builder = new StringBuilder();
SelectBookExs.Clear();
foreach (BookEx item in bookExs)
{
builder.Append(item.BookN.Name + ",");
SelectBookExs.Add((BookEx)item);
}
SelectedText = builder == null ? string.Empty : builder.ToString();
RefreshLog();
}
}
}
#endregion #endregion


#region Command #region Command


+ 16
- 0
BPASmartClient/Control/IOTView.xaml View File

@@ -0,0 +1,16 @@
<UserControl x:Class="BPASmartClient.Control.IOTView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.Control"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<wv2:WebView2
Name="webView"
Width="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualHeight}" />
</Grid>
</UserControl>

+ 29
- 0
BPASmartClient/Control/IOTView.xaml.cs View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;

namespace BPASmartClient.Control
{
/// <summary>
/// IOTView.xaml 的交互逻辑
/// </summary>
public partial class IOTView : UserControl
{
public IOTView()
{
InitializeComponent();
webView.Source = new Uri("http://iot.black-pa.com");
}
}
}

+ 9
- 3
BPASmartClient/Control/LogView.xaml View File

@@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:k="clr-namespace:BPASmartClient.Model;assembly=BPASmartClient.Model"
xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel" xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel"
xmlns:local="clr-namespace:BPASmartClient.Control" xmlns:local="clr-namespace:BPASmartClient.Control"
mc:Ignorable="d" mc:Ignorable="d"
@@ -25,8 +26,13 @@


<!--查询按钮栏--> <!--查询按钮栏-->
<StackPanel Orientation="Horizontal" Margin="10,0,10,0"> <StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<!--<CheckBox Margin="10,0,0,0" IsChecked="{Binding RealTimeModel, UpdateSourceTrigger=PropertyChanged}" >实时模式</CheckBox>
<CheckBox Margin="10,0,0,0" IsChecked="{Binding TimedClear, UpdateSourceTrigger=PropertyChanged}">定时清除</CheckBox>-->
<ComboBox Width="130" Text="{Binding SelectedText}" IsEditable="True" ItemsSource="{Binding Path=BookExs}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type k:BookEx}">
<CheckBox Width="120" IsChecked="{Binding IsChecked}" Content="{Binding BookN.Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding ExcelCommand}" Style="{DynamicResource CommonBtn_返回}" Width="75">导出日志</Button> <Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding ExcelCommand}" Style="{DynamicResource CommonBtn_返回}" Width="75">导出日志</Button>
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding OpenCommand}" Style="{DynamicResource CommonBtn_返回}" Width="75">打开文件</Button> <Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding OpenCommand}" Style="{DynamicResource CommonBtn_返回}" Width="75">打开文件</Button>
</StackPanel> </StackPanel>
@@ -54,7 +60,7 @@
<DataGridTemplateColumn Header="日志类型" Width="300"> <DataGridTemplateColumn Header="日志类型" Width="300">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock HorizontalAlignment="Center" Text="{Binding type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock HorizontalAlignment="Center" Text="{Binding type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14" Foreground="{Binding foreground, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>


+ 1
- 7
BPASmartClient/MainWindow.xaml View File

@@ -102,17 +102,11 @@
Header="设备监视" Header="设备监视"
Tag="DeviceMonitorView" /> Tag="DeviceMonitorView" />
<Separator /> <Separator />
<MenuItem
Click="MenuItem_Click"
FontSize="12"
Header="告警监视"
Tag="LogView" />
<Separator />
<MenuItem <MenuItem
Click="MenuItem_Click" Click="MenuItem_Click"
FontSize="12" FontSize="12"
Header="IOT监视" Header="IOT监视"
Tag="LogView" />
Tag="IOTView" />
<Separator /> <Separator />
</MenuItem> </MenuItem>
<MenuItem Header="综合查询"> <MenuItem Header="综合查询">


Loading…
Cancel
Save