Beispiel #1
0
        /// <summary>
        /// Check if view was renamed by the first part of the alter query. If so, change attributes row
        /// to reflect this fact.
        /// </summary>
        protected override void SaveFailed()
        {
            // If view is new, do nothing
            if (IsNew)
            {
                base.SaveFailed();
                return;
            }

            // Enumerate old view
            DataTable oldView = ViewDescriptor.Enumerate(Connection, OldObjectID);
            // Enumerate new view
            DataTable newView = ViewDescriptor.Enumerate(Connection, ObjectID);

            // Check if old view still exists
            if (oldView == null || oldView.Rows == null || oldView.Rows.Count <= 0)
            {
                // Check if new view is exists
                if (newView == null || newView.Rows == null || newView.Rows.Count <= 0)
                {
                    // New view doesn't exist, view will be considered as pre-dropped
                    CloneToName(Name);
                    ResetToNew();
                    UIHelper.ShowWarning(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Resources.Warning_ObjectPreDropped,
                                             Name));
                }
                else
                {
                    // New view is exisits - view will be considered as renamed
                    // Save all view attributtes
                    object[] currentAttributtes = Attributes.ItemArray;

                    // Reset hierarchy item to be recreated later
                    ResetHierarchyItem();

                    // Rename document
                    Hierarchy.Rename(OldMoniker, Moniker, HierarchyItemID);

                    // Set new name for the hierarchy item
                    Hierarchy.SetName(HierarchyItemID, Name);

                    // Refresh hierarchy to reflect view renaming
                    Hierarchy.Refresh();

                    // Notify user about rename of the view
                    UIHelper.ShowWarning(String.Format(
                                             CultureInfo.CurrentCulture,
                                             Resources.Warning_ViewWasRenamed,
                                             OldName,
                                             Name));

                    // Change attributes row for renamed view
                    ChangeAttributesRow(newView.Rows[0]);

                    // Copy view options to the new attributes row
                    for (int i = 0; i < currentAttributtes.Length; i++)
                    {
                        DataInterpreter.SetValueIfChanged(Attributes, newView.Columns[i].ColumnName, currentAttributtes[i]);
                    }
                }
            }

            // Call to base before exit
            base.SaveFailed();
        }