Exemplo n.º 1
0
        // 查找<xpath>对应的<nstable>
        // return:
        //		-1	出错
        //		0	没找到	strError里面有出错信息
        //		1	找到
        //		2	不使用
        private static int FindNsTable(XmlNode nodeXpath,
                                       out XmlNode nodeNstable,
                                       out string strError)
        {
            nodeNstable = null;
            strError    = "";

            string strNstableName = DomUtil.GetAttrDiff(nodeXpath, "nstable");

            if (strNstableName == null)
            {
                return(2);
            }

            string strXPath = "";

            // 向内找
            if (strNstableName == "")
            {
                strXPath = ".//nstable";
            }
            else
            {
                strXPath = ".//nstable[@name='" + strNstableName + "']";
            }

            nodeNstable = nodeXpath.SelectSingleNode(strXPath);
            if (nodeNstable != null)
            {
                return(1);
            }

            // 向外找
            if (strNstableName == "")
            {
                strXPath = "//nstable[@name=''] | //nstable[not(@name)]";  //???找属性值为空,或未定义该属性
            }
            else
            {
                strXPath = "//nstable[@name='" + strNstableName + "']";
            }

            nodeNstable = nodeXpath.SelectSingleNode(strXPath);
            if (nodeNstable != null)
            {
                return(1);
            }

            strError = "没找到名字叫'" + strNstableName + "'的<nstable>节点。";
            return(0);
        }
