private void SaveNewUserQuery(ChildWindow childWindow) { string title; MetadataStructureItem newItem; if (string.IsNullOrEmpty(childWindow.QueryText)) { return; } do { var window = new WindowNameQuery { Owner = this }; var answer = window.ShowDialog(); if (answer != true) { return; } title = window.NameQuery; if (UserQueries.IsUserQueryExist(childWindow.SqlQuery.SQLContext.MetadataContainer, title)) { var path = QueriesView.GetPathAtUserQuery(title); var message = string.IsNullOrEmpty(path) ? @"The same-named query already exists in the root folder." : string.Format("The same-named query already exists in the \"{0}\" folder.", path); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } var atItem = QueriesView.FocusedItem ?? QueriesView.MetadataStructure; if (!UserQueries.IsFolder(atItem)) { atItem = atItem.Parent; } newItem = UserQueries.AddUserQuery(childWindow.SqlQuery.SQLContext.MetadataContainer, atItem, title, childWindow.FormattedQueryText, (int)DefaultImageListImageIndices.VirtualObject, ActiveQueryBuilder.View.Helpers.GetLayout(childWindow.SqlQuery.QueryRoot)); break; } while (true); childWindow.Title = title; childWindow.UserMetadataStructureItem = newItem; childWindow.SqlSourceType = SourceType.UserQueries; childWindow.IsModified = false; SaveSettings(); }
private bool SaveNewUserQuery(ChildForm childWindow) { if (string.IsNullOrEmpty(childWindow.SqlQuery.SQL)) { MessageBox.Show("Nothing to save: SQL query is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } MetadataStructureItem node = null; string title; do { using (QueryNameForm window = new QueryNameForm()) { window.QueryName = childWindow.SqlQuery.SQLContext.MetadataContainer.GetUniqueItemName( MetadataType.UserQuery, Helpers.Localizer.GetString("strNewQuery", LocalizableConstantsUI.strNewQuery)); if (window.ShowDialog() != DialogResult.OK) { return(false); } title = window.QueryName; } if (!UserQueries.IsUserQueryExist(childWindow.SqlQuery.SQLContext.MetadataContainer, title)) { var atItem = userQueriesView1.FocusedItem ?? userQueriesView1.MetadataStructure; if (!UserQueries.IsFolder(atItem)) { atItem = atItem.Parent; } try { node = UserQueries.AddUserQuery(childWindow.SqlQuery.SQLContext.MetadataContainer, atItem, title, childWindow.FormattedQueryText, (int)DefaultImageListImageIndices.VirtualObject, childWindow.QueryView.LayoutSQL); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } break; } var path = userQueriesView1.GetPathAtUserQuery(title); var message = string.IsNullOrEmpty(path) ? @"The same-named query already exists in the root folder." : string.Format("The same-named query already exists in the \"{0}\" folder.", path); MessageBox.Show(message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } while(true); childWindow.SqlSourceType = ChildForm.SourceType.UserQuery; childWindow.FileSourcePath = title; childWindow.Text = title; childWindow.UserMetadataStructureItem = node; SaveSettings(); return(true); }