Exemple #1
0
        public string GetPrevNextRecPath(string strStyle)
        {
            if (_recpaths.Count == 0)
            {
                return("");
            }

            while (true)
            {
                if (strStyle == "prev")
                {
                    _currentIndex--;
                }
                else
                {
                    _currentIndex++;
                }
                if (_currentIndex >= _recpaths.Count ||
                    _currentIndex < 0)
                {
                    return("");
                }
                string recpath = _recpaths[_currentIndex];
                // 遇到 Z39.50 命令行,要跳过去
                if (BiblioSearchForm.IsCmdLine(recpath) == false)
                {
                    return(recpath);
                }
            }
        }
Exemple #2
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            this.button_OK.Enabled = false;
            if (this.listView_records.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "尚未选择事项");
                this.button_OK.Enabled = true;
                return;
            }

            if (this.listView_records.SelectedItems.Count == 1)
            {
                string strPath = this.listView_records.SelectedItems[0].SubItems[0].Text;

                if (this.LoadNext != null &&
                    BiblioSearchForm.IsCmdLine(strPath))
                {
                    LoadNextBatchEventArgs e1 = new LoadNextBatchEventArgs {
                        All = false
                    };
                    this.LoadNext(this, e1);
                    this.button_OK.Enabled = true;
                    return;
                }
            }

            OnLoadDetail();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #3
0
        /*
         * private void listView_records_DoubleClick(object sender, EventArgs e)
         * {
         *  OnLoadDetail();
         *
         *  this.DialogResult = DialogResult.OK;
         *  this.Close();
         * }
         */

        string GetFirstRecordPath()
        {
            foreach (ListViewItem item in this.listView_records.Items)
            {
                var path = item.Text;
                if (BiblioSearchForm.IsCmdLine(path))
                {
                    continue;
                }
                return(path);
            }

            return(null);
        }
Exemple #4
0
        // 在固定面板区“浏览”属性页显示重复的书目记录列表
        // parameters:
        //      strRecPathList  路径字符串列表,逗号分隔。如果为空,表示要清除浏览窗口中原有的内容
        public int DisplayDupBiblioList(string strRecPathList,
                                        out string strError)
        {
            strError = "";

            BiblioSearchForm search_form = null;

            if (this.CurrentBrowseControl != null)
            {
                search_form = GetOwnerBiblioSearchForm(this.CurrentBrowseControl);
            }

            if (search_form == null)
            {
                search_form = new BiblioSearchForm();
                search_form.Show();
                search_form.DoDock(true);
            }
            else
            {
                search_form.ClearListViewItems();
            }

            this.ActivateFixPage("browse");

            List <string> list = StringUtil.SplitList(strRecPathList);

            search_form.EnableControls(false);
            if (list.Count == 0)
            {
                search_form.ClearListViewItems();
            }
            else
            {
                foreach (string recpath in list)
                {
                    search_form.AddLineToBrowseList(recpath);
                }
            }
            search_form.EnableControls(true);

            if (list.Count > 0)
            {
                search_form.RefreshAllLines();
            }
            return(0);
        }
Exemple #5
0
        public string GetPrevNextRecPath(string strStyle)
        {
REDO:
            ListViewItem item = BiblioSearchForm.MoveSelectedItem(this.listView_records, strStyle);

            if (item == null)
            {
                return("");
            }
            string text = ListViewUtil.GetItemText(item, 0);

            // 遇到 Z39.50 命令行,要跳过去
            if (BiblioSearchForm.IsCmdLine(text))
            {
                goto REDO;
            }
            return(text);
        }
Exemple #6
0
        // 根据 ListView 找到它所从属的 BiblioSearchForm
        public BiblioSearchForm GetOwnerBiblioSearchForm(Control listView)
        {
            if (_dockedBiblioSearchForm != null && _dockedBiblioSearchForm.ListViewRecords == listView)
            {
                return(_dockedBiblioSearchForm);
            }

            foreach (Form child in this.MdiChildren)
            {
                if (child is BiblioSearchForm)
                {
                    BiblioSearchForm searchForm = (BiblioSearchForm)child;
                    if (searchForm.ListViewRecords == listView)
                    {
                        return(searchForm);
                    }
                }
            }

            return(null);
        }
