예제 #1
0
        // 创建针对同一个服务器的查询 XML
        public int BuildQueryXml(
    int nPerMax,
    string strLang,
    out string strQueryXml,
    out string strError)
        {
            strError = "";
            strQueryXml = "";

            int nQueryCount = 0;
            for (int i = 0; i < this.Lines.Count; i++)
            {
                dp2QueryLine line = this.Lines[i];

                if (i != 0
                    && string.IsNullOrEmpty(line.WordString) == true
                    && line.MatchStyleString != "空值")
                    continue;

                if (string.IsNullOrEmpty(line.DbNameString) == true)
                {
                    strError = "第 " + (i + 1).ToString() + " 行:尚未指定数据库名";
                    return -1;
                }
                if (string.IsNullOrEmpty(line.FromString) == true)
                {
                    strError = "第 " + (i + 1).ToString() + " 行:尚未指定检索途径";
                    return -1;
                }
                if (string.IsNullOrEmpty(line.MatchStyleString) == true)
                {
                    strError = "第 " + (i + 1).ToString() + " 行:尚未指定匹配方式";
                    return -1;
                }

                string strMatchStyle = GetMatchStyle(line.MatchStyleString);
                if (strMatchStyle == "null")
                {
                    if (string.IsNullOrEmpty(line.WordString) == false)
                    {
                        strError = "第 " + (i + 1).ToString() + " 行:要进行(匹配方式为)空值的检索,请保持该行的检索词为空";
                        return -1;
                    }

                    strMatchStyle = "exact";
                }

                string strFromStyles = "";
                if (this.GetFromStyle != null)
                {
                    GetFromStyleArgs e = new GetFromStyleArgs();
                    e.FromCaption = line.FromString;
                    this.GetFromStyle(line, e);
                    strFromStyles = e.FromStyles;
                }

                string strRelation = "=";
                string strDataType = "string";

                if (line.FromString == "__id")
                {
                    // 如果为范围式
                    if (line.WordString.IndexOfAny(new char[] { '-', '~' }) != -1)
                    {
                        strRelation = "draw";
                        strDataType = "number";
                    }
                    else if (String.IsNullOrEmpty(line.WordString) == false)
                    {
                        strDataType = "number";
                    }
                }
                else if (StringUtil.IsInList("_time", strFromStyles) == true)
                {
                    // 如果为范围式
                    if (line.WordString.IndexOf("~") != -1)
                    {
                        strRelation = "range";
                        strDataType = "number";
                    }
                    else
                    {
                        strDataType = "number";

                        // 如果检索词为空,并且匹配方式为前方一致、中间一致、后方一致,那么认为这是意图要命中全部记录
                        // 注意:如果检索词为空,并且匹配方式为精确一致,则需要认为是获取空值,也就是不存在对应检索点的记录
                        if (strMatchStyle != "exact" && string.IsNullOrEmpty(line.WordString) == true)
                        {
                            strMatchStyle = "exact";
                            strRelation = "range";
                            line.WordString = "~";
                        }
                    }

                    // 最后统一修改为exact。不能在一开始修改,因为strMatchStyle值还有帮助判断的作用
                    strMatchStyle = "exact";
                }

                string strFromList = BuildFromList(line.DbNameString, line.FromString);

                string strOneQueryXml = "<target list='"
    + StringUtil.GetXmlStringSimple(strFromList)
    + "'><item>"
    + "<word>"
    + StringUtil.GetXmlStringSimple(line.WordString)
    + "</word><match>" + strMatchStyle + "</match><relation>" + strRelation + "</relation><dataType>" + strDataType + "</dataType><maxCount>" + nPerMax.ToString() + "</maxCount></item><lang>" + strLang + "</lang></target>";

                if (string.IsNullOrEmpty(strQueryXml) == false)
                    strQueryXml += "<operator value='" + line.LogicOperator + "'/>"; ;

                strQueryXml += strOneQueryXml;
                nQueryCount++;
            }

            if (nQueryCount > 1)
                strQueryXml = "<group>" + strQueryXml + "</group>";

            return 0;
        }
예제 #2
0
 private void dp2QueryControl1_GetFromStyle(object sender, GetFromStyleArgs e)
 {
     e.FromStyles = this.MainForm.GetBiblioFromStyle(e.FromCaption);
 }