コード例 #1
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);
        }
コード例 #2
0
ファイル: QueryUtil.cs プロジェクト: zszqwe/dp2
        // 根据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);
        }