예제 #1
0
        internal void ClearListViewItems()
        {
            this._listviewRecords.Items.Clear();

            /*
             * // 2008/11/22
             * this.SortColumns.Clear();
             * SortColumns.ClearColumnSortDisplay(this.listView_records.Columns);
             * */
            ListViewUtil.ClearSortColumns(this._listviewRecords);

            // 清除所有需要确定的栏标题
            for (int i = 1; i < this._listviewRecords.Columns.Count; i++)
            {
                this._listviewRecords.Columns[i].Text = i.ToString();
            }

            ClearBiblioTable();
            ClearCommentViewer();
        }
예제 #2
0
        /// <summary>
        /// 从记录路径文件导入
        /// </summary>
        /// <param name="strFileName">文件名</param>
        /// <param name="strStyle">风格。"clear" 表示加入新内容前试图清除 list 中已有的内容,会出现对话框警告。如果没有这个值,则追加到现有内容后面</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错 0: 放弃处理 1:正常结束</returns>
        public int ImportFromRecPathFile(string strFileName,
                                         string strStyle,
                                         out string strError)
        {
            strError = "";

            SetStatusMessage("");   // 清除以前残留的显示

            if (string.IsNullOrEmpty(strFileName) == true)
            {
                OpenFileDialog dlg = new OpenFileDialog();

                dlg.Title            = "请指定要打开的" + this.DbTypeCaption + "记录路径文件名";
                dlg.FileName         = this.m_strUsedRecPathFilename;
                dlg.Filter           = "记录路径文件 (*.txt)|*.txt|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return(0);
                }

                this.m_strUsedRecPathFilename = dlg.FileName;
            }
            else
            {
                this.m_strUsedRecPathFilename = strFileName;
            }

            StreamReader sr = null;

            // bool bSkipBrowse = false;

            try
            {
                // TODO: 最好自动探测文件的编码方式?
                sr = new StreamReader(this.m_strUsedRecPathFilename, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                strError = "打开文件 " + this.m_strUsedRecPathFilename + " 失败: " + ex.Message;
                goto ERROR1;
            }

            stop.Style   = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在导入记录路径 ...");
            stop.BeginLoop();

            this.EnableControls(false);
            try
            {
                // 导入的事项是没有序的,因此需要清除已有的排序标志
                ListViewUtil.ClearSortColumns(this._listviewRecords);
                stop.SetProgressRange(0, sr.BaseStream.Length);

                List <ListViewItem> items = new List <ListViewItem>();

                if (this._listviewRecords.Items.Count > 0 &&
                    StringUtil.IsInList("clear", strStyle) == true)
                {
                    DialogResult result = MessageBox.Show(this,
                                                          "导入前是否要清除命中记录列表中的现有的 " + this._listviewRecords.Items.Count.ToString() + " 行?\r\n\r\n(如果不清除,则新导入的行将追加在已有行后面)\r\n(Yes 清除;No 不清除(追加);Cancel 放弃导入)",
                                                          this.DbType + "SearchForm",
                                                          MessageBoxButtons.YesNoCancel,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == DialogResult.Cancel)
                    {
                        return(0);
                    }
                    if (result == DialogResult.Yes)
                    {
                        ClearListViewItems();
                    }
                }

                for (; ;)
                {
                    Application.DoEvents();     // 出让界面控制权

                    if (stop != null)
                    {
                        if (stop.State != 0)
                        {
                            MessageBox.Show(this, "用户中断");
                            return(0);
                        }
                    }

                    string strRecPath = sr.ReadLine();

                    stop.SetProgressValue(sr.BaseStream.Position);

                    if (strRecPath == null)
                    {
                        break;
                    }

                    // 检查路径的正确性,检查数据库是否为实体库之一
                    string strDbName = Global.GetDbName(strRecPath);
                    if (string.IsNullOrEmpty(strDbName) == true)
                    {
                        strError = "'" + strRecPath + "' 不是合法的记录路径";
                        goto ERROR1;
                    }

                    if (this.DbType == "item")
                    {
                        if (this.MainForm.IsItemDbName(strDbName) == false)
                        {
                            strError = "路径 '" + strRecPath + "' 中的数据库名 '" + strDbName + "' 不是合法的实体库名。很可能所指定的文件不是实体库的记录路径文件";
                            goto ERROR1;
                        }
                    }
                    else if (this.DbType == "comment")
                    {
                        if (this.MainForm.IsCommentDbName(strDbName) == false)
                        {
                            strError = "路径 '" + strRecPath + "' 中的数据库名 '" + strDbName + "' 不是合法的评注库名。很可能所指定的文件不是评注库的记录路径文件";
                            goto ERROR1;
                        }
                    }
                    else if (this.DbType == "order")
                    {
                        if (this.MainForm.IsOrderDbName(strDbName) == false)
                        {
                            strError = "路径 '" + strRecPath + "' 中的数据库名 '" + strDbName + "' 不是合法的订购库名。很可能所指定的文件不是订购库的记录路径文件";
                            goto ERROR1;
                        }
                    }
                    else if (this.DbType == "issue")
                    {
                        if (this.MainForm.IsIssueDbName(strDbName) == false)
                        {
                            strError = "路径 '" + strRecPath + "' 中的数据库名 '" + strDbName + "' 不是合法的期库名。很可能所指定的文件不是期库的记录路径文件";
                            goto ERROR1;
                        }
                    }
                    else
                    {
                        throw new Exception("未知的DbType '" + this.DbType + "'");
                    }

                    ListViewItem item = new ListViewItem();
                    item.Text = strRecPath;

                    this._listviewRecords.Items.Add(item);

                    items.Add(item);

#if NO
                    if (bSkipBrowse == false &&
                        !(Control.ModifierKeys == Keys.Control))
                    {
                        int nRet = RefreshBrowseLine(item,
                                                     out strError);
                        if (nRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
                                                                  "获得浏览内容时出错: " + strError + "。\r\n\r\n是否继续获取浏览内容? (Yes 获取;No 不获取;Cancel 放弃导入)",
                                                                  this.DbType + "SearchForm",
                                                                  MessageBoxButtons.YesNoCancel,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button1);
                            if (result == System.Windows.Forms.DialogResult.No)
                            {
                                bSkipBrowse = true;
                            }
                            if (result == System.Windows.Forms.DialogResult.Cancel)
                            {
                                strError = "已中断";
                                break;
                            }
                        }
                    }
#endif
                }

                // 刷新浏览行
                int nRet = RefreshListViewLines(items,
                                                "",
                                                false,
                                                true,
                                                out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // 2014/1/15
                // 刷新书目摘要
                nRet = FillBiblioSummaryColumn(items,
                                               false,
                                               out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;

                this.EnableControls(true);

                if (sr != null)
                {
                    sr.Close();
                }
            }
            return(1);

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