コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Query.cs プロジェクト: zhangandding/dp2
        // 功能: 检查检索单元match,relation,dataType三项的关系
        // 如果存在矛盾:
        // 如果处理警告的级别为0,会给检索单元node加warning信息,不自动更正,返回-1,
        // 如果级别为非0(应该固定为1),则系统自动更加,并在更正的地方加comment信息,返回0
        // 不存在矛盾:返回0
        // parameter:
        //		nodeItem    检索单元节点
        // return:
        //		0   正常(如果有矛盾,但由于处理警告级别为非0,自动更正,也返回0)
        //		-1  存在矛盾,且警告级别为0
        public int ProcessRelation(XmlNode nodeItem)
        {
            //匹配方式
            XmlNode nodeMatch = nodeItem.SelectSingleNode("match");
            string  strMatch  = "";

            if (nodeMatch != null)
            {
                strMatch = DomUtil.GetNodeText(nodeMatch).Trim();
            }


            if (strMatch == "")
            {
                DomUtil.SetNodeText(nodeMatch, "left");
                DomUtil.SetAttr(nodeMatch, "comment",
                                "原为" + strMatch + ",修改为缺省的left");
            }

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

            if (nodeRelation != null)
            {
                strRelation = DomUtil.GetNodeText(nodeRelation).Trim();
            }
            strRelation = QueryUtil.ConvertLetterToOperator(strRelation);

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

            if (nodeDataType != null)
            {
                strDataType = DomUtil.GetNodeText(nodeDataType).Trim();
            }

            if (strDataType == "number")
            {
                if (strMatch == "left" || strMatch == "right")
                {
                    //当dataType值为number时,match值为left或right或
                    //修改可以自动有两种:
                    //1.将left换成exact;
                    //2.将dataType设为string,
                    //我们先按dataType优先,将match改为exact

                    if (m_nWarningLevel == 0)
                    {
                        DomUtil.SetAttr(nodeItem,
                                        "warningInfo",
                                        "匹配方式为值‘" + strMatch + "'与数据类型的值'" + strDataType + "'矛盾,且处理警告级别为0,自动不进行自动更正");

                        return(-1);
                    }
                    else
                    {
                        DomUtil.SetNodeText(nodeMatch, "exact");
                        DomUtil.SetAttr(nodeMatch,
                                        "comment",
                                        "原为" + strMatch + ",由于与数据类型'" + strDataType + "'矛盾,修改为exact");
                    }
                }
            }

            if (strDataType == "string")
            {
                //如果dataType值为string,
                //match值为left或right,且relation值不等于"="

                //出现矛盾,(我们认为match的left或rgith值,只与relation的"="值匹配)
                //有两种裁决办法:
                //1.将relation值改为"="号;
                //2.将match值由left或right改为exact
                //目前按1进行修改

                if ((strMatch == "left" || strMatch == "right") && strRelation != "=")
                {
                    //根据处理警告级别做不同的处理
                    if (m_nWarningLevel == 0)
                    {
                        DomUtil.SetAttr(nodeItem,
                                        "warningInfo",
                                        "关系操作符'" + strRelation + "'与数据类型" + strDataType + "和匹配方式'" + strMatch + "'不匹配");
                        return(-1);
                    }
                    else
                    {
                        DomUtil.SetNodeText(nodeRelation, "=");
                        DomUtil.SetAttr(nodeRelation,
                                        "comment",
                                        "原为" + strRelation + ",由于与数据类型'" + strDataType + "和匹配方式'" + strMatch + "'不匹配,修改为'='");
                    }
                }
            }
            return(0);
        }