Browse Source

load 选择库的表 视图

net45
BearXiongLaoXiong 5 years ago
parent
commit
710b941904
  1. 26
      XCoderWpf/App.config
  2. 2
      XCoderWpf/Models/DataBasePublishModel.cs
  3. 2
      XCoderWpf/Resources/Templates.xaml
  4. 68
      XCoderWpf/ViewModels/DataBasePublishViewModel.cs
  5. 26
      XCoderWpf/Views/DataBasePublish.xaml
  6. 4
      XCoderWpf/Views/MainWindow.xaml.cs
  7. 11
      XCoderWpf/XCoderWpf.csproj
  8. 51
      XCoderWpf/appsettings.json

26
XCoderWpf/App.config

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="SQLite" connectionString="Data Source=test.db;" providerName="Sqlite" />
<add name="MySql" connectionString="Server=.;Port=3306;Database=mysql;Uid=root;Pwd=;NameFormat=Upper" providerName="MySql.Data.MySqlClient" />
<add name="MSSQL" connectionString="Server=.;User ID=sa;Password=sa;Database=Test;datapath=~\App_Data;NameFormat=Upper" providerName="System.Data.SqlClient" />
<add name="mssql119" connectionString="Data Source=10.127.1.119;Initial Catalog=TPA_PROD;user=sa;password=shujukuceshidb1!" providerName="System.Data.SqlClient"/>
<add name="master117" connectionString="Server=10.127.1.117;User ID=sa;Password=sa;Database=Test;datapath=~\App_Data;NameFormat=Upper" providerName="System.Data.SqlClient" />
<add name="Oracle" connectionString="Data Source=Tcp://127.0.0.1/ORC;User ID=sys;Password=admin;Owner=mis;NameFormat=Upper" providerName="System.Data.OracleClient" />
<add name="PostgreSQL" connectionString="Server=.;Database=master;Uid=root;Pwd=root;NameFormat=Upper" providerName="PostgreSQL.Data.PostgreSQLClient" />
<add name="MSSQL" connectionString="Server=.;Integrated Security=SSPI;Database=Test;NameFormat=Upper" providerName="System.Data.SqlClient" />
<add name="Oracle" connectionString="Data Source=orc;User ID=sys;Password=admin;NameFormat=Upper" providerName="System.Data.OracleClient" />
<add name="Access" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=~\App_Data\Test.mdb;Persist Security Info=False;OLE DB Services=-1;NameFormat=Upper" providerName="Access"/>
<add name="SqlCe" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe1" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe2" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe3" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe4" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe5" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe6" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe7" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe8" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCe9" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
<add name="SqlCea" connectionString="Data Source=test.sdf;" providerName="SqlCe" />
</connectionStrings>
</configuration>

2
XCoderWpf/Models/DataBasePublishModel.cs

@ -15,7 +15,7 @@ namespace XCoderWpf.Models
public string Title { get; set; }
public string Server { get; set; }
public string ShortName => Server?.Length > 30 ? Server.Substring(0, 30) : Server ?? "";
public DelegateCommand<ConnectionStringModel> SelectCmd { get; set; }
public DelegateCommand<ConnectionStringModel> SelectConncectionCmd { get; set; }
}
public class TableInfoModel

2
XCoderWpf/Resources/Templates.xaml

@ -7,7 +7,7 @@
<DataTemplate x:Key="DataBaseItems">
<ContentControl>
<!--CommandParameter="{Binding}"-->
<RadioButton GroupName="ConnectionStringGroup" Command="{Binding SelectCmd}" CommandParameter="{Binding}"
<RadioButton GroupName="ConnectionStringGroup" Command="{Binding SelectConncectionCmd}" CommandParameter="{Binding}"
Style="{x:Null}">
<RadioButton.Template>

68
XCoderWpf/ViewModels/DataBasePublishViewModel.cs

