DataSourceViewModel.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.UI.Charting.Command;
  6. using System.Windows.Input;
  7. using Aitex.UI.Charting.View;
  8. using Aitex.UI.Charting.Model;
  9. using System.Windows;
  10. namespace Aitex.UI.Charting.ViewModel
  11. {
  12. public class DataSourceViewModel : ChartingBaseViewModel
  13. {
  14. public DataSourceViewModel()
  15. {
  16. CommonViewModel = CommonViewModel.Instance;
  17. ConfigDbConnectionCommand = new ChartingCommand((o) => true, (o) =>
  18. {
  19. DbConnConfig view = new DbConnConfig() { Owner = System.Windows.Application.Current.MainWindow };
  20. view.ShowDialog();
  21. });
  22. SelectDataSourceCommand = new ChartingCommand((o) => true, (o) =>
  23. {
  24. DataSourceSelection view = new DataSourceSelection() { Owner = System.Windows.Application.Current.MainWindow };
  25. view.ShowDialog();
  26. });
  27. SelectFileSourceCommand = new ChartingCommand((o) => true, (o) =>
  28. {
  29. Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  30. dlg.DefaultExt = ".arch"; // Default file extension
  31. dlg.Filter = "Archive File (.arch)|*.arch"; // Filter files by extension
  32. // Show open file dialog box
  33. Nullable<bool> result = dlg.ShowDialog();
  34. if (result.HasValue && result.Value)
  35. {
  36. string fileName = dlg.FileName;
  37. CommonViewModel.AddDataSource(new ArchievedFileDataSource(fileName));
  38. }
  39. });
  40. SyncSourceTimeCommand = new ChartingCommand((o) => true, (o) =>
  41. {
  42. var param = (Tuple<string, DateTime, string>)o;
  43. CommonViewModel.SyncSourceTime(param.Item1, param.Item2, param.Item3);
  44. });
  45. RemoveAllDataSourceCommand = new ChartingCommand((o) => true, (o) =>
  46. {
  47. if (MessageBox.Show("确认删除所有的数据源?", "数据操作", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  48. {
  49. CommonViewModel.RemoveDataSource(string.Empty);
  50. }
  51. });
  52. }
  53. public ICommand ConfigDbConnectionCommand { get; private set; }
  54. public ICommand SelectDataSourceCommand { get; private set; }
  55. public ICommand SelectFileSourceCommand { get; private set; }
  56. public ICommand SyncSourceTimeCommand { get; private set; }
  57. public ICommand RemoveAllDataSourceCommand { get; private set; }
  58. public CommonViewModel CommonViewModel { get; private set; }
  59. }
  60. }