Example #1
0
        // 将一条书目记录下属的若干册记录装入列表
        // return:
        //      -2  用户中断
        //      -1  出错
        //      >=0 装入的册记录条数
        int LoadBiblioSubItems(
            LibraryChannel channel,
            string strBiblioRecPath,
            out string strError)
        {
            strError = "";

            Progress.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 下属的册记录 ...");

            if (this.FunctionType == "read")
            {
                AddBiblioLine(strBiblioRecPath);
            }

            int nCount = 0;

            long lPerCount    = 100; // 每批获得多少个
            long lStart       = 0;
            long lResultCount = 0;
            long lCount       = -1;

            for (; ;)
            {
                if (Progress.State != 0)
                {
                    strError = "用户中断";
                    return(-2);
                }

                EntityInfo[] entities = null;

                long lRet = channel.GetEntities(
                    Progress,
                    strBiblioRecPath,
                    lStart,
                    lCount,
                    "", // bDisplayOtherLibraryItem == true ? "getotherlibraryitem" : "",
                    "zh",
                    out entities,
                    out strError);
                if (lRet == -1)
                {
                    return(-1);
                }

                lResultCount = lRet;

                if (lRet == 0)
                {
                    return(nCount);
                }

                Debug.Assert(entities != null, "");

                foreach (EntityInfo entity in entities)
                {
                    string strXml = entity.OldRecord;

                    XmlDocument dom = new XmlDocument();
                    {
                        try
                        {
                            if (string.IsNullOrEmpty(strXml) == false)
                            {
                                dom.LoadXml(strXml);
                            }
                            else
                            {
                                dom.LoadXml("<root />");
                            }
                        }
                        catch (Exception ex)
                        {
                            strError = "XML 装入 DOM 出错: " + ex.Message;
                            return(-1);
                        }
                    }

                    DpRow row = new DpRow();

                    string strState    = DomUtil.GetElementText(dom.DocumentElement, "state");
                    string strBorrower = DomUtil.GetElementText(dom.DocumentElement, "borrower");
                    if (this.FunctionType == "borrow")
                    {
                        // 在借的册、或者状态有值的需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == false ||
                            string.IsNullOrEmpty(strState) == false)
                        {
                            SetGrayText(row);
                        }
                    }
                    else if (this.FunctionType == "return")
                    {
                        // 没有在借的册需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == true)
                        {
                            SetGrayText(row);
                        }
                        if (string.IsNullOrEmpty(this.VerifyBorrower) == false)
                        {
                            // 验证还书时,不是要求的读者所借阅的册,显示为灰色
                            if (strBorrower != this.VerifyBorrower)
                            {
                                SetGrayText(row);
                            }
                        }
                    }
                    else if (this.FunctionType == "renew")
                    {
                        // 没有在借的册需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == true)
                        {
                            SetGrayText(row);
                        }
                    }

                    string strBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode");
                    string strRefID   = DomUtil.GetElementText(dom.DocumentElement, "refID");

                    // 状态
                    DpCell cell = new DpCell();
                    cell.Text = strState;
                    row.Add(cell);

                    // 册条码号
                    cell = new DpCell();
                    if (string.IsNullOrEmpty(strBarcode) == false)
                    {
                        cell.Text = strBarcode;
                    }
                    else
                    {
                        cell.Text = "@refID:" + strRefID;
                    }
                    row.Add(cell);

                    // 在借情况
                    cell = new DpCell();
                    if (string.IsNullOrEmpty(strBorrower) == false)
                    {
                        string strReaderSummary = Program.MainForm.GetReaderSummary(strBorrower, false);
                        bool   bError           = (string.IsNullOrEmpty(strReaderSummary) == false && strReaderSummary[0] == '!');

                        if (bError == true)
                        {
                            cell.BackColor = Color.FromArgb(180, 0, 0);
                        }
                        else
                        {
                            if (IsGray(row) == true)
                            {
                                cell.BackColor = Color.FromArgb(220, 220, 0);
                            }
                            else
                            {
                                cell.BackColor = Color.FromArgb(180, 180, 0);
                            }
                        }

                        if (bError == false)
                        {
                            cell.Font = new System.Drawing.Font(this.dpTable_items.Font.FontFamily.Name, this.dpTable_items.Font.Size * 2, FontStyle.Bold);
                        }

                        cell.ForeColor = Color.FromArgb(255, 255, 255);
                        cell.Alignment = DpTextAlignment.Center;
                        cell.Text      = strReaderSummary;
                        // TODO: 后面还可加上借阅时间,应还时间
                    }
                    row.Add(cell);

                    // 书目摘要
                    string strSummary = "";
                    if (entity.ErrorCode != ErrorCodeValue.NoError)
                    {
                        strSummary = entity.ErrorInfo;
                    }
                    else
                    {
                        int nRet = Program.MainForm.GetBiblioSummary("@bibliorecpath:" + strBiblioRecPath,
                                                                     "",
                                                                     false,
                                                                     out strSummary,
                                                                     out strError);
                        if (nRet == -1)
                        {
                            strSummary = strError;
                        }
                    }
                    cell      = new DpCell();
                    cell.Text = strSummary;
                    row.Add(cell);

                    // 卷册
                    string strVolume = DomUtil.GetElementText(dom.DocumentElement, "volume");
                    cell      = new DpCell();
                    cell.Text = strVolume;
                    row.Add(cell);

                    // 地点
                    string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location");
                    cell      = new DpCell();
                    cell.Text = strLocation;
                    row.Add(cell);

                    // 价格
                    string strPrice = DomUtil.GetElementText(dom.DocumentElement, "price");
                    cell      = new DpCell();
                    cell.Text = strPrice;
                    row.Add(cell);

                    // 册记录路径
                    cell      = new DpCell();
                    cell.Text = entity.OldRecPath;
                    row.Add(cell);

                    this.dpTable_items.Rows.Add(row);
                    nCount++;
                }

                lStart += entities.Length;
                if (lStart >= lResultCount)
                {
                    break;
                }

                if (lCount == -1)
                {
                    lCount = lPerCount;
                }

                if (lStart + lCount > lResultCount)
                {
                    lCount = lResultCount - lStart;
                }
            }

            // 分割行
            if (lStart > 0)
            {
                DpRow row = new DpRow();
                row.Style = DpRowStyle.Seperator;
                this.dpTable_items.Rows.Add(row);
            }

            return(nCount);
        }
