管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-02-08 6eafc81a275b14cc6a2fc653f883e94c0313bc43
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
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.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
    {
        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()
        {
            InitializeComponent();
            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;
 
            this.btnLoad.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);
            LogOut.Info("************  应用程序启动成功! ************");
        }
 
        // 登录
        private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            //win = new LoginWin();
            //this.Hide();
            //win.Show();
 
            SetLoginInfo();
        }
 
        public void SetLoginInfo()
        {
            //if (win != null) win.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.btnLoad.IsEnabled = true;
            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 Load_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SourcePath) || !Directory.Exists(SourcePath))
            {
                MessageBox.Show("请选择数据目录!", "提示");
                return;
            }
            if (string.IsNullOrEmpty(TargetPath) || !Directory.Exists(TargetPath))
            {
                MessageBox.Show("请选择入库目录!", "提示");
                return;
            }
 
            string[] files = Directory.GetFiles(SourcePath);
            if (null == files || files.Length == 0)
            {
                MessageBox.Show("数据目录下没有文件!", "提示");
                return;
            }
 
            this.viewDatas.Clear();
            Importor.GetFiles(viewDatas, SourcePath);
        }
 
        // 导入
        private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            if (viewDatas.Count == 0) return;
 
            Thread thread = new Thread(new ThreadStart(() =>
            {
                Importor.ImportFiles(viewDatas, TargetPath);
 
                lvView.Dispatcher.BeginInvoke((ThreadStart)delegate {
                    ICollectionView view = CollectionViewSource.GetDefaultView(viewDatas);
                    view.Refresh();
                });
 
                MessageBox.Show("数据导入完成!", "提示");
            }));
            thread.Start();
        }
    }
}