123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using Aitex.UI.Charting.ViewModel;
- using System.Threading;
- using DataAnalysisControl.Core;
- using Aitex.UI.Charting.Model;
- namespace Aitex.UI.Charting.View
- {
- /// <summary>
- /// Interaction logic for DataSourceExportingDialog.xaml
- /// </summary>
- public partial class DataSeriesExportingDialog : Window
- {
- public DataSeriesExportingDialog(string uniqueDataId, string fileName)
- {
- InitializeComponent();
- _uniqueDataId = uniqueDataId;
- _viewModel = CommonViewModel.Instance;
- _line = _viewModel.GetDataLineSeries(uniqueDataId);
- if (_line == null)
- {
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_DataSeriesExportingDialog_zero_not_exist, uniqueDataId));
- }
- else
- {
- txt_Info.Content = string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_DataSeriesExportingDialog_exporting,
- uniqueDataId,
- _line.DataSource.BeginTime.ToString("yyyy/MM/dd HH:mm:ss"),
- _line.DataSource.EndTime.ToString("yyyy/MM/dd HH:mm:ss"));
- txt_Completed.Content = "50%";
- progressBar1.Value = 50;
- _archieveFilePath = fileName;
- _thread = new Thread(new ThreadStart(Task_Export));
- _thread.Name = "数据集导出线程";
- _thread.IsBackground = true;
- _thread.Start();
- }
- }
- CommonViewModel _viewModel;
- string _uniqueDataId;
- string _archieveFilePath;
- Thread _thread;
- MyLineSeries _line;
- private void Task_Export()
- {
- try
- {
- var source = _line.DataSource;
- DataItem datas;
- var ret = source.GetData(_line.SeriesName, source.BeginTime, source.EndTime, out datas);
- if (ret)
- {
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(_archieveFilePath))
- {
- fs.Write("Time");
- fs.Write(",");
- fs.WriteLine(datas.DataName);
- for (int i = 0; i < datas.RawData.Count; i++)
- {
- fs.Write(datas.TimeStamp[i].ToString("yyyy/MM/dd HH:mm:ss"));
- fs.Write(",");
- fs.WriteLine(datas.RawData[i].ToString());
- }
- }
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_Task_Export_export_ok, _uniqueDataId, _archieveFilePath), "DataExport",
- MessageBoxButton.OK, MessageBoxImage.Information);
- }
- else
- {
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_Task_Export_export_failed, _uniqueDataId), "DataExport", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- catch (Exception ex)
- {
- CONTEXT.WriteLog(ex, string.Format("导出数据{0}发生异常", _uniqueDataId));
- MessageBox.Show(string.Format(DataAnalysisControl.Properties.Resource.DataSeriesExportingDialog_Task_Export_export_error, ex.Message), "DataExport", 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();
- }
- }
- }
|