添加项目文件。

This commit is contained in:
czj
2026-06-05 10:57:09 +08:00
parent f29671b374
commit d960cb5912
166 changed files with 15996 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using MonitorModule.Views;
using System.Reflection;
namespace MonitorModule
{
public class MonitorModule: IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
IRegionManager regionManager = containerProvider.Resolve<IRegionManager>();
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<MonitorView>("MonitorView");
containerRegistry.RegisterForNavigation<RecordView>("RecordView");
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Service\Service.csproj" />
<ProjectReference Include="..\UIShare\UIShare.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,330 @@
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Legends;
using OxyPlot.Series;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Threading;
using UIShare.GlobalVariable;
using UIShare.PubEvent;
using UIShare.ViewModelBase;
namespace MonitorModule.ViewModels
{
/// <summary>
/// 监控界面 VM —— 基于 OxyPlot 的曲线监控壳。
/// 当前阶段不接入真实数据源,仅搭好框架:
/// - 添加信号 / 删除信号
/// - 重置视图(按数据范围复原)
/// - 刷新(重绘 PlotView
/// 仍延续 ScopedContext 隔离 + 双击展开 的范式,每个工位独立一份图表与信号列表。
/// </summary>
public class MonitorViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
{
#region
private readonly IScopedProvider _scope;
// 颜色轮转池,给新加的信号自动分配区分色
private static readonly OxyColor[] _palette =
{
OxyColors.SteelBlue, OxyColors.IndianRed, OxyColors.SeaGreen,
OxyColors.DarkOrange, OxyColors.MediumPurple, OxyColors.Goldenrod,
OxyColors.Teal, OxyColors.Crimson, OxyColors.OliveDrab
};
private int _signalCounter;
// ===== 模拟数据相关 =====
// 模拟定时器:周期性给每条信号追加新点,形成滚动效果
private readonly DispatcherTimer _simTimer;
// 全局采样时间(秒),每 tick 自增 _simInterval
private double _simT;
// 采样间隔(秒),与 DispatcherTimer.Interval 保持一致
private const double _simInterval = 0.1;
// 滚动窗口大小:每条曲线最多保留 200 个点(约 20 秒)
private const int _maxPoints = 200;
// 用于 random walk 的随机源
private static readonly Random _rng = new();
#endregion
#region /
public bool KeepAlive => true;
public ScopedContext _scopedContext { get; }
public GlobalInfo GlobalInfoRef { get; }
private string _testStatus = string.Empty;
public string TestStatus
{
get => _testStatus;
set => SetProperty(ref _testStatus, value);
}
#endregion
#region OxyPlot
/// <summary>PlotView 直接绑这个 PlotModel</summary>
public PlotModel Plot { get; }
/// <summary>当前已添加的信号集合(左侧列表展示)</summary>
public ObservableCollection<SignalItem> Signals { get; } = new();
private SignalItem? _selectedSignal;
public SignalItem? SelectedSignal
{
get => _selectedSignal;
set => SetProperty(ref _selectedSignal, value);
}
private string _statusMessage = "图表已就绪,暂无信号";
public string StatusMessage
{
get => _statusMessage;
set => SetProperty(ref _statusMessage, value);
}
#endregion
#region
public ICommand AddSignalCommand { get; }
public ICommand DeleteSignalCommand { get; }
public ICommand ResetViewCommand { get; }
public ICommand RefreshDataCommand { get; }
// 双击展开/折叠:与 RecordView/AutomatedTestingView 共用同一套 ExpandViewEvent
public ICommand RefreshCommand { get; }
#endregion
public MonitorViewModel(IContainerExtension container) : base(container)
{
_scope = container.CreateScope();
GlobalInfoRef = container.Resolve<GlobalInfo>();
_scopedContext = _scope.Resolve<ScopedContext>();
Plot = BuildEmptyPlot();
AddSignalCommand = new DelegateCommand(OnAddSignal);
DeleteSignalCommand = new DelegateCommand(OnDeleteSignal);
ResetViewCommand = new DelegateCommand(OnResetView);
RefreshDataCommand = new DelegateCommand(OnRefreshData);
RefreshCommand = new DelegateCommand(OnExpand);
// 启动模拟数据定时器100ms 一帧,给每条信号喂一个新点
_simTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(_simInterval) };
_simTimer.Tick += OnSimTick;
_simTimer.Start();
// 默认预置 3 条模拟信号,便于直接看到滚动效果
OnAddSignal(); // sin
OnAddSignal(); // cos
OnAddSignal(); // random walk
}
public void Dispose()
{
_simTimer?.Stop();
_scope?.Dispose();
}
#region PlotModel
private static PlotModel BuildEmptyPlot()
{
var pm = new PlotModel
{
Title = string.Empty,
PlotAreaBorderColor = OxyColors.LightGray,
Background = OxyColors.White
};
pm.Axes.Add(new LinearAxis
{
Position = AxisPosition.Bottom,
Title = "X",
MajorGridlineStyle = LineStyle.Dot,
MinorGridlineStyle = LineStyle.None
});
pm.Axes.Add(new LinearAxis
{
Position = AxisPosition.Left,
Title = "Y",
MajorGridlineStyle = LineStyle.Dot,
MinorGridlineStyle = LineStyle.None
});
pm.Legends.Add(new Legend
{
LegendPosition = LegendPosition.RightTop,
LegendBackground = OxyColor.FromAColor(200, OxyColors.White),
LegendBorder = OxyColors.LightGray
});
return pm;
}
#endregion
#region
/// <summary>
/// 添加一条信号:按 _signalCounter 轮转选择不同波形 generator
/// 后续 _simTimer 每帧会调用 generator(t) 给曲线追加新点形成滚动效果。
/// </summary>
private void OnAddSignal()
{
_signalCounter++;
var color = _palette[(_signalCounter - 1) % _palette.Length];
// 6 种波形轮转sin / cos / 锯齿 / 方波 / 衰减正弦 / random walk
var (waveName, generator) = BuildGenerator(_signalCounter);
var name = $"{waveName}_{_signalCounter}";
var series = new LineSeries
{
Title = name,
Color = color,
StrokeThickness = 1.5
};
var item = new SignalItem(name, series, generator);
Signals.Add(item);
SelectedSignal = item;
Plot.Series.Add(series);
Plot.InvalidatePlot(true);
StatusMessage = $"已添加信号 [{name}],当前共 {Signals.Count} 条";
}
/// <summary>
/// 按索引返回一种模拟波形发生器。
/// 振幅 / 频率 / 相位都做了区分,让多条曲线视觉上分开。
/// </summary>
private static (string waveName, Func<double, double> generator) BuildGenerator(int index)
{
// 给同种波形不同实例一些随机偏移,避免完全重叠
double phase = (index * 0.7) % (2 * Math.PI);
double amp = 1.0 + (index % 3) * 0.3;
double freq = 0.5 + (index % 4) * 0.2;
return (index % 6) switch
{
0 => ("Sin", t => amp * Math.Sin(2 * Math.PI * freq * t + phase)),
1 => ("Cos", t => amp * Math.Cos(2 * Math.PI * freq * t + phase)),
2 => ("Saw", t => amp * (2 * ((t * freq) - Math.Floor(t * freq + 0.5)))),
3 => ("Square", t => amp * Math.Sign(Math.Sin(2 * Math.PI * freq * t + phase))),
4 => ("Decay", t => amp * Math.Exp(-0.05 * t) * Math.Sin(2 * Math.PI * freq * t + phase)),
_ => RandomWalkGenerator(amp),
};
}
/// <summary>构造一个随机游走 generator在前一次值基础上叠加高斯噪声。</summary>
private static (string, Func<double, double>) RandomWalkGenerator(double amp)
{
double last = 0;
return ("Walk", _ =>
{
last += (_rng.NextDouble() - 0.5) * 0.2 * amp;
// 软约束在 [-amp*3, amp*3],避免一直跑偏
if (last > amp * 3) last = amp * 3;
if (last < -amp * 3) last = -amp * 3;
return last;
});
}
/// <summary>删除当前选中信号;若未选中则删除最后一条。</summary>
private void OnDeleteSignal()
{
var target = SelectedSignal ?? Signals.LastOrDefault();
if (target == null)
{
StatusMessage = "无可删除的信号";
return;
}
Plot.Series.Remove(target.Series);
Signals.Remove(target);
SelectedSignal = Signals.LastOrDefault();
Plot.InvalidatePlot(true);
StatusMessage = $"已删除信号 [{target.Name}],剩余 {Signals.Count} 条";
}
/// <summary>按数据范围复原视图(重置所有坐标轴的缩放/平移)。</summary>
private void OnResetView()
{
Plot.ResetAllAxes();
Plot.InvalidatePlot(false);
StatusMessage = "视图已按数据范围复原";
}
/// <summary>刷新:触发 PlotView 重绘;后续接数据源时可在此重拉数据。</summary>
private void OnRefreshData()
{
Plot.InvalidatePlot(true);
StatusMessage = $"已刷新({DateTime.Now:HH:mm:ss}";
}
/// <summary>双击展开 / 折叠九宫格。</summary>
private void OnExpand()
{
if (string.IsNullOrEmpty(TestStatus)) return;
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
GlobalInfoRef.CurrentScope = TestStatus;
}
/// <summary>
/// 模拟数据 tick每条信号按当前 _simT 算出新点并追加。
/// 超过 _maxPoints 时丢弃最旧的点形成滚动窗口。
/// </summary>
private void OnSimTick(object? sender, EventArgs e)
{
_simT += _simInterval;
if (Signals.Count == 0)
{
return;
}
foreach (var item in Signals)
{
double y = item.Generator(_simT);
item.Series.Points.Add(new DataPoint(_simT, y));
if (item.Series.Points.Count > _maxPoints)
{
item.Series.Points.RemoveAt(0);
}
}
// 让 X 轴跟着最新数据滚动
var xAxis = Plot.Axes.FirstOrDefault(a => a.Position == AxisPosition.Bottom);
if (xAxis != null)
{
double window = _maxPoints * _simInterval;
xAxis.Minimum = Math.Max(0, _simT - window);
xAxis.Maximum = _simT + 0.5;
}
Plot.InvalidatePlot(true);
}
#endregion
#region
public override void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
if (navigationContext.Parameters.ContainsKey("Name"))
{
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
Plot.Title = $"监控 - {TestStatus}";
Plot.InvalidatePlot(false);
}
}
#endregion
}
/// <summary>
/// 信号列表项UI 显示名 + 对应的 OxyPlot LineSeries 引用 + 模拟数据 generator。
/// generator(t) 接收当前模拟时间,返回该时刻 y 值。
/// </summary>
public class SignalItem
{
public string Name { get; }
public LineSeries Series { get; }
public Func<double, double> Generator { get; }
public SignalItem(string name, LineSeries series, Func<double, double> generator)
{
Name = name;
Series = series;
Generator = generator;
}
}
}

