using System; using System.Collections.Generic; using System.Linq; using System.Text; using Aitex.UI.Charting.Command; using System.Windows.Input; using Aitex.UI.Charting.View; using Aitex.UI.Charting.Model; using System.Windows; namespace Aitex.UI.Charting.ViewModel { public class DataSourceViewModel : ChartingBaseViewModel { public DataSourceViewModel() { CommonViewModel = CommonViewModel.Instance; ConfigDbConnectionCommand = new ChartingCommand((o) => true, (o) => { DbConnConfig view = new DbConnConfig() { Owner = System.Windows.Application.Current.MainWindow }; view.ShowDialog(); }); SelectDataSourceCommand = new ChartingCommand((o) => true, (o) => { DataSourceSelection view = new DataSourceSelection() { Owner = System.Windows.Application.Current.MainWindow }; view.ShowDialog(); }); SelectFileSourceCommand = new ChartingCommand((o) => true, (o) => { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".arch"; // Default file extension dlg.Filter = "Archive File (.arch)|*.arch"; // Filter files by extension // Show open file dialog box Nullable result = dlg.ShowDialog(); if (result.HasValue && result.Value) { string fileName = dlg.FileName; CommonViewModel.AddDataSource(new ArchievedFileDataSource(fileName)); } }); SyncSourceTimeCommand = new ChartingCommand((o) => true, (o) => { var param = (Tuple)o; CommonViewModel.SyncSourceTime(param.Item1, param.Item2, param.Item3); }); RemoveAllDataSourceCommand = new ChartingCommand((o) => true, (o) => { if (MessageBox.Show("确认删除所有的数据源?", "数据操作", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { CommonViewModel.RemoveDataSource(string.Empty); } }); } public ICommand ConfigDbConnectionCommand { get; private set; } public ICommand SelectDataSourceCommand { get; private set; } public ICommand SelectFileSourceCommand { get; private set; } public ICommand SyncSourceTimeCommand { get; private set; } public ICommand RemoveAllDataSourceCommand { get; private set; } public CommonViewModel CommonViewModel { get; private set; } } }