示例#1
0
        public EnumInfo CreateNewEnum(string name)
        {
            if (EnumInfoCollection.GetByName(name) != null)
                return null;

            EnumInfo enumInfo = new EnumInfo();
            enumInfo.Name = name;
            EnumInfoCollection.AddNewItem(enumInfo);

            return enumInfo;
        }
        private void EnumList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
                return;

            EnumInfo info = e.AddedItems[0] as EnumInfo;
            if (info != null)
            {
                _CurEnum = info;
                EnumItems.ItemsSource = _CurEnum._EnumItemCollection;
            }
        }
        public static void WriteFile(EnumInfo file)
        {
            if (file == null)
                return;

            if (!file.IsNeedWrite())
                return;

            string configPath = EnuminfoConfig.ENUMINFO_FOLD_PATH + "/" + file.Name + ".xml";
            XmlDocument xmlDoc = new XmlDocument();
            if (!File.Exists(configPath))
            {
                XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(EnuminfoConfig.INIT_VERSION_STR, EnuminfoConfig.INIT_ENCODING_STR, null);
                xmlDoc.AppendChild(dec);
                XmlElement rootInit = xmlDoc.CreateElement(EnuminfoConfig.DOC_ROOT_STR);
                xmlDoc.AppendChild(rootInit);
                xmlDoc.Save(configPath);
            }
            else
            {
                xmlDoc.Load(configPath);
            }
            XmlNode root = xmlDoc.SelectSingleNode(EnuminfoConfig.DOC_ROOT_STR);
            root.RemoveAll();

            XmlElement xmlItem = null;
            foreach (EnumItem item in file._EnumItemCollection)
            {
                XmlElement xmlColumn = xmlDoc.CreateElement(EnuminfoConfig.ENUMINFO_ELEMENT_COLUMN);

                xmlItem = xmlDoc.CreateElement(EnuminfoConfig.ENUMINFO_ELEMENT_NAME);
                xmlItem.InnerText = item.Name;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(EnuminfoConfig.ENUMINFO_ELEMENT_CODE);
                xmlItem.InnerText = item.ItemCode;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(EnuminfoConfig.ENUMINFO_ELEMENT_VALUE);
                xmlItem.InnerText = item.ItemValue;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(EnuminfoConfig.ENUMINFO_ELEMENT_DESC);
                xmlItem.InnerText = item.ItemDesc;
                xmlColumn.AppendChild(xmlItem);

                root.AppendChild(xmlColumn);
            }
            xmlDoc.Save(configPath);

            file.AlreadyWrite();
        }
        public static void ReadFile(FileInfo fileInfo)
        {
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(fileInfo.FullName);

                string fileName = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf("."));
                EnumInfo enumInfo = new EnumInfo();
                enumInfo.Name = fileName;
                EnumManager.Instance.AddEnum(enumInfo);

                XmlNode root = xmlDoc.SelectSingleNode(EnuminfoConfig.DOC_ROOT_STR);
                foreach (XmlElement childElement in root.ChildNodes.OfType<XmlElement>())
                {
                    if (childElement.Name == EnuminfoConfig.ENUMINFO_ELEMENT_COLUMN)
                    {
                        EnumItem item = ReadColumn(childElement);
                        if (item != null)
                        {
                            enumInfo.AddEnumItem(item);
                        }

                        //重置写标记
                        item.WriteFlag = false;
                    }
                    
                }

                //重置写标记
                enumInfo.WriteFlag = false;

            }
            catch (Exception e)
            {

            }
        }
示例#5
0
 public void AddEnum(EnumInfo enumInfo)
 {
     EnumInfoCollection.AddNewItem(enumInfo);
 }
示例#6
0
 public void AddEnum(EnumInfo enumInfo)
 {
     EnumInfoCollection.AddNewItem(enumInfo);
 }