View File

@@ -0,0 +1,362 @@
using Logger;
using SqlSugar;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Input;
using UIShare.GlobalVariable;
using UIShare.PubEvent;
using UIShare.ViewModelBase;
namespace MonitorModule.ViewModels
{
/// <summary>
/// 记录界面:用于查看运行目录下 SQL/ADP.db 中的数据。
/// 功能:表选择 / 关键字 WHERE 查询 / 分页 / 导出 CSV。
/// 仍延续 ScopedContext 隔离 + 双击展开 的范式,每个工位独立一份查询状态。
/// </summary>
public class RecordViewModel : NavigateViewModelBase, IRegionMemberLifetime, IDisposable
{
#region
// 数据库相对路径:运行目录\SQL\ADP.db数据库未就绪时容错处理不抛异常
private static readonly string DbFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SQL");
private static readonly string DbPath = Path.Combine(DbFolder, "ADP.db");
private static readonly string ConnStr = $"Data Source={DbPath};Version=3;";
private readonly IScopedProvider _scope;
#endregion
#region ScopedContext
public bool KeepAlive => true;
public ScopedContext _scopedContext { get; }
// 公开一份 GlobalInfo 供双击展开逻辑使用(基类的 _globalInfo 是 private
public GlobalInfo GlobalInfoRef { get; }
#endregion
#region
private string _testStatus = string.Empty;
public string TestStatus
{
get => _testStatus;
set => SetProperty(ref _testStatus, value);
}
#endregion
#region / /
private ObservableCollection<string> _tableNames = new();
public ObservableCollection<string> TableNames
{
get => _tableNames;
set => SetProperty(ref _tableNames, value);
}
private string? _selectedTable;
public string? SelectedTable
{
get => _selectedTable;
set
{
if (SetProperty(ref _selectedTable, value))
{
PageIndex = 1;
Query();
}
}
}
// 用户填写的 WHERE 子句(不带 WHERE 关键字例如Status='OK' AND Id>10
private string _whereClause = string.Empty;
public string WhereClause
{
get => _whereClause;
set => SetProperty(ref _whereClause, value);
}
private DataTable _resultTable = new();
public DataTable ResultTable
{
get => _resultTable;
set => SetProperty(ref _resultTable, value);
}
private string _statusMessage = "未连接";
public string StatusMessage
{
get => _statusMessage;
set => SetProperty(ref _statusMessage, value);
}
#endregion
#region
private int _pageIndex = 1;
public int PageIndex
{
get => _pageIndex;
set => SetProperty(ref _pageIndex, value);
}
private int _pageSize = 50;
public int PageSize
{
get => _pageSize;
set
{
if (SetProperty(ref _pageSize, value <= 0 ? 50 : value))
{
RaisePropertyChanged(nameof(TotalPages));
PageIndex = 1;
Query();
}
}
}
private long _totalCount;
public long TotalCount
{
get => _totalCount;
set
{
SetProperty(ref _totalCount, value);
RaisePropertyChanged(nameof(TotalPages));
}
}
public int TotalPages
{
get
{
if (PageSize <= 0) return 1;
var pages = (int)((TotalCount + PageSize - 1) / PageSize);
return pages <= 0 ? 1 : pages;
}
}
#endregion
#region
public ICommand LoadedCommand { get; }
public ICommand RefreshTablesCommand { get; }
public ICommand QueryCommand { get; }
public ICommand FirstPageCommand { get; }
public ICommand PrevPageCommand { get; }
public ICommand NextPageCommand { get; }
public ICommand LastPageCommand { get; }
public ICommand ExportCsvCommand { get; }
// 双击展开/折叠:与 MonitorView/AutomatedTestingView 共用
public ICommand RefreshCommand { get; }
#endregion
public RecordViewModel(IContainerExtension container) : base(container)
{
_scope = container.CreateScope();
GlobalInfoRef = container.Resolve<GlobalInfo>();
_scopedContext = _scope.Resolve<ScopedContext>();
LoadedCommand = new DelegateCommand(LoadTables);
RefreshTablesCommand = new DelegateCommand(LoadTables);
QueryCommand = new DelegateCommand(() => { PageIndex = 1; Query(); });
FirstPageCommand = new DelegateCommand(() => { if (PageIndex > 1) { PageIndex = 1; Query(); } });
PrevPageCommand = new DelegateCommand(() => { if (PageIndex > 1) { PageIndex--; Query(); } });
NextPageCommand = new DelegateCommand(() => { if (PageIndex < TotalPages) { PageIndex++; Query(); } });
LastPageCommand = new DelegateCommand(() => { if (PageIndex < TotalPages) { PageIndex = TotalPages; Query(); } });
ExportCsvCommand = new DelegateCommand(ExportCsv);
RefreshCommand = new DelegateCommand(OnExpand);
}
public void Dispose()
{
_scope?.Dispose();
}
#region
private SqlSugarClient CreateClient()
{
return new SqlSugarClient(new ConnectionConfig
{
DbType = SqlSugar.DbType.Sqlite,
ConnectionString = ConnStr,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
}
/// <summary>
/// 读取数据库中的所有用户表。数据库不存在时不报错,仅在状态栏提示。
/// </summary>
private void LoadTables()
{
try
{
if (!Directory.Exists(DbFolder)) Directory.CreateDirectory(DbFolder);
if (!File.Exists(DbPath))
{
TableNames = new ObservableCollection<string>();
SelectedTable = null;
ResultTable = new DataTable();
TotalCount = 0;
StatusMessage = $"数据库尚未创建:{DbPath}";
return;
}
using var db = CreateClient();
var tables = db.DbMaintenance.GetTableInfoList(false)
.Select(t => t.Name)
.OrderBy(n => n)
.ToList();
TableNames = new ObservableCollection<string>(tables);
if (tables.Count == 0)
{
SelectedTable = null;
ResultTable = new DataTable();
TotalCount = 0;
StatusMessage = "数据库已连接,但暂无数据表";
}
else
{
StatusMessage = $"已连接:{DbPath}{tables.Count} 张表)";
if (string.IsNullOrEmpty(SelectedTable) || !tables.Contains(SelectedTable))
{
SelectedTable = tables[0]; // setter 会触发 Query
}
else
{
Query();
}
}
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"加载数据表失败:{ex.Message}");
StatusMessage = $"加载失败:{ex.Message}";
}
}
/// <summary>
/// 执行分页查询。WHERE 为空则查询全部。
/// </summary>
private void Query()
{
if (string.IsNullOrEmpty(SelectedTable) || !File.Exists(DbPath))
{
ResultTable = new DataTable();
TotalCount = 0;
return;
}
try
{
using var db = CreateClient();
string table = $"[{SelectedTable}]";
string where = string.IsNullOrWhiteSpace(WhereClause) ? "1=1" : WhereClause;
// COUNT 总数
var countSql = $"SELECT COUNT(*) FROM {table} WHERE {where}";
TotalCount = db.Ado.GetLong(countSql);
// 修正越界
if (PageIndex > TotalPages) PageIndex = TotalPages;
if (PageIndex < 1) PageIndex = 1;
int offset = (PageIndex - 1) * PageSize;
var dataSql = $"SELECT * FROM {table} WHERE {where} LIMIT {PageSize} OFFSET {offset}";
ResultTable = db.Ado.GetDataTable(dataSql);
StatusMessage = $"表 [{SelectedTable}] 共 {TotalCount} 行 第 {PageIndex}/{TotalPages} 页";
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"查询失败:{ex.Message}");
StatusMessage = $"查询失败:{ex.Message}";
ResultTable = new DataTable();
TotalCount = 0;
}
}
#endregion
#region CSV
/// <summary>
/// 按当前 WHERE 条件导出全部结果到 CSV不分页
/// </summary>
private void ExportCsv()
{
if (string.IsNullOrEmpty(SelectedTable) || !File.Exists(DbPath))
{
StatusMessage = "无可导出数据";
return;
}
var dlg = new Microsoft.Win32.SaveFileDialog
{
Filter = "CSV 文件 (*.csv)|*.csv|所有文件|*.*",
FileName = $"{SelectedTable}_{DateTime.Now:yyyyMMdd_HHmmss}.csv",
Title = $"导出 [{SelectedTable}] 为 CSV"
};
if (dlg.ShowDialog() != true) return;
try
{
using var db = CreateClient();
string table = $"[{SelectedTable}]";
string where = string.IsNullOrWhiteSpace(WhereClause) ? "1=1" : WhereClause;
var sql = $"SELECT * FROM {table} WHERE {where}";
var dt = db.Ado.GetDataTable(sql);
WriteCsv(dlg.FileName, dt);
StatusMessage = $"导出完成:{dlg.FileName}{dt.Rows.Count} 行)";
LoggerHelper.InfoWithNotify($"工位 [{TestStatus}] 导出 [{SelectedTable}] 至 {dlg.FileName},共 {dt.Rows.Count} 行");
}
catch (Exception ex)
{
LoggerHelper.ErrorWithNotify($"导出失败:{ex.Message}");
StatusMessage = $"导出失败:{ex.Message}";
}
}
private static void WriteCsv(string path, DataTable dt)
{
// 写 UTF-8 BOM 让 Excel 直接识别中文
using var sw = new StreamWriter(path, false, new UTF8Encoding(true));
// 表头
sw.WriteLine(string.Join(",", dt.Columns.Cast<DataColumn>().Select(c => Escape(c.ColumnName))));
// 行
foreach (DataRow row in dt.Rows)
{
sw.WriteLine(string.Join(",", row.ItemArray.Select(v => Escape(v?.ToString() ?? string.Empty))));
}
}
private static string Escape(string field)
{
if (field.Contains('"') || field.Contains(',') || field.Contains('\r') || field.Contains('\n'))
{
return "\"" + field.Replace("\"", "\"\"") + "\"";
}
return field;
}
#endregion
#region
private void OnExpand()
{
if (string.IsNullOrEmpty(TestStatus)) return;
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
GlobalInfoRef.CurrentScope = TestStatus;
}
#endregion
#region
public override void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
if (navigationContext.Parameters.ContainsKey("Name"))
{
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
}
// 进入界面时自动加载表
LoadTables();
}
#endregion
}
}

