管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-09-04 dbed0354a00fde9db87862b9f03db0fbf0d3aabc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
 
namespace DataLoader
{
    public partial class MainWindow : Window
    {
        private bool isBusy;
 
        public ResWin resWin;
 
        private LoginWin loginWin;
 
        private ObservableCollection<ViewData> viewDatas = new ObservableCollection<ViewData>();
 
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
        }
 
        // 窗口加载完成
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            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 md5 = MD5Helper.GetMD5Hash("E:\\data\\mpt\\A4mpt20131125.mpt");
            LogOut.Info("************  应用程序启动成功! ************");
        }
 
        // 获取元数据类型
        private List<MetaType> GetMetaTypes()
        {
            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("三维模型"));
 
            return list;
        }
 
        // 登录
        private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            loginWin = new LoginWin();
            this.Hide();
            loginWin.Show();
        }
 
        // 设置登录信息
        public void SetLoginInfo()
        {
            if (loginWin != null) loginWin.Close();
            this.Show();
 
            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(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;
 
            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(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;
 
            this.tbTarget.Text = CommonProp.TargetPath = dialog.SelectedPath.Trim();
        }
 
        // 加载
        private void Load_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            if (isBusy) return;
            if (string.IsNullOrEmpty(CommonProp.Dircode))
            {
                MessageBox.Show("请选择资源目录!", "提示");
                return;
            }
 
            CommonProp.SourcePath = this.tbSource.Text.Trim();
            if (string.IsNullOrEmpty(CommonProp.SourcePath) || !Directory.Exists(CommonProp.SourcePath))
            {
                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.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 (isBusy || viewDatas.Count == 0) return;
 
            this.isBusy = true;
            Thread thread = new Thread(new ThreadStart(() =>
            {
                Importor.ImportFiles(viewDatas);
 
                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;
            }
        }
    }
}