123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using Aitex.UI.Charting.ViewModel;
- namespace Aitex.UI.Charting.View
- {
- /// <summary>
- /// Interaction logic for DataSeriesEdit.xaml
- /// </summary>
- public partial class DataSeriesEdit : UserControl
- {
- public DataSeriesEdit()
- {
- InitializeComponent();
- dataGrid_DataList.CanUserAddRows = false;
- dataGrid_DataList.CanUserAddRows = false;
- Loaded += new RoutedEventHandler(DataSeriesEdit_Loaded);
- }
- void DataSeriesEdit_Loaded(object sender, RoutedEventArgs e)
- {
- _viewModel = new DataSeriesEditViewModel();
- DataContext = _viewModel;
- }
- DataSeriesEditViewModel _viewModel;
- #if false
- private void dataGrid_DataConfig_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- dataGrid_DataList.Items.Refresh();
- var cm = new System.Windows.Controls.ContextMenu();
- this.dataGrid_DataList.ContextMenu = cm;
- var mi = new MenuItem() { Header = "添加当前数据列表" };
- //mi.Click += new RoutedEventHandler(Save_Data_Config_Click);
- cm.Items.Add(mi);
- mi = new MenuItem() { Header = "管理已存数据列表" };
- //mi.Click += new RoutedEventHandler(Manager_Data_Config_Click);
- cm.Items.Add(mi);
- mi = new MenuItem() { Header = "删除所有选择的数据" };
- mi.Click += (s1, e1) =>
- {
- _viewModel.CommonViewModel.RemoveDataSeries(null);
- dataGrid_DataList.CancelEdit();
- dataGrid_DataList.Items.Refresh();
- };
- cm.Items.Add(mi);
- try
- {
- var fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
- fileName = fileName.Substring(0, fileName.LastIndexOf("\\")) + "\\charting.xml";
- System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
- if (fi.Exists)
- {
- cm.Items.Add(new Separator());
- XmlDocument doc = new XmlDocument();
- doc.Load(fileName);
- foreach (XmlElement node in doc.SelectNodes("/Aitex/DataPreset/Data"))
- {
- var it = new MenuItem() { Header = "载入 " + node.Attributes["Name"].Value, Tag = node.Attributes["Name"].Value };
- //it.Click += new RoutedEventHandler(Load_Data_Config_Click);
- cm.Items.Add(it);
- }
- }
- cm.Visibility = System.Windows.Visibility.Visible;
- }
- catch (Exception ex)
- {
- CONTEXT.WriteLog(ex);
- }
- }
- #endif
- private void OnRemoveChartingItem(object sender, RoutedEventArgs e)
- {
- string seriesId = (string)(sender as Button).Tag;
- _viewModel.CommonViewModel.RemoveDataSeries(seriesId);
- }
- private void OnExportingData2File(object sender, RoutedEventArgs e)
- {
- string seriesId = (string)(sender as Button).Tag;
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.FileName = seriesId.Replace("/", "_").Replace(":", "_").Replace(" ", "_"); // Default file name
- dlg.DefaultExt = ".csv"; // Default file extension
- dlg.Filter = "Excel (.csv)|*.csv"; // Filter files by extension
- // Show open file dialog box
- Nullable<bool> result = dlg.ShowDialog();
- if (result.HasValue && result.Value)
- {
- DataSeriesExportingDialog processDialog = new DataSeriesExportingDialog(seriesId, dlg.FileName) { Owner = Application.Current.MainWindow };
- processDialog.Show();
- }
- }
- private void OnChangeLineColor(object sender, RoutedEventArgs e)
- {
- var btn = (Button)sender;
- if (btn != null)
- {
- string dataId = (string)btn.Tag;
- var color = _viewModel.ChangeLineColorCommand();
- if (color.HasValue)
- {
- var line = CommonViewModel.Instance.GetDataLineSeries(dataId);
- if(line != null)
- line.SeriesColor = color.Value;
- }
- }
- }
- private void OnChangeDrawingItemVisibility(object sender, RoutedEventArgs e)
- {
- var checkbox = (CheckBox)sender;
- if (checkbox != null && checkbox.IsChecked.HasValue)
- {
- string dataId = (string)checkbox.Tag;
- var line = CommonViewModel.Instance.GetDataLineSeries(dataId);
- if (line != null)
- line.IsVisible = checkbox.IsChecked.Value;
- }
- }
- }
- }
|