Esempio n. 1
0
        public static void WriteFile(ConstructFile file)
        {
            if (file == null)
            {
                return;
            }

            if (!file.IsNeedWrite())
            {
                return;
            }

            string      configPath = ConstructConfig.CONSTUCT_FOLD_PATH + "/" + file.Name + ".xml";
            XmlDocument xmlDoc     = new XmlDocument();

            if (!File.Exists(configPath))
            {
                XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(ConstructConfig.INIT_VERSION_STR, ConstructConfig.INIT_ENCODING_STR, null);
                xmlDoc.AppendChild(dec);
                XmlElement rootInit = xmlDoc.CreateElement(ConstructConfig.DOC_ROOT_STR);
                xmlDoc.AppendChild(rootInit);
                xmlDoc.Save(configPath);
            }
            else
            {
                xmlDoc.Load(configPath);
            }
            XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR);

            root.RemoveAll();

            //表格信息
            XmlElement xmlTableClass = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_CLASS);

            xmlTableClass.InnerText = file.Class;
            root.AppendChild(xmlTableClass);

            XmlElement xmlTableDesc = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_DESC);

            xmlTableDesc.InnerText = file.Desc;
            root.AppendChild(xmlTableDesc);

            XmlElement xmlTableOldName = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_OLD_NAME);

            xmlTableOldName.InnerText = file.OldName;
            root.AppendChild(xmlTableOldName);

            //项信息
            XmlElement xmlItem = null;

            foreach (ConstructItem item in file.ConstructItems)
            {
                XmlElement xmlColumn = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_COLUMN);

                xmlItem           = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_NAME);
                xmlItem.InnerText = item.Name;
                xmlColumn.AppendChild(xmlItem);

                xmlItem           = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_CODE);
                xmlItem.InnerText = item.ItemCode;
                xmlColumn.AppendChild(xmlItem);

                xmlItem           = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE1);
                xmlItem.InnerText = item.ItemType1;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2);
                foreach (TableBaseItem type2s in item.ItemType2)
                {
                    XmlElement type2Ele = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2);
                    type2Ele.InnerText = type2s.Name;
                    xmlItem.AppendChild(type2Ele);
                }
                xmlColumn.AppendChild(xmlItem);

                xmlItem           = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT);
                xmlItem.InnerText = item.ItemDefault;
                xmlColumn.AppendChild(xmlItem);

                xmlItem           = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_REPEAT);
                xmlItem.InnerText = item.ItemRepeat.ToString();
                xmlColumn.AppendChild(xmlItem);

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

            file.AlreadyWrite();
            file.NeedReloadContent = true;
        }
        public static void WriteFile(ConstructFile file)
        {
            if (file == null)
                return;

            if (!file.IsNeedWrite())
                return;

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

            //表格信息
            XmlElement xmlTableClass = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_CLASS);
            xmlTableClass.InnerText = file.Class;
            root.AppendChild(xmlTableClass);

            XmlElement xmlTableDesc = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_DESC);
            xmlTableDesc.InnerText = file.Desc;
            root.AppendChild(xmlTableDesc);

            XmlElement xmlTableOldName = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_OLD_NAME);
            xmlTableOldName.InnerText = file.OldName;
            root.AppendChild(xmlTableOldName);

            //项信息
            XmlElement xmlItem = null;
            foreach (ConstructItem item in file.ConstructItems)
            {
                XmlElement xmlColumn = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_COLUMN);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_NAME);
                xmlItem.InnerText = item.Name;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_CODE);
                xmlItem.InnerText = item.ItemCode;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE1);
                xmlItem.InnerText = item.ItemType1;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2);
                foreach (TableBaseItem type2s in item.ItemType2)
                {
                    XmlElement type2Ele = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2);
                    type2Ele.InnerText = type2s.Name;
                    xmlItem.AppendChild(type2Ele);
                }
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT);
                xmlItem.InnerText = item.ItemDefault;
                xmlColumn.AppendChild(xmlItem);

                xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_REPEAT);
                xmlItem.InnerText = item.ItemRepeat.ToString();
                xmlColumn.AppendChild(xmlItem);

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

            file.AlreadyWrite();
            file.NeedReloadContent = true;
        }