示例#1
0
        private void deleteClass(object sender, System.EventArgs e)
        {
            TreeNode    selectedNode;
            ModelFolder parentFolder;
            ModelClass  deleteClass;
            ModelClass  scanClass;

            parentFolder = null;
            selectedNode = modelTree.SelectedNode;

            if (selectedNode.Tag is ModelClass)
            {
                // Check to make sure there are no immediate dependencies
                // otherwise display error. Also find the entry's parent
                // folder if the class can be deleted.

                deleteClass = (ModelClass)selectedNode.Tag;

                foreach (ModelFolder folder in model.Folders)
                {
                    foreach (object i in folder.Items)
                    {
                        if (i is ModelClass)
                        {
                            scanClass = (ModelClass)i;

                            if (deleteClass == scanClass)
                            {
                                parentFolder = folder;
                            }

                            foreach (ReferenceField child in scanClass.ReferenceFields)
                            {
                                if (child.ReferenceType.ParentClassEntry == deleteClass)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }

                // Since the loop completed, that means there
                // were not references found. Delete the class.
                if (parentFolder != null)
                {
                    parentFolder.Items.Remove(deleteClass);
                    DataTypeManager.DeleteDataType(deleteClass);
                    refreshTree();
                }
            }
        }