管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-09-04 dbed0354a00fde9db87862b9f03db0fbf0d3aabc
DataLoader/MainWindow.xaml.cs
@@ -15,6 +15,8 @@
{
    public partial class MainWindow : Window
    {
        private bool isBusy;
        public ResWin resWin;
        private LoginWin loginWin;
@@ -27,14 +29,14 @@
            this.DataContext = this;
        }
        // 窗口加载完成
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CommonProp.Owner = this;
            CommonProp.Init();
            //this.cbMetaType.ItemsSource= GetMetaTypes();
            //this.cbMetaType.SelectedIndex= 0;
            this.btnLoad.IsEnabled = false;
            this.btnDel.IsEnabled = false;
            this.btnImport.IsEnabled = false;
            lvView.DataContext = viewDatas;
@@ -44,6 +46,7 @@
            LogOut.Info("************  应用程序启动成功! ************");
        }
        // 获取元数据类型
        private List<MetaType> GetMetaTypes()
        {
            List<MetaType> list = new List<MetaType>();
@@ -59,7 +62,7 @@
            return list;
        }
        // 设置
        // 登录
        private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            loginWin = new LoginWin();
@@ -67,6 +70,7 @@
            loginWin.Show();
        }
        // 设置登录信息
        public void SetLoginInfo()
        {
            if (loginWin != null) loginWin.Close();
@@ -83,14 +87,14 @@
        // 资源目录
        private void Dir_MouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            resWin = new ResWin();
            if (null == resWin) resWin = new ResWin();
            this.Hide();
            resWin.Show();
            this.resWin.Show();
        }
        // 设置资源信息
        public void SetRes(string dircode, string fullName)
        {
            if (resWin != null) resWin.Close();
            this.Show();
            if (!string.IsNullOrEmpty(dircode))
@@ -127,40 +131,67 @@
        // 加载
        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;
            //}
            if (isBusy) return;
            if (string.IsNullOrEmpty(CommonProp.Dircode))
            {
                MessageBox.Show("请选择资源目录!", "提示");
                return;
            }
            //string[] files = Directory.GetFiles(SourcePath);
            //if (null == files || files.Length == 0)
            //{
            //    MessageBox.Show("数据目录下没有文件!", "提示");
            //    return;
            //}
            CommonProp.SourcePath = this.tbSource.Text.Trim();
            if (string.IsNullOrEmpty(CommonProp.SourcePath) || !Directory.Exists(CommonProp.SourcePath))
            {
                MessageBox.Show("请选择数据目录或数据目录不存在!", "提示");
                return;
            }
            //this.viewDatas.Clear();
            //Importor.GetFiles(viewDatas, SourcePath);
            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 (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
                {
@@ -168,9 +199,21 @@
                    view.Refresh();
                });
                isBusy = false;
                MessageBox.Show("数据导入完成!", "提示");
            }));
            thread.Start();
        }
        // 窗口关闭中事件
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (isBusy)
            {
                MessageBox.Show("正在导入数据,请稍后~", "提示");
                e.Cancel = true;
                return;
            }
        }
    }
}