From 95869b034691c668ea854bc3e6315f0f1ff84b91 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 01 一月 2023 09:21:43 +0800 Subject: [PATCH] 1 --- DataLoader/MainWindow.xaml.cs | 77 +++++++++++++++++++++---- DataLoader/MainWindow.xaml | 47 ++++++++++----- DataLoader/DataLoader.csproj | 1 3 files changed, 96 insertions(+), 29 deletions(-) diff --git a/DataLoader/DataLoader.csproj b/DataLoader/DataLoader.csproj index 4db963d..4013be1 100644 --- a/DataLoader/DataLoader.csproj +++ b/DataLoader/DataLoader.csproj @@ -50,6 +50,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Core" /> diff --git a/DataLoader/MainWindow.xaml b/DataLoader/MainWindow.xaml index 5d46b51..5f9bbfb 100644 --- a/DataLoader/MainWindow.xaml +++ b/DataLoader/MainWindow.xaml @@ -4,6 +4,29 @@ Height="480" Width="600" Loaded="Window_Loaded" Title="鏁版嵁鍏ュ簱" WindowStartupLocation="CenterScreen"> + <Window.Resources> + <Style x:Key="btn" TargetType="Button"> + <Setter Property="Background" Value="#005699"/> + <Setter Property="BorderBrush" Value="#136BAF"/> + <Setter Property="BorderThickness" Value="1"/> + <Setter Property="Foreground" Value="White"/> + <Setter Property="FontSize" Value="15"/> + <Setter Property="Width" Value="60"/> + <Setter Property="Height" Value="30"/> + <Setter Property="Cursor" Value="Hand"/> + <Style.Triggers> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Foreground" Value="Red"/> + </Trigger> + </Style.Triggers> + </Style> + <Style x:Key="tb" TargetType="TextBox"> + <Setter Property="VerticalAlignment" Value="Center"/> + <Setter Property="HorizontalAlignment" Value="Stretch"/> + <Setter Property="Height" Value="30"/> + <Setter Property="FontSize" Value="20"/> + </Style> + </Window.Resources> <Grid x:Name="gMain"> <Grid.RowDefinitions> <RowDefinition Height="40"/> @@ -23,24 +46,18 @@ </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0" Content="鐢ㄦ埛ID锛�" VerticalAlignment="Center" HorizontalAlignment="Right" /> - <TextBox x:Name="tbUid" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="30" FontSize="20"/> + <TextBox x:Name="tbUid" Grid.Row="0" Grid.Column="1" Style="{StaticResource tb}" IsReadOnly="True"/> <Label Grid.Row="0" Grid.Column="2" Content="浠ょ墝锛�" VerticalAlignment="Center" HorizontalAlignment="Right" /> - <TextBox x:Name="tbToken" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="30" FontSize="20"/> - <Border Grid.Row="0" Grid.Column="4" BorderBrush="#136BAF" BorderThickness="1" Cursor="Hand" Width="60" Height="30"> - <TextBlock Text="鐧� 褰�" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" MouseLeftButtonDown="Login_MouseLeftButtonDown"/> - </Border> + <TextBox x:Name="tbToken" Grid.Row="0" Grid.Column="3" Style="{StaticResource tb}" IsReadOnly="True"/> + <Button Grid.Row="0" Grid.Column="4" Content="鐧� 褰�" Style="{StaticResource btn}" Click="Login_MouseLeftButtonDown"/> <Label Grid.Row="1" Grid.Column="0" Content="婧愮洰褰曪細" VerticalAlignment="Center" HorizontalAlignment="Right" /> - <TextBox x:Name="tbSource" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="30" FontSize="20"/> - <Border Grid.Row="1" Grid.Column="4" BorderBrush="#136BAF" BorderThickness="1" Cursor="Hand" Width="60" Height="30"> - <TextBlock Text="閫� 鎷�" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" MouseLeftButtonDown="Source_MouseLeftButtonDown"/> - </Border> + <TextBox x:Name="tbSource" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource tb}" Text="{Binding Path=SourcePath, Mode=TwoWay}"/> + <Button Grid.Row="1" Grid.Column="4" Content="閫� 鎷�" Style="{StaticResource btn}" Click="Source_MouseLeftButtonDown"/> <Label Grid.Row="2" Grid.Column="0" Content="鍏ュ簱鐩綍锛�" VerticalAlignment="Center" HorizontalAlignment="Right" /> - <TextBox x:Name="tbTarget" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="30" FontSize="20"/> - <Border Grid.Row="2" Grid.Column="4" BorderBrush="#136BAF" BorderThickness="1" Cursor="Hand" Width="60" Height="30"> - <TextBlock Text="閫� 鎷�" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" MouseLeftButtonDown="Target_MouseLeftButtonDown"/> - </Border> + <TextBox x:Name="tbTarget" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource tb}" Text="{Binding Path=TargetPath, Mode=TwoWay}"/> + <Button Grid.Row="2" Grid.Column="4" Content="閫� 鎷�" Style="{StaticResource btn}" Click="Target_MouseLeftButtonDown"/> <ScrollViewer Grid.Row="3" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="4" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="2"> <ListView x:Name="lvView"> @@ -55,8 +72,6 @@ </ListView.View> </ListView> </ScrollViewer> - <Border Grid.Row="3" Grid.Column="4" BorderBrush="#136BAF" BorderThickness="1" Cursor="Hand" Width="60" Height="30"> - <TextBlock Text="瀵� 鍏�" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" MouseLeftButtonDown="Import_MouseLeftButtonDown"/> - </Border> + <Button Grid.Row="3" Grid.Column="4" Content="瀵� 鍏�" Style="{StaticResource btn}" Click="Import_MouseLeftButtonDown"/> </Grid> </Window> diff --git a/DataLoader/MainWindow.xaml.cs b/DataLoader/MainWindow.xaml.cs index 0615a44..26c564e 100644 --- a/DataLoader/MainWindow.xaml.cs +++ b/DataLoader/MainWindow.xaml.cs @@ -2,28 +2,60 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; +using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace DataLoader { - public partial class MainWindow : Window + public partial class MainWindow : Window, INotifyPropertyChanged { private ObservableCollection<ViewData> viewDatas = new ObservableCollection<ViewData>(); + + public event PropertyChangedEventHandler PropertyChanged; + + private string _sourcePath; + + private string _targetPath; + + public string SourcePath + { + get { return _sourcePath; } + set + { + if (!String.IsNullOrEmpty(value) && Directory.Exists(value)) + { + _sourcePath = value; + PropertyChanged(this, new PropertyChangedEventArgs("SourcePath")); + } + } + } + + public string TargetPath + { + get { return _targetPath; } + set + { + if (!String.IsNullOrEmpty(value) && Directory.Exists(value)) + { + _targetPath = value; + PropertyChanged(this, new PropertyChangedEventArgs("TargetPath")); + } + } + } public MainWindow() { InitializeComponent(); + this.DataContext = this; + } + + protected virtual void OnPropertyChanged(string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private void Window_Loaded(object sender, RoutedEventArgs e) @@ -34,26 +66,45 @@ lvView.SetBinding(ListView.ItemsSourceProperty, new Binding()); } + // 鐧诲綍 - private void Login_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e) { } // 婧愮洰褰� - private void Source_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void Source_MouseLeftButtonDown(object sender, RoutedEventArgs e) { + System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); + if (!String.IsNullOrEmpty(SourcePath) && Directory.Exists(SourcePath)) dialog.SelectedPath = SourcePath; + System.Windows.Forms.DialogResult result = dialog.ShowDialog(); + if (result == System.Windows.Forms.DialogResult.Cancel) + { + return; + } + + this.SourcePath = dialog.SelectedPath.Trim(); } // 鐩爣鐩綍 - private void Target_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void Target_MouseLeftButtonDown(object sender, RoutedEventArgs e) { + System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); + if (!String.IsNullOrEmpty(TargetPath) && Directory.Exists(TargetPath)) dialog.SelectedPath = TargetPath; + System.Windows.Forms.DialogResult result = dialog.ShowDialog(); + if (result == System.Windows.Forms.DialogResult.Cancel) + { + return; + } + + this.TargetPath = dialog.SelectedPath.Trim(); } // 瀵煎叆 - private void Import_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) { viewDatas.Add(new ViewData() { ID = 1, FilePath = "c:\\", Status = "鍔犺浇涓�" }); viewDatas.Add(new ViewData() { ID = 2, FilePath = "c:\\", Status = "瀹屾垚" }); -- Gitblit v1.9.3