コード例 #1
0
ファイル: PrepForm.cs プロジェクト: jasonliaocn/chord
        private void button_search_Click(object sender, EventArgs e)
        {
            string strError = "";

            this.listView_results.Items.Clear();

            MainForm mainForm = null;

            if (this.MdiParent is MainForm)
            {
                mainForm = this.MdiParent as MainForm;
            }

            Debug.Assert(mainForm != null, "MdiParent 父窗口为 null");

            mainForm.SetMessage("");

            string strQueryWord  = this.textBox_queryWord.Text;
            string strFrom       = "读者证条码号";
            string strMatchStyle = "exact";

            if (string.IsNullOrEmpty(strQueryWord))
            {
                strFrom       = "__id";
                strMatchStyle = "left";
            }

            string strQueryXml = "<target list='" + mainForm.ArrivedDbName + ":" + strFrom + "'>" +
                                 "<item>" +
                                 "<word>" + strQueryWord + "</word>" +
                                 "<match>" + strMatchStyle + "</match>" +
                                 "<relation>=</relation>" +
                                 "<dataType>string</dataType>" +
                                 "</item>" +
                                 "<lang>zh</lang>" +
                                 "</target>";

            LibraryChannel channel = mainForm.GetChannel();

            try
            {
                string         strOutputStyle = "";
                SearchResponse searchResponse = channel.Search(strQueryXml, "", strOutputStyle);
                long           lRet           = searchResponse.SearchResult.Value;
                if (lRet == -1)
                {
                    strError = "检索发生错误:" + strError;
                    goto ERROR1;
                }
                else if (lRet == 0)
                {
                    strError = "读者'" + strQueryWord + "'没有到书信息";
                    goto ERROR1;
                }


                long     lHitCount     = lRet;
                long     lStart        = 0;
                long     lCount        = lHitCount;
                Record[] searchresults = null;
                for (; ;)
                {
                    Application.DoEvents();

                    lRet = channel.GetSearchResult("",
                                                   lStart,
                                                   lCount,
                                                   "id,xml",// cols,
                                                   "zh",
                                                   out searchresults,
                                                   out strError);
                    if (lRet == -1)
                    {
                        strError = "获得检索结果发生错误:" + strError;
                        goto ERROR1;
                    }
                    else if (lRet == 0)
                    {
                        strError = "没有获得到 0 条检索结果";
                        goto ERROR1;
                    }


                    int i = 0;
                    foreach (Record record in searchresults)
                    {
                        // string[] cols = record.Cols;
                        string strPath = record.Path;

                        string      strXML = record.RecordBody.Xml;
                        XmlDocument dom    = new XmlDocument();
                        dom.LoadXml(strXML);


                        string strState = DomUtil.GetElementText(dom.DocumentElement, "state");
                        if ("arrived" == strState)
                        {
                            strState = "图书在馆";
                        }
                        else if ("outof" == strState)
                        {
                            strState = "超过保留期";
                        }

                        string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location");
                        string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo");


                        string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode");
                        if (string.IsNullOrEmpty(strItemBarcode))
                        {
                            continue;
                        }
                        GetItemInfoResponse itemInfoResponse = channel.GetItemInfo(strItemBarcode,
                                                                                   "xml", // "xml:noborrowhistory", // resultType (itemType)
                                                                                   "xml"  // biblioType
                                                                                   );
                        lRet = itemInfoResponse.GetItemInfoResult.Value;
                        string strErrorInfo = itemInfoResponse.GetItemInfoResult.ErrorInfo;
                        if (lRet != 1)
                        {
                            MessageBox.Show(strErrorInfo);
                            continue;
                        }

                        string strOutMarcSyntax = "";
                        string strMARC          = "";
                        string strMarcXml       = itemInfoResponse.strBiblio;
                        int    nRet             = MarcUtil.Xml2Marc(strMarcXml,
                                                                    false,
                                                                    "", // 自动识别 MARC 格式
                                                                    out strOutMarcSyntax,
                                                                    out strMARC,
                                                                    out strError);
                        if (nRet == -1)
                        {
                            continue;
                        }

                        MarcRecord marcRecord = new MarcRecord(strMARC);
                        string     strISBN    = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent;
                        string     strTitle   = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent;
                        string     strAuthor  = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent;


                        string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode");
                        GetReaderInfoResponse readerInfoResponse = channel.GetReaderInfo(strReaderBarcode, "xml:noborrowhistory");
                        lRet         = readerInfoResponse.GetReaderInfoResult.Value;
                        strErrorInfo = readerInfoResponse.GetReaderInfoResult.ErrorInfo;
                        if (lRet != 1)
                        {
                            MessageBox.Show(strErrorInfo);
                            continue;
                        }

                        string strReaderXml = readerInfoResponse.results[0];
                        dom.LoadXml(strReaderXml);
                        string strName = DomUtil.GetElementText(dom.DocumentElement, "name");
                        string strDept = DomUtil.GetElementText(dom.DocumentElement, "department");


                        // MessageBox.Show(strXML);
                        string[] cols = new string[this.listView_results.Columns.Count];
                        cols[0]  = strItemBarcode;
                        cols[1]  = strISBN;
                        cols[2]  = strTitle;
                        cols[3]  = strAuthor;
                        cols[4]  = strAccessNo;
                        cols[5]  = strLocation;
                        cols[6]  = strReaderBarcode;
                        cols[7]  = strName;
                        cols[8]  = strDept;
                        cols[9]  = strState;
                        cols[10] = "未打印";


                        AppendNewLine(this.listView_results, strPath, cols);

                        mainForm.SetMessage((lStart + i + 1).ToString() + " / " + lHitCount);
                        i++;
                    }

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

                // this.listView_results.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            finally
            {
                mainForm.ReturnChannel(channel);
            }
            return;

ERROR1:
            MessageBox.Show(strError);
        }
コード例 #2
0
        string[] FillListViewItem(LibraryChannel channel, Record record)
        {
            string strErrorInfo = "";
            string strError     = "";

            string[] cols = new string[11];

            long lRet = 0;

            string      strXML = record.RecordBody.Xml;
            XmlDocument dom    = new XmlDocument();

            dom.LoadXml(strXML);

            string strState = DomUtil.GetElementText(dom.DocumentElement, "state");

            if ("arrived" == strState)
            {
                strState = "图书在馆";
            }
            else if ("outof" == strState)
            {
                strState = "超过保留期";
            }

            string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location");
            string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo");


            string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode");

            if (!string.IsNullOrEmpty(strItemBarcode))
            {
                GetItemInfoResponse itemInfoResponse = channel.GetItemInfo(strItemBarcode,
                                                                           "xml", // "xml:noborrowhistory", // resultType (itemType)
                                                                           "xml");

                lRet         = itemInfoResponse.GetItemInfoResult.Value;
                strErrorInfo = itemInfoResponse.GetItemInfoResult.ErrorInfo;
                if (lRet == 1)
                {
                    string strOutMarcSyntax = "";
                    string strMARC          = "";
                    string strMarcXml       = itemInfoResponse.strBiblio;
                    int    nRet             = MarcUtil.Xml2Marc(strMarcXml,
                                                                false,
                                                                "", // 自动识别 MARC 格式
                                                                out strOutMarcSyntax,
                                                                out strMARC,
                                                                out strError);
                    if (nRet != -1)
                    {
                        MarcRecord marcRecord = new MarcRecord(strMARC);
                        string     strISBN    = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent;
                        string     strTitle   = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent;
                        string     strAuthor  = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent;

                        cols[1] = strISBN;
                        cols[2] = strTitle;
                        cols[3] = strAuthor;
                    }
                }
            }

            string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode");
            GetReaderInfoResponse readerInfoResponse = channel.GetReaderInfo(strReaderBarcode, "xml:noborrowhistory");

            lRet         = readerInfoResponse.GetReaderInfoResult.Value;
            strErrorInfo = readerInfoResponse.GetReaderInfoResult.ErrorInfo;
            if (lRet == 1)
            {
                string strReaderXml = readerInfoResponse.results[0];
                dom.LoadXml(strReaderXml);
                string strName = DomUtil.GetElementText(dom.DocumentElement, "name");
                string strDept = DomUtil.GetElementText(dom.DocumentElement, "department");

                cols[6] = strReaderBarcode;
                cols[7] = strName;
                cols[8] = strDept;
            }

            cols[0]  = strItemBarcode;
            cols[4]  = strAccessNo;
            cols[5]  = strLocation;
            cols[9]  = strState;
            cols[10] = "未打印";

            return(cols);
        }
コード例 #3
0
ファイル: PrepForm.cs プロジェクト: renyh/dp2mini
        /// <summary>
        /// 获取记录详细信息
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="strRecord"></param>
        /// <param name="cols"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        int GetDetailInfo(RestChannel channel,
                          string recPath,
                          string strRecordXml,
                          out ReservationItem reserItem,
                          out string strError)
        {
            strError = "";

            reserItem         = new ReservationItem();
            reserItem.RecPath = recPath;

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(strRecordXml);
            XmlNode nodeRoot = dom.DocumentElement;

            reserItem.RecPath       = recPath;
            reserItem.State         = DomUtil.GetElementText(nodeRoot, "state");
            reserItem.ItemBarcode   = DomUtil.GetElementText(nodeRoot, "itemBarcode");
            reserItem.ItemRefID     = DomUtil.GetElementText(nodeRoot, "itemRefID");
            reserItem.PatronBarcode = DomUtil.GetElementText(nodeRoot, "readerBarcode");
            reserItem.LibraryCode   = DomUtil.GetElementText(nodeRoot, "libraryCode");
            reserItem.OnShelf       = DomUtil.GetElementText(nodeRoot, "onShelf");
            reserItem.NotifyTime    = DateTimeUtil.ToLocalTime(DomUtil.GetElementText(nodeRoot, "notifyDate"), "yyyy-MM-dd HH:mm:ss");
            reserItem.Location      = DomUtil.GetElementText(nodeRoot, "location");
            reserItem.AccessNo      = DomUtil.GetElementText(nodeRoot, "accessNo");

            // 以下字段为图书信息
            reserItem.ISBN   = "";
            reserItem.Title  = "";
            reserItem.Author = "";

            // 以下字段是读者信息
            reserItem.PatronName  = "";
            reserItem.Department  = "";
            reserItem.PatronTel   = "";
            reserItem.RequestTime = "";
            reserItem.ArrivedTime = "";

            // 备书产生的字段
            reserItem.PrintState  = DomUtil.GetElementText(nodeRoot, "printState");
            reserItem.CheckResult = "";// 是否找到图书,值为:找到/未找到

            // 过了保留期的数据,不再获取详细数据
            if (reserItem.State == C_State_outof)
            {
                strError = "因为过了保留期,不必再获取详细数据了。";
                return(0);
            }

            // 获取册信息以及书目信息
            if (!string.IsNullOrEmpty(reserItem.ItemBarcode))
            {
                GetItemInfoResponse response = channel.GetItemInfo(reserItem.ItemBarcode,
                                                                   "xml",
                                                                   "xml");
                if (response.GetItemInfoResult.Value == -1)
                {
                    strError = "获取册记录'" + reserItem.ItemBarcode + "'出错:" + response.GetItemInfoResult.ErrorInfo;
                    return(-1);
                }
                if (response.GetItemInfoResult.Value == 0)
                {
                    strError = "获取册记录'" + reserItem.ItemBarcode + "未命中";
                    return(-1);
                }

                string strOutMarcSyntax = "";
                string strMARC          = "";
                string strMarcXml       = response.strBiblio;
                int    nRet             = MarcUtil.Xml2Marc(strMarcXml,
                                                            false,
                                                            "", // 自动识别 MARC 格式
                                                            out strOutMarcSyntax,
                                                            out strMARC,
                                                            out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                MarcRecord marcRecord = new MarcRecord(strMARC);
                reserItem.ISBN   = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent;
                reserItem.Title  = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent;
                reserItem.Author = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent;
            }

            // 获取读者信息
            if (string.IsNullOrEmpty(reserItem.PatronBarcode) == false)
            {
                GetReaderInfoResponse readerRet = channel.GetReaderInfo(reserItem.PatronBarcode,
                                                                        "xml:noborrowhistory");
                if (readerRet.GetReaderInfoResult.Value == -1)
                {
                    strError = "获取册记录'" + reserItem.ItemBarcode + "'出错:" + readerRet.GetReaderInfoResult.ErrorInfo;
                    return(-1);
                }
                if (readerRet.GetReaderInfoResult.Value == 0)
                {
                    strError = "获取册记录'" + reserItem.ItemBarcode + "'未命中。";// + readerRet.GetReaderInfoResult.ErrorInfo;
                    return(-1);
                }

                string strPatronXml = readerRet.results[0];
                dom.LoadXml(strPatronXml);
                XmlNode rootNode = dom.DocumentElement;
                reserItem.PatronName = DomUtil.GetElementText(rootNode, "name");
                reserItem.Department = DomUtil.GetElementText(rootNode, "department");
                reserItem.PatronTel  = DomUtil.GetElementText(rootNode, "tel");

                /*
                 * - <root expireDate="">
                 * <barcode>XZP10199</barcode>
                 * <readerType>学生</readerType>
                 * <name>李明</name>
                 * <overdues />
                 * - <reservations>
                 * <request items="XZ000101" requestDate="Tue, 11 Feb 2020 00:30:27 +0800"
                 *  operator="XZP10199" state="arrived" arrivedDate="Tue, 11 Feb 2020 00:31:45 +0800"
                 *  arrivedItemBarcode="XZ000101" notifyID="59abfc23-f44f-4b34-a22c-f8a8aa5e289e"
                 *  accessNo="K825.6=76/Z780" location="星洲学校/图书馆,#reservation" />
                 * </reservations>
                 * </root>
                 */
                XmlNodeList nodeList = rootNode.SelectNodes("reservations/request");
                foreach (XmlNode node in nodeList)
                {
                    string arrivedItemBarcode = DomUtil.GetAttr(node, "arrivedItemBarcode");
                    if (arrivedItemBarcode == reserItem.ItemBarcode)
                    {
                        reserItem.RequestTime = DateTimeUtil.ToLocalTime(DomUtil.GetAttr(node, "requestDate"), "yyyy-MM-dd HH:mm:ss");
                        reserItem.ArrivedTime = DateTimeUtil.ToLocalTime(DomUtil.GetAttr(node, "arrivedDate"), "yyyy-MM-dd HH:mm:ss");
                        break;
                    }
                }
            }

            return(0);
        }