Пример #1
0
        // 将 XML 检索式变化为简明格式检索式
        public static int GetQueryString(
            FromCollection Froms,
            string strQueryXml,
            IsbnConvertInfo isbnconvertinfo,
            out string strQueryString,
            out string strError)
        {
            strError       = "";
            strQueryString = "";

            if (String.IsNullOrEmpty(strQueryXml) == true)
            {
                return(0);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strQueryXml);
            }
            catch (Exception ex)
            {
                strError = "strQueryXml装入XMLDOM时出错: " + ex.Message;
                return(-1);
            }

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("line");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node     = nodes[i];
                string  strLogic = DomUtil.GetAttr(node, "logic");
                string  strWord  = DomUtil.GetAttr(node, "word");
                string  strFrom  = DomUtil.GetAttr(node, "from");

                if (strWord == "")
                {
                    continue;
                }

                strLogic = GetLogicString(strLogic);    // 2011/8/30

                if (strQueryString != "")
                {
                    strQueryString += " " + strLogic + " ";
                }

                int nRet = strFrom.IndexOf("-");
                if (nRet != -1)
                {
                    strFrom = strFrom.Substring(0, nRet).Trim();
                }

                string strValue = Froms.GetValue(strFrom);
                if (strValue == null)
                {
                    strError = "名称 '" + strFrom + "' 在use表中没有找到对应的编号";
                    return(-1);
                }

                // 对ISBN检索词进行预处理
                if (strFrom == "ISBN" &&
                    isbnconvertinfo != null)
                {
                    /*
                     * // return:
                     * //      -1  出错
                     * //      0   没有必要转换
                     * //      1   已经转换
                     * nRet = isbnconvertinfo.ConvertISBN(ref strWord,
                     * out strError);
                     * if (nRet == -1)
                     * {
                     *  strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                     *  return -1;
                     * }
                     * */
                    List <string> isbns = null;
                    // return:
                    //      -1  出错
                    //      0   没有必要转换
                    //      1   已经转换
                    nRet = isbnconvertinfo.ConvertISBN(strWord,
                                                       out isbns,
                                                       out strError);
                    if (nRet == -1)
                    {
                        strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                        return(-1);
                    }

                    int j = 0;
                    foreach (string isbn in isbns)
                    {
                        if (j > 0)
                        {
                            strQueryString += " OR ";
                        }
                        // string strIsbn = isbn.Replace("\"", "\\\"");    // 字符 " 替换为 \"
                        string strIsbn = StringUtil.EscapeString(isbn, "\"/=");    // eacape 特殊字符
                        strQueryString += "\""
                                          + strIsbn + "\"" + "/1="
                                          + strValue;
                        j++;
                    }
                    continue;
                }

                // strWord = strWord.Replace("\"", "\\\""); // 字符 " 替换为 \"
                strWord         = StringUtil.EscapeString(strWord, "\"/="); // eacape 特殊字符
                strQueryString += "\""
                                  + strWord + "\"" + "/1="
                                  + strValue;
            }

            return(1);
        }
Пример #2
0
        // 检索一个服务器
        // 启动检索以后控制就立即返回
        // thread:
        //      界面线程
        // parameters:
        //      nodeServerOrDatabase    服务器或者数据库类型的节点
        // return:
        //      -2  尚未输入检索词
        //      -1  一般错误
        //      0   成功启动检索
        public int DoSearchOneServer(
            // bool bInDirSearch,
            TreeNode nodeServerOrDatabase,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            ZConnection connection = null;

            try
            {
                connection = this.GetZConnection(nodeServerOrDatabase);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return -1;
            }

            Debug.Assert(connection.TargetInfo != null, "");

            if (connection.TargetInfo.DbNames == null
                || connection.TargetInfo.DbNames.Length == 0)
            {
                strError = "服务器节点 '" + nodeServerOrDatabase.Text + "' 下的 " + nodeServerOrDatabase.Nodes.Count.ToString() + "  个数据库节点全部为 '在全选时不参与检索' 属性,所以通过选定该服务器节点无法直接进行检索,只能通过选定其下的某个数据库节点进行检索";
                return -1;
            }

            connection.Searching = 0;

            Debug.Assert(connection.TreeNode == nodeServerOrDatabase, "");

            string strQueryString = "";
            if (nodeServerOrDatabase == this.zTargetControl1.SelectedNode)
            {

                connection.QueryXml = this.queryControl1.GetContent(true);

                connection.TargetInfo.PreferredRecordSyntax = this.comboBox_recordSyntax.Text;
                connection.TargetInfo.DefaultElementSetName = this.comboBox_elementSetName.Text; 

                // this.ClearResultInfo(connection);
            }
            else
            {
                // strQueryString = connection.QueryString;

            }
            IsbnConvertInfo isbnconvertinfo = new IsbnConvertInfo();
            isbnconvertinfo.IsbnSplitter = this.MainForm.IsbnSplitter;
            isbnconvertinfo.ConvertStyle =
                (connection.TargetInfo.IsbnAddHyphen == true ? "addhyphen," : "")
                + (connection.TargetInfo.IsbnRemoveHyphen == true ? "removehyphen," : "")
                + (connection.TargetInfo.IsbnForce10 == true ? "force10," : "")
                + (connection.TargetInfo.IsbnForce13 == true ? "force13," : "")
                + (connection.TargetInfo.IsbnWild == true ? "wild," : "");


                nRet = ZQueryControl.GetQueryString(
                    this.MainForm.Froms,
                    connection.QueryXml,
                    isbnconvertinfo,
                    out strQueryString,
                    out strError);
                if (nRet == -1)
                    return -1;

                connection.QueryString = strQueryString;

            if (strQueryString == "")
            {
                strError = "尚未输入检索词";
                return -2;
            }

#if THREAD_POOLING
            List<string> commands = new List<string>();
            commands.Add("search");
            commands.Add("present");

            connection.SetSearchParameters(
    connection.QueryString,
    connection.TargetInfo.DefaultQueryTermEncoding,
    connection.TargetInfo.DbNames,
    connection.TargetInfo.DefaultResultSetName);

            connection.SetPresentParameters(
    connection.TargetInfo.DefaultResultSetName,
    0, // nStart,
    connection.TargetInfo.PresentPerBatchCount, // nCount,
    connection.TargetInfo.PresentPerBatchCount,   // 推荐的每次数量
    connection.DefaultElementSetName,    // "F" strElementSetName,
    connection.PreferredRecordSyntax,
    true);

            connection.BeginCommands(commands);
#else
            connection.Search();
#endif
            return 0;
        }
