Exemple #1
0
        /// <summary>
        /// 更新函数
        /// </summary>
        /// <param name="update">更新节点</param>
        /// <param name="Functionfather">要更新的函数父节点</param>
        /// <param name="Function">函数的内容</param>
        public static void UpdateFunction(XmlDocument update, XmlElement Functionfather, PicFunctionTabPage func)
        {
            ///写入标识
            XmlElement function = update.CreateElement("Function");

            function.SetAttribute("Title", func.Title);
            function.SetAttribute("ID", func.Id.ToString());
            function.SetAttribute("OpenType", func.MyOpenType.ToString());
            function.SetAttribute("OverrideType", func.MyOverride.ToString());
            ///循环所有代码块
            foreach (CodeBox box in func.ListCodeBoxChild.Values)
            {
                DataWriteFunction.UpdateCodeBoxAribute(update, function, box);
            }
            ///循环所有贝塞尔曲线
            foreach (BezierLine line in func.GetBezierLines.Values)
            {
                DataWriteFunction.UpdateBezierLine(update, function, line);
            }
            ///加入子节点
            Functionfather.AppendChild(function);
        }
Exemple #2
0
        /// <summary>
        /// 将代码图转换为文件
        /// </summary>
        /// <param name="Page">代码图对象</param>
        /// <param name="path">文件存放路径</param>
        public void PicToXml(PicTabPage pic, string path)
        {
            string filePath = path + pic.Title;

            ///检测本地文件是否已经存在
            #region 如果文件不存在则创建
            if (!CheckFile(filePath))
            {
                XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement(RootName);
                writer.WriteAttributeString("Title", pic.Title);
                writer.WriteAttributeString("ID", pic.Id.ToString());
                ///循环所有代码块
                writer.WriteStartElement("MainCodeBoxs");
                foreach (CodeBox box in pic.ListCodeBoxChild.Values)
                {
                    DataWriteFunction.WriteCodeBoxAribute(writer, box);
                }
                writer.WriteEndElement();
                ///循环所有贝塞尔曲线
                writer.WriteStartElement("MainBezierLines");
                foreach (BezierLine line in pic.GetBezierLines.Values)
                {
                    DataWriteFunction.WriteBezierLine(writer, line);
                }
                writer.WriteEndElement();
                ///循环所有函数
                foreach (PicFunctionTabPage func in pic.ListFunction)
                {
                    DataWriteFunction.WriteFunction(writer, func);
                }
                ///循环所有属性
                foreach (XAribute bute in pic.ListXAributes)
                {
                    DataWriteFunction.WriteXAribute(writer, bute);
                }
                writer.WriteEndElement();
                writer.Close();
            }
            #endregion
            #region 如果存在则更新
            else
            {
                XmlDocument XmlLoad = new XmlDocument();
                XmlLoad.Load(path + pic.Title);
                XmlNode root = XmlLoad.SelectSingleNode(RootName);
                ///先清除所有然后在写入
                root.RemoveAll();
                XmlElement picroot = (XmlElement)root;
                picroot.SetAttribute("Title", pic.Title);
                picroot.SetAttribute("ID", pic.Id.ToString());
                ///循环所有代码块
                ///创建存放代码块的主节点
                XmlElement MainCodeBoxs = XmlLoad.CreateElement("MainCodeBoxs");
                foreach (CodeBox box in pic.ListCodeBoxChild.Values)
                {
                    DataWriteFunction.UpdateCodeBoxAribute(XmlLoad, MainCodeBoxs, box);
                }
                picroot.AppendChild(MainCodeBoxs);
                ///循环所有贝塞尔曲线
                ///创建存放贝塞尔曲线的主节点
                XmlElement MainBeizierLines = XmlLoad.CreateElement("MainBezierLines");
                foreach (BezierLine line in pic.GetBezierLines.Values)
                {
                    DataWriteFunction.UpdateBezierLine(XmlLoad, MainBeizierLines, line);
                }
                ///添加节点
                picroot.AppendChild(MainBeizierLines);
                ///循环所有函数
                foreach (PicFunctionTabPage func in pic.ListFunction)
                {
                    DataWriteFunction.UpdateFunction(XmlLoad, picroot, func);
                }
                ///循环所有属性
                foreach (XAribute bute in pic.ListXAributes)
                {
                    DataWriteFunction.UpdateXAribute(XmlLoad, picroot, bute);
                }
                XmlLoad.Save(path + pic.Title);
            }
            #endregion
        }