首次上传
This commit is contained in:
+156
@@ -0,0 +1,156 @@
|
||||
<UserControl x:Class="MECF.Framework.UI.Client.CenterViews.DataLogs.Statistics.StatisticsView"
|
||||
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:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:micro="clr-namespace:Caliburn.Micro"
|
||||
xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
|
||||
mc:Ignorable="d" >
|
||||
<Grid HorizontalAlignment="Left">
|
||||
<TabControl>
|
||||
|
||||
<TabItem Header="Statistic Item List ">
|
||||
|
||||
<DataGrid Grid.Row="1" AlternationCount="2" HorizontalAlignment="Left" CanUserAddRows="False" AutoGenerateColumns="False" RowHeaderWidth="0"
|
||||
VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling"
|
||||
ItemsSource="{Binding StatData}" Margin="0,5,0,0" IsEnabled="{ Binding IsPermission}">
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="Name" Width="300">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" >
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Header="Last Reset Time" Width="200">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding LastResetTime}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Header="Value" Width="100">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Value}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="150">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="Reset Value" Width="120" Height="25" FontSize="14">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Click">
|
||||
<micro:ActionMessage MethodName="ResetValue">
|
||||
<micro:Parameter Value="{Binding }" />
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Header="Enable Alarm" Width="150">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Height="35" Width="35" VerticalContentAlignment="Center" IsChecked="{Binding AlarmEnable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Checked">
|
||||
<micro:ActionMessage MethodName="ResetEnableAlarm">
|
||||
<micro:Parameter Value="{Binding }" />
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="Unchecked">
|
||||
<micro:ActionMessage MethodName="ResetEnableAlarm">
|
||||
<micro:Parameter Value="{Binding }" />
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</CheckBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
|
||||
<DataGridTemplateColumn Header="Alarm Value" Width="120">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding AlarmValue}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Header="Alarm Value Set" Width="120">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<controls:TextBoxEx Text="{Binding Path=AlarmValueSetPoint, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextSaved="{Binding AlarmTextSaved, Mode=TwoWay}" Width="110" Height="25"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="100">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="Set" Width="60" Height="25" FontSize="14">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Click">
|
||||
<micro:ActionMessage MethodName="SetAlarmValue">
|
||||
<micro:Parameter Value="{Binding }" />
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
|
||||
<DataGridTemplateColumn Header="Last Reset Total" Width="200">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding LastResetTotalTime}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Header="Total" Width="100">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Total}" Margin="5,0" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" HorizontalAlignment="Left" VerticalAlignment="Center" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="150" >
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="Reset Total" Width="120" Height="25" FontSize="14">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Click">
|
||||
<micro:ActionMessage MethodName="ResetTotalValue">
|
||||
<micro:Parameter Value="{Binding }" />
|
||||
</micro:ActionMessage>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.DataLogs.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for IOView.xaml
|
||||
/// </summary>
|
||||
public partial class StatisticsView : UserControl
|
||||
{
|
||||
public StatisticsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.CommonData;
|
||||
using MECF.Framework.Common.DataCenter;
|
||||
using MECF.Framework.Common.OperationCenter;
|
||||
using MECF.Framework.UI.Client.ClientBase;
|
||||
using OpenSEMI.ClientBase;
|
||||
using SciChart.Core.Extensions;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.DataLogs.Statistics
|
||||
{
|
||||
public class StatsDataListItem : NotifiableItem
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Total { get; set; }
|
||||
public string LastUpdateTime { get; set; }
|
||||
public string LastResetTime { get; set; }
|
||||
public string LastResetTotalTime { get; set; }
|
||||
public string AlarmValue { get; set; }
|
||||
public string AlarmValueSetPoint { get; set; }
|
||||
public bool AlarmEnable { get; set; }
|
||||
|
||||
public bool AlarmTextSaved { get; set; }
|
||||
public bool IsVisible { get; set; }
|
||||
}
|
||||
|
||||
public class StatisticsViewModel : UiViewModelBase
|
||||
{
|
||||
|
||||
public ObservableCollection<StatsDataListItem> StatData { get; set; }
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
StatData = new ObservableCollection<StatsDataListItem>();
|
||||
|
||||
base.OnInitialize();
|
||||
}
|
||||
protected override void OnActivate()
|
||||
{
|
||||
base.OnActivate();
|
||||
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(bool close)
|
||||
{
|
||||
base.OnDeactivate(close);
|
||||
}
|
||||
|
||||
protected override void Poll()
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM \"stats_data\" order by \"name\" ASC;";
|
||||
|
||||
DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
|
||||
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (dbData == null || dbData.Rows.Count == 0)
|
||||
return;
|
||||
|
||||
string[] clearedNameList = Array.ConvertAll<StatsDataListItem, string>(StatData.ToArray(), x => x.Name);
|
||||
|
||||
List<string> removableList = new List<string>();
|
||||
if (clearedNameList.Length > 0)
|
||||
removableList = clearedNameList.ToList();
|
||||
for (int i = 0; i < dbData.Rows.Count; i++)
|
||||
{
|
||||
if (!dbData.Rows[i]["is_visible"].Equals(DBNull.Value) && !Convert.ToBoolean(dbData.Rows[i]["is_visible"].ToString()))
|
||||
continue;
|
||||
|
||||
string name = dbData.Rows[i]["name"].ToString();
|
||||
removableList.RemoveIfContains(name);
|
||||
|
||||
StatsDataListItem item = StatData.FirstOrDefault(x => x.Name == name);
|
||||
if (item == null)
|
||||
{
|
||||
item = new StatsDataListItem();
|
||||
item.Name = dbData.Rows[i]["name"].ToString();
|
||||
item.AlarmEnable = false;
|
||||
item.IsVisible = true;
|
||||
item.AlarmTextSaved = true;
|
||||
item.AlarmValueSetPoint = dbData.Rows[i]["alarm_value"].ToString();
|
||||
StatData.Add(item);
|
||||
}
|
||||
|
||||
item.Description = dbData.Rows[i]["description"].ToString();
|
||||
item.Value = dbData.Rows[i]["value"].ToString();
|
||||
item.Total = dbData.Rows[i]["total"].ToString();
|
||||
|
||||
if (!dbData.Rows[i]["enable_alarm"].Equals(DBNull.Value))
|
||||
item.AlarmEnable = Convert.ToBoolean(dbData.Rows[i]["enable_alarm"].ToString());
|
||||
|
||||
item.AlarmValue = dbData.Rows[i]["alarm_value"].ToString();
|
||||
|
||||
if (!dbData.Rows[i]["last_update_time"].Equals(DBNull.Value))
|
||||
item.LastUpdateTime = ((DateTime)dbData.Rows[i]["last_update_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
|
||||
|
||||
if (!dbData.Rows[i]["last_reset_time"].Equals(DBNull.Value))
|
||||
item.LastResetTime = ((DateTime)dbData.Rows[i]["last_reset_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
|
||||
|
||||
if (!dbData.Rows[i]["last_total_reset_time"].Equals(DBNull.Value))
|
||||
item.LastResetTotalTime = ((DateTime)dbData.Rows[i]["last_total_reset_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
|
||||
|
||||
item.InvokePropertyChanged(nameof(item.AlarmValue));
|
||||
item.InvokePropertyChanged(nameof(item.Value));
|
||||
item.InvokePropertyChanged(nameof(item.Total));
|
||||
item.InvokePropertyChanged(nameof(item.LastUpdateTime));
|
||||
item.InvokePropertyChanged(nameof(item.LastResetTime));
|
||||
item.InvokePropertyChanged(nameof(item.LastResetTotalTime));
|
||||
}
|
||||
|
||||
foreach (var name in removableList)
|
||||
{
|
||||
StatsDataListItem item = StatData.FirstOrDefault(x => x.Name == name);
|
||||
if (item != null)
|
||||
StatData.Remove(item);
|
||||
}
|
||||
|
||||
|
||||
}));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.Write(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetValue(StatsDataListItem item)
|
||||
{
|
||||
InvokeClient.Instance.Service.DoOperation("System.Stats.ResetValue", item.Name);
|
||||
}
|
||||
|
||||
public void ResetEnableAlarm(StatsDataListItem item)
|
||||
{
|
||||
InvokeClient.Instance.Service.DoOperation("System.Stats.EnableAlarm", item.Name, item.AlarmEnable);
|
||||
}
|
||||
|
||||
public void SetAlarmValue(StatsDataListItem item)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.AlarmValueSetPoint) ||
|
||||
!int.TryParse(item.AlarmValueSetPoint, out int setValue))
|
||||
{
|
||||
DialogBox.ShowWarning("Alarm value not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
InvokeClient.Instance.Service.DoOperation("System.Stats.SetAlarmValue", item.Name, setValue);
|
||||
|
||||
item.AlarmTextSaved = true;
|
||||
item.InvokePropertyChanged(nameof(item.AlarmTextSaved));
|
||||
}
|
||||
|
||||
public void ResetTotalValue(StatsDataListItem item)
|
||||
{
|
||||
InvokeClient.Instance.Service.DoOperation("System.Stats.ResetTotalValue", item.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user