@ -5,12 +5,14 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using HandyControl.Controls;
using Microsoft.Win32;
using NewLife;
using NewLife.Configuration;
using NewLife.Threading;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
@ -18,6 +20,7 @@ using Prism.Services.Dialogs;
using XCode.DataAccessLayer;
using XCoder;
using XCoderWpf.Models;
using XCoderWpf.Views;
namespace XCoderWpf.ViewModels
{
@ -28,10 +31,6 @@ namespace XCoderWpf.ViewModels
/// </summary>
private List<ConnectionStringModel> _connectionStringList;
public IList<IDataTable> Tables { get; set; }
private IList<string> _datalist;
public IList<string> DataList { get { return _datalist; } set { SetProperty(ref _datalist, value); } }
public DataBasePublishViewModel()
{
@ -40,7 +39,7 @@ namespace XCoderWpf.ViewModels
Title = x.Key,
Server = x.Value,
IconSource = new Uri($"/Resources/Images/SqlServer/{DAL.Create(x.Key).DbType.ToString().ToLower()}.png", UriKind.Relative),
SelectCmd = new Lazy<DelegateCommand<ConnectionStringModel>>(() => new DelegateCommand<ConnectionStringModel>((x) => _selectConnectionStringModel = x)).Value,
SelectConncectionCmd = new Lazy<DelegateCommand<ConnectionStringModel>>(() => new DelegateCommand<ConnectionStringModel>((x) => _selectConnectionStringModel = x)).Value,
}));
_connectionStringCollection = new ObservableCollection<ConnectionStringModel>(_connectionStringList);
@ -85,8 +84,8 @@ namespace XCoderWpf.ViewModels
private bool _isAllSelected;
public bool IsAllSelected { get => _isAllSelected; set { SetProperty(ref _isAllSelected, value); } }
private bool _isView;
public bool IsView { get => _isView; set { SetProperty(ref _isView, value); } }
private bool _isContainsView = true;
public bool IsContainsView { get => _isContainsView; set { SetProperty(ref _isContainsView, value); _ = SetTablesListByIsView(); } }
private MenuModel selectedMenu;
/// <summary>选中菜单</summary>
@ -96,7 +95,8 @@ namespace XCoderWpf.ViewModels
set { selectedMenu = value; RaisePropertyChanged(); }
}
private int _tableListCount;
public int TableListCount { get => _tableListCount; set { SetProperty(ref _tableListCount, value); } }
#endregion
@ -107,7 +107,7 @@ namespace XCoderWpf.ViewModels
MessageBox.Show("123");
});
public DelegateCommand ImportXmlCmd => new DelegateCommand(() =>
public DelegateCommand ImportXmlCmd => new Lazy<DelegateCommand>(new DelegateCommand(() =>
{
var openFileDialog = new OpenFileDialog();
if (!openFileDialog.ShowDialog().Value || String.IsNullOrEmpty(openFileDialog.FileName)) return;
@ -132,37 +132,49 @@ namespace XCoderWpf.ViewModels
//MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
});
})).Value;
public DelegateCommand ImportConfigCmd => new Lazy<DelegateCommand>(new DelegateCommand(() =>
public DelegateCommand ImportConfigCmd => new Lazy<DelegateCommand>(new DelegateCommand(async () =>
{
await GetTablesList();
})).Value;
public DelegateCommand<ConnectionStringModel> SelectConncectionCmd => new Lazy<DelegateCommand<ConnectionStringModel>>(new DelegateCommand<ConnectionStringModel>((x) =>
{
MessageBox.Show("aaaaaaaaaa");
})).Value;
#endregion
#region Method
private async Task GetTablesList()
{
try
{
var list = DAL.Create(ModelConfig.Current.ConnName).Tables;
if (IsView) list = list.Where(t => !t.IsView).ToList();
//if (Config.NeedFix) list = Engine.FixTable(list);
IList<IDataTable> list = null;
await Task.Run(() => { Thread.Sleep(10000); list = DAL.Create(_selectConnectionStringModel.Title).Tables; });
if (list == null) return;
Tables = list;
_TableCollection.Clear();
_TableCollection.AddRange(list.Select(x => new TableInfoModel { Name = $"{x.TableName} ({(string.IsNullOrWhiteSpace(x.Description) ? x.Name : x.Description)})", IsView = x.IsView }));
await SetTablesListByIsView();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
Debug.WriteLine("33333333333333333333333");
}
})).Value;
#endregion
#region Method
/// <summary>
/// 读取xml文件
/// </summary>
private void ImportModel()
private async Task<IList<IDataTable>> SetTablesListByIsView()
{
var list = Tables;
if (!_isContainsView) list = list.Where(t => !t.IsView).ToList();
TableListCount = list.Count();
_TableCollection.Clear();
_TableCollection.AddRange(list.Select(x => new TableInfoModel { Name = $"{x.TableName} ({(string.IsNullOrWhiteSpace(x.Description) ? x.Name : x.Description)})", IsView = x.IsView }));
return await Task.FromResult(list);
}
//private void SetTables(Object source)

26
XCoderWpf/Views/DataBasePublish.xaml

