| | |
| | | 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 partial class MainWindow : Window, INotifyPropertyChanged |
| | | public partial class MainWindow : Window |
| | | { |
| | | private bool isBusy; |
| | | |
| | | public ResWin resWin; |
| | | |
| | | private LoginWin loginWin; |
| | | |
| | | private ObservableCollection<ViewData> viewDatas = new ObservableCollection<ViewData>(); |
| | | |
| | | public event PropertyChangedEventHandler PropertyChanged; |
| | | |
| | | private string _sourcePath = @"D:\LF\data\mdb"; |
| | | |
| | | private string _targetPath = @"\\LAPTOP-DRTGLTU2\share"; |
| | | |
| | | 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() |
| | | { |
| | |
| | | this.DataContext = this; |
| | | } |
| | | |
| | | protected virtual void OnPropertyChanged(string propertyName = null) |
| | | { |
| | | //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; |
| | | CommonProp.Owner = this; |
| | | CommonProp.Init(); |
| | | |
| | | this.btnLoad.IsEnabled = false; |
| | | this.btnDel.IsEnabled = false; |
| | | this.btnImport.IsEnabled = false; |
| | | |
| | | lvView.DataContext = viewDatas; |
| | | lvView.SetBinding(ListView.ItemsSourceProperty, new Binding()); |
| | | |
| | | //String file = "E:\\data\\mpt\\A4mpt20131125.mpt"; |
| | | //string md5 = MD5Helper.GetMD5Hash(file); |
| | | // string md5 = MD5Helper.GetMD5Hash("E:\\data\\mpt\\A4mpt20131125.mpt"); |
| | | LogOut.Info("************ 应用程序启动成功! ************"); |
| | | } |
| | | |
| | | // 设置 |
| | | private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | // 获取元数据类型 |
| | | private List<MetaType> GetMetaTypes() |
| | | { |
| | | //win = new LoginWin(); |
| | | //this.Hide(); |
| | | //win.Show(); |
| | | List<MetaType> list = new List<MetaType>(); |
| | | list.Add(new MetaType("默认")); |
| | | list.Add(new MetaType("数字正射影像图")); |
| | | list.Add(new MetaType("数字高程模型")); |
| | | list.Add(new MetaType("单波段栅格数据")); |
| | | list.Add(new MetaType("多光谱栅格数据")); |
| | | list.Add(new MetaType("高光谱栅格数据")); |
| | | list.Add(new MetaType("矢量图层")); |
| | | list.Add(new MetaType("三维模型")); |
| | | |
| | | //SetLoginInfo(); |
| | | //GdalHelper.Instance.ReadTiff(); |
| | | GdalHelper.Instance.GenerateTiles(); |
| | | return list; |
| | | } |
| | | |
| | | // 登录 |
| | | private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | loginWin = new LoginWin(); |
| | | this.Hide(); |
| | | loginWin.Show(); |
| | | } |
| | | |
| | | // 设置登录信息 |
| | | public void SetLoginInfo() |
| | | { |
| | | //if (win != null) win.Close(); |
| | | //this.Show(); |
| | | if (loginWin != null) loginWin.Close(); |
| | | this.Show(); |
| | | |
| | | //this.tbUid.Text = Tool.UserId.ToString(); |
| | | //this.tbToken.Text = Tool.Token; |
| | | |
| | | string uidStr = this.tbUid.Text.Trim(); |
| | | string didStr = this.tbDir.Text.Trim(); |
| | | |
| | | int.TryParse(uidStr, out Tool.UserId); |
| | | int.TryParse(didStr, out Tool.DirId); |
| | | this.tbUid.Text = CommonProp.UserId.ToString(); |
| | | this.tbUname.Text = CommonProp.Uname; |
| | | this.tbToken.Text = CommonProp.Token; |
| | | |
| | | this.btnLoad.IsEnabled = true; |
| | | this.btnImport.IsEnabled = true; |
| | | } |
| | | |
| | | // 源目录 |
| | | // 资源目录 |
| | | private void Dir_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (null == resWin) resWin = new ResWin(); |
| | | this.Hide(); |
| | | this.resWin.Show(); |
| | | } |
| | | |
| | | // 设置资源信息 |
| | | public void SetRes(string dircode, string fullName) |
| | | { |
| | | this.Show(); |
| | | |
| | | if (!string.IsNullOrEmpty(dircode)) |
| | | { |
| | | CommonProp.Dircode = dircode; |
| | | this.tbDir.Text = fullName; |
| | | } |
| | | } |
| | | |
| | | // 数据目录 |
| | | 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; |
| | | if (!String.IsNullOrEmpty(CommonProp.SourcePath) && Directory.Exists(CommonProp.SourcePath)) dialog.SelectedPath = CommonProp.SourcePath; |
| | | |
| | | System.Windows.Forms.DialogResult result = dialog.ShowDialog(); |
| | | if (result == System.Windows.Forms.DialogResult.Cancel) |
| | | { |
| | | return; |
| | | } |
| | | if (result == System.Windows.Forms.DialogResult.Cancel) return; |
| | | |
| | | this.SourcePath = dialog.SelectedPath.Trim(); |
| | | this.tbSource.Text = CommonProp.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; |
| | | if (!String.IsNullOrEmpty(CommonProp.TargetPath) && Directory.Exists(CommonProp.TargetPath)) dialog.SelectedPath = CommonProp.TargetPath; |
| | | |
| | | System.Windows.Forms.DialogResult result = dialog.ShowDialog(); |
| | | if (result == System.Windows.Forms.DialogResult.Cancel) |
| | | { |
| | | return; |
| | | } |
| | | if (result == System.Windows.Forms.DialogResult.Cancel) return; |
| | | |
| | | this.TargetPath = dialog.SelectedPath.Trim(); |
| | | this.tbTarget.Text = CommonProp.TargetPath = dialog.SelectedPath.Trim(); |
| | | } |
| | | |
| | | // 加载 |
| | | private void Load_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (string.IsNullOrEmpty(SourcePath) || !Directory.Exists(SourcePath)) |
| | | if (isBusy) return; |
| | | if (string.IsNullOrEmpty(CommonProp.Dircode)) |
| | | { |
| | | 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) |
| | | CommonProp.SourcePath = this.tbSource.Text.Trim(); |
| | | if (string.IsNullOrEmpty(CommonProp.SourcePath) || !Directory.Exists(CommonProp.SourcePath)) |
| | | { |
| | | MessageBox.Show("数据目录下没有文件!", "提示"); |
| | | MessageBox.Show("请选择数据目录或数据目录不存在!", "提示"); |
| | | return; |
| | | } |
| | | |
| | | CommonProp.TargetPath = this.tbTarget.Text.Trim(); |
| | | if (string.IsNullOrEmpty(CommonProp.TargetPath) || !Directory.Exists(CommonProp.TargetPath)) |
| | | { |
| | | MessageBox.Show("请选择入库目录或入库目录不存在!", "提示"); |
| | | return; |
| | | } |
| | | |
| | | ContentControl ccSensor = this.tbSensorType.SelectedItem as ContentControl; |
| | | int.TryParse(ccSensor.Tag.ToString(), out CommonProp.SensorType); |
| | | |
| | | ContentControl ccMeta = this.cbMetaType.SelectedItem as ContentControl; |
| | | int.TryParse(ccMeta.Tag.ToString(), out CommonProp.MetaType); |
| | | |
| | | CommonProp.AcqTime = this.dpAcqTime.SelectedDate; |
| | | |
| | | this.isBusy = true; |
| | | this.viewDatas.Clear(); |
| | | Importor.GetFiles(viewDatas, SourcePath); |
| | | Importor.Loading(viewDatas); |
| | | this.isBusy = false; |
| | | } |
| | | |
| | | // 删除 |
| | | private void Del_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (null == this.viewDatas || this.viewDatas.Count == 0) return; |
| | | |
| | | int i = 0; |
| | | while (i < this.viewDatas.Count) |
| | | { |
| | | if (this.viewDatas[i] != null && this.viewDatas[i].Checked) |
| | | { |
| | | this.viewDatas.RemoveAt(i); |
| | | continue; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | // 导入 |
| | | private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (viewDatas.Count == 0) return; |
| | | if (isBusy || viewDatas.Count == 0) return; |
| | | |
| | | string str = this.tbStart.Text.Trim(); |
| | | int start = 1; |
| | | int.TryParse(str, out start); |
| | | |
| | | this.isBusy = true; |
| | | Thread thread = new Thread(new ThreadStart(() => |
| | | { |
| | | Importor.ImportFiles(viewDatas, TargetPath, start); |
| | | Importor.ImportFiles(viewDatas); |
| | | |
| | | lvView.Dispatcher.BeginInvoke((ThreadStart)delegate { |
| | | lvView.Dispatcher.BeginInvoke((ThreadStart)delegate |
| | | { |
| | | ICollectionView view = CollectionViewSource.GetDefaultView(viewDatas); |
| | | view.Refresh(); |
| | | }); |
| | | |
| | | isBusy = false; |
| | | MessageBox.Show("数据导入完成!", "提示"); |
| | | })); |
| | | thread.Start(); |
| | | } |
| | | |
| | | // 窗口关闭中事件 |
| | | private void Window_Closing(object sender, CancelEventArgs e) |
| | | { |
| | | if (isBusy) |
| | | { |
| | | MessageBox.Show("正在导入数据,请稍后~", "提示"); |
| | | e.Cancel = true; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |