From 566e0d21293a5fe6423fd7a16541bce00eeb2e38 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 27 九月 2024 11:15:21 +0800
Subject: [PATCH] OK

---
 DataLoader/MainWindow.xaml.cs |  208 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 149 insertions(+), 59 deletions(-)

diff --git a/DataLoader/MainWindow.xaml.cs b/DataLoader/MainWindow.xaml.cs
index f297ef8..3b7ddd5 100644
--- a/DataLoader/MainWindow.xaml.cs
+++ b/DataLoader/MainWindow.xaml.cs
@@ -1,54 +1,27 @@
 锘縰sing 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;
-using System.Windows.Forms.VisualStyles;
 
 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;
-
-        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()
         {
@@ -56,74 +29,191 @@
             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;
+            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("鏁板瓧姝e皠褰卞儚鍥�"));
+            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)
         {
-            win = new LoginWin();
+            loginWin = new LoginWin();
             this.Hide();
-            win.Show();
+            loginWin.Show();
         }
 
+        // 璁剧疆鐧诲綍淇℃伅
         public void SetLoginInfo()
         {
-            if (win != null) win.Close();
+            if (loginWin != null) loginWin.Close();
             this.Show();
 
-            this.tbUid.Text = Main.UserId.ToString() + "锛�" + Main.Uname;
-            this.tbToken.Text = Main.Token;
+            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)
+            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;
             }
 
-            this.TargetPath = dialog.SelectedPath.Trim();
+            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)
         {
-            viewDatas.Add(new ViewData() { ID = 1, FilePath = "c:\\", Status = "鍔犺浇涓�" });
-            viewDatas.Add(new ViewData() { ID = 2, FilePath = "c:\\", Status = "瀹屾垚" });
+            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湪瀵煎叆鏁版嵁锛岃绋嶅悗~", "鎻愮ず");
+                e.Cancel = true;
+                return;
+            }
         }
     }
 }

--
Gitblit v1.9.3