Exemplo n.º 2
0
        // TODO: XPathExpression可以缓存起来,加快速度
        // 创建指定记录的浏览格式集合
        // parameters:
        //		domData	    记录数据dom 不能为null
        //      nStartCol   开始的列号。一般为0
        //      cols        浏览格式数组
        //		strError	out参数,出错信息
        // return:
        //		-1	出错
        //		>=0	成功。数字值代表每个列包含的字符数之和
        public int BuildCols(XmlDocument domData,
                             int nStartCol,
                             out string[] cols,
                             out string strError)
        {
            strError = "";
            cols     = new string[0];

            Debug.Assert(domData != null, "BuildCols()调用错误,domData参数不能为null。");

            // 没有浏览格式定义时,就没有信息
            if (this._dom == null)
            {
                return(0);
            }

            int nResultLength = 0;

            XPathNavigator nav = domData.CreateNavigator();

            List <string> col_array = new List <string>();

            if (this._dom.DocumentElement.Prefix == "")
            {
                // 得到xpath的值
                // XmlNodeList nodeListXpath = this._dom.SelectNodes(@"//xpath");
                XmlNodeList nodeListCol = this._dom.DocumentElement.SelectNodes("col");

CREATE_CACHE:
                // 创建Cache
                if (m_exprCache.Count == 0 && nodeListCol.Count > 0)
                {
                    // 汇总需要创建的列名
                    this._useNames = GetUseColNames();

                    foreach (XmlElement nodeCol in nodeListCol)
                    {
                        CacheItem cache_item = new CacheItem();
                        m_exprCache[nodeCol] = cache_item;

                        // XmlNode nodeXpath = nodeListXpath[i];
                        XmlElement nodeXPath = nodeCol.SelectSingleNode("xpath") as XmlElement;
                        string     strXpath  = "";
                        if (nodeXPath != null)
                        {
                            strXpath = nodeXPath.InnerText.Trim();
                        }
                        if (string.IsNullOrEmpty(strXpath) == false)
                        {
                            string strNstableName     = DomUtil.GetAttrDiff(nodeXPath, "nstable");
                            XmlNamespaceManager nsmgr = (XmlNamespaceManager)this.tableNsClient[nodeXPath];
#if DEBUG
                            if (nsmgr != null)
                            {
                                Debug.Assert(strNstableName != null, "此时应该没有定义'nstable'属性。");
                            }
                            else
                            {
                                Debug.Assert(strNstableName == null, "此时必须没有定义'nstable'属性。");
                            }
#endif


                            XPathExpression expr = nav.Compile(strXpath);
                            if (nsmgr != null)
                            {
                                expr.SetContext(nsmgr);
                            }

                            cache_item.expr = expr;
                        }


                        // 把 convert 参数也缓存起来
                        // XmlNode nodeCol = nodeXpath.ParentNode;
                        string strConvert = DomUtil.GetAttr(nodeCol, "convert");
                        if (string.IsNullOrEmpty(strConvert) == false)
                        {
                            List <string> convert_methods = GetMethods(strConvert);
                            cache_item.convert_methods = convert_methods;
                        }
                        else
                        {
                            cache_item.convert_methods = new List <string>();
                        }

                        // 把 use 元素 text 缓存起来
                        XmlElement nodeUse = nodeCol.SelectSingleNode("use") as XmlElement;
                        string     strUse  = "";
                        if (nodeUse != null)
                        {
                            strUse = nodeUse.InnerText.Trim();
                        }
                        if (string.IsNullOrEmpty(strUse) == false)
                        {
                            cache_item.Use = strUse;
                        }
                    }
                }

                Dictionary <string, MarcColumn> results = null;
                string filter = this._dom.DocumentElement.GetAttribute("filter");
                if (filter == "marc" && this._useNames.Count > 0)
                {
                    results = MarcBrowse.Build(domData,
                                               this._useNames);
                }

                foreach (XmlElement nodeCol in nodeListCol)
                {
#if NO
                    XmlNode nodeXpath = nodeListXpath[i];
                    string  strXpath  = nodeXpath.InnerText.Trim(); // 2012/2/16
                    if (string.IsNullOrEmpty(strXpath) == true)
                    {
                        continue;
                    }

                    // 优化速度 2014/1/29
                    XmlNode nodeCol = nodeXpath.ParentNode;
#endif
                    CacheItem     cache_item      = m_exprCache[nodeCol] as CacheItem;
                    List <string> convert_methods = cache_item.convert_methods;
                    if (convert_methods == null)
                    {
                        Debug.Assert(false, "");
                        string strConvert = DomUtil.GetAttr(nodeCol, "convert");
                        convert_methods = GetMethods(strConvert);
                    }

                    string strText = "";

                    XPathExpression expr = cache_item.expr;

                    if (expr != null)
                    {
                        if (expr == null)
                        {
#if NO
                            this.m_exprCache.Clear();
                            this.m_methodsCache.Clear();
                            goto CREATE_CACHE; // TODO: 如何预防死循环?
#endif
                        }

                        Debug.Assert(expr != null, "");


                        if (expr.ReturnType == XPathResultType.Number)
                        {
                            strText = nav.Evaluate(expr).ToString();//Convert.ToString((int)(nav.Evaluate(expr)));
                            strText = ConvertText(convert_methods, strText);
                        }
                        else if (expr.ReturnType == XPathResultType.Boolean)
                        {
                            strText = Convert.ToString((bool)(nav.Evaluate(expr)));
                            strText = ConvertText(convert_methods, strText);
                        }
                        else if (expr.ReturnType == XPathResultType.String)
                        {
                            strText = (string)(nav.Evaluate(expr));
                            strText = ConvertText(convert_methods, strText);
                        }
                        else if (expr.ReturnType == XPathResultType.NodeSet)
                        {
                            // 看看是否要插入什么分隔符
                            string strSep = GetSepString(convert_methods);

                            XPathNodeIterator iterator = nav.Select(expr);
                            StringBuilder     text     = new StringBuilder(4096);
                            while (iterator.MoveNext())
                            {
                                XPathNavigator navigator  = iterator.Current;
                                string         strOneText = navigator.Value;
                                if (strOneText == "")
                                {
                                    continue;
                                }

                                strOneText = ConvertText(convert_methods, strOneText);

                                // 加入分隔符号
                                if (text.Length > 0 && string.IsNullOrEmpty(strSep) == false)
                                {
                                    text.Append(strSep);
                                }

                                text.Append(strOneText);
                            }

                            strText = text.ToString();
                        }
                        else
                        {
                            strError = "XPathExpression的ReturnType为'" + expr.ReturnType.ToString() + "'无效";
                            return(-1);
                        }
                    }

                    if (string.IsNullOrEmpty(cache_item.Use) == false)
                    {
                        MarcColumn column = null;
                        results.TryGetValue(cache_item.Use, out column);
                        if (column != null && string.IsNullOrEmpty(column.Value) == false)
                        {
                            strText += column.Value;
                        }
                    }

                    // 空内容也要算作一列

                    // 2008/12/18

                    col_array.Add(strText);
                    nResultLength += strText.Length;
                }
            }
            else if (this._dom.DocumentElement.Prefix == "xsl")
            {
                if (this.m_xt == null)
                {
                    // <col>元素下的<title>元素要去掉
                    XmlDocument temp = new XmlDocument();
                    temp.LoadXml(this._dom.OuterXml);
                    XmlNodeList nodes = temp.DocumentElement.SelectNodes("//col/title");
                    foreach (XmlNode node in nodes)
                    {
                        node.ParentNode.RemoveChild(node);
                    }

                    XmlReader xr = new XmlNodeReader(temp);

                    // 把xsl加到XslTransform
                    XslCompiledTransform xt = new XslCompiledTransform(); // 2006/10/26 changed
                    xt.Load(xr /*, new XmlUrlResolver(), null*/);

                    this.m_xt = xt;
                }

                // 输出到的地方
                string strResultXml = "";

                using (TextWriter tw = new StringWriter())
                    using (XmlTextWriter xw = new XmlTextWriter(tw))
                    {
                        //执行转换
                        this.m_xt.Transform(domData.CreateNavigator(), /*null,*/ xw /*, null*/);

                        // tw.Close();
                        tw.Flush(); // 2015/11/24 增加此句

                        strResultXml = tw.ToString();
                    }

                XmlDocument resultDom = new XmlDocument();
                try
                {
                    if (string.IsNullOrEmpty(strResultXml) == false)
                    {
                        resultDom.LoadXml(strResultXml);
                    }
                    else
                    {
                        resultDom.LoadXml("<root />");
                    }
                }
                catch (Exception ex)
                {
                    strError = "browse 角色文件生成的结果文件加载到 XMLDOM 时出错:" + ex.Message;
                    return(-1);
                }

                XmlNodeList colList = resultDom.DocumentElement.SelectNodes("//col");
                foreach (XmlNode colNode in colList)
                {
                    string strColText = colNode.InnerText.Trim();  // 2012/2/16

                    // 2008/12/18
                    string        strConvert      = DomUtil.GetAttr(colNode, "convert");
                    List <string> convert_methods = GetMethods(strConvert);

                    // 2008/12/18
                    if (String.IsNullOrEmpty(strConvert) == false)
                    {
                        strColText = ConvertText(convert_methods, strColText);
                    }

                    //if (strColText != "")  //空内容也要算作一列
                    col_array.Add(strColText);
                    nResultLength += strColText.Length;
                }
            }
            else
            {
                strError = "browse 角色文件的根元素的前缀'" + this._dom.DocumentElement.Prefix + "'不合法。";
                return(-1);
            }

            // 把col_array转到cols里
            cols = new string[col_array.Count + nStartCol];
            col_array.CopyTo(cols, nStartCol);
            // cols = ConvertUtil.GetStringArray(nStartCol, col_array);
            return(nResultLength);
        }
