예제 #1
0
        // 得到行对象。如果不存在,则临时创建一个
        /// <summary>
        /// 得到行对象。如果不存在,则临时创建一个
        /// </summary>
        /// <param name="strEntry">事项名</param>
        /// <returns>已经存在的或者新创建的 StringCacheItem 对象</returns>
        public StringCacheItem EnsureItem(string strEntry)
        {
#if NEWLOCK
            this.m_lock.EnterWriteLock();
#else
            this.m_lock.AcquireWriterLock(m_nLockTimeout);
#endif

            try
            {
                if (items.Count > MaxItems)
                {
                    this.items.Clear();
                }

                // 检查line事项是否存在
                StringCacheItem item = (StringCacheItem)items[strEntry];

                if (item == null)
                {
                    item     = new StringCacheItem();
                    item.Key = strEntry;

                    items.Add(strEntry, item);
                }

                Debug.Assert(item != null, "line在这里应该!=null");

                return(item);
            }
            finally
            {
#if NEWLOCK
                this.m_lock.ExitWriteLock();
#else
                this.m_lock.ReleaseWriterLock();
#endif
            }
        }
예제 #2
0
        // 2012/10/6
        // 获得读者摘要
        /// <summary>
        /// 获得读者摘要
        /// </summary>
        /// <param name="strPatronBarcode">读者证条码号</param>
        /// <returns>读者摘要</returns>
        public string GetPatronSummary(string strPatronBarcode)
        {
            string strError   = "";
            string strSummary = "";

            int nRet = strPatronBarcode.IndexOf("|");

            if (nRet != -1)
            {
                return("证条码号字符串 '" + strPatronBarcode + "' 中不应该有竖线字符");
            }


            // 看看cache中是否已经有了
            StringCacheItem item = null;

            item = Program.MainForm.SummaryCache.SearchItem(
                "P:" + strPatronBarcode);   // 前缀是为了和册条码号区别
            if (item != null)
            {
                Application.DoEvents();
                strSummary = item.Content;
                return(strSummary);
            }

            string strXml = "";

            string[] results = null;
            long     lRet    = Channel.GetReaderInfo(stop,
                                                     strPatronBarcode,
                                                     "xml",
                                                     out results,
                                                     out strError);

            if (lRet == -1)
            {
                strSummary = strError;
                return(strSummary);
            }
            else if (lRet > 1)
            {
                strSummary = "读者证条码号 " + strPatronBarcode + " 有重复记录 " + lRet.ToString() + "条";
                return(strSummary);
            }

            // 2012/10/1
            if (lRet == 0)
            {
                return("");  // not found
            }
            Debug.Assert(results.Length > 0, "");
            strXml = results[0];

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strSummary = "读者记录XML装入DOM时出错: " + ex.Message;
                return(strSummary);
            }

            // 读者姓名
            strSummary = DomUtil.GetElementText(dom.DocumentElement,
                                                "name");

            // 如果cache中没有,则加入cache
            item = Program.MainForm.SummaryCache.EnsureItem(
                "P:" + strPatronBarcode);
            item.Content = strSummary;

            return(strSummary);
        }