Ejemplo n.º 1
0
        /*public*/
        void ThreadFillAmercedMain()
        {
            string strError = "";
            m_bStopFillAmerced = false;

            LibraryChannel channel = new LibraryChannel();
            channel.Url = this.MainForm.LibraryServerUrl;

            channel.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin);

            channel.AfterLogin += new AfterLoginEventHandle(Channel_AfterLogin);

            try
            {
                string strResultSetName = "";
                // 获得一些系统参数
                string strDbName = "违约金";
                string strQueryXml = "";
                string strLang = "zh";

                long lRet = Channel.GetSystemParameter(
                    stop,
                    "amerce",
                    "dbname",
                    out strDbName,
                    out strError);
                if (lRet == -1)
                    goto ERROR1;

                if (m_bStopFillAmerced == true)
                    return;

                // 2010/12/16 change
                if (lRet == 0 || String.IsNullOrEmpty(strDbName) == true)
                {
                    if (String.IsNullOrEmpty(strError) == true)
                        strError = "违约金库名没有配置。";
                    goto ERROR1;
                }

                if (string.IsNullOrEmpty(this.FillAmercedParam.ReaderBarcode) == false)
                {
                    Safe_clearList(this.listView_amerced);

                    string strFrom = "读者证条码";
                    string strMatchStyle = "exact";

                    // 2007/4/5 改造 加上了 GetXmlStringSimple()
                    strQueryXml = "<target list='" + strDbName + ":" + strFrom + "'><item><word>"
        + StringUtil.GetXmlStringSimple(this.FillAmercedParam.ReaderBarcode)
        + "</word><match>" + strMatchStyle + "</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>" + strLang + "</lang></target>";

                    strResultSetName = "amercing";
                } // end of strReaderBarcode != ""
                else
                {
                    if (this.FillAmercedParam.IDs == null || this.FillAmercedParam.IDs.Count == 0)
                    {
                        strError = "IDs 参数不能为空";
                        goto ERROR1;
                    }

                    string strFrom = "ID";
                    string strMatchStyle = "exact";

                    strQueryXml = "<target list='" + strDbName + ":" + strFrom + "'>";
                    for (int i = 0; i < this.FillAmercedParam.IDs.Count; i++)
                    {
                        string strID = this.FillAmercedParam.IDs[i];

                        if (i > 0)
                            strQueryXml += "<operator value='OR' />";

                        strQueryXml += "<item><word>"
            + StringUtil.GetXmlStringSimple(strID)
            + "</word><match>" + strMatchStyle + "</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>" + strLang + "</lang>";
                    }
                    strQueryXml += "</target>";

                    strResultSetName = "amerced";
                }

                // 开始检索
                lRet = channel.Search(
    stop,
    strQueryXml,
    strResultSetName,
    "", // strOutputStyle
    out strError);
                if (lRet == 0)
                {
                    strError = "not found";
                    return;   // not found
                }
                if (lRet == -1)
                    goto ERROR1;

                if (m_bStopFillAmerced == true)
                    return;

                long lHitCount = lRet;

                long lStart = 0;
                long lPerCount = Math.Min(50, lHitCount);
                Record[] searchresults = null;

                // 获得结果集,装入listview
                for (; ; )
                {

                    if (m_bStopFillAmerced == true)
                    {
                        strError = "中断,列表不完整...";
                        goto ERROR1;
                    }
                    // stop.SetMessage("正在装入浏览信息 " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    lRet = channel.GetSearchResult(
                        stop,
                        strResultSetName,   // strResultSetName
                        lStart,
                        lPerCount,
                        "id",   // "id,cols"
                        strLang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                        goto ERROR1;

                    if (lRet == 0)
                    {
                        strError = "未命中";
                        return;
                    }

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        if (m_bStopFillAmerced == true)
                        {
                            strError = "中断,列表不完整...";
                            goto ERROR1;
                        }

                        string strPath = searchresults[i].Path;

                        byte[] timestamp = null;
                        string strXml = "";

                        lRet = channel.GetRecord(stop,
                            strPath,
                            out timestamp,
                            out strXml,
                            out strError);
                        if (lRet == -1)
                        {
                            if (channel.ErrorCode == ErrorCode.AccessDenied)
                                continue;
                            goto ERROR1;
                        }

                        int nRet = Safe_fillAmercedLine(
                            stop,
                            strXml,
                            strPath,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;

                    }

                    lStart += searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                        break;
                }


                // 第二阶段,填充摘要
                if (this.FillAmercedParam.FillSummary == true)
                {
                    List<ListViewItem> items = Safe_getItemList(this.listView_amerced);

                    for (int i = 0; i < items.Count; i++)
                    {
                        if (this.m_bStopFillAmerced == true)
                            return;

                        ListViewItem item = items[i];

                        string strSummary = "";
                        string strItemBarcode = "";

                        Safe_getBarcodeAndSummary(listView_amerced,
        item,
        out strItemBarcode,
        out strSummary);

                        // 已经有内容了,就不刷新了
                        if (String.IsNullOrEmpty(strSummary) == false)
                            continue;

                        if (String.IsNullOrEmpty(strItemBarcode) == true
                            /*&& String.IsNullOrEmpty(strItemRecPath) == true*/)
                            continue;

                        try
                        {
                            string strBiblioRecPath = "";
                            lRet = channel.GetBiblioSummary(
                                null,
                                strItemBarcode,
                                "", // strItemRecPath,
                                null,
                                out strBiblioRecPath,
                                out strSummary,
                                out strError);
                            if (lRet == -1)
                            {
                                strSummary = strError;  // 2009/3/13 changed
                                // return -1;
                            }

                        }
                        finally
                        {
                        }

                        Safe_changeItemText(item, COLUMN_AMERCING_BIBLIOSUMMARY, strSummary);
                    }
                }
                return;
            }
            finally
            {
                channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin);
                channel.AfterLogin -= new AfterLoginEventHandle(Channel_AfterLogin);
                channel.Close();
                m_bStopFillAmerced = true;
            }

        ERROR1:
            Safe_setError(this.listView_amerced, strError);
            // Safe_errorBox(strError);
        }