Example #2
0
        // 将一条书目记录下属的若干册记录装入列表
        // return:
        //      -2  用户中断
        //      -1  出错
        //      >=0 装入的册记录条数
        int LoadBiblioSubItems(
            out string strError)
        {
            strError = "";
            int nRet = 0;

            _biblio.ClearEntityEditControls("normal");

            string strBiblioRecPath = this._biblio.BiblioRecPath;
            if (string.IsNullOrEmpty(strBiblioRecPath) == true)
            {
                // 册信息部分显示为空
                // this._biblio.TrySetBlank("none");
                this._biblio.AddPlus();
                return 0;
            }

            AccountInfo _currentAccount = _base.GetAccountInfo(this._biblio.ServerName);
            if (_currentAccount == null)
            {
                strError = "服务器名 '" + this._biblio.ServerName + "' 没有配置";
                return -1;
            }

            // 如果不是本地服务器,则不需要装入册记录
            if (_currentAccount.IsLocalServer == false)
            {
                _base.CurrentAccount = null;
                // 册信息部分显示为空
                // this._biblio.TrySetBlank("none");
                this._biblio.AddPlus();
                return 0;
            }

            _channel = _base.GetChannel(_currentAccount.ServerUrl, _currentAccount.UserName);

            this.Progress.OnStop += new StopEventHandler(this.DoStop);
            //this.Progress.Initial("正在装入书目记录 '" + strBiblioRecPath + "' 下属的册记录 ...");
            this.Progress.BeginLoop();
            try
            {
                int nCount = 0;

                long lPerCount = 100; // 每批获得多少个
                long lStart = 0;
                long lResultCount = 0;
                long lCount = -1;
                for (; ; )
                {
                    if (Progress.State != 0)
                    {
                        strError = "用户中断";
                        return -2;
                    }

                    EntityInfo[] entities = null;

                    long lRet = _channel.GetEntities(
             Progress,
             strBiblioRecPath,
             lStart,
             lCount,
             "",  // bDisplayOtherLibraryItem == true ? "getotherlibraryitem" : "",
             "zh",
             out entities,
             out strError);
                    if (lRet == -1)
                        return -1;

                    lResultCount = lRet;

                    if (lRet == 0)
                    {
                        // 册信息部分显示为空
                        // this._biblio.TrySetBlank("none");
                        // return nCount;
                        goto END1;
                    }

                    Debug.Assert(entities != null, "");

                    foreach (EntityInfo entity in entities)
                    {
                        // string strXml = entity.OldRecord;
                        if (entity.ErrorCode != ErrorCodeValue.NoError)
                        {
                            // TODO: 显示错误信息
                            continue;
                        }

                        EntityEditControl edit_control = null;
                        // 添加一个新的册对象
                        nRet = this._biblio.NewEntity(entity.OldRecPath,
                            entity.OldTimestamp,
                            entity.OldRecord,
                            false,  // 不必滚入视野
                            false,  // 不改变 Focus
                            out edit_control,
                            out strError);
                        if (nRet == -1)
                            return -1;

                        nCount++;
                    }

                    lStart += entities.Length;
                    if (lStart >= lResultCount)
                        break;

                    if (lCount == -1)
                        lCount = lPerCount;

                    if (lStart + lCount > lResultCount)
                        lCount = lResultCount - lStart;
                }

                END1:
                this._biblio.AddPlus();
                return nCount;
            }
            finally
            {
                this.Progress.EndLoop();
                this.Progress.OnStop -= new StopEventHandler(this.DoStop);
                // this.Progress.Initial("");

                _base.ReturnChannel(_channel);
                _channel = null;
                _currentAccount = null;
            }
        }