@ -36,7 +36,7 @@
</DockPanel>
<Border Margin="0,10,0,0" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}">
<ScrollViewer VerticalScrollBarVisibility="Auto" >
<ItemsControl ItemsSource="{Binding ConnectionStringCollection}" BorderThickness="0" ItemTemplate="{StaticResource DataBaseItems}">
<ItemsControl ItemsSource="{Binding ConnectionStringCollection}" BorderThickness="0" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemTemplate="{StaticResource DataBaseItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
@ -100,8 +100,8 @@
<DockPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsAllSelected}" Margin="5,0,0,0" Content="全选"/>
<CheckBox IsChecked="{Binding IsView}" Margin="10,0,0,0" Content="包含视图"/>
<hc:Badge HorizontalAlignment="Right" Text="125" BadgeMargin="0,-14,-20,0" Height="30" Margin="10,3,0,3" Style="{StaticResource BadgeDanger}">
<CheckBox IsChecked="{Binding IsContainsView}" Margin="10,0,0,0" Content="包含视图"/>
<hc:Badge HorizontalAlignment="Right" Text="{Binding TableListCount}" BadgeMargin="0,-14,-20,0" Height="30" Margin="10,3,0,3" Style="{StaticResource BadgeDanger}">
<Button Content="刷新"/>
</hc:Badge>
@ -116,13 +116,13 @@
</DockPanel>
</Border>
<Border Style="{StaticResource BorderRegion}" Margin="10" Padding="1">
<ListBox ItemsSource="{Binding TableCollection}" BorderThickness="0">
<ListBox.ItemsPanel>
<ListBox ItemsSource="{Binding TableCollection}" BorderThickness="0" VirtualizingStackPanel.VirtualizationMode="Recycling">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
@ -130,13 +130,13 @@
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Height="40">
<CheckBox VerticalAlignment="Center" Style="{x:Null}" Name="CheckBoxZone"/>
<Label Content="表" BorderThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="35" Margin="30,5,50,5" Padding="3" hc:BorderElement.CornerRadius="10">
<Label BorderThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="35" Margin="30,5,50,5" Padding="3" hc:BorderElement.CornerRadius="10">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
@ -162,7 +162,7 @@
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</Border>

4
XCoderWpf/Views/MainWindow.xaml.cs

@ -31,4 +31,8 @@ namespace XCoderWpf.Views
}
#endregion
}
public class LoadingWindow : Window
{
}
}

11
XCoderWpf/XCoderWpf.csproj

@ -30,8 +30,15 @@
<ItemGroup>
<PackageReference Include="HandyControls" Version="2.5.3.2" />
<PackageReference Include="NewLife.XCode" Version="9.19.2020.802" />
<PackageReference Include="Prism.DryIoc" Version="8.0.0.1740-pre" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.0-preview1.20235.1" />
<PackageReference Include="NewLife.XCode" Version="9.20.2020.901" />
<PackageReference Include="Prism.DryIoc" Version="8.0.0.1850-pre" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

51
XCoderWpf/appsettings.json

@ -0,0 +1,51 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"SQLite": {
"connectionString": "Data Source=test.db;",
"providerNamee": "Sqlite"
},
"MySql": {
"connectionString": "Server=.;Port=3306;Database=mysql;Uid=root;Pwd=;",
"providerName": "MySql.Data.MySqlClient"
},
"MSSQL": {
"connectionString": "Server=.;User ID=sa;Password=sa;Database=Test;datapath=~\\App_Data",
"providerName": "System.Data.SqlClient"
},
"MSSQL119": {
"connectionString": "Server=10.127.1.119;Database=TPA_PROD;User ID=sa;Password=shujukuceshidb1!;",
"providerName": "System.Data.SqlClient"
},
"Oracle": {
"connectionString": "Data Source=Tcp://127.0.0.1/ORC;User ID=sys;Password=admin;Owner=mis",
"providerName": "System.Data.OracleClient"
},
"PostgreSQL": {
"connectionString": "Server=.;Database=master;Uid=root;Pwd=root;",
"providerName": "PostgreSQL.Data.PostgreSQLClient"
},
"MSSQL2": {
"connectionString": "Server=.;Integrated Security=SSPI;Database=Test",
"providerName": "System.Data.SqlClient"
},
"Oracle2": {
"connectionString": "Data Source=orc;User ID=sys;Password=admin;",
"providerName": "System.Data.OracleClient"
},
//OLE DB Services=-1±íʾ´ò¿ªÁ¬½Ó³Ø
"Access": {
"connectionString": "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=~\\App_Data\\Test.mdb;Persist Security Info=False;OLE DB Services=-1",
"providerName": "Access"
},
"SqlCe": {
"connectionString": "Data Source=test.sdf;",
"providerName": "SqlCe"
}
}
}
Loading…
Cancel
Save