Example #1
0
        // 通用的,遍历和处理读者记录的函数
        // 该函数的弱点是速度慢,优点是能按照特殊风格来获取读者记录
        // return:
        //      -1  出错。包括用户中断的情况
        //      >=0 实际处理的读者记录数
        public int ProcessPatrons(List<string> reader_barcodes,
            string strGetReaderInfoStyle,
            Delegate_processPatron func,
            out string strError)
        {
            strError = "";

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在处理读者记录 ...");
            stop.BeginLoop();

            EnableControls(false);
            this.listView_records.Enabled = false;

            try
            {
                if (stop != null)
                    stop.SetProgressRange(0, reader_barcodes.Count);

                int nReaderIndex = 0;
                foreach (string strBarcode in reader_barcodes)
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        return -1;
                    }

                    if (string.IsNullOrEmpty(strBarcode) == true)
                        continue;

                    // 获得读者记录
                    byte[] baTimestamp = null;
                    string strOutputRecPath = "";

                    stop.SetMessage("正在处理读者记录 " + strBarcode + " ...");

                    string[] results = null;
                    long lRet = Channel.GetReaderInfo(
                        stop,
                        strBarcode,
                        string.IsNullOrEmpty(strGetReaderInfoStyle) ?
                        "advancexml,advancexml_borrow_bibliosummary,advancexml_overdue_bibliosummary"
                        : strGetReaderInfoStyle, // advancexml_history_bibliosummary
                        out results,
                        out strOutputRecPath,
                        out baTimestamp,
                        out strError);
                    if (lRet == -1)
                        return -1;

                    if (lRet == 0)
                        return -1;

                    if (lRet > 1)   // 不可能发生吧?
                    {
                        strError = "读者证条码号 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。";
                        return -1;
                    }
                    if (results == null || results.Length < 1)
                    {
                        strError = "返回的results不正常。";
                        return -1;
                    }

                    string strXml = results[0];

                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载读者记录 XML 到 DOM 时发生错误: " + ex.Message;
                        return -1;
                    }

                    if (func != null)
                    {
                        if (func(strOutputRecPath,
                dom,
                baTimestamp) == false)
                            break;
                    }

                    nReaderIndex++;
                    if (stop != null)
                        stop.SetProgressValue(nReaderIndex);
                }

                return nReaderIndex;    // 实际处理的读者记录数
            }
            catch (Exception ex)
            {
                strError = "ProcessPatrons() 出现异常: " + ExceptionUtil.GetExceptionText(ex);
                return -1;
            }
            finally
            {
                EnableControls(true);
                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;
            }
        }
Example #2
0
        // 通用的,遍历和处理读者记录的函数
        // 该函数的弱点是不能按照特殊风格来获取读者记录,而 ProcessPatrons() 能做到
        // 优点是速度特别快
        // return:
        //      -1  出错。包括用户中断的情况
        //      >=0 实际处理的读者记录数
        public int ProcessSelectedPatrons(
            Delegate_processPatron func,
            out string strError)
        {
            strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要处理的读者记录事项";
                return -1;
            }

            // 读者信息缓存
            // 如果已经初始化,则保持
            if (this.m_biblioTable == null)
                this.m_biblioTable = new Hashtable();

            this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始进行读者记录校验</div>");

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在处理读者记录 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.listView_records.Enabled = false;
            try
            {
                if (stop != null)
                    stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);

                List<ListViewItem> items = new List<ListViewItem>();
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    if (string.IsNullOrEmpty(item.Text) == true)
                        continue;

                    items.Add(item);
                }

                ListViewPatronLoader loader = new ListViewPatronLoader(this.Channel,
                    stop,
                    items,
                    this.m_biblioTable);
                loader.DbTypeCaption = this.DbTypeCaption;

                int i = 0;
                foreach (LoaderItem item in loader)
                {
                    Application.DoEvents();	// 出让界面控制权

                    if (stop != null && stop.State != 0)
                    {
                        strError = "用户中断";
                        return -1;
                    }

                    stop.SetProgressValue(i);

                    BiblioInfo info = item.BiblioInfo;

                    // this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(info.RecPath) + "</div>");

                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(info.OldXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载读者记录 XML 到 DOM 时发生错误: " + ex.Message;
                        return -1;
                    }

                    if (func != null)
                    {
                        if (func(info.RecPath,
                dom,
                info.Timestamp) == false)
                            break;
                    }

                    i++;
                }

                return i;
            }
            catch (Exception ex)
            {
                strError = "处理读者记录的过程中出现异常: " + ExceptionUtil.GetDebugText(ex);
                return -1;
            }
            finally
            {
                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.EnableControls(true);

                this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束执行读者记录处理</div>");
            }
        }