Exemple #7
0
        private void listView_records_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            ContextMenu contextMenu = new ContextMenu();
            MenuItem    menuItem    = null;

            int    nSelectedItemCount = this.listView_records.SelectedItems.Count;
            string strFirstColumn     = "";

            if (nSelectedItemCount > 0)
            {
                strFirstColumn = ListViewUtil.GetItemText(this.listView_records.SelectedItems[0], 0);
            }

            if (nSelectedItemCount == 1 && BiblioSearchForm.IsCmdLine(strFirstColumn))
            {
                CommandPopupMenu(sender, e);
                return;
            }
        }
Exemple #8
0
        Hashtable _biblioXmlTable = new Hashtable(); // biblioRecPath --> xml

        private void button_search_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            // 按下 Control 的时候空字符串也可以检索
            if (!(Control.ModifierKeys == Keys.Control) &&
                string.IsNullOrEmpty(this.textBox_queryWord.Text) == true)
            {
                strError = "请输入检索词";
                goto ERROR1;
            }

            this._biblioXmlTable.Clear();
            this._biblioRecPaths.Clear();
            this.dpTable_items.Rows.Clear();

            LibraryChannel channel = this.GetChannel();

            Progress.Style   = StopStyle.EnableHalfStop;
            Progress.OnStop += new StopEventHandler(this.DoStop);
            Progress.Initial("正在检索 ...");
            Progress.BeginLoop();

            this.EnableControls(false);

            m_nInSearching++;

            this.SetFloatMessage("waiting", "正在检索 ...");

            try
            {
                if (this.comboBox_from.Text == "")
                {
                    strError = "尚未选定检索途径";
                    goto ERROR1;
                }
                string strFromStyle = "";

                try
                {
                    strFromStyle = BiblioSearchForm.GetBiblioFromStyle(this.comboBox_from.Text);
                }
                catch (Exception ex)
                {
                    strError = "GetBiblioFromStyle() exception: " + ExceptionUtil.GetAutoText(ex);
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + this.comboBox_from.Text + "' 对应的style字符串";
                    goto ERROR1;
                }

                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (this.textBox_queryWord.Text == "")
                {
                    if (strMatchStyle == "null")
                    {
                        this.textBox_queryWord.Text = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                string strQueryWord = GetBiblioQueryString();

                string strQueryXml = "";
                long   lRet        = channel.SearchBiblio(Progress,
                                                          this.GetBiblioDbNames(), // "<全部>",
                                                          strQueryWord,            // this.textBox_queryWord.Text,
                                                          1000,
                                                          strFromStyle,
                                                          strMatchStyle,
                                                          this.Lang,
                                                          null, // strResultSetName
                                                          "",   // strSearchStyle
                                                          "",   // strOutputStyle
                                                          "",
                                                          out strQueryXml,
                                                          out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                // TODO: 最多检索1000条的限制,可以作为参数配置?

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    strError = "从途径 '" + strFromStyle + "' 检索 '" + strQueryWord + "' 没有命中";
                    this.SetFloatMessage("", strError);
                    this.textBox_queryWord.SelectAll();
                    this.textBox_queryWord.Focus();
                    return;
                }

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

                // 装入浏览格式
                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

                    if (Progress != null)
                    {
                        if (Progress.State != 0)
                        {
                            // MessageBox.Show(this, "用户中断");
                            break;  // 已经装入的还在
                        }
                    }

                    Progress.SetMessage("正在装入书目记录ID " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    lRet = channel.GetSearchResult(
                        Progress,
                        null,   // strResultSetName
                        lStart,
                        lPerCount,
                        this.FunctionType == "read" ? "id,xml" : "id", // "id,cols",
                        this.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        if (Progress.State != 0)
                        {
                            // MessageBox.Show(this, "用户中断");
                            break;
                        }

                        goto ERROR1;
                    }

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

                    // 处理浏览结果
                    foreach (DigitalPlatform.LibraryClient.localhost.Record record in searchresults)
                    {
                        this._biblioRecPaths.Add(record.Path);
                        // 存储书目记录 XML
                        if (this.FunctionType == "read" && record.RecordBody != null)
                        {
                            this._biblioXmlTable[record.Path] = record.RecordBody.Xml;
                        }
                    }

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

                this.SetFloatMessage("waiting", "正在装入册记录 ...");
                Progress.SetProgressRange(0, this._biblioRecPaths.Count);
                // 将每条书目记录下属的册记录装入
                int i = 0;
                foreach (string strBiblioRecPath in this._biblioRecPaths)
                {
                    Application.DoEvents();

                    if (Progress.State != 0)
                    {
                        break;
                    }

                    nRet = LoadBiblioSubItems(
                        channel,
                        strBiblioRecPath,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                    Progress.SetProgressValue(++i);
                }
                // MessageBox.Show(this, Convert.ToString(lRet) + " : " + strError);
            }
            finally
            {
                Progress.EndLoop();
                Progress.OnStop -= new StopEventHandler(this.DoStop);
                Progress.Initial("");
                Progress.HideProgress();

                // this.button_search.Enabled = true;
                this.EnableControls(true);

                this.ReturnChannel(channel);

                m_nInSearching--;
            }

            int nClickableCount = GetClickableCount();

            if (nClickableCount == 0)
            {
                this.SetFloatMessage("", "没有可用的册记录");
            }
            else
            {
                this.SetFloatMessage("", "");
                SelectFirstUseableItem();
                if (nClickableCount == 1 &&
                    this.AutoOperSingleItem == true)
                {
                    this.dpTable_items_DoubleClick(this, new EventArgs());
                }
            }
            this.textBox_queryWord.SelectAll();
            return;

ERROR1:
            this.SetFloatMessage("", strError);
            if (this.Visible == true)
            {
                MessageBox.Show(this, strError);
            }
            this.textBox_queryWord.SelectAll();
            this.textBox_queryWord.Focus();
        }
Exemple #9
0
        // 装载数据
        public override bool LoadData()
        {
            string strError = "";
            int    nRet     = 0;

            BiblioInfo info       = this.BiblioInfo;
            string     strRecPath = this.BiblioInfo.RecPath;

            if (string.IsNullOrEmpty(info.OldXml) == true)
            {
                lock (syncRoot)
                {
                    channel = this.Container.MainForm.GetChannel();
                }
                try
                {
                    // 显示 正在处理
                    this.HTML = GetWaitingHtml("正在获取书目记录 " + strRecPath);

                    ShowData();

                    string[] results     = null;
                    byte[]   baTimestamp = null;
                    // 获得书目记录
                    channel.Timeout = new TimeSpan(0, 0, 5);
                    long lRet = channel.GetBiblioInfos(
                        Stop,
                        strRecPath,
                        "",
                        new string[] { "xml" },   // formats
                        out results,
                        out baTimestamp,
                        out strError);
                    if (lRet == 0)
                    {
                        nRet     = -1;
                        strError = "获取书目记录 " + strRecPath + " 时出错: " + strError;
                    }
                    else if (lRet == -1)
                    {
                        nRet     = -1;
                        strError = "获取书目记录 " + strRecPath + " 时出错: " + strError;
                    }
                    else
                    {
                        if (results == null || results.Length == 0)
                        {
                            strError = "results error";
                            throw new Exception(strError);
                        }

                        // TODO: 对 BiblioInfo 的成员进行操作的时候,是否要 lock 一下对象?
                        string strXml = results[0];
                        info.OldXml    = strXml;
                        info.Timestamp = baTimestamp;
                        info.RecPath   = strRecPath;
                    }
                }
                finally
                {
                    LibraryChannel temp_channel = channel;
                    lock (syncRoot)
                    {
                        channel = null;
                    }
                    this.Container.MainForm.ReturnChannel(temp_channel);
                }
            }

            string strXml1  = "";
            string strHtml2 = "";
            string strXml2  = "";

            if (nRet == -1)
            {
                strHtml2 = HttpUtility.HtmlEncode(strError);
            }
            else
            {
                nRet = BiblioSearchForm.GetXmlHtml(info,
                                                   out strXml1,
                                                   out strXml2,
                                                   out strHtml2,
                                                   out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }
            }

            this.HTML = "<html>" +
                        this.Container.MainForm.GetMarcHtmlHeadString(true) +
                        "<body>" +
                        strHtml2 +
                        EntityForm.GetTimestampHtml(info.Timestamp) +
                        "</body></html>";

            this.XML = BiblioSearchForm.MergeXml(strXml1, strXml2);

            return(true);
        }
Exemple #10
0
        void menu_exportToBiblioSearchForm_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要装入其它查询窗的行";
                goto ERROR1;
            }

            BiblioSearchForm form = new BiblioSearchForm();
            form.MdiParent = this.MainForm;
            form.Show();

            form.EnableControls(false);
            foreach (ListViewItem item in this.listView_records.SelectedItems)
            {
                string strLine = Global.BuildLine(item);
                form.AddLineToBrowseList(strLine);
            }
            form.EnableControls(true);

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemple #11
0
        // 在一个新开的书目查询窗内检索key
        void listView_searchKeysAtNewWindow_Click(object sender, EventArgs e)
        {
            if (this.listView_records.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "尚未在列表中选定要操作的事项");
                return;
            }

            BiblioSearchForm form = new BiblioSearchForm();
            form.MdiParent = this.MainForm;
            // form.MainForm = this.MainForm;
            form.Show();

            ItemQueryParam query = (ItemQueryParam)this.listView_records.SelectedItems[0].Tag;
            Debug.Assert(query != null, "");

            ItemQueryParam input_query = new ItemQueryParam();

            input_query.QueryWord = ListViewUtil.GetItemText(this.listView_records.SelectedItems[0], 1);
            input_query.DbNames = query.DbNames;
            input_query.From = query.From;
            input_query.MatchStyle = "精确一致";

            // 检索命中记录(而不是key)
            form.DoSearch(false, false, input_query);
        }
Exemple #12
0
        // TODO: 优化后,和导出书目记录路径文件合并代码
        // 将从属的书目记录装入书目查询窗
        void menu_exportToBiblioSearchForm_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要装入书目查询窗的行";
                goto ERROR1;
            }

            BiblioSearchForm form = new BiblioSearchForm();
            form.MdiParent = this.MainForm;
            form.Show();

            int nWarningLineCount = 0;
            int nDupCount = 0;

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在装入记录到书目查询窗 ...");
            stop.BeginLoop();

            form.EnableControls(false);
            try
            {
#if NO
                List<string> biblio_recpaths = new List<string>();
                Hashtable table = new Hashtable();
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    int nCol = -1;
                    string strBiblioRecPath = "";
                    // 获得事项所从属的书目记录的路径
                    // return:
                    //      -1  出错
                    //      0   相关数据库没有配置 parent id 浏览列
                    //      1   找到
                    nRet = GetBiblioRecPath(item,
                        true,
                        out nCol,
                        out strBiblioRecPath,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        // TODO: 转而采用检索法获得书目记录路径
                        nWarningLineCount++;
                        continue;
                    }

                    // 去重,并保持原始顺序
                    if (table.ContainsKey(strBiblioRecPath) == false)
                    {
                        biblio_recpaths.Add(strBiblioRecPath);
                        table[strBiblioRecPath] = 1;
                    }
                    else
                        nDupCount++;
                }
#endif
                List<string> biblio_recpaths = new List<string>();
                nRet = GetSelectedBiblioRecPath(out biblio_recpaths,
            ref nWarningLineCount,
            ref nDupCount,
            out strError);
                if (nRet == -1)
                    goto ERROR1;

                foreach (string path in biblio_recpaths)
                {
                    form.AddLineToBrowseList(path);
                }
            }
            finally
            {
                form.EnableControls(true);

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

            form.RefreshAllLines();

            string strText = "";
            if (nWarningLineCount > 0)
                strText = "有 " + nWarningLineCount.ToString() + " 行因为相关库浏览格式没有包含父记录 ID 列而被忽略";
            if (nDupCount > 0)
            {
                if (string.IsNullOrEmpty(strText) == false)
                    strText += "\r\n\r\n";
                strText += "书目记录有 " + nDupCount.ToString() + " 项重复被忽略";
            }

            if (string.IsNullOrEmpty(strText) == false)
                MessageBox.Show(this, strText);

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }