using DataLoader.CS;
|
using DataLoader.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.IO;
|
using System.Linq;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Data;
|
using System.Windows.Forms.VisualStyles;
|
|
namespace DataLoader
|
{
|
public partial class MainWindow : Window, INotifyPropertyChanged
|
{
|
private ObservableCollection<ViewData> viewDatas = new ObservableCollection<ViewData>();
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
private string _sourcePath;
|
|
private string _targetPath;
|
|
private LoginWin win;
|
|
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)
|
{
|
Main.Owner = this;
|
|
this.btnImport.IsEnabled = false;
|
lvView.DataContext = viewDatas;
|
lvView.SetBinding(ListView.ItemsSourceProperty, new Binding());
|
}
|
|
|
// 登录
|
private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e)
|
{
|
win = new LoginWin();
|
this.Hide();
|
win.Show();
|
}
|
|
public void SetLoginInfo()
|
{
|
if (win != null) win.Close();
|
this.Show();
|
|
this.tbUid.Text = Main.UserId.ToString() + "," + Main.Uname;
|
this.tbToken.Text = Main.Token;
|
this.btnImport.IsEnabled = true;
|
}
|
|
// 源目录
|
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, 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, RoutedEventArgs e)
|
{
|
viewDatas.Clear();
|
|
Dispatcher.Invoke(new Action(delegate
|
{
|
this.btnImport.IsEnabled = false;
|
Importor.Import(viewDatas, SourcePath, TargetPath);
|
this.btnImport.IsEnabled = true;
|
}));
|
}
|
}
|
}
|