Exemplo n.º 3
0
        // 根据nodeItem得到检索的相关信息
        // parameter:
        //		nodeItem	配置节点
        //		strTarget	out参数,返回检索目标,会是多库的多途径
        //		strWord	    out参数,返回检索词
        //		strMatch	out参数,返回匹配方式
        //		strRelation	out参数,返回关系符
        //		strDataType	out参数,返回检索的数据类型
        //		strIdOrder	out参数,返回id的排序规则
        //		strKeyOrder	out参数,返回key的排序规则
        //		strOrderBy	out参数,返回由order与originOrder组合的排序规则,例如" keystring ASC,idstring DESC "
        //		nMax	    out参数,返回最大条数
        //		strError	out参数,返回出错信息
        // return:
        //		-1	出错
        //		0	成功
        public static int GetSearchInfo(XmlNode nodeItem,
                                        out string strTarget,
                                        out string strWord,
                                        out string strMatch,
                                        out string strRelation,
                                        out string strDataType,
                                        out string strIdOrder,
                                        out string strKeyOrder,
                                        out string strOrderBy,
                                        out int nMaxCount,
                                        out string strError)
        {
            strTarget   = "";
            strWord     = "";
            strMatch    = "";
            strRelation = "";
            strDataType = "";
            strIdOrder  = "";
            strKeyOrder = "";
            strOrderBy  = "";
            nMaxCount   = 0;
            strError    = "";

            //--------------------------------------
            //调GetTarget函数,得到检索目标target节点
            XmlNode nodeTarget = QueryUtil.GetTarget(nodeItem);

            if (nodeTarget == null)
            {
                strError = "检索式的target元素未定义";
                return(-1);
            }
            strTarget = DomUtil.GetAttrDiff(nodeTarget, "list");
            if (strTarget == null)
            {
                strError = "target元素的list属性未定义";
            }
            strTarget = strTarget.Trim();
            if (strTarget == "")
            {
                strError = "target元素的list属性值不能为空字符串";
                return(-1);
            }


            //-------------------------------------------
            //检索文本 可以为空字符串
            XmlNode nodeWord = nodeItem.SelectSingleNode("word");

            if (nodeWord == null)
            {
                strError = "检索式的word元素未定义";
                return(-1);
            }
            strWord = DomUtil.GetNodeText(nodeWord);
            strWord = strWord.Trim();


            //------------------------------------
            //匹配方式
            XmlNode nodeMatch = nodeItem.SelectSingleNode("match");

            if (nodeMatch == null)
            {
                strError = "检索式的match元素未定义";
                return(-1);
            }
            strMatch = DomUtil.GetNodeText(nodeMatch);
            strMatch = strMatch.Trim();
            if (strMatch == "")
            {
                strError = "检索式的match元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckMatch(strMatch) == false)
            {
                strError = "检索式的match元素内容'" + strMatch + "'不合法,必须为left,middle,right,exact";
                return(-1);
            }

            //--------------------------------------------
            //关系操作符
            XmlNode nodeRelation = nodeItem.SelectSingleNode("relation");

            if (nodeRelation == null)
            {
                strError = "检索式的relation元素未定义";
                return(-1);
            }
            strRelation = DomUtil.GetNodeText(nodeRelation);
            strRelation = strRelation.Trim();
            if (strRelation == "")
            {
                strError = "检索式的relation元素内容不能为空字符串";
                return(-1);
            }
            strRelation = QueryUtil.ConvertLetterToOperator(strRelation);
            if (QueryUtil.CheckRelation(strRelation) == false)
            {
                strError = "检索式的relation元素内容'" + strRelation + "'不合法.";
                return(-1);
            }

            //-------------------------------------------
            //数据类型
            XmlNode nodeDataType = nodeItem.SelectSingleNode("dataType");

            if (nodeDataType == null)
            {
                strError = "检索式的dataType元素未定义";
                return(-1);
            }
            strDataType = DomUtil.GetNodeText(nodeDataType);
            strDataType = strDataType.Trim();
            if (strDataType == "")
            {
                strError = "检索式的dataType元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckDataType(strDataType) == false)
            {
                strError = "检索式的dataType元素内容'" + strDataType + "'不合法,必须为string,number";
                return(-1);
            }


            // ----------order可以不存在----------
            int    nOrderIndex       = -1;
            string strOrder          = null;
            int    nOriginOrderIndex = -1;
            string strOriginOrder    = null;

            //id的序  //ASC:升序  //DESC:降序
            XmlNode nodeOrder = nodeItem.SelectSingleNode("order");

            // 当定义了order元素时,才会id进行排序
            if (nodeOrder != null)
            {
                string strOrderText = DomUtil.GetNodeText(nodeOrder);
                strOrderText = strOrderText.Trim();
                if (strOrderText != "")
                {
                    strOrder    = "idstring " + strOrderText;
                    nOrderIndex = DomUtil.GetIndex(nodeOrder);
                    strIdOrder  = strOrderText;
                }
            }

            //key的序  //ASC:升序  //DESC:降序
            XmlNode nodeOriginOrder = nodeItem.SelectSingleNode("originOrder");

            // 当定义了order元素时,才会id进行排序
            if (nodeOriginOrder != null)
            {
                string strOriginOrderText = DomUtil.GetNodeText(nodeOriginOrder);
                strOriginOrderText = strOriginOrderText.Trim();
                if (strOriginOrderText != "")
                {
                    strOriginOrder    = "keystring " + strOriginOrderText;
                    nOriginOrderIndex = DomUtil.GetIndex(nodeOriginOrder);
                    strKeyOrder       = strOriginOrderText;
                }
            }

            if (strOrder != null &&
                strOriginOrder != null)
            {
                if (nOrderIndex == -1 ||
                    nOriginOrderIndex == -1)
                {
                    strError = "此时nOrderIndex和nOriginOrderIndex都不可能为-1";
                    return(-1);
                }
                if (nOrderIndex == nOriginOrderIndex)
                {
                    strError = "nOrderIndex 与 nOriginOrderIndex不可能相等";
                    return(-1);
                }
                if (nOrderIndex > nOriginOrderIndex)
                {
                    strOrderBy = strOrder + "," + strOriginOrder;
                }
                else
                {
                    strOrderBy = strOriginOrder + "," + strOrder;
                }
            }
            else
            {
                if (strOrder != null)
                {
                    strOrderBy = strOrder;
                }
                if (strOriginOrder != null)
                {
                    strOrderBy = strOriginOrder;
                }
            }


            //-------------------------------------------
            //最大个数
            XmlNode nodeMaxCount = nodeItem.SelectSingleNode("maxCount");

            /*
             *          if (nodeMaxCount == null)
             *          {
             *              strError = "检索式的maxCount元素未定义";
             *              return -1;
             *          }
             */
            string strMaxCount = "";

            if (nodeMaxCount != null)
            {
                strMaxCount = DomUtil.GetNodeText(nodeMaxCount).Trim();
            }
            if (strMaxCount == "")
            {
                strMaxCount = "-1";
            }

            /*
             *          if (strMaxCount == "")
             *          {
             *              strError = "检索式的maxCount元素的值为空字符串";
             *              return -1;
             *          }
             */
            try
            {
                nMaxCount = Convert.ToInt32(strMaxCount);
                if (nMaxCount < -1)
                {
                    strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                    return(-1);
                }
            }
            catch
            {
                strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                return(-1);
            }

            return(0);
        }
Exemplo n.º 4
0
        // 根据nodeItem得到检索的相关信息
        // parameter:
        //		nodeItem	配置节点
        //		strTarget	out参数,返回检索目标,会是多库的多途径
        //		strWord	    out参数,返回检索词
        //		strMatch	out参数,返回匹配方式
        //		strRelation	out参数,返回关系符
        //		strDataType	out参数,返回检索的数据类型
        //		strIdOrder	out参数,返回id的排序规则
        //		strKeyOrder	out参数,返回key的排序规则
        //		strOrderBy	out参数,返回由order与originOrder组合的排序规则,例如" keystring ASC,idstring DESC "
        //		nMax	    out参数,返回最大条数
        //		strError	out参数,返回出错信息
        // return:
        //		-1	出错
        //		0	成功
        public static int GetSearchInfo(XmlNode nodeItem,
                                        string strOutputStyle,
                                        out string strTarget,
                                        out string strWord,
                                        out string strMatch,
                                        out string strRelation,
                                        out string strDataType,
                                        out string strIdOrder,
                                        out string strKeyOrder,
                                        out string strOrderBy,
                                        out int nMaxCount,
                                        out string strHint,
                                        out string strError)
        {
            strTarget   = "";
            strWord     = "";
            strMatch    = "";
            strRelation = "";
            strDataType = "";
            strIdOrder  = "";
            strKeyOrder = "";
            strOrderBy  = "";
            nMaxCount   = 0;
            strHint     = "";
            strError    = "";

            bool bOutputKeyCount = StringUtil.IsInList("keycount", strOutputStyle);
            bool bOutputKeyID    = StringUtil.IsInList("keyid", strOutputStyle);

            //--------------------------------------
            //调GetTarget函数,得到检索目标target节点
            XmlElement nodeTarget = QueryUtil.GetTarget(nodeItem);

            if (nodeTarget == null)
            {
                strError = "检索式的target元素未定义";
                return(-1);
            }
            strTarget = DomUtil.GetAttrDiff(nodeTarget, "list");
            if (strTarget == null)
            {
                strError = "target元素的list属性未定义";
            }
            strTarget = strTarget.Trim();
            if (strTarget == "")
            {
                strError = "target元素的list属性值不能为空字符串";
                return(-1);
            }

            // 2015/11/8
            strHint = nodeTarget.GetAttribute("hint");

            //-------------------------------------------
            //检索文本 可以为空字符串
            XmlNode nodeWord = nodeItem.SelectSingleNode("word");

            if (nodeWord == null)
            {
                strError = "检索式的word元素未定义";
                return(-1);
            }
            strWord = nodeWord.InnerText.Trim();    //  // 2012/2/16
            strWord = strWord.Trim();


            //------------------------------------
            //匹配方式
            XmlNode nodeMatch = nodeItem.SelectSingleNode("match");

            if (nodeMatch == null)
            {
                strError = "检索式的match元素未定义";
                return(-1);
            }
            strMatch = nodeMatch.InnerText.Trim(); // 2012/2/16
            if (string.IsNullOrEmpty(strMatch) == true)
            {
                strError = "检索式的match元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckMatch(strMatch) == false)
            {
                strError = "检索式的match元素内容'" + strMatch + "'不合法,必须为left,middle,right,exact之一";
                return(-1);
            }

            //--------------------------------------------
            //关系操作符
            XmlNode nodeRelation = nodeItem.SelectSingleNode("relation");

            if (nodeRelation == null)
            {
                strError = "检索式的relation元素未定义";
                return(-1);
            }
            strRelation = nodeRelation.InnerText.Trim(); // 2012/2/16
            if (string.IsNullOrEmpty(strRelation) == true)
            {
                strError = "检索式的relation元素内容不能为空字符串";
                return(-1);
            }
            strRelation = QueryUtil.ConvertLetterToOperator(strRelation);
            if (QueryUtil.CheckRelation(strRelation) == false)
            {
                strError = "检索式的relation元素内容 '" + strRelation + "' 不合法.";
                return(-1);
            }

            //-------------------------------------------
            //数据类型
            XmlNode nodeDataType = nodeItem.SelectSingleNode("dataType");

            if (nodeDataType == null)
            {
                strError = "检索式的dataType元素未定义";
                return(-1);
            }
            strDataType = nodeDataType.InnerText.Trim(); // 2012/2/16
            if (string.IsNullOrEmpty(strDataType) == true)
            {
                strError = "检索式的dataType元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckDataType(strDataType) == false)
            {
                strError = "检索式的dataType元素内容'" + strDataType + "'不合法,必须为string,number";
                return(-1);
            }


            // ----------order可以不存在----------
            int    nOrderIndex       = -1;
            string strOrder          = null;
            int    nOriginOrderIndex = -1;
            string strOriginOrder    = null;

            //id的序  //ASC:升序  //DESC:降序
            XmlNode nodeOrder = nodeItem.SelectSingleNode("order");

            // 当定义了order元素时,才会id进行排序
            if (nodeOrder != null)
            {
                string strOrderText = nodeOrder.InnerText; // 2012/2/16
                strOrderText = strOrderText.Trim().ToUpper();
                if (strOrderText != "ASC" &&
                    strOrderText != "DESC")
                {
                    strError = "<order>元素值应为 ASC DESC 之一";
                    return(-1);
                }

                if (String.IsNullOrEmpty(strOrderText) == false)
                {
                    // 2010/5/10
                    if (bOutputKeyCount == true)
                    {
                        strOrder    = "keystring " + strOrderText;
                        nOrderIndex = DomUtil.GetIndex(nodeOrder);
                        strIdOrder  = strOrderText;
                    }
                    else if (bOutputKeyID == true)
                    {
                        strOrder    = "keystring " + strOrderText;
                        nOrderIndex = DomUtil.GetIndex(nodeOrder);
                        strIdOrder  = strOrderText;
                    }
                    else
                    {
                        strOrder    = "idstring " + strOrderText;
                        nOrderIndex = DomUtil.GetIndex(nodeOrder);
                        strIdOrder  = strOrderText;
                    }
                }
            }

            //key的序  //ASC:升序  //DESC:降序
            XmlNode nodeOriginOrder = nodeItem.SelectSingleNode("originOrder");

            // 当定义了order元素时,才会id进行排序
            if (nodeOriginOrder != null)
            {
                string strOriginOrderText = nodeOriginOrder.InnerText;   // 2012/2/16
                strOriginOrderText = strOriginOrderText.Trim().ToUpper();
                if (strOriginOrderText != "ASC" &&
                    strOriginOrderText != "DESC")
                {
                    strError = "<originOrder>元素值应为 ASC DESC 之一";
                    return(-1);
                }
                if (string.IsNullOrEmpty(strOriginOrderText) == false)
                {
                    strOriginOrder    = "keystring " + strOriginOrderText;
                    nOriginOrderIndex = DomUtil.GetIndex(nodeOriginOrder);
                    strKeyOrder       = strOriginOrderText;
                }
            }

            if (strOrder != null &&
                strOriginOrder != null)
            {
                if (nOrderIndex == -1 ||
                    nOriginOrderIndex == -1)
                {
                    strError = "此时nOrderIndex和nOriginOrderIndex都不可能为-1";
                    return(-1);
                }
                if (nOrderIndex == nOriginOrderIndex)
                {
                    strError = "nOrderIndex 与 nOriginOrderIndex不可能相等";
                    return(-1);
                }
                if (nOrderIndex > nOriginOrderIndex)
                {
                    strOrderBy = strOrder + "," + strOriginOrder;
                }
                else
                {
                    strOrderBy = strOriginOrder + "," + strOrder;
                }
            }
            else
            {
                if (strOrder != null)
                {
                    strOrderBy = strOrder;
                }
                if (strOriginOrder != null)
                {
                    strOrderBy = strOriginOrder;
                }
            }


            //-------------------------------------------
            //最大个数
            XmlNode nodeMaxCount = nodeItem.SelectSingleNode("maxCount");

            /*
             *          if (nodeMaxCount == null)
             *          {
             *              strError = "检索式的maxCount元素未定义";
             *              return -1;
             *          }
             */
            string strMaxCount = "";

            if (nodeMaxCount != null)
            {
                strMaxCount = nodeMaxCount.InnerText.Trim(); // 2012/2/16
            }
            if (string.IsNullOrEmpty(strMaxCount) == true)
            {
                strMaxCount = "-1";
            }

            /*
             *          if (strMaxCount == "")
             *          {
             *              strError = "检索式的maxCount元素的值为空字符串";
             *              return -1;
             *          }
             */
            try
            {
                nMaxCount = Convert.ToInt32(strMaxCount);
                if (nMaxCount < -1)
                {
                    strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                    return(-1);
                }
            }
            catch
            {
                strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                return(-1);
            }

            return(0);
        }
Exemplo n.º 5
0
        // 初始化: 把xml中的信息填入treeview
        int InitialRights(XmlNode parentXmlNode,
                          TreeNode parentTreeNode)
        {
            // 服务器节点特殊
            if (parentTreeNode.ImageIndex == ResTree.RESTYPE_SERVER)
            {
                string strName = DomUtil.GetAttr(parentXmlNode, "name");

                NodeInfo nodeinfo = null;
                nodeinfo = (NodeInfo)parentTreeNode.Tag;
                if (nodeinfo == null)
                {
                    nodeinfo           = new NodeInfo();
                    nodeinfo.TreeNode  = parentTreeNode;
                    parentTreeNode.Tag = nodeinfo;
                }
                nodeinfo.NodeState |= NodeState.Account | NodeState.Object;

                nodeinfo.DefElement = parentXmlNode.Name;
                nodeinfo.DefName    = strName;
                nodeinfo.Rights     = DomUtil.GetAttrDiff(parentXmlNode, "rights");
            }



            for (int i = 0; i < parentXmlNode.ChildNodes.Count; i++)
            {
                XmlNode childXmlNode = parentXmlNode.ChildNodes[i];
                if (childXmlNode.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                string strName = DomUtil.GetAttr(childXmlNode, "name");

                int  nType       = 0;
                bool bExpandable = false;
                // 数据库
                if (childXmlNode.Name == "database")
                {
                    nType       = ResTree.RESTYPE_DB;
                    bExpandable = true;
                }
                // 目录
                if (childXmlNode.Name == "dir")
                {
                    nType       = ResTree.RESTYPE_FOLDER;
                    bExpandable = true;
                }
                // 文件
                if (childXmlNode.Name == "file")
                {
                    nType       = ResTree.RESTYPE_FILE;
                    bExpandable = true;
                }

                TreeNode childTreeNode = FindTreeNode(parentTreeNode, strName);

                NodeInfo nodeinfo = null;

                // 没有找到
                if (childTreeNode == null)
                {
                    // 新创建一个,但是标注为未使用的
                    childTreeNode = new TreeNode(strName, nType, nType);

                    nodeinfo            = new NodeInfo();
                    nodeinfo.TreeNode   = childTreeNode;
                    nodeinfo.Expandable = bExpandable;
                    nodeinfo.NodeState |= NodeState.Account;
                    childTreeNode.Tag   = nodeinfo;

                    childTreeNode.ForeColor = ControlPaint.LightLight(childTreeNode.ForeColor); // 灰色

                    parentTreeNode.Nodes.Add(childTreeNode);
                }
                else // 找到
                {
                    nodeinfo = (NodeInfo)childTreeNode.Tag;
                    if (nodeinfo == null)
                    {
                        nodeinfo          = new NodeInfo();
                        nodeinfo.TreeNode = childTreeNode;
                        childTreeNode.Tag = nodeinfo;
                    }
                    nodeinfo.NodeState |= NodeState.Account | NodeState.Object;
                }


                nodeinfo.DefElement = childXmlNode.Name;
                nodeinfo.DefName    = strName;
                nodeinfo.Rights     = DomUtil.GetAttrDiff(childXmlNode, "rights");

                if (nodeinfo.Rights == "" || nodeinfo.Rights == null)
                {
                    childTreeNode.ForeColor = SystemColors.GrayText;    // ControlPaint.LightLight(nodeNew.ForeColor);
                }
                else
                {
                    childTreeNode.ForeColor = SystemColors.WindowText;
                }


                // 递归
                InitialRights(childXmlNode,
                              childTreeNode);
            }

            return(0);
        }
Exemplo n.º 6
0
        // parameters:
        //		node	<table>节点
        //      strKeysTableNamePrefix  表名前缀字符串,如果 == null,表示使用"keys_"。如果不要前缀,应该是""
        public int Initial(XmlNode node,
                           string strKeysTableNamePrefix,
                           out string strError)
        {
            Debug.Assert(node != null, "Initial()调用错误,node参数值不能为null。");
            strError = "";

            this.Node = node;

            string strPartSqlTableName = DomUtil.GetAttr(this.m_node, "name").Trim();

            if (strPartSqlTableName == "")
            {
                strError = "未定义 'name' 属性。";
                return(-1);
            }

            if (string.Compare(strPartSqlTableName, "records", true) == 0)
            {
                strError = "'name' 属性中的表名不能为 'records'。因为这是一个系统的保留字。";
                return(-1);
            }

            if (strKeysTableNamePrefix == null)
            {
                strKeysTableNamePrefix = "keys_";
            }

            this.SqlTableName = strKeysTableNamePrefix + strPartSqlTableName;

            if (node != null)
            {
                this.ID         = DomUtil.GetAttr(node, "id");
                this.TypeString = DomUtil.GetAttr(node, "type");
            }

            if (this.ID == "")
            {
                strError = "未定义'id'属性。";
                return(-1);
            }

            XmlNode nodeConvert = node.SelectSingleNode("convert");

            if (nodeConvert != null)
            {
                string strStopwordTable = DomUtil.GetAttrDiff(nodeConvert, "stopwordTable");
                if (strStopwordTable != null)
                {
                    strError = "keys配置文件是旧版本,而目前<convert>元素已经不支持'stopwordTable'属性。请修改配置文件";
                    return(-1);
                }
            }

            XmlNode nodeConvertQuery = node.SelectSingleNode("convertquery");

            if (nodeConvertQuery != null)
            {
                string strStopwordTable = DomUtil.GetAttrDiff(nodeConvertQuery, "stopwordTable");
                if (strStopwordTable != null)
                {
                    strError = "keys配置文件是旧版本,而目前<convertquery>元素已经不支持'stopwordTable'属性。请修改配置文件";
                    return(-1);
                }
            }

            this.nodeConvertKeyString = node.SelectSingleNode("convert/string");
            this.nodeConvertKeyNumber = node.SelectSingleNode("convert/number");

            this.nodeConvertQueryString = node.SelectSingleNode("convertquery/string");
            this.nodeConvertQueryNumber = node.SelectSingleNode("convertquery/number");

            SetExtTypeString();
            return(0);
        }
Exemplo n.º 7
0
        // 按照预定模式修改一个节点以及以下的全部子节点的权限
        void ModiRights(int nFound,
                        List <TreeNode> selectedTreeNodes,
                        TreeNode curtreenode,
                        List <XmlNode> cfgnodes)
        {
            for (int i = 0; i < cfgnodes.Count; i++)
            {
                // 当前xml节点信息
                XmlNode node = cfgnodes[i];

                string strType   = DomUtil.GetAttr(node, "type");
                string strName   = DomUtil.GetAttr(node, "name");
                string strRights = DomUtil.GetAttrDiff(node, "rights");
                int    nStyle    = QuickRights.GetStyleInt(DomUtil.GetAttr(node, "style"));

                // 匹配对象名
                if (strName != "" && strName != "*")
                {
                    // @
                    if (strName != curtreenode.Text)
                    {
                        continue;
                    }
                }

                // 匹配对象类型
                bool bRet = QuickRights.MatchType(curtreenode.ImageIndex,
                                                  strType);
                if (bRet == false)
                {
                    continue;
                }

                // 匹配对象风格
                if (nStyle != 0)
                {
                    if (this.GetNodeStyle == null)
                    {
                        // 缺省行为

                        /*
                         * if (nStyle != ResRightTree.GetNodeStyle(curtreenode))
                         *  continue;
                         */
                    }
                    else
                    {
                        GetNodeStyleEventArgs e = new GetNodeStyleEventArgs();
                        e.Node  = curtreenode;
                        e.Style = 0;
                        this.GetNodeStyle(this, e);
                        if (nStyle != e.Style)
                        {
                            continue;
                        }
                    }
                }

                int nIndex = -1;
                if (nFound == 0)
                {
                    nIndex = selectedTreeNodes.IndexOf(curtreenode);
                }

                // 触发事件
                // 如果strRights == null,表示当前对象不需修改其rights值,但是递归仍然要进行
                if (strRights != null &&
                    (nIndex != -1 || nFound > 0))
                {
                    if (this.SetRights != null)
                    {
                        SetRightsEventArgs e = new SetRightsEventArgs();
                        e.Node = curtreenode;
                        if (strRights == "{clear}" || strRights == "{null}")
                        {
                            e.Rights = null;
                        }
                        else
                        {
                            e.Rights = strRights;
                        }
                        this.SetRights(this, e);
                    }
                }

                // DOCHILDREN:

                // 组织树子对象数组
                List <TreeNode> nodes = new List <TreeNode>();
                for (int j = 0; j < curtreenode.Nodes.Count; j++)
                {
                    nodes.Add(curtreenode.Nodes[j]);
                }

                // 递归
                if (nodes.Count != 0)
                {
                    List <XmlNode> chidrencfgnodes = new List <XmlNode>();
                    for (int j = 0; j < node.ChildNodes.Count; j++)
                    {
                        XmlNode cur = node.ChildNodes[j];

                        if (cur.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }

                        if (cur.Name != "object")
                        {
                            continue;
                        }

                        chidrencfgnodes.Add(cur);
                    }

                    if (nIndex != -1)
                    {
                        nFound++;
                    }
                    ModiRights(nFound,
                               selectedTreeNodes,
                               nodes,
                               chidrencfgnodes);
                    if (nIndex != -1)
                    {
                        nFound--;
                    }
                }
            }
        }