⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 framenode.cs

📁 结构很好的三层数据访问组件。开放源码。是微软企业库数据访问的替代产品之一。
💻 CS
字号:
namespace FrameCountry
{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Xml;

    internal class FrameNode
    {
        private string ClassAlias = "ND";
        private FrameCity frameCity = new FrameCity();

        public XmlNode GetNode(string ServiceName, string OperatorName, ref string ErrorInfo)
        {
            string functionAlias = "02";
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" + ServiceName + ".xml");
                int count = document.SelectNodes("./ConfigList/" + OperatorName).Count;
                if (count != 1)
                {
                    throw new Exception(string.Concat(new object[] { "节点 ", OperatorName, " 的节点数目为 ", count, " ,不唯一!" }));
                }
                return document.SelectNodes("./ConfigList/" + OperatorName)[0];
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "读取 " + ServiceName + ".xml 文件下节点 " + OperatorName + " 错误,错误信息如下:\n\r" + exception.Message);
            }
            return null;
        }

        public bool GetNodeInnerText(string ServiceName, string XPathName, ref string InnerText, ref string ErrorInfo)
        {
            string functionAlias = "01";
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\" + ServiceName + ".xml");
                InnerText = document.SelectNodes(XPathName).Item(0).InnerText;
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "配置文件 " + ServiceName + ".xml 读取错误!,错误信息:\n\r" + exception.Message);
                return false;
            }
            return true;
        }

        public bool SetNodeInnerText(string ServiceName, string XPathName, string InnerText, ref string ErrorInfo)
        {
            string functionAlias = "00";
            try
            {
                XmlDocument document = new XmlDocument();
                string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                directoryName = directoryName.Substring(6, directoryName.Length - 6);
                document.Load(directoryName + @"\" + ServiceName + ".xml");
                document.SelectNodes(XPathName).Item(0).InnerText = InnerText;
                document.Save(directoryName + @"\" + ServiceName + ".xml");
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "配置文件 " + ServiceName + ".xml 写入错误!,错误信息:\n\r" + exception.Message);
                return false;
            }
            return true;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -