Beispiel #1
0
        // 快速修改记录
        void menu_quickChangeRecords_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;
            // bool bSkipUpdateBrowse = false; // 是否要跳过更新浏览行

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要快速修改的读者记录事项";
                goto ERROR1;
            }

            ChangeReaderActionDialog dlg = new ChangeReaderActionDialog();
            MainForm.SetControlFont(dlg, this.Font, false);
            dlg.Text = "快速修改读者记录 -- 请指定动作参数";
            dlg.MainForm = this.MainForm;
            dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable);
            dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable);

            this.MainForm.AppInfo.LinkFormState(dlg, "readersearchform_quickchangedialog_state");
            dlg.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(dlg);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            DateTime now = DateTime.Now;

            // TODO: 检查一下,看看是否一项修改动作都没有
            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();

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

            int nProcessCount = 0;
            int nChangedCount = 0;
            try
            {
                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);

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

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

                    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;
                        goto ERROR1;
                    }

                    string strDebugInfo = "";
                    // 修改一个读者记录XmlDocument
                    // return:
                    //      -1  出错
                    //      0   没有实质性修改
                    //      1   发生了修改
                    nRet = ModifyRecord(ref dom,
                        now,
                        out strDebugInfo,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    this.MainForm.OperHistory.AppendHtml("<div class='debug normal'>" + HttpUtility.HtmlEncode(strDebugInfo).Replace("\r\n", "<br/>") + "</div>");

                    nProcessCount++;

                    if (nRet == 1)
                    {
                        string strXml = dom.OuterXml;
                        if (info != null)
                        {
                            if (string.IsNullOrEmpty(info.NewXml) == true)
                                this.m_nChangedCount++;
                            info.NewXml = strXml;
                        }

                        item.ListViewItem.BackColor = SystemColors.Info;
                        item.ListViewItem.ForeColor = SystemColors.InfoText;
                    }

                    i++;
                    nChangedCount++;
                }
            }
            finally
            {
                EnableControls(true);
                this.listView_records.Enabled = true;

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

                this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束快速修改读者记录</div>");
            }

            DoViewComment(false);
            MessageBox.Show(this, "修改读者记录 " + nChangedCount.ToString() + " 条 (共处理 " + nProcessCount.ToString() + " 条)\r\n\r\n(注意修改并未自动保存。请在观察确认后,使用保存命令将修改保存回读者库)");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Beispiel #2
0
        // 快速修改记录
        void menu_quickChangeRecords_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;
            bool bSkipUpdateBrowse = false; // 是否要跳过更新浏览行

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选择要快速修改的读者记录事项";
                goto ERROR1;
            }

            ChangeReaderActionDialog dlg = new ChangeReaderActionDialog();
            MainForm.SetControlFont(dlg, this.Font, false);
            dlg.Text = "快速修改读者记录 -- 请指定动作参数";
            dlg.MainForm = this.MainForm;
            dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable);
            dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable);

            this.MainForm.AppInfo.LinkFormState(dlg, "readersearchform_quickchangedialog_state");
            dlg.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(dlg);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            DateTime now = DateTime.Now;

            // TODO: 检查一下,看看是否一项修改动作都没有

            stop.Style = StopStyle.EnableHalfStop;
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("快速修改读者记录 ...");
            stop.BeginLoop();

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

            int nProcessCount = 0;
            int nChangedCount = 0;
            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);

                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    string strRecPath = item.Text;

                    if (string.IsNullOrEmpty(strRecPath) == true)
                    {
                        // Debug.Assert(false, "");
                        continue;
                    }

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

                    stop.SetMessage("正在装入读者记录 " + strRecPath + " ...");

                    string[] results = null;
                    long lRet = Channel.GetReaderInfo(
                        stop,
                        "@path:" + strRecPath,
                        "xml",
                        out results,
                        out strOutputRecPath,
                        out baTimestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        goto ERROR1;
                    }

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

                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载XML到DOM时发生错误: " + ex.Message;
                        goto ERROR1;
                    }

                    // 修改一个读者记录XmlDocument
                    // return:
                    //      -1  出错
                    //      0   没有实质性修改
                    //      1   发生了修改
                    nRet = ModifyRecord(ref dom,
                        now,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    nProcessCount++;

                    if (nRet == 0)
                        continue;

                    Debug.Assert(nRet == 1, "");


                    ErrorCodeValue kernel_errorcode;

                    byte[] baNewTimestamp = null;
                    string strExistingXml = "";
                    string strSavedXml = "";
                    string strSavedPath = "";
                    lRet = Channel.SetReaderInfo(
    stop,
    "change",
    strRecPath,
    dom.OuterXml,
    strXml,
    baTimestamp,
    out strExistingXml,
    out strSavedXml,
    out strSavedPath,
    out baNewTimestamp,
    out kernel_errorcode,
    out strError);
                    if (lRet == -1)
                    {
                        DialogResult result = MessageBox.Show(this,
"保存读者记录 '" + strRecPath + "' 时出错: " + strError + "。\r\n\r\n是否重试保存? (Yes 重试;No 忽略此条记录的保存,但是急需处理后面的记录;Cancel 中断批修改操作)",
"ReaderSearchForm",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
                        if (result == System.Windows.Forms.DialogResult.Yes)
                            goto REDO_CHANGE;

                        if (result == System.Windows.Forms.DialogResult.No)
                            continue;
                        if (result == System.Windows.Forms.DialogResult.Cancel)
                            goto ERROR1;
                    }

                    // 刷新浏览行
                    if (bSkipUpdateBrowse == false)
                    {
                        nRet = RefreshBrowseLine(item,
    out strError);
                        if (nRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
        "刷新浏览内容时出错: " + strError + "。\r\n\r\n后面是否继续(在修改操作后)刷新浏览内容? (Yes 获取;No 不获取;Cancel 中断批修改操作)",
        "ReaderSearchForm",
        MessageBoxButtons.YesNoCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                            if (result == System.Windows.Forms.DialogResult.No)
                                bSkipUpdateBrowse = true;
                            if (result == System.Windows.Forms.DialogResult.Cancel)
                                break;
                        }
                    }

                    stop.SetProgressValue(++i);
                    nChangedCount++;
                }
            }
            finally
            {
                EnableControls(true);
                this.listView_records.Enabled = true;

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();
                stop.Style = StopStyle.None;
            }
            MessageBox.Show(this, "成功修改读者记录 " + nChangedCount.ToString() + " 条 (共处理 "+nProcessCount.ToString()+" 条)");
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }