123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Threading;
- using Aitex.UI.Charting.Model;
- using Aitex.UI.Charting.ViewModel;
- using DataAnalysisControl.Core;
-
- namespace Aitex.UI.Charting.View
- {
- /// <summary>
- /// Interaction logic for DataSourceExportingDialog.xaml
- /// </summary>
- public partial class DataSeriesExportingAll : Window
- {
- public DataSeriesExportingAll(string fileName)
- {
- InitializeComponent();
- _viewModel = CommonViewModel.Instance;
- _lines = _viewModel.GetAllDataLineSeries();
- if (_lines == null)
- {
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_DataSeriesExportingAll_No_data));
- }
- else
- {
- txt_Info.Content = string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_DataSeriesExportingAll_exporting);
- txt_Completed.Content = "50%";
- progressBar1.Value = 50;
- _archieveFilePath = fileName;
- _thread = new Thread(new ThreadStart(Task_Export));
- _thread.Name = "data analysis export all thread";
- _thread.IsBackground = true;
- _thread.Start();
- }
- }
- CommonViewModel _viewModel;
- string _archieveFilePath;
- Thread _thread;
- List<MyLineSeries> _lines;
- private void Task_Export()
- {
- try
- {
- List<DataItem> datas;
- List<string> dataNames = new List<string>();
- foreach (MyLineSeries _line in _lines)
- {
- dataNames.Add(_line.SeriesName);
- }
- var source = _lines[0].DataSource;
- var ret = source.GetData(dataNames, source.BeginTime, source.EndTime, out datas);
- if (ret)
- {
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(_archieveFilePath))
- {
- fs.Write("Time");
- foreach (DataItem data in datas)
- {
- fs.Write(",");
- fs.Write(data.DataName);
- }
- fs.WriteLine("");
- for (int i = 0; i < datas[0].RawData.Count; i++)
- {
- fs.Write(datas[0].TimeStamp[i].ToString("yyyy/MM/dd HH:mm:ss"));
- foreach (DataItem data in datas)
- {
- fs.Write(",");
- fs.Write(data.RawData[i].ToString());
- }
- fs.WriteLine("");
- }
- }
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_Task_Export_exportto, _archieveFilePath), DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_Task_Export_data_export,
- MessageBoxButton.OK, MessageBoxImage.Information);
- }
- else
- {
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_Task_Export_export_error), DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_Task_Export_data_export, MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- catch (Exception ex)
- {
- CONTEXT.WriteLog(ex, string.Format("导出数据发生异常"));
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_Task_Export_export_error, ex.Message), DataAnalysisControl.Properties.Resource.DataSeriesExportingAll_Task_Export_data_export, MessageBoxButton.OK, MessageBoxImage.Error);
- }
- finally
- {
- this.Dispatcher.BeginInvoke(new Action(() => { Close(); }));
- }
- }
- private void btnAbort_Click(object sender, RoutedEventArgs e)
- {
- if(_thread != null)
- _thread.Abort();
- Close();
- }
- }
- }
|