DataSourceView.xaml.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.UI.Charting.ViewModel;
  15. using Aitex.UI.Charting.Model;
  16. namespace Aitex.UI.Charting.View
  17. {
  18. /// <summary>
  19. /// Interaction logic for DataSourceView.xaml
  20. /// </summary>
  21. public partial class DataSourceView : UserControl
  22. {
  23. public DataSourceView()
  24. {
  25. InitializeComponent();
  26. Loaded += new RoutedEventHandler(DataSourceView_Loaded);
  27. _viewModel = new DataSourceViewModel();
  28. DataContext = _viewModel;
  29. }
  30. DataSourceViewModel _viewModel;
  31. void DataSourceView_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. //_viewModel = new DataSourceViewModel();
  34. //DataContext = _viewModel;
  35. }
  36. /// <summary>
  37. /// DataGrid的SelectionChange不支持ICommand接口,此处采用message handling方式处理
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. private void DataSource_SelectionChanged(object sender, SelectionChangedEventArgs e)
  42. {
  43. if(dataGrid_DataSources.SelectedItem != null)
  44. {
  45. CommonViewModel.Instance.CurrentSelectedDataSource = (IDataSource)dataGrid_DataSources.SelectedItem;
  46. }
  47. }
  48. #if false
  49. /// <summary>
  50. /// Template模板中的事件不能通过ICommand绑定
  51. /// </summary>
  52. /// <param name="sender"></param>
  53. /// <param name="e"></param>
  54. private void DataSource_SyncTime(object sender, SelectionChangedEventArgs e)
  55. {
  56. if (sender is ComboBox)
  57. {
  58. var combo = (ComboBox)sender;
  59. var selection = combo.SelectedItem as RecipeSyncPoint;
  60. string sourceName = (string)((ComboBox)sender).Tag;
  61. _viewModel.SyncSourceTimeCommand.Execute(new Tuple<string, DateTime, string>(sourceName, selection.StepTime, selection.StepName));
  62. }
  63. }
  64. #endif
  65. private void DataSource_Export(object sender, RoutedEventArgs e)
  66. {
  67. string sourceName = (string)((Button)sender).Tag;
  68. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  69. dlg.FileName = sourceName.Replace("/", "_").Replace(":", "_").Replace(" ", "_"); // Default file name
  70. dlg.DefaultExt = ".arch"; // Default file extension
  71. dlg.Filter = "Archive File (.arch)|*.arch"; // Filter files by extension
  72. // Show open file dialog box
  73. Nullable<bool> result = dlg.ShowDialog();
  74. if (result.HasValue && result.Value)
  75. {
  76. DataSourceExportingDialog processDialog = new DataSourceExportingDialog(sourceName, dlg.FileName) { Owner = Application.Current.MainWindow };
  77. processDialog.Show();
  78. }
  79. }
  80. private void DataSource_Remove(object sender, RoutedEventArgs e)
  81. {
  82. var sourceName = (string)((Button)sender).Tag;
  83. CommonViewModel.Instance.RemoveDataSource(sourceName);
  84. }
  85. }
  86. }