From e3868d4d61ded0e76fc8fe3fdacdd9e6d9113cf1 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 13 十月 2025 08:50:15 +0800
Subject: [PATCH] 优化HMI;
---
HMI.DataViewer/DbSettingModal.xaml.cs | 71 ++++++++++++++++++++++++++++-------
1 files changed, 57 insertions(+), 14 deletions(-)
diff --git a/HMI.DataViewer/DbSettingModal.xaml.cs b/HMI.DataViewer/DbSettingModal.xaml.cs
index 31bf8f0..5ab9ed8 100644
--- a/HMI.DataViewer/DbSettingModal.xaml.cs
+++ b/HMI.DataViewer/DbSettingModal.xaml.cs
@@ -1,13 +1,15 @@
锘縰sing HMI.Core.Util;
using HMI.DataViewer.Entity;
-using HMI.UI;
+using HMI.UI.DpUtil;
using HMI.UI.Util;
using log4net;
using Microsoft.Win32;
using Panuon.WPF.UI;
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
+using System.IO;
using System.Linq;
using System.Windows.Controls;
@@ -87,7 +89,7 @@
catch (Exception ex)
{
log.Error("IPManage Form Submit Failed.", ex);
- ToastHelper.Error(this, $"鏈煡寮傚父锛亄ex.Message}");
+ ToastHelper.Error(this, $"{this.lang("App.App.UnhandledException")}: {ex.Message}");
e.Cancel = true;
return;
}
@@ -133,7 +135,16 @@
programInput.Text = Data.Program;
dbFilePathInput.Text = Data.DBFilePath;
tableNameInput.Text = Data.TableName;
-
+ Conditions = data?.Condition ?? new ObservableCollection<QueryCondition>();
+
+ if (!string.IsNullOrEmpty(Data.DBFilePath) && File.Exists(Data.DBFilePath))
+ {
+ UpdateDbHelper(Data.DBFilePath);
+ UpdateTableSource();
+ tableNameInput.SelectedItem = Data.TableName;
+ UpdateColumnSource(Data.TableName);
+ }
+
return this.ShowDialog();
}
@@ -164,7 +175,8 @@
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
Button btn = sender as Button;
- switch (btn.Name) {
+ switch (btn.Name)
+ {
case "searchBtn":
OpenSelectDbDialog();
break;
@@ -175,31 +187,56 @@
AddCondition();
break;
case "delBtn":
+ RemoveCondition();
break;
default:
break;
}
-
+
+ }
+
+ private void UpdateDbHelper(string filePath)
+ {
+ if (Helper == null)
+ {
+ Helper = new SqliteHelper(filePath);
+ }
+ else if (Helper.DataBaseFile != filePath)
+ {
+ Helper.Close();
+ Helper = new SqliteHelper(filePath);
+ }
+ }
+
+ private void UpdateTableSource()
+ {
+ string[] tableNames = Helper.GetAllTableInFile();
+ tableNameInput.ItemsSource = tableNames;
+ }
+
+ private void UpdateColumnSource(string tableName)
+ {
+ string[] cols = Helper.GetColumnNameFromTable(tableName);
+ Columns = new ObservableCollection<string>(cols);
}
private void OpenSelectDbDialog()
{
- string BasePath = PathHelper.IconFolder;
+ string BasePath = PathHelper.ConfigFolder;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "(*.db)|*.db";
openFileDialog.InitialDirectory = BasePath;
- openFileDialog.Title = "閫夋嫨鏁版嵁搴撴枃浠�";
+ openFileDialog.Title = this.lang("Dv.SelectDbFile");
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == true)
{
string FileName = openFileDialog.FileName;
dbFilePathInput.Text = FileName;
- Helper = new SqliteHelper(FileName);
- string[] tableNames = Helper.GetAllTableInFile();
- tableNameInput.ItemsSource = tableNames;
+ UpdateDbHelper(FileName);
+ UpdateTableSource();
}
}
@@ -220,11 +257,17 @@
Conditions = temp;
}
-
- private void ComboxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
+ private void RemoveCondition()
{
- string[] cols = Helper.GetColumnNameFromTable(e.AddedItems[0].ToString());
- Columns = new ObservableCollection<string>(cols);
+ if (conditionTable.SelectedItems == null || conditionTable.SelectedItems.Count <= 0) return;
+ Conditions = new ObservableCollection<QueryCondition>(
+ Conditions.Where(d => !conditionTable.SelectedItems.Contains(d)).ToList());
+ }
+
+ private void ComboxSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ UpdateColumnSource(e.AddedItems[0].ToString());
+ Conditions = new ObservableCollection<QueryCondition>();
}
private void RadioButton_Click(object sender, System.Windows.RoutedEventArgs e)
--
Gitblit v1.9.1