DataSeriesEdit.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using Aitex.UI.Charting.ViewModel;
  5. namespace Aitex.UI.Charting.View
  6. {
  7. /// <summary>
  8. /// Interaction logic for DataSeriesEdit.xaml
  9. /// </summary>
  10. public partial class DataSeriesEdit : UserControl
  11. {
  12. public DataSeriesEdit()
  13. {
  14. InitializeComponent();
  15. dataGrid_DataList.CanUserAddRows = false;
  16. dataGrid_DataList.CanUserAddRows = false;
  17. Loaded += new RoutedEventHandler(DataSeriesEdit_Loaded);
  18. }
  19. void DataSeriesEdit_Loaded(object sender, RoutedEventArgs e)
  20. {
  21. _viewModel = new DataSeriesEditViewModel();
  22. DataContext = _viewModel;
  23. }
  24. DataSeriesEditViewModel _viewModel;
  25. #if false
  26. private void dataGrid_DataConfig_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  27. {
  28. dataGrid_DataList.Items.Refresh();
  29. var cm = new System.Windows.Controls.ContextMenu();
  30. this.dataGrid_DataList.ContextMenu = cm;
  31. var mi = new MenuItem() { Header = "添加当前数据列表" };
  32. //mi.Click += new RoutedEventHandler(Save_Data_Config_Click);
  33. cm.Items.Add(mi);
  34. mi = new MenuItem() { Header = "管理已存数据列表" };
  35. //mi.Click += new RoutedEventHandler(Manager_Data_Config_Click);
  36. cm.Items.Add(mi);
  37. mi = new MenuItem() { Header = "删除所有选择的数据" };
  38. mi.Click += (s1, e1) =>
  39. {
  40. _viewModel.CommonViewModel.RemoveDataSeries(null);
  41. dataGrid_DataList.CancelEdit();
  42. dataGrid_DataList.Items.Refresh();
  43. };
  44. cm.Items.Add(mi);
  45. try
  46. {
  47. var fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  48. fileName = fileName.Substring(0, fileName.LastIndexOf("\\")) + "\\charting.xml";
  49. System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
  50. if (fi.Exists)
  51. {
  52. cm.Items.Add(new Separator());
  53. XmlDocument doc = new XmlDocument();
  54. doc.Load(fileName);
  55. foreach (XmlElement node in doc.SelectNodes("/Aitex/DataPreset/Data"))
  56. {
  57. var it = new MenuItem() { Header = "载入 " + node.Attributes["Name"].Value, Tag = node.Attributes["Name"].Value };
  58. //it.Click += new RoutedEventHandler(Load_Data_Config_Click);
  59. cm.Items.Add(it);
  60. }
  61. }
  62. cm.Visibility = System.Windows.Visibility.Visible;
  63. }
  64. catch (Exception ex)
  65. {
  66. CONTEXT.WriteLog(ex);
  67. }
  68. }
  69. #endif
  70. private void OnRemoveChartingItem(object sender, RoutedEventArgs e)
  71. {
  72. string seriesId = (string)(sender as Button).Tag;
  73. _viewModel.CommonViewModel.RemoveDataSeries(seriesId);
  74. }
  75. private void OnExportingData2File(object sender, RoutedEventArgs e)
  76. {
  77. string seriesId = (string)(sender as Button).Tag;
  78. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  79. dlg.FileName = seriesId.Replace("/", "_").Replace(":", "_").Replace(" ", "_"); // Default file name
  80. dlg.DefaultExt = ".csv"; // Default file extension
  81. dlg.Filter = "Excel (.csv)|*.csv"; // Filter files by extension
  82. // Show open file dialog box
  83. Nullable<bool> result = dlg.ShowDialog();
  84. if (result.HasValue && result.Value)
  85. {
  86. DataSeriesExportingDialog processDialog = new DataSeriesExportingDialog(seriesId, dlg.FileName) { Owner = Application.Current.MainWindow };
  87. processDialog.Show();
  88. }
  89. }
  90. private void OnChangeLineColor(object sender, RoutedEventArgs e)
  91. {
  92. var btn = (Button)sender;
  93. if (btn != null)
  94. {
  95. string dataId = (string)btn.Tag;
  96. var color = _viewModel.ChangeLineColorCommand();
  97. if (color.HasValue)
  98. {
  99. var line = CommonViewModel.Instance.GetDataLineSeries(dataId);
  100. if(line != null)
  101. line.SeriesColor = color.Value;
  102. }
  103. }
  104. }
  105. private void OnChangeDrawingItemVisibility(object sender, RoutedEventArgs e)
  106. {
  107. var checkbox = (CheckBox)sender;
  108. if (checkbox != null && checkbox.IsChecked.HasValue)
  109. {
  110. string dataId = (string)checkbox.Tag;
  111. var line = CommonViewModel.Instance.GetDataLineSeries(dataId);
  112. if (line != null)
  113. line.IsVisible = checkbox.IsChecked.Value;
  114. }
  115. }
  116. }
  117. }