View File

@@ -0,0 +1,236 @@
<UserControl x:Class="MonitorModule.Views.MonitorView"
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:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare"
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
xmlns:oxy="http://oxyplot.org/wpf"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="700"
d:DesignWidth="1200">
<UserControl.Resources>
<converters:LessThanConverter x:Key="LessThanConverter"/>
</UserControl.Resources>
<!-- 外层 Border装 MouseDoubleClickBehavior 实现九宫格双击展开 -->
<Border Background="#F5F7FA">
<i:Interaction.Behaviors>
<b:MouseDoubleClickBehavior
Command="{Binding DataContext.RefreshCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
</i:Interaction.Behaviors>
<!-- 给最外层 Grid 命名,方便子控件 DataTrigger 监听 ActualWidth -->
<Grid x:Name="RootGrid" Margin="8">
<Grid.RowDefinitions>
<!-- Row0 标题:窄宽时折叠为 0 高度 -->
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
<!-- Row1 工具栏:窄宽时折叠为 0 -->
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
<!-- Row2 主体(图表区) -->
<RowDefinition Height="*"/>
<!-- Row3 状态栏:窄宽时折叠为 0 -->
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Height" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
</Grid.RowDefinitions>
<!-- ====== Row0标题 ====== -->
<TextBlock Grid.Row="0"
Text="{Binding TestStatus, StringFormat=监控界面 - {0}}"
FontSize="20" FontWeight="Bold"
Margin="4,0,0,8">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<!-- ====== Row1工具栏 ====== -->
<Border Grid.Row="1"
Background="White"
BorderBrush="#DDD" BorderThickness="1"
CornerRadius="4" Padding="8" Margin="0,0,0,6">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel Orientation="Horizontal">
<Button Content="+ 添加信号"
Command="{Binding AddSignalCommand}"
Padding="12,4"/>
<Button Content=" 删除信号"
Command="{Binding DeleteSignalCommand}"
Padding="12,4" Margin="6,0,0,0"/>
<Button Content="↺ 复原视图"
Command="{Binding ResetViewCommand}"
Padding="12,4" Margin="20,0,0,0"
ToolTip="按数据范围重置坐标轴缩放/平移"/>
<Button Content="⟳ 刷新"
Command="{Binding RefreshDataCommand}"
Padding="12,4" Margin="6,0,0,0"
ToolTip="重新绘制图表"/>
</StackPanel>
</Border>
<!-- ====== Row2主体左信号列表 + 右图表)====== -->
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<!-- Col0 信号列表:窄宽时折叠为 0 宽 -->
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="220"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Width" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
<!-- Col1 拖拽条:窄宽时折叠为 0 宽 -->
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="6"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Width" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 左:信号列表(窄宽时整体隐藏) -->
<Border Grid.Column="0"
Background="White"
BorderBrush="#DDD" BorderThickness="1"
CornerRadius="4">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<DockPanel>
<Border DockPanel.Dock="Top"
Background="#ECEFF4"
Padding="8,4">
<TextBlock Text="信号列表" FontWeight="Bold"/>
</Border>
<ListBox ItemsSource="{Binding Signals}"
SelectedItem="{Binding SelectedSignal}"
BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="2">
<Border Width="12" Height="12"
CornerRadius="2"
Background="#888"
VerticalAlignment="Center"/>
<TextBlock Text="{Binding Name}"
Margin="6,0,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Border>
<GridSplitter Grid.Column="1"
HorizontalAlignment="Stretch"
Background="Transparent">
<GridSplitter.Style>
<Style TargetType="GridSplitter">
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</GridSplitter.Style>
</GridSplitter>
<!-- 右OxyPlot 图表(核心,始终显示) -->
<Border Grid.Column="2"
Background="White"
BorderBrush="#DDD" BorderThickness="1"
CornerRadius="4">
<oxy:PlotView Model="{Binding Plot}"
Background="Transparent"/>
</Border>
</Grid>
<!-- ====== Row3状态栏 ====== -->
<Border Grid.Row="3"
Background="#ECEFF4"
Padding="8,4" Margin="0,6,0,0"
CornerRadius="2">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ActualWidth, ElementName=RootGrid, Converter={StaticResource LessThanConverter}, ConverterParameter=600}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="{Binding StatusMessage}"
Foreground="#444"
FontSize="12"/>
</Border>
</Grid>
</Border>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MonitorModule.Views
{
/// <summary>
/// MonitorView.xaml 的交互逻辑
/// </summary>
public partial class MonitorView : UserControl
{
public MonitorView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,170 @@
<UserControl x:Class="MonitorModule.Views.RecordView"
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:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
xmlns:b="clr-namespace:UIShare.Behaviors;assembly=UIShare"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="700"
d:DesignWidth="1200">
<!-- 外层 Border1) 装 MouseDoubleClickBehavior 实现九宫格双击展开;
2) 给整个记录界面一个浅色背景 -->
<Border Background="#F5F7FA">
<i:Interaction.Behaviors>
<b:MouseDoubleClickBehavior
Command="{Binding DataContext.RefreshCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
</i:Interaction.Behaviors>
<Grid Margin="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<!-- 标题 -->
<RowDefinition Height="Auto"/>
<!-- 工具栏 -->
<RowDefinition Height="*"/>
<!-- 数据表 -->
<RowDefinition Height="Auto"/>
<!-- 分页 -->
<RowDefinition Height="Auto"/>
<!-- 状态栏 -->
</Grid.RowDefinitions>
<!-- 顶部:工位名称(区分九宫格) -->
<TextBlock Grid.Row="0"
Text="{Binding TestStatus, StringFormat=记录界面 - {0}}"
FontSize="20" FontWeight="Bold"
Margin="4,0,0,8"/>
<!-- 工具栏:表选择 / WHERE 条件 / 查询 / 刷新表 / 导出 -->
<Border Grid.Row="1"
Background="White"
BorderBrush="#DDD" BorderThickness="1"
CornerRadius="4" Padding="8" Margin="0,0,0,6">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="180"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="表:"
VerticalAlignment="Center"
Margin="0,0,4,0"/>
<ComboBox Grid.Column="1"
materialDesign:HintAssist.Hint="数据表"
ItemsSource="{Binding TableNames}"
SelectedItem="{Binding SelectedTable}"
VerticalAlignment="Center"/>
<TextBlock Grid.Column="2"
Text="WHERE"
VerticalAlignment="Center"
Margin="12,0,4,0"/>
<TextBox Grid.Column="3"
Text="{Binding WhereClause, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center"
materialDesign:HintAssist.Hint="条件筛选"
ToolTip="例如Status='OK' AND Id>10。留空表示查询全部">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding QueryCommand}"/>
</TextBox.InputBindings>
</TextBox>
<Button Grid.Column="4"
Content="查询"
Command="{Binding QueryCommand}"
Padding="12,4" Margin="8,0,0,0"/>
<Button Grid.Column="5"
Content="刷新表"
Command="{Binding RefreshTablesCommand}"
Padding="12,4" Margin="6,0,0,0"/>
<Button Grid.Column="6"
Content="导出 CSV"
Command="{Binding ExportCsvCommand}"
Padding="12,4" Margin="6,0,0,0"/>
</Grid>
</Border>
<!-- DataGrid自动生成列绑 DataTable.DefaultView 直显示 -->
<DataGrid Grid.Row="2"
ItemsSource="{Binding ResultTable}"
AutoGenerateColumns="True"
IsReadOnly="True"
CanUserAddRows="False"
CanUserDeleteRows="False"
GridLinesVisibility="All"
HeadersVisibility="All"
AlternatingRowBackground="#F9FAFB"
RowBackground="White"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"/>
<!-- 分页控件 -->
<Border Grid.Row="3"
Background="White"
BorderBrush="#DDD" BorderThickness="1"
CornerRadius="4" Padding="8" Margin="0,6,0,0">
<Grid>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left">
<TextBlock Text="每页:" VerticalAlignment="Center"/>
<ComboBox Text="{Binding PageSize, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
IsEditable="True"
materialDesign:HintAssist.Hint="页码"
Width="80" VerticalAlignment="Center" Margin="4,0,0,0">
<ComboBoxItem Content="20"/>
<ComboBoxItem Content="50"/>
<ComboBoxItem Content="100"/>
<ComboBoxItem Content="200"/>
<ComboBoxItem Content="500"/>
</ComboBox>
<TextBlock Text="{Binding TotalCount, StringFormat=共 {0} 行}"
VerticalAlignment="Center" Margin="16,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right">
<Button Content="« 首页"
Command="{Binding FirstPageCommand}"
Padding="10,3"/>
<Button Content=" 上一页"
Command="{Binding PrevPageCommand}"
Padding="10,3" Margin="6,0,0,0"/>
<TextBlock VerticalAlignment="Center" Margin="12,0">
<Run Text="第 "/>
<Run Text="{Binding PageIndex}" FontWeight="Bold"/>
<Run Text=" / "/>
<Run Text="{Binding TotalPages, Mode=OneWay}" FontWeight="Bold"/>
<Run Text=" 页"/>
</TextBlock>
<Button Content="下一页 "
Command="{Binding NextPageCommand}"
Padding="10,3"/>
<Button Content="末页 »"
Command="{Binding LastPageCommand}"
Padding="10,3" Margin="6,0,0,0"/>
</StackPanel>
</Grid>
</Border>
<!-- 底部状态栏 -->
<Border Grid.Row="4"
Background="#ECEFF4"
Padding="8,4" Margin="0,6,0,0"
CornerRadius="2">
<TextBlock Text="{Binding StatusMessage}"
Foreground="#444"
FontSize="12"/>
</Border>
</Grid>
</Border>
</UserControl>

View File

@@ -0,0 +1,28 @@
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 MonitorModule.Views
{
/// <summary>
/// RecordView.xaml 的交互逻辑
/// </summary>
public partial class RecordView : UserControl
{
public RecordView()
{
InitializeComponent();
}
}
}