Example #3
0
        // 检索出册数据
        // 带有偏移量的版本
        // 2009/6/9 
        // return:
        //      -2  实体库没有定义
        //      -1  出错
        //      其他  命中的全部结果数量。
        //
        public static int OpacSearchItems(
            OpacApplication app,
            LibraryChannel channel,
            ItemLoadEventHandler itemLoadProc,
            string strBiblioRecPath,
            int nStart,
            int nMaxCount,
            string strLang,
            string strLibraryCode,
            out string strError)
        {
            strError = "";
            // string strXml = "";

            // LibraryChannel channel = this.GetChannel(true, this.m_strParameters);
            try
            {
                string strStyle = "opac";
                if (string.IsNullOrEmpty(strLibraryCode) == true)
                    strStyle += ",getotherlibraryitem";
                else
                    strStyle += ",librarycode:" + strLibraryCode;

                long lStart = nStart;
                long lCount = nMaxCount;
                long lTotalCount = 0;
                for (; ; )
                {
                    EntityInfo[] iteminfos = null;
                    long lRet = // this.Channel.
                        channel.GetEntities(
                        null,
                        strBiblioRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        strLang,
                        out iteminfos,
                        out strError);
                    if (lRet == -1)
                    {
                        if (//this.Channel.
                            channel.ErrorCode == ErrorCode.ItemDbNotDef)
                            return -2;
                        return -1;
                    }

                    if (lRet == 0)
                    {
                        strError = "没有找到";
                        return 0;
                    }

                    lTotalCount = lRet;

                    if (lCount < 0)
                        lCount = lTotalCount - lStart;

                    if (lStart + lCount > lTotalCount)
                        lCount = lTotalCount - lStart;

                    // 处理
                    for (int i = 0; i < iteminfos.Length; i++)
                    {
                        EntityInfo info = iteminfos[i];

                        if (//this.ItemLoad != null
                            itemLoadProc != null)
                        {
                            ItemLoadEventArgs e = new ItemLoadEventArgs();
                            e.Path = info.OldRecPath;
                            e.Index = i;    // +nStart;
                            e.Count = nMaxCount;    // (int)lTotalCount - nStart;
                            e.Timestamp = info.OldTimestamp;
                            e.Xml = info.OldRecord;

                            //this.ItemLoad(this, e);
                            itemLoadProc(null, e);
                        }
                    }

                    lStart += iteminfos.Length;
                    lCount -= iteminfos.Length;

                    if (lStart >= lTotalCount)
                        break;
                    if (lCount <= 0)
                        break;
                }

                return (int)lTotalCount;
            }
            finally
            {
                // this.ReturnChannel(channel);
            }
        }
