Example #1
0
        void RefreshLines(List<ListViewItem> items,
    bool bFillBiblioSummary)
        {
            string strError = "";
            string strTimeMessage = "";
            int nRet = 0;

            EnableControls(false);
            // MainForm.ShowProgress(true);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在刷新 ...");
            stop.BeginLoop();

            try
            {
                stop.SetProgressRange(0, items.Count);
                ProgressEstimate estimate = new ProgressEstimate();
                estimate.SetRange(0, items.Count);
                estimate.Start();

                int nLineCount = 0;
                List<string> lines = new List<string>();
                List<ListViewItem> part_items = new List<ListViewItem>();
                for (int i = 0; i < items.Count; i++)
                {
                    if (stop.State != 0)
                    {
                        strError = "用户中断1";
                        goto ERROR1;
                    }

                    ListViewItem item = items[i];

                    stop.SetMessage("正在刷新 " + item.Text + " ...");
                    stop.SetProgressValue(i);

                    string strRecPath = ListViewUtil.GetItemText(item, COLUMN_RECPATH);

                    lines.Add(strRecPath);
                    part_items.Add(item);
                    if (lines.Count >= 100)
                    {
                        if (lines.Count > 0)
                            stop.SetMessage("(" + i.ToString() + " / " + nLineCount.ToString() + ") 正在装入路径 " + lines[0] + " 等记录。"
                                + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(i)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));

                        // 处理一小批记录的装入
                        nRet = DoLoadRecords(lines,
                            part_items,
                            bFillBiblioSummary,
                            new string [] {"summary","@isbnissn"},
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;
                        lines.Clear();
                        part_items.Clear();
                    }
                }

                // 最后剩下的一批
                if (lines.Count > 0)
                {
                    if (lines.Count > 0)
                        stop.SetMessage("(" + nLineCount.ToString() + " / " + nLineCount.ToString() + ") 正在装入路径 " + lines[0] + " 等记录...");

                    // 处理一小批记录的装入
                    nRet = DoLoadRecords(lines,
                        part_items,
                        bFillBiblioSummary,
                        new string[] { "summary", "@isbnissn" },
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    lines.Clear();
                    part_items.Clear();
                }

                strTimeMessage = "共刷新册信息 " + nLineCount.ToString() + " 条。耗费时间: " + estimate.GetTotalTime().ToString();

            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("刷新完成。");
                stop.HideProgress();

                EnableControls(true);
                // MainForm.ShowProgress(false);
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Example #2
0
        // 从记录路径文件装载
        /// <summary>
        /// 从记录路径文件装载
        /// </summary>
        /// <param name="strRecPathFilename">记录路径文件名(全路径)</param>
        /// <param name="bClearBefore">是否要在装载前情况浏览列表</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错,错误信息在 strError 参数返回; 0: 成功</returns>
        public int LoadFromRecPathFile(string strRecPathFilename,
            bool bClearBefore,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (bClearBefore == true)
                ClearBefore();

            string strTimeMessage = "";

            StreamReader sr = null;
            try
            {
                // 打开文件
                sr = new StreamReader(strRecPathFilename);

                EnableControls(false);
                // MainForm.ShowProgress(true);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在初始化浏览器组件 ...");
                stop.BeginLoop();
                this.Update();
                this.MainForm.Update();

                try
                {
                    // this.m_nGreenItemCount = 0;

                    // 逐行读入文件内容
                    // 测算文件行数
                    int nLineCount = 0;
                    for (; ; )
                    {
                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "用户中断1";
                                goto ERROR1;
                            }
                        }

                        string strLine = "";
                        strLine = sr.ReadLine();

                        if (strLine == null)
                            break;

                        strLine = strLine.Trim();
                        if (String.IsNullOrEmpty(strLine) == true)
                            continue;

                        // 检查路径所从属书目库是否为图书/期刊库?
                        // return:
                        //      -1  error
                        //      0   不符合要求。提示信息在strError中
                        //      1   符合要求
                        nRet = CheckItemRecPath(this.comboBox_load_type.Text,
                            strLine,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;
                        if (nRet == 0)
                        {
                            GetErrorInfoForm().WriteHtml(strError + "\r\n");
                        }

                        nLineCount++;
                        // stop.SetMessage("正在装入册条码号 " + strLine + " 对应的记录...");
                    }

                    // 设置进度范围
                    stop.SetProgressRange(0, nLineCount);
                    sr.Close();

                    ProgressEstimate estimate = new ProgressEstimate();
                    estimate.SetRange(0, nLineCount);
                    estimate.Start();

                    List<string> lines = new List<string>();
                    // 正式开始处理
                    sr = new StreamReader(strRecPathFilename);
                    for (int i = 0; ; i++)
                    {
                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "用户中断1";
                                goto ERROR1;
                            }
                        }

                        string strLine = "";
                        strLine = sr.ReadLine();

                        stop.SetProgressValue(i);

                        if (strLine == null)
                            break;

                        strLine = strLine.Trim();
                        if (String.IsNullOrEmpty(strLine) == true)
                            continue;

                        if (strLine[0] == '#')
                            continue;   // 注释行

                        lines.Add(strLine);
                        if (lines.Count >= 100)
                        {
                            if (lines.Count > 0)
                                stop.SetMessage("(" + i.ToString() + " / " + nLineCount.ToString() + ") 正在装入路径 " + lines[0] + " 等记录。"
                                    + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(i)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));

                            // 处理一小批记录的装入
                            nRet = DoLoadRecords(lines,
                                null,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;
                            lines.Clear();
                        }
                    }

                    // 最后剩下的一批
                    if (lines.Count > 0)
                    {
                        if (lines.Count > 0)
                            stop.SetMessage("(" + nLineCount.ToString() + " / " + nLineCount.ToString() + ") 正在装入路径 " + lines[0] + " 等记录...");

                        // 处理一小批记录的装入
                        nRet = DoLoadRecords(lines,
                            null,
                            out strError);
                        if (nRet == -1)
                            goto ERROR1;
                        lines.Clear();
                    }

                    strTimeMessage = "共装入册记录 " + nLineCount.ToString() + " 条。耗费时间: " + estimate.GetTotalTime().ToString();
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("装入完成。");
                    stop.HideProgress();

                    EnableControls(true);
                    // MainForm.ShowProgress(false);
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                sr.Close();
            }

            this.MainForm.StatusBarMessage = strTimeMessage;

            return 0;
        ERROR1:
            return -1;
        }