| | |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using System.Windows.Data; |
| | | using System.Windows.Forms.VisualStyles; |
| | | using System.Windows.Threading; |
| | | |
| | | namespace DataLoader |
| | | { |
| | |
| | | |
| | | public event PropertyChangedEventHandler PropertyChanged; |
| | | |
| | | private string _sourcePath= "D:\\LF\\data\\mdb"; |
| | | private string _sourcePath = "D:\\opting\\得文数据"; // "D:\\LF\\data\\mdb"; |
| | | |
| | | private string _targetPath= "D:\\LF\\upload"; |
| | | private string _targetPath = "D:\\LF\\upload"; |
| | | |
| | | private LoginWin win; |
| | | |
| | |
| | | |
| | | protected virtual void OnPropertyChanged(string propertyName = null) |
| | | { |
| | | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
| | | //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
| | | if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
| | | } |
| | | |
| | | private void Window_Loaded(object sender, RoutedEventArgs e) |
| | | { |
| | | Tool.Owner = this; |
| | | |
| | | this.btnLoad.IsEnabled = false; |
| | | this.btnImport.IsEnabled = false; |
| | | |
| | | lvView.DataContext = viewDatas; |
| | | lvView.SetBinding(ListView.ItemsSourceProperty, new Binding()); |
| | | |
| | |
| | | if (win != null) win.Close(); |
| | | this.Show(); |
| | | |
| | | this.tbUid.Text = Tool.UserId.ToString() + "," + Tool.Uname; |
| | | this.tbUid.Text = Tool.UserId.ToString() + "-" + Tool.Uname; |
| | | this.tbToken.Text = Tool.Token; |
| | | |
| | | this.btnLoad.IsEnabled = true; |
| | | this.btnImport.IsEnabled = true; |
| | | } |
| | | |
| | |
| | | this.TargetPath = dialog.SelectedPath.Trim(); |
| | | } |
| | | |
| | | // 导入 |
| | | private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | // 加载 |
| | | private void Load_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (string.IsNullOrEmpty(SourcePath) || !Directory.Exists(SourcePath)) |
| | | { |
| | | MessageBox.Show("请选择数据目录!"); |
| | | MessageBox.Show("请选择数据目录!", "提示"); |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(TargetPath) || !Directory.Exists(TargetPath)) |
| | | { |
| | | MessageBox.Show("请选择入库目录!"); |
| | | MessageBox.Show("请选择入库目录!", "提示"); |
| | | return; |
| | | } |
| | | string[] files = Directory.GetFiles(SourcePath); |
| | | if (null == files || files.Length == 0) |
| | | { |
| | | MessageBox.Show("数据目录下没有文件!"); |
| | | MessageBox.Show("数据目录下没有文件!", "提示"); |
| | | return; |
| | | } |
| | | |
| | | viewDatas.Clear(); |
| | | this.viewDatas.Clear(); |
| | | Importor.GetFiles(viewDatas, SourcePath); |
| | | } |
| | | |
| | | Dispatcher.Invoke(new Action(delegate |
| | | // 导入 |
| | | private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (viewDatas.Count == 0) return; |
| | | |
| | | Thread thread = new Thread(new ThreadStart(() => |
| | | { |
| | | this.btnImport.IsEnabled = false; |
| | | Importor.Import(viewDatas, SourcePath, TargetPath); |
| | | this.btnImport.IsEnabled = true; |
| | | Importor.ImportFiles(viewDatas, TargetPath); |
| | | |
| | | lvView.Dispatcher.BeginInvoke((ThreadStart)delegate { |
| | | ICollectionView view = CollectionViewSource.GetDefaultView(viewDatas); |
| | | view.Refresh(); |
| | | }); |
| | | |
| | | MessageBox.Show("数据导入完成!", "提示"); |
| | | })); |
| | | thread.Start(); |
| | | } |
| | | } |
| | | } |