Example #4
0
        public static int OutputEntities(
            Stop stop,
            LibraryChannel channel,
            string strBiblioRecPath,
            string strDbType,
            XmlTextWriter writer,
            out string strError)
        {
            strError = "";

            bool bBegin = false;

            long lPerCount = 100; // 每批获得多少个
            long lStart = 0;
            long lResultCount = 0;
            long lCount = -1;
            for (; ; )
            {
                if (stop != null && stop.State != 0)
                {
                    strError = "用户中断";
                    return -1;
                }

                EntityInfo[] entities = null;

                long lRet = 0;

                channel.Timeout = new TimeSpan(0, 5, 0);
                if (strDbType == "item")
                {
                    lRet = channel.GetEntities(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "order")
                {
                    lRet = channel.GetOrders(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "issue")
                {
                    lRet = channel.GetIssues(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (strDbType == "comment")
                {
                    lRet = channel.GetComments(
                         stop,
                         strBiblioRecPath,
                         lStart,
                         lCount,
                         "", // "onlygetpath",
                         "zh",
                         out entities,
                         out strError);
                }
                if (lRet == -1)
                    return -1;

                lResultCount = lRet;

                if (lRet == 0)
                    return 0;

                Debug.Assert(entities != null, "");

                foreach (EntityInfo info in entities)
                {
                    if (info.ErrorCode != ErrorCodeValue.NoError)
                    {
                        strError = "路径为 '" + info.OldRecPath + "' 的册记录装载中发生错误: " + info.ErrorInfo;  // NewRecPath
                        return -1;
                    }

                    if (bBegin == false)
                    {
                        writer.WriteStartElement("dprms", strDbType + "Collection", DpNs.dprms);
                        bBegin = true;
                    }

                    XmlDocument item_dom = new XmlDocument();
                    item_dom.LoadXml(info.OldRecord);

                    writer.WriteStartElement("dprms", strDbType, DpNs.dprms);
                    writer.WriteAttributeString("path", info.OldRecPath);
                    writer.WriteAttributeString("timestamp", ByteArray.GetHexTimeStampString(info.OldTimestamp));
                    DomUtil.RemoveEmptyElements(item_dom.DocumentElement);
                    item_dom.DocumentElement.WriteContentTo(writer);
                    writer.WriteEndElement();
                }

                lStart += entities.Length;
                if (lStart >= lResultCount)
                    break;

                if (lCount == -1)
                    lCount = lPerCount;

                if (lStart + lCount > lResultCount)
                    lCount = lResultCount - lStart;
            }

            if (bBegin == true)
                writer.WriteEndElement();

            return 1;
        }
Example #5
0
        // 将一条书目记录下属的若干册记录装入列表
        // return:
        //      -2  用户中断
        //      -1  出错
        //      >=0 装入的册记录条数
        int LoadBiblioSubItems(
            LibraryChannel channel,
            string strBiblioRecPath,
            out string strError)
        {
            strError = "";

            Progress.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 下属的册记录 ...");

            if (this.FunctionType == "read")
            {
                AddBiblioLine(strBiblioRecPath);
            }

            int nCount = 0;

            long lPerCount = 100; // 每批获得多少个
            long lStart = 0;
            long lResultCount = 0;
            long lCount = -1;
            for (; ; )
            {
                if (Progress.State != 0)
                {
                    strError = "用户中断";
                    return -2;
                }

                EntityInfo[] entities = null;

                long lRet = channel.GetEntities(
         Progress,
         strBiblioRecPath,
         lStart,
         lCount,
         "",  // bDisplayOtherLibraryItem == true ? "getotherlibraryitem" : "",
         "zh",
         out entities,
         out strError);
                if (lRet == -1)
                    return -1;

                lResultCount = lRet;

                if (lRet == 0)
                    return nCount;

                Debug.Assert(entities != null, "");

                foreach (EntityInfo entity in entities)
                {
                    string strXml = entity.OldRecord;

                    XmlDocument dom = new XmlDocument();
                    {
                        try
                        {
                            if (string.IsNullOrEmpty(strXml) == false)
                                dom.LoadXml(strXml);
                            else
                                dom.LoadXml("<root />");
                        }
                        catch (Exception ex)
                        {
                            strError = "XML 装入 DOM 出错: " + ex.Message;
                            return -1;
                        }
                    }

                    DpRow row = new DpRow();

                    string strState = DomUtil.GetElementText(dom.DocumentElement, "state");
                    string strBorrower = DomUtil.GetElementText(dom.DocumentElement, "borrower");
                    if (this.FunctionType == "borrow")
                    {
                        // 在借的册、或者状态有值的需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == false
                            || string.IsNullOrEmpty(strState) == false)
                            SetGrayText(row);
                    }
                    else if (this.FunctionType == "return")
                    {
                        // 没有在借的册需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == true)
                            SetGrayText(row);
                        if (string.IsNullOrEmpty(this.VerifyBorrower) == false)
                        {
                            // 验证还书时,不是要求的读者所借阅的册,显示为灰色
                            if (strBorrower != this.VerifyBorrower)
                                SetGrayText(row);
                        }
                    }
                    else if (this.FunctionType == "renew")
                    {
                        // 没有在借的册需要显示为灰色
                        if (string.IsNullOrEmpty(strBorrower) == true)
                            SetGrayText(row);
                    }

                    string strBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode");
                    string strRefID = DomUtil.GetElementText(dom.DocumentElement, "refID");

                    // 状态
                    DpCell cell = new DpCell();
                    cell.Text = strState;
                    row.Add(cell);

                    // 册条码号
                    cell = new DpCell();
                    if (string.IsNullOrEmpty(strBarcode) == false)
                        cell.Text = strBarcode;
                    else
                        cell.Text = "@refID:" + strRefID;
                    row.Add(cell);

                    // 在借情况
                    cell = new DpCell();
                    if (string.IsNullOrEmpty(strBorrower) == false)
                    {
                        string strReaderSummary = this.MainForm.GetReaderSummary(strBorrower, false);
                        bool bError = (string.IsNullOrEmpty(strReaderSummary) == false && strReaderSummary[0] == '!');

                        if (bError == true)
                            cell.BackColor = Color.FromArgb(180, 0, 0);
                        else
                        {
                            if (IsGray(row) == true)
                                cell.BackColor = Color.FromArgb(220, 220, 0);
                            else
                                cell.BackColor = Color.FromArgb(180, 180, 0);
                        }

                        if (bError == false)
                            cell.Font = new System.Drawing.Font(this.dpTable_items.Font.FontFamily.Name, this.dpTable_items.Font.Size * 2, FontStyle.Bold);

                        cell.ForeColor = Color.FromArgb(255, 255, 255);
                        cell.Alignment = DpTextAlignment.Center;
                        cell.Text = strReaderSummary;
                        // TODO: 后面还可加上借阅时间,应还时间
                    }
                    row.Add(cell);

                    // 书目摘要
                    string strSummary = "";
                    if (entity.ErrorCode != ErrorCodeValue.NoError)
                    {
                        strSummary = entity.ErrorInfo;
                    }
                    else
                    {
                        int nRet = this.MainForm.GetBiblioSummary("@bibliorecpath:" + strBiblioRecPath,
                            "",
                            false,
                            out strSummary,
                            out strError);
                        if (nRet == -1)
                            strSummary = strError;
                    }
                    cell = new DpCell();
                    cell.Text = strSummary;
                    row.Add(cell);

                    // 卷册
                    string strVolume = DomUtil.GetElementText(dom.DocumentElement, "volume");
                    cell = new DpCell();
                    cell.Text = strVolume;
                    row.Add(cell);

                    // 地点
                    string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location");
                    cell = new DpCell();
                    cell.Text = strLocation;
                    row.Add(cell);

                    // 价格
                    string strPrice = DomUtil.GetElementText(dom.DocumentElement, "price");
                    cell = new DpCell();
                    cell.Text = strPrice;
                    row.Add(cell);

                    // 册记录路径
                    cell = new DpCell();
                    cell.Text = entity.OldRecPath;
                    row.Add(cell);

                    this.dpTable_items.Rows.Add(row);
                    nCount++;
                }

                lStart += entities.Length;
                if (lStart >= lResultCount)
                    break;

                if (lCount == -1)
                    lCount = lPerCount;

                if (lStart + lCount > lResultCount)
                    lCount = lResultCount - lStart;
            }

            // 分割行
            if (lStart > 0)
            {
                DpRow row = new DpRow();
                row.Style = DpRowStyle.Seperator;
                this.dpTable_items.Rows.Add(row);
            }

            return nCount;
        }