public PagedDataGrid() { InitializeComponent(); ExportContentCommand = new AsynchronousDelegateCommand( () => { bool?success = true; try { //success = DataAccess.Export.CreateExcelWorkBookFromCollection(View.SourceCollection.Cast<dynamic>()); } catch (Exception e) { App.ToLogException(e); } if (success != null && success == false) { App.ShowWarning("Не удалось экспортировать результат запроса.", "Экспорт"); } }, (param) => { return(View != null); }); (ExportContentCommand as AsynchronousDelegateCommand).Executing += OnExportContentCommandExecuting; (ExportContentCommand as AsynchronousDelegateCommand).Executed += OnExportContentCommandExecuted; DataContext = this; }
public BaseFuncViewModel() { GetCommand = new AsynchronousDelegateCommand( (param) => { Execute(param); }, (p) => CanExecute(p), GetCommandHeader); Отладка = new FuncParameter("debug", "1"); Филиал = new FuncParameter("f", Properties.Settings.Default.Filial); Properties.Settings.Default.PropertyChanged += Settings_PropertyChanged; }
public ResultViewerViewModel() { ViewContentAsTextCommand = new DelegateCommand( () => { _showAsText = !_showAsText; UpdateUI(); OnPropertyChanged("ViewContentAsTextCommand"); }, (param) => { return(Data.HasData); }, () => { return(_showAsText ? (Data.HasData == false ? "<???>" : SelectedFormatType.ToString()) : "Как текст"); } ); ViewContentInNewWindowCommand = new DelegateCommand( () => { View.ContentWindow window = new View.ContentWindow() { Content = GetViewerControl(), Owner = App.Current.MainWindow, Title = "Просмотр результата запроса - размер: " + GetFileSizeHumanReadable(Data.ResultAsString.Length) }; window.Show(); /*if ((data.StartsWith("{") || data.StartsWith("[")) && (data.EndsWith("{") || data.EndsWith("["))) * { * var gen = new JsonClassGenerator(); * gen.Example = data; * gen.CodeWriter = new Common.JsonUtils.JsonClassGenerator.CodeWriters.CSharpCodeWriter(); * gen.UseProperties = true; * gen.MainClass = "EzSbytServiceSqlFuncRequest"; * gen.UsePascalCase = true; * gen.UseNestedClasses = true; * gen.SingleFile = true; * if (gen == null) return; * try * { * using (var sw = new System.IO.StringWriter()) * { * gen.OutputStream = sw; * gen.GenerateClasses(); * sw.Flush(); * string result = sw.ToString(); * } * } * catch (Exception ex) * { * App.LogException(ex); * } * }*/ }, (param) => Data.HasData, "В новом окне"); ViewContentAsTableCommand = new DelegateCommand( () => { View.ContentWindow tableWindow = new View.ContentWindow() { Content = GetDataGridViewer(), Owner = App.Current.MainWindow, Title = "Просмотр результата запроса в виде таблицы - размер: " + GetFileSizeHumanReadable(Data.ResultAsString.Length) }; tableWindow.Show(); }, (param) => Data.HasData && Source != null, "Как таблицу"); SaveContentCommand = new DelegateCommand( () => { TMP.Wpf.CommonControls.Viewers.IStringBasedViewer viewer = ResultViewerControl as TMP.Wpf.CommonControls.Viewers.IStringBasedViewer; if (viewer != null) { viewer.SaveContent(); } }, (param) => Data.HasData, "Сохранить в файл ..."); ExportCommand = new AsynchronousDelegateCommand( () => { bool?success = false; _parent.State = Shared.State.Busy; try { success = DataAccess.Export.CreateExcelWorkBookFromCollection(Source, SourceItemType); if (success != null && success == false) { App.UIAction(() => App.ShowWarning("Не удалось экспортировать результат запроса.", "Экспорт")); } _parent.State = Shared.State.Idle; } catch (Exception e) { _parent.State = Shared.State.Idle; App.ToLogException(e); } }, (param) => Data.HasData && Source != null, "Экспорт в Excel" ); this.PropertyChanged += ResultViewerViewModel_PropertyChanged; }