Пример #3
0
        // 将XML检索式变化为简明格式检索式
        public static int GetQueryString(
            FromCollection Froms,
            string strQueryXml,
            IsbnConvertInfo isbnconvertinfo,
            out string strQueryString,
            out string strError)
        {
            strError = "";
            strQueryString = "";

            if (String.IsNullOrEmpty(strQueryXml) == true)
                return 0;

            XmlDocument dom = new XmlDocument();
            try
            {
                dom.LoadXml(strQueryXml);
            }
            catch (Exception ex)
            {
                strError = "strQueryXml装入XMLDOM时出错: " + ex.Message;
                return -1;
            }

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("line");


            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];
                string strLogic = DomUtil.GetAttr(node, "logic");
                string strWord = DomUtil.GetAttr(node, "word");
                string strFrom = DomUtil.GetAttr(node, "from");

                if (strWord == "")
                    continue;

                strLogic = GetLogicString(strLogic);    // 2011/8/30

                if (strQueryString != "")
                    strQueryString += " " + strLogic + " ";

                int nRet = strFrom.IndexOf("-");
                if (nRet != -1)
                    strFrom = strFrom.Substring(0, nRet).Trim();



                string strValue = Froms.GetValue(strFrom);
                if (strValue == null)
                {
                    strError = "名称 '" + strFrom + "' 在use表中没有找到对应的编号";
                    return -1;
                }

                // 对ISBN检索词进行预处理
                if (strFrom == "ISBN"
                    && isbnconvertinfo != null)
                {
                    /*
                    // return:
                    //      -1  出错
                    //      0   没有必要转换
                    //      1   已经转换
                    nRet = isbnconvertinfo.ConvertISBN(ref strWord,
                out strError);
                    if (nRet == -1)
                    {
                        strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                        return -1;
                    }
                     * */
                    List<string> isbns = null;
                    // return:
                    //      -1  出错
                    //      0   没有必要转换
                    //      1   已经转换
                    nRet = isbnconvertinfo.ConvertISBN(strWord,
                        out isbns,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                        return -1;
                    }

                    int j = 0;
                    foreach (string isbn in isbns)
                    {
                        if (j > 0)
                            strQueryString += " OR ";
                        string strIsbn = isbn.Replace("\"", "\\\"");
                        strQueryString += "\""
                            + strIsbn + "\"" + "/1="
                            + strValue;
                        j++;
                    }
                    continue;
                }

                strWord = strWord.Replace("\"", "\\\"");
                strQueryString += "\""
                    + strWord + "\"" + "/1="
                    + strValue;
            }

            return 1;
        }
Пример #4
0
        // 准备检索一个服务器
        // 并不启动检索
        // thread:
        //      界面线程
        // return:
        //      -2  尚未输入检索词
        //      -1  一般错误
        //      0   成功准备检索
        public int PrepareSearchOneServer(
            TreeNode nodeServerOrDatabase,
            string strQueryXml,
            ref List<ZConnection> connections,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            ZConnection connection = this.GetZConnection(nodeServerOrDatabase);

            Debug.Assert(connection.TargetInfo != null, "");
            Debug.Assert(connection.TreeNode == nodeServerOrDatabase, "");

            string strQueryString = "";

            IsbnConvertInfo isbnconvertinfo = new IsbnConvertInfo();
            isbnconvertinfo.IsbnSplitter = this.MainForm.IsbnSplitter;
            isbnconvertinfo.ConvertStyle =
                (connection.TargetInfo.IsbnAddHyphen == true ? "addhyphen," : "")
                + (connection.TargetInfo.IsbnRemoveHyphen == true ? "removehyphen," : "")
                + (connection.TargetInfo.IsbnForce10 == true ? "force10," : "")
                + (connection.TargetInfo.IsbnForce13 == true ? "force13," : "")
                + (connection.TargetInfo.IsbnWild == true ? "wild," : "");

            nRet = ZQueryControl.GetQueryString(
                this.MainForm.Froms,
                strQueryXml,
                isbnconvertinfo,
                out strQueryString,
                out strError);
            if (nRet == -1)
                return -1;

            connection.QueryString = strQueryString;
            connection.QueryXml = strQueryXml;

            if (strQueryString == "")
            {
                strError = "尚未输入检索词";
                return -2;
            }


            // this.m_nServerCount++;  // 累加服务器数
            this.m_stops.Add(connection.Stop);

            connection.Stop.OnBeginLoop -= new BeginLoopEventHandler(Stop_OnBeginLoop);
            connection.Stop.OnEndLoop -= new EndLoopEventHandler(Stop_OnEndLoop);

            connection.Stop.OnBeginLoop += new BeginLoopEventHandler(Stop_OnBeginLoop);
            connection.Stop.OnEndLoop += new EndLoopEventHandler(Stop_OnEndLoop);

            connections.Add(connection);

            return 0;
        }