作用域配置
This commit is contained in:
@@ -18,40 +18,24 @@ namespace MonitorModule.ViewModels
|
||||
/// </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 验证用)
|
||||
#region 属性
|
||||
public bool KeepAlive => true;
|
||||
public ScopedContext _scopedContext { get; }
|
||||
// 公开一份 GlobalInfo 供双击展开逻辑使用(基类的 _globalInfo 是 private)
|
||||
public GlobalInfo GlobalInfoRef { get; }
|
||||
#endregion
|
||||
public ScopedContext _scopedContext { get; set; }
|
||||
public GlobalInfo _globalInfo { get; }
|
||||
|
||||
#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;
|
||||
@@ -66,37 +50,30 @@ namespace MonitorModule.ViewModels
|
||||
}
|
||||
|
||||
// 用户填写的 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;
|
||||
@@ -111,7 +88,6 @@ namespace MonitorModule.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private long _totalCount;
|
||||
public long TotalCount
|
||||
{
|
||||
get => _totalCount;
|
||||
@@ -145,13 +121,27 @@ namespace MonitorModule.ViewModels
|
||||
// 双击展开/折叠:与 MonitorView/AutomatedTestingView 共用
|
||||
public ICommand RefreshCommand { get; }
|
||||
#endregion
|
||||
#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 bool IsInitiated = false;
|
||||
private IScopedProvider _scope;
|
||||
private string _testStatus = string.Empty;
|
||||
private ObservableCollection<string> _tableNames = new();
|
||||
private string? _selectedTable;
|
||||
private string _whereClause = string.Empty;
|
||||
private DataTable _resultTable = new();
|
||||
private string _statusMessage = "未连接";
|
||||
private int _pageIndex = 1;
|
||||
private int _pageSize = 50;
|
||||
private long _totalCount;
|
||||
#endregion
|
||||
|
||||
public RecordViewModel(IContainerExtension container) : base(container)
|
||||
{
|
||||
_scope = container.CreateScope();
|
||||
GlobalInfoRef = container.Resolve<GlobalInfo>();
|
||||
_scopedContext = _scope.Resolve<ScopedContext>();
|
||||
|
||||
_globalInfo = container.Resolve<GlobalInfo>();
|
||||
LoadedCommand = new DelegateCommand(LoadTables);
|
||||
RefreshTablesCommand = new DelegateCommand(LoadTables);
|
||||
QueryCommand = new DelegateCommand(() => { PageIndex = 1; Query(); });
|
||||
@@ -341,20 +331,23 @@ namespace MonitorModule.ViewModels
|
||||
private void OnExpand()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TestStatus)) return;
|
||||
_globalInfo.CurrentScope = TestStatus;
|
||||
_eventAggregator.GetEvent<ExpandViewEvent>().Publish(TestStatus);
|
||||
GlobalInfoRef.CurrentScope = TestStatus;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导航
|
||||
#region 重写
|
||||
public override void OnNavigatedTo(NavigationContext navigationContext)
|
||||
{
|
||||
base.OnNavigatedTo(navigationContext);
|
||||
if (navigationContext.Parameters.ContainsKey("Name"))
|
||||
if (!IsInitiated&&navigationContext.Parameters.ContainsKey("Name"))
|
||||
{
|
||||
TestStatus = navigationContext.Parameters.GetValue<string>("Name");
|
||||
_scope = _globalInfo.ScopeDic[TestStatus];
|
||||
_scopedContext = _globalInfo.ContextDic[TestStatus];
|
||||
IsInitiated = true;
|
||||
}
|
||||
// 进入界面时自动加载表
|
||||
LoadTables();
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user