// 添加自由词,前半部分工作 void CommentControl_AddSubject(object sender, AddSubjectEventArgs e) { string strError = ""; // 根据书目库名获得MARC格式语法名 // return: // null 没有找到指定的书目库名 string strMarcSyntax = MainForm.GetBiblioSyntax(this.BiblioDbName); if (strMarcSyntax == null) { strError = "书目库名 '" + this.BiblioDbName + "' 居然没有找到"; goto ERROR1; } List<string> reserve_subjects = null; List<string> exist_subjects = null; int nRet = ItemInfoForm.GetSubjectInfo(this.GetMarc(), // this.m_marcEditor.Marc, strMarcSyntax, out reserve_subjects, out exist_subjects, out strError); if (nRet == -1) goto ERROR1; AddSubjectDialog dlg = new AddSubjectDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.ReserveSubjects = reserve_subjects; dlg.ExistSubjects = exist_subjects; dlg.HiddenNewSubjects = e.HiddenSubjects; dlg.NewSubjects = e.NewSubjects; this.MainForm.AppInfo.LinkFormState(dlg, "entityform_addsubjectdialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) { e.Canceled = true; return; } List<string> subjects = new List<string>(); subjects.AddRange(dlg.ExistSubjects); subjects.AddRange(dlg.NewSubjects); StringUtil.RemoveDupNoSort(ref subjects); // 去重 StringUtil.RemoveBlank(ref subjects); // 去掉空元素 string strMARC = this.GetMarc(); // this.m_marcEditor.Marc; // 修改指示符1为空的那些 610 字段 // parameters: // strSubject 可以修改的自由词的总和。包括以前存在的和本次添加的 nRet = ItemInfoForm.ChangeSubject(ref strMARC, strMarcSyntax, subjects, out strError); if (nRet == -1) goto ERROR1; // this.m_marcEditor.Marc = strMARC; // this.m_marcEditor.Changed = true; this.SetMarc(strMARC); this.SetMarcChanged(true); return; ERROR1: e.ErrorInfo = strError; if (e.ShowErrorBox == true) MessageBox.Show(this, strError); e.Canceled = true; }
// 增添自由词 private void toolStripButton_addSubject_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取书目记录 ..."); stop.BeginLoop(); try { List<string> reserve_subjects = null; List<string> exist_subjects = null; byte[] biblio_timestamp = null; string strBiblioXml = ""; nRet = GetExistSubject( this.BiblioRecPath, out strBiblioXml, out reserve_subjects, out exist_subjects, out biblio_timestamp, out strError); if (nRet == -1) goto ERROR1; string strCommentState = ""; string strNewSubject = ""; byte[] item_timestamp = null; nRet = GetCommentContent(this.ItemRecPath, out strNewSubject, out strCommentState, out item_timestamp, out strError); if (nRet == -1) goto ERROR1; AddSubjectDialog dlg = new AddSubjectDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.ReserveSubjects = reserve_subjects; dlg.ExistSubjects = exist_subjects; dlg.HiddenNewSubjects = StringUtil.SplitList(strNewSubject.Replace("\\r", "\n"), '\n'); if (StringUtil.IsInList("已处理", strCommentState) == false) dlg.NewSubjects = dlg.HiddenNewSubjects; this.MainForm.AppInfo.LinkFormState(dlg, "iteminfoform_addsubjectdialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) return; List<string> subjects = new List<string>(); subjects.AddRange(dlg.ExistSubjects); subjects.AddRange(dlg.NewSubjects); StringUtil.RemoveDupNoSort(ref subjects); // 去重 StringUtil.RemoveBlank(ref subjects); // 去掉空元素 // 修改指示符1为空的那些 610 字段 // parameters: // strSubject 可以修改的自由词的总和。包括以前存在的和本次添加的 nRet = ChangeSubject(ref strBiblioXml, subjects, out strError); // 保存书目记录 byte[] output_timestamp = null; string strOutputBiblioRecPath = ""; long lRet = Channel.SetBiblioInfo( stop, "change", this.BiblioRecPath, "xml", strBiblioXml, biblio_timestamp, "", out strOutputBiblioRecPath, out output_timestamp, out strError); if (lRet == -1) goto ERROR1; // 修改评注记录状态 // return: // -1 出错 // 0 没有发生修改 // 1 发生了修改 nRet = ChangeCommentState( this.BiblioRecPath, this.ItemRecPath, "已处理", "", out strError); if (nRet == -1) goto ERROR1; } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } // 重新装载内容 this.Reload(); return; ERROR1: MessageBox.Show(this, strError); }