/// <summary> /// Open *.sql/*.txt file in new query window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenQueryFile_OnExecuted(object sender, ExecutedRoutedEventArgs e) { var dialog = new OpenFileDialog { Filter = "SQL Files|*.sql|Text Files|*.txt|All files|*.*", Multiselect = false }; bool?showDialog = dialog.ShowDialog(this); if (!showDialog.Value) { return; } string text = File.ReadAllText(dialog.FileName); var panel = new QueryPanel { Text = text, FilePath = dialog.FileName }; panel.QueryResultReady += PanelOnQueryResultReady; panel.BuildNewQueryPanel(this, Path.GetFileNameWithoutExtension(dialog.FileName)); MainDocumentPane.Children.Add(panel.Anchorable); int indexOf = MainDocumentPane.Children.IndexOf(panel.Anchorable); MainDocumentPane.SelectedContentIndex = indexOf; }
/// <summary> /// Add new query panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void NewQuery_OnExecuted(object sender, ExecutedRoutedEventArgs e) { var title = await this.ShowInputAsync("New query", "Query name", new MetroDialogSettings { DefaultText = "SQL Query" }); if (title != string.Empty) { var panel = new QueryPanel(); panel.QueryResultReady += PanelOnQueryResultReady; panel.BuildNewQueryPanel(this, title); MainDocumentPane.Children.Add(panel.Anchorable); int indexOf = MainDocumentPane.Children.IndexOf(panel.Anchorable); MainDocumentPane.SelectedContentIndex = indexOf; } }
/// <summary> /// Generate DDL for current dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GenerateDdl_OnExecuted(object sender, ExecutedRoutedEventArgs e) { DatabaseModelDesigner designer; if (TryGetSelectedDesigner(out designer)) { var ddlGenerator = BaseGenerator.CreateGenerator(designer.ViewModel.TableViewModels.Select(t => t.Model), designer.ViewModel.ConnectionInfoViewModels.Select(t => t.RelationshipModel), SessionProvider.Instance.ConnectionType, SessionProvider.Instance.Username); string sql = ddlGenerator.GenerateDdl(); var panel = new QueryPanel { Text = sql }; panel.QueryResultReady += PanelOnQueryResultReady; panel.BuildNewQueryPanel(this, $"{designer.ViewModel.DiagramTitle}_DDL"); MainDocumentPane.Children.Add(panel.Anchorable); int indexOf = MainDocumentPane.Children.IndexOf(panel.Anchorable); MainDocumentPane.SelectedContentIndex = indexOf; } }