Example #1
0
        // 获得一个普通数据库的定义(包括数据库名captions,froms name captions)
        // 格式为

        /*
         * <database>
         *  <caption lang="zh-cn">中文图书</caption>
         *  <caption lang="en">Chinese book</caption>
         *  <from style="title">
         *      <caption lang="zh-cn">题名</caption>
         *      <caption lang="en">Title</caption>
         *  </from>
         *  ...
         *  <from name="__id" />
         * </database>         * */
        // return:
        //      -1  error
        //      0   not found such database
        //      1   found and succeed
        public int GetDatabaseDef(
            string strDbName,
            out string strDef,
            out string strError)
        {
            strError = "";
            strDef   = "";

            int nRet = 0;

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<database />");


            {
                ResInfoItem dbitem = KernelDbInfo.GetDbItem(
                    this.root_dir_results,
                    strDbName);
                if (dbitem == null)
                {
                    strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项";
                    return(0);
                }

                // 在根下加入<caption>元素
                for (int i = 0; i < dbitem.Names.Length; i++)
                {
                    string strText = dbitem.Names[i];
                    nRet = strText.IndexOf(":");
                    if (nRet == -1)
                    {
                        strError = "names字符串 '" + strText + "' 格式不正确。";
                        return(-1);
                    }
                    string strLang = strText.Substring(0, nRet);
                    string strName = strText.Substring(nRet + 1);

                    XmlNode newnode = dom.CreateElement("caption");
                    dom.DocumentElement.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

            //
            ResInfoItem[] fromitems = (ResInfoItem[])this.db_dir_results[strDbName];
            if (fromitems == null)
            {
                strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项";
                return(0);
            }

            for (int i = 0; i < fromitems.Length; i++)
            {
                ResInfoItem item = fromitems[i];
                if (item.Type != ResTree.RESTYPE_FROM)
                {
                    continue;
                }

                // 插入<from>元素
                XmlNode fromnode = dom.CreateElement("from");
                dom.DocumentElement.AppendChild(fromnode);
                DomUtil.SetAttr(fromnode, "style", item.TypeString);    // style

                if (item.Names == null)
                {
                    continue;
                }

                // 插入caption
                for (int j = 0; j < item.Names.Length; j++)
                {
                    string strText = item.Names[j];
                    nRet = strText.IndexOf(":");
                    if (nRet == -1)
                    {
                        strError = "names字符串 '" + strText + "' 格式不正确。";
                        return(-1);
                    }

                    string strLang = strText.Substring(0, nRet);
                    string strName = strText.Substring(nRet + 1);

                    XmlNode newnode = dom.CreateElement("caption");
                    fromnode.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

            strDef = dom.OuterXml;

            return(1);
        }
Example #2
0
        // 初始化数据库和From的一些属性, 以便将来运行起来快速方便
        // 在<database>元素下要插入若干<from>元素
        // 这些信息属于软件初始化的范畴, 避免人工去配置
        public int InitialAllProperty(
            ResInfoItem[] root_dir_results,
            Hashtable db_dir_results,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (nodeDatabase == null)
            {
                strError = "nodeDatabase尚未设置值";
                return(-1);
            }

            if (this.IsVirtual != false)
            {
                strError = "该函数只适用于<database>元素的初始化";
                return(-1);
            }

            string strDbName = DomUtil.GetAttr(nodeDatabase, "name");

            RemoveChildren(nodeDatabase);

            ResInfoItem dbitem = KernelDbInfo.GetDbItem(
                root_dir_results,
                strDbName);

            if (dbitem == null)
            {
                strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项";
                return(-1);
            }

            // 在下级加入<caption>元素
            for (int i = 0; i < dbitem.Names.Length; i++)
            {
                string strText = dbitem.Names[i];
                nRet = strText.IndexOf(":");
                if (nRet == -1)
                {
                    strError = "names字符串 '" + strText + "' 格式不正确。";
                    return(-1);
                }
                string strLang = strText.Substring(0, nRet);
                string strName = strText.Substring(nRet + 1);

                XmlNode newnode = nodeDatabase.OwnerDocument.CreateElement("caption");
                newnode = nodeDatabase.AppendChild(newnode);
                DomUtil.SetAttr(newnode, "lang", strLang);
                DomUtil.SetNodeText(newnode, strName);
            }

            //
            ResInfoItem[] fromitems = (ResInfoItem[])db_dir_results[strDbName];
            if (fromitems == null)
            {
                strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项";
                return(-1);
            }

            for (int i = 0; i < fromitems.Length; i++)
            {
                ResInfoItem item = fromitems[i];
                if (item.Type != ResTree.RESTYPE_FROM)
                {
                    continue;
                }

                // 插入<from>元素
                XmlNode fromnode = nodeDatabase.OwnerDocument.CreateElement("from");
                fromnode = nodeDatabase.AppendChild(fromnode);
                DomUtil.SetAttr(fromnode, "name", item.Name);    // 当前工作语言下的名字

                if (item.Names == null)
                {
                    continue;
                }

                // 插入caption
                for (int j = 0; j < item.Names.Length; j++)
                {
                    string strText = item.Names[j];
                    nRet = strText.IndexOf(":");
                    if (nRet == -1)
                    {
                        strError = "names字符串 '" + strText + "' 格式不正确。";
                        return(-1);
                    }

                    string strLang = strText.Substring(0, nRet);
                    string strName = strText.Substring(nRet + 1);

                    XmlNode newnode = fromnode.OwnerDocument.CreateElement("caption");
                    newnode = fromnode.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

            return(0);
        }