예제 #1
0
        public void AddCategory()
        {
            Expand();
            ConfigCategory cat      = new ConfigCategory();
            int            n        = 1;
            string         nameBase = "Category";

            cat.CategoryName = nameBase + n.ToString();
            bool b = true;

            while (b)
            {
                b = false;
                for (int i = 0; i < Nodes.Count; i++)
                {
                    TreeNodeCategory cn = Nodes[i] as TreeNodeCategory;
                    if (cn != null)
                    {
                        ConfigCategory c = cn.Category;
                        if (string.Compare(cat.CategoryName, c.CategoryName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            n++;
                            cat.CategoryName = nameBase + n.ToString();
                            b = true;
                        }
                    }
                }
            }
            TreeNodeCategory tc = new TreeNodeCategory(cat, false);

            Nodes.Add(tc);
            this.Expand();
            this.TreeView.SelectedNode = tc;
        }
        public void VerifyConfigCategory(ConfigCategory defCat)
        {
            ConfigCategory cat = FindCategoryByName(defCat.CategoryName);

            if (cat == null)
            {
                cat = CreateSection(defCat.CategoryName);
            }
            if (defCat.Properties.Properties.Count > 0)
            {
                foreach (ConfigProperty p in defCat.Properties.Properties)
                {
                    ConfigProperty p0 = cat.GetConfigProperty(p.DataName);
                    if (p0 == null)
                    {
                        p0             = cat.CreateConfigProperty(p.DataName);
                        p0.DataType    = p.DataType;
                        p0.DefaultData = p.DefaultData;
                    }
                    else
                    {
                        if (!p0.DataType.Equals(p.DataType))
                        {
                            p0.DataType    = p.DataType;
                            p0.DefaultData = p.DefaultData;
                        }
                    }
                }
            }
        }
        public bool LoadFromDocument(XmlDocument doc, string file)
        {
            bool bRet = true;

            _filePath = file;
            _doc      = doc;
            _list     = new List <ConfigCategory>();
            if (_doc.DocumentElement == null)
            {
                XmlNode node = _doc.CreateElement(XML_Root);
                _doc.AppendChild(node);
            }
            _guid = XmlUtil.GetAttributeGuid(_doc.DocumentElement, XMLATT_Guid);
            if (_guid == Guid.Empty)
            {
                _guid = Guid.NewGuid();
                XmlUtil.SetAttribute(_doc.DocumentElement, XMLATT_Guid, _guid);
                bRet = false;
            }
            XmlNodeList list = _doc.DocumentElement.SelectNodes(XML_Item);

            if (list != null && list.Count > 0)
            {
                foreach (XmlNode nd in list)
                {
                    ConfigCategory cat = new ConfigCategory(nd);
                    _list.Add(cat);
                }
            }
            return(bRet);
        }
 public PropertyDescriptorConfig(string name, Attribute[] attrs, ApplicationConfiguration config, ConfigCategory category, ConfigProperty property)
     : base(name, attrs)
 {
     _config = config;
     _cat    = category;
     _prop   = property;
 }
        public object Clone()
        {
            ConfigCategory cat = new ConfigCategory();

            cat._name    = _name;
            cat._xmlNode = _xmlNode;
            if (_properties != null)
            {
                cat._properties = (ConfigPropertyList)_properties.Clone();
            }
            return(cat);
        }
        public ConfigCategory CreateSection(string name)
        {
            XmlNode catNode = _doc.CreateElement(XML_Item);

            _doc.DocumentElement.AppendChild(catNode);
            XmlUtil.SetNameAttribute(catNode, name);
            ConfigCategory cat = new ConfigCategory(catNode);

            if (_list == null)
            {
                _list = new List <ConfigCategory>();
            }
            _list.Add(cat);
            return(cat);
        }
        public ConfigCategory GetCategoryByName(string name)
        {
            if (_list == null)
            {
                _list = new List <ConfigCategory>();
            }
            foreach (ConfigCategory cat in _list)
            {
                if (string.CompareOrdinal(cat.CategoryName, name) == 0)
                {
                    return(cat);                   //found existing category
                }
            }
            ConfigCategory cat0 = CreateSection(name);            //not found, create a new one

            return(cat0);
        }
예제 #8
0
 public TreeNodeCategory(ConfigCategory cat, bool dataOnly)
 {
     _isDataOnly        = dataOnly;
     _cat               = cat;
     _cat.IsDataOnly    = dataOnly;
     Text               = _cat.CategoryName;
     ImageIndex         = TreeNodeCat.IMG_CAT;
     SelectedImageIndex = TreeNodeCat.IMG_CAT;
     Nodes.Add(new CLoader());
     if (!dataOnly)
     {
         this.ContextMenu = new ContextMenu();
         MenuItem mi = new MenuItem("Add Property", mnu_addProp);
         ContextMenu.MenuItems.Add(mi);
         mi = new MenuItem("-");
         ContextMenu.MenuItems.Add(mi);
         mi = new MenuItem("Delete Category", mnu_delCat);
         ContextMenu.MenuItems.Add(mi);
     }
     _cat.NameChanging = nameChanging;
 }
예제 #9
0
        private void toolStripButtonOK_Click(object sender, EventArgs e)
        {
            Ret = new CategoryList();
            TreeNodeAppConfig ta = null;

            for (int i = 0; i < treeView1.Nodes.Count; i++)
            {
                ta = treeView1.Nodes[i] as TreeNodeAppConfig;
                if (ta != null)
                {
                    break;
                }
            }
            if (ta != null)
            {
                for (int i = 0; i < ta.Nodes.Count; i++)
                {
                    TreeNodeCategory tc = ta.Nodes[i] as TreeNodeCategory;
                    if (tc != null)
                    {
                        ConfigCategory cat = tc.Category;
                        cat.Properties.Properties.Clear();
                        Ret.Categories.Add(cat);
                        for (int j = 0; j < tc.Nodes.Count; j++)
                        {
                            TreeNodeConfigProperty tp = tc.Nodes[j] as TreeNodeConfigProperty;
                            if (tp != null)
                            {
                                cat.Properties.Properties.Add(tp.Property);
                            }
                        }
                    }
                }
            }
            this.DialogResult = DialogResult.OK;
        }
예제 #10
0
 public CategoryWrapper(ConfigCategory category, ApplicationConfiguration owner)
 {
     _cat   = category;
     _owner = owner;
 }