alielie
2025-10-10 15bbd62b0b24b72c717ae91ab45348a2083ad04e
HMI.DataViewer/DbSettingModal.xaml.cs
@@ -6,8 +6,10 @@
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)