| | |
| | | using System; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Windows.Controls; |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | base.OnClosing(e); |
| | | } |
| | | |
| | | public bool ValidateDBAddress(object value, out string err) |
| | | public bool ValidateName(object value, out string err) |
| | | { |
| | | err = null; |
| | | |
| | | var target = Datasource.FirstOrDefault(e => e.Program == value.ToString()); |
| | | if (target != null && target != Data) |
| | | { |
| | | err = this.lang("App.MustBeUnique", LangUtil.Get("Dv.Datasource.Name")); ; |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | |
| | | Data.Program = programInput.Text; |
| | | Data.DBFilePath = dbFilePathInput.Text; |
| | | Data.TableName = tableNameInput.Text; |
| | | Data.Pattern = TbPattern.Text; |
| | | Data.TimeCol = Conditions.FirstOrDefault(c => c.IsTimeCol)?.Key; |
| | | Data.Condition = Conditions; |
| | | } |
| | |
| | | programInput.Text = Data.Program; |
| | | dbFilePathInput.Text = Data.DBFilePath; |
| | | tableNameInput.Text = Data.TableName; |
| | | |
| | | TbPattern.Text = Data.Pattern; |
| | | |
| | | if (!string.IsNullOrEmpty(Data.DBFilePath) && File.Exists(Data.DBFilePath)) |
| | | { |
| | | UpdateDbHelper(Data.DBFilePath); |
| | | UpdateTableSource(); |
| | | tableNameInput.SelectedItem = Data.TableName; |
| | | UpdateColumnSource(Data.TableName); |
| | | } |
| | | Conditions = data?.Condition ?? new ObservableCollection<QueryCondition>(); |
| | | |
| | | return this.ShowDialog(); |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | |
| | | 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) |