// 追加保存到数据库 void menu_saveToDatabase_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; if (this.listView_browse.SelectedIndices.Count == 0) { strError = "尚未选定要保存记录的浏览行"; goto ERROR1; } string strLastSavePath = m_mainForm.LastSavePath; if (String.IsNullOrEmpty(strLastSavePath) == false) { string strOutputPath = ""; nRet = MarcDetailForm.ChangePathToAppendStyle(strLastSavePath, out strOutputPath, out strError); if (nRet == -1) { m_mainForm.LastSavePath = ""; // 避免下次继续出错 goto ERROR1; } strLastSavePath = strOutputPath; } SaveRecordDlg dlg = new SaveRecordDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.SaveToDbMode = true; // 不允许在textbox中修改路径 dlg.MainForm = this.m_mainForm; dlg.GetDtlpSearchParam += new GetDtlpSearchParamEventHandle(dlg_GetDtlpSearchParam); dlg.GetDp2SearchParam += new GetDp2SearchParamEventHandle(dlg_GetDp2SearchParam); { dlg.RecPath = strLastSavePath; dlg.Text = "请选择目标数据库"; } // dlg.StartPosition = FormStartPosition.CenterScreen; this.MainForm.AppInfo.LinkFormState(dlg, "SaveRecordDlg_state"); dlg.UiState = this.MainForm.AppInfo.GetString("AmazonSearchForm", "SaveRecordDlg_uiState", ""); dlg.ShowDialog(this); this.MainForm.AppInfo.SetString("AmazonSearchForm", "SaveRecordDlg_uiState", dlg.UiState); if (dlg.DialogResult != DialogResult.OK) return; m_mainForm.LastSavePath = dlg.RecPath; string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(dlg.RecPath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; bool bForceFull = false; if (HasSelectionContainBriefRecords() == true) { DialogResult result = MessageBox.Show(this, "即将保存的记录中有Brief(简要)格式的记录,是否在保存前重新获取为Full(完整)格式的记录?\r\n\r\n(Yes: 是,要完整格式的记录; No: 否,依然保存简明格式的记录; Cancel: 取消,放弃整个保存操作", "AmazonSearchForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Cancel) return; if (result == System.Windows.Forms.DialogResult.Yes) bForceFull = true; } // 首先获得详细记录 if (bForceFull == true) { ReloadFullElementSet(); bool bError = WaitSearchFinish(); } // TODO: 禁止问号以外的其它ID DigitalPlatform.Stop stop = null; stop = new DigitalPlatform.Stop(); stop.Register(m_mainForm.stopManager, true); // 和容器关联 stop.BeginLoop(); this.EnableControls(false); try { // dtlp协议的记录保存 if (strProtocol.ToLower() == "dtlp") { DtlpSearchForm dtlp_searchform = this.GetDtlpSearchForm(); if (dtlp_searchform == null) { strError = "没有连接的或者打开的DTLP检索窗,无法保存记录"; goto ERROR1; } for (int i = 0; i < this.listView_browse.SelectedIndices.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } int index = this.listView_browse.SelectedIndices[i]; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; string strMARC = ""; nRet = this.GetOneRecord( "marc", index, // 即将废止 "index:" + index.ToString(), bForceFull == true ? "force_full" : "", // false, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = ""; if (record.m_strSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (record.m_strSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; // TODO: 有些格式不适合保存到目标数据库 byte[] baOutputTimestamp = null; string strOutputPath = ""; nRet = dtlp_searchform.SaveMarcRecord( strPath, strMARC, baTimestamp, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; } MessageBox.Show(this, "保存成功"); return; } else if (strProtocol.ToLower() == "dp2library") { dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法保存记录"; goto ERROR1; } string strDp2ServerName = ""; string strPurePath = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strDp2ServerName, out strPurePath); string strTargetMarcSyntax = ""; try { NormalDbProperty prop = dp2_searchform.GetDbProperty(strDp2ServerName, dp2SearchForm.GetDbName(strPurePath)); strTargetMarcSyntax = prop.Syntax; if (string.IsNullOrEmpty(strTargetMarcSyntax) == true) strTargetMarcSyntax = "unimarc"; } catch (Exception ex) { strError = "在获得目标库特性时出错: " + ex.Message; goto ERROR1; } bool bSkip = false; int nSavedCount = 0; for (int i = 0; i < this.listView_browse.SelectedIndices.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } } int index = this.listView_browse.SelectedIndices[i]; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; string strMARC = ""; nRet = this.GetOneRecord( "marc", index, // 即将废止 "index:" + index.ToString(), bForceFull == true ? "force_full" : "", // false, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = ""; if (record.m_strSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (record.m_strSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; // 有些格式不适合保存到目标数据库 if (strTargetMarcSyntax != strMarcSyntax) { if (bSkip == true) continue; strError = "记录 " + (index + 1).ToString() + " 的格式类型为 '" + strMarcSyntax + "',和目标库的格式类型 '" + strTargetMarcSyntax + "' 不符合,因此无法保存到目标库"; DialogResult result = MessageBox.Show(this, strError + "\r\n\r\n要跳过这些记录而继续保存后面的记录么?\r\n\r\n(Yes: 跳过格式不吻合的记录,继续保存后面的; No: 放弃整个保存操作)", "AmazonSearchForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) goto ERROR1; bSkip = true; continue; } string strProtocolPath = this.CurrentProtocol + ":" + this.CurrentResultsetPath + "/" + (index + 1).ToString(); string strOutputPath = ""; byte[] baOutputTimestamp = null; string strComment = "copy from " + strProtocolPath; // strSavePath; // return: // -2 timestamp mismatch // -1 error // 0 succeed nRet = dp2_searchform.SaveMarcRecord( false, strPath, strMARC, strMarcSyntax, baTimestamp, strXmlFragment, strComment, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; nSavedCount++; } MessageBox.Show(this, "共保存记录 " + nSavedCount.ToString() + " 条"); return; } else if (strProtocol.ToLower() == "z3950") { strError = "目前暂不支持Z39.50协议的保存操作"; goto ERROR1; } else { strError = "无法识别的协议名 '" + strProtocol + "'"; goto ERROR1; } } finally { stop.EndLoop(); stop.Unregister(); // 和容器关联 stop = null; this.EnableControls(true); } // return 0; ERROR1: MessageBox.Show(this, strError); }
// 追加保存到数据库 void menu_saveToDatabase_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; string strPreferedMarcSyntax = ""; if (this._linkMarcFile != null) strPreferedMarcSyntax = this._linkMarcFile.MarcSyntax; else { // 观察要保存的第一条记录的marc syntax nRet = GetOneRecordSyntax(0, this.m_bInSearching, out strPreferedMarcSyntax, out strError); if (nRet == -1) goto ERROR1; } string strLastSavePath = MainForm.LastSavePath; if (String.IsNullOrEmpty(strLastSavePath) == false) { string strOutputPath = ""; nRet = MarcDetailForm.ChangePathToAppendStyle(strLastSavePath, out strOutputPath, out strError); if (nRet == -1) { MainForm.LastSavePath = ""; // 避免下次继续出错 goto ERROR1; } strLastSavePath = strOutputPath; } SaveRecordDlg dlg = new SaveRecordDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.SaveToDbMode = true; // 不允许在textbox中修改路径 dlg.MainForm = this.MainForm; dlg.GetDtlpSearchParam += new GetDtlpSearchParamEventHandle(dlg_GetDtlpSearchParam); dlg.GetDp2SearchParam += new GetDp2SearchParamEventHandle(dlg_GetDp2SearchParam); { dlg.RecPath = strLastSavePath; dlg.Text = "请选择目标数据库"; } // dlg.StartPosition = FormStartPosition.CenterScreen; this.MainForm.AppInfo.LinkFormState(dlg, "SaveRecordDlg_state"); dlg.UiState = this.MainForm.AppInfo.GetString("dp2SearchForm", "SaveRecordDlg_uiState", ""); dlg.ShowDialog(this); this.MainForm.AppInfo.SetString("dp2SearchForm", "SaveRecordDlg_uiState", dlg.UiState); if (dlg.DialogResult != DialogResult.OK) return; MainForm.LastSavePath = dlg.RecPath; string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(dlg.RecPath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; #if NO string strDp2ServerName = ""; string strPurePath = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strDp2ServerName, out strPurePath); string strDbName = GetDbName(strPurePath); string strSyntax = ""; // 获得一个数据库的数据syntax // return: // -1 error // 0 not found // 1 found nRet = GetDbSyntax(this.stop, bUseNewChannel, strServerName, strServerUrl, strDbName, out strSyntax, out strError); if (nRet == -1) goto ERROR1; // 获得一个数据库的数据syntax // parameters: // stop 如果!=null,表示使用这个stop,它已经OnStop += // 如果==null,表示会自动使用this.stop,并自动OnStop+= // return: // -1 error // 0 not found // 1 found nRet = this.GetDbSyntax( null, strServerName, strBiblioDbName, out strSyntax, out strError); if (nRet == -1) { strError = "获取书目库 '" + strBiblioDbName + "的数据格式时发生错误: " + strError; goto ERROR1; } #endif // TODO: 禁止问号以外的其它ID this.stop.BeginLoop(); this.EnableControlsInSearching(false); try { // dtlp协议的记录保存 if (strProtocol.ToLower() == "dtlp") { DtlpSearchForm dtlp_searchform = this.GetDtlpSearchForm(); if (dtlp_searchform == null) { strError = "没有连接的或者打开的DTLP检索窗,无法保存记录"; goto ERROR1; } if (stop != null) stop.SetProgressRange(0, this.listView_browse.SelectedItems.Count); for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } stop.SetProgressValue(i); } ListViewItem item = this.listView_browse.SelectedItems[i]; string strSourcePath = item.Text; string strRecord = ""; string strOutputPath = ""; string strOutStyle = ""; byte[] baTimestamp = null; DigitalPlatform.Z3950.Record record = null; Encoding currrentEncoding; string strXmlFragment = ""; nRet = InternalGetOneRecord( false, "marc", strSourcePath, "current", "", out strRecord, out strXmlFragment, out strOutputPath, out strOutStyle, out baTimestamp, out record, out currrentEncoding, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = ""; if (record.m_strSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (record.m_strSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; if (string.IsNullOrEmpty(strMarcSyntax) == true) { strError = "记录 '" + strSourcePath + "' 不是MARC格式,无法保存到DTLP服务器"; goto ERROR1; } byte[] baOutputTimestamp = null; nRet = dtlp_searchform.SaveMarcRecord( strPath, strRecord, baTimestamp, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; } MessageBox.Show(this, "保存成功"); return; } else if (strProtocol.ToLower() == "dp2library") { if (stop != null) stop.SetProgressRange(0, this.listView_browse.SelectedItems.Count); for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++) { Application.DoEvents(); // 出让界面控制权 if (stop != null) { if (stop.State != 0) { strError = "用户中断"; goto ERROR1; } stop.SetProgressValue(i); } ListViewItem item = this.listView_browse.SelectedItems[i]; string strSourcePath = item.Text; string strRecord = ""; string strOutputPath = ""; string strOutStyle = ""; byte[] baTimestamp = null; DigitalPlatform.Z3950.Record record = null; Encoding currrentEncoding; string strXmlFragment = ""; nRet = InternalGetOneRecord( false, "marc", strSourcePath, "current", "", out strRecord, out strXmlFragment, out strOutputPath, out strOutStyle, out baTimestamp, out record, out currrentEncoding, out strError); if (nRet == -1) goto ERROR1; string strMarcSyntax = MarcDetailForm.GetMarcSyntax(record.m_strSyntaxOID); if (string.IsNullOrEmpty(strMarcSyntax) == true) strMarcSyntax = "unimarc"; byte[] baOutputTimestamp = null; string strComment = "copy from " + strSourcePath; // return: // -2 timestamp mismatch // -1 error // 0 succeed nRet = this.SaveMarcRecord( false, strPath, strRecord, strMarcSyntax, baTimestamp, strXmlFragment, strComment, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; } MessageBox.Show(this, "保存成功"); return; } else if (strProtocol.ToLower() == "z3950") { strError = "目前暂不支持Z39.50协议的保存操作"; goto ERROR1; } else { strError = "无法识别的协议名 '" + strProtocol + "'"; goto ERROR1; } } finally { this.stop.EndLoop(); this.stop.HideProgress(); this.EnableControlsInSearching(true); } // return 0; ERROR1: MessageBox.Show(this, strError); }
// 保存记录 // parameters: // strStyle "saveas"另存 其他为普通保存 public int SaveRecord(string strStyle = "save") { string strError = ""; int nRet = 0; string strLastSavePath = MainForm.LastSavePath; if (String.IsNullOrEmpty(strLastSavePath) == false) { string strOutputPath = ""; nRet = ChangePathToAppendStyle(strLastSavePath, out strOutputPath, out strError); if (nRet == -1) { MainForm.LastSavePath = ""; // 避免下次继续出错 2011/3/4 goto ERROR1; } strLastSavePath = strOutputPath; } string strCurrentUserName = ""; string strSavePath = this.SavePath == "" ? strLastSavePath : this.SavePath; if (strStyle == "save" && string.IsNullOrEmpty(this.SavePath) == false && (Control.ModifierKeys & Keys.Control) == 0) { // 2011/8/8 // 保存时如果已经有了路径,就不用打开对话框了 } else { SaveRecordDlg dlg = new SaveRecordDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.MainForm = this.MainForm; dlg.GetDtlpSearchParam += new GetDtlpSearchParamEventHandle(dlg_GetDtlpSearchParam); dlg.GetDp2SearchParam += new GetDp2SearchParamEventHandle(dlg_GetDp2SearchParam); if (strStyle == "save") dlg.RecPath = this.SavePath == "" ? strLastSavePath : this.SavePath; else { dlg.RecPath = strLastSavePath; // 2011/6/19 dlg.Text = "另存记录"; } // dlg.StartPosition = FormStartPosition.CenterScreen; this.MainForm.AppInfo.LinkFormState(dlg, "SaveRecordDlg_state"); dlg.UiState = this.MainForm.AppInfo.GetString("MarcDetailForm", "SaveRecordDlg_uiState", ""); dlg.ShowDialog(this); this.MainForm.AppInfo.SetString("MarcDetailForm", "SaveRecordDlg_uiState", dlg.UiState); if (dlg.DialogResult != DialogResult.OK) return 0; MainForm.LastSavePath = dlg.RecPath; strSavePath = dlg.RecPath; strCurrentUserName = dlg.CurrentUserName; } /* if (String.IsNullOrEmpty(this.SavePath) == true) { strError = "缺乏保存路径"; goto ERROR1; } * */ string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(strSavePath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; this.stop.BeginLoop(); this.EnableControls(false); try { // dtlp协议的记录保存 if (strProtocol.ToLower() == "dtlp") { DtlpSearchForm dtlp_searchform = this.GetDtlpSearchForm(); if (dtlp_searchform == null) { strError = "没有连接的或者打开的DTLP检索窗,无法保存记录"; goto ERROR1; } /* string strOutPath = ""; nRet = DtlpChannel.CanonicalizeWritePath(strPath, out strOutPath, out strError); if (nRet == -1) goto ERROR1; strPath = strOutPath; * */ string strOutputPath = ""; byte[] baOutputTimestamp = null; nRet = dtlp_searchform.SaveMarcRecord( strPath, this.MarcEditor.Marc, this.CurrentTimestamp, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; // TODO: 时间戳冲突? this.SavePath = strProtocol + ":" + strOutputPath; this.CurrentTimestamp = baOutputTimestamp; this.BiblioChanged = false; // 是否刷新MARC记录? //AutoCloseMessageBox.Show(this, "保存成功"); // MessageBox.Show(this, "保存成功"); return 0; } else if (strProtocol.ToLower() == "dp2library") { dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法保存记录"; goto ERROR1; } #if NO // 迫使登录一次 if (string.IsNullOrEmpty(strCurrentUserName) == true && string.IsNullOrEmpty(this.CurrentUserName) == true) { string strServerName = ""; string strLocalPath = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strServerName, out strLocalPath); string strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath); string strSyntax = ""; nRet = dp2_searchform.GetDbSyntax( null, strServerName, strBiblioDbName, out strSyntax, out strError); } #endif // 保存前的准备工作 { // 初始化 dp2catalog_marc_autogen.cs 的 Assembly,并new MarcDetailHost对象 // return: // -2 清除了Assembly // -1 error // 0 没有重新初始化Assembly,而是直接用以前Cache的Assembly (可能本来就是空) // 1 重新(或者首次)初始化了Assembly nRet = InitialAutogenAssembly(out strError); if (nRet == -1) goto ERROR1; if (this.m_detailHostObj != null) { // 模拟出this.SavePath 2011/11/22 string strOldSavePath = this.textBox_savePath.Text; this.textBox_savePath.Text = strSavePath; try { BeforeSaveRecordEventArgs e = new BeforeSaveRecordEventArgs(); e.CurrentUserName = strCurrentUserName; this.m_detailHostObj.BeforeSaveRecord(this.MarcEditor, e); if (string.IsNullOrEmpty(e.ErrorInfo) == false) { MessageBox.Show(this, "保存前的准备工作失败: " + e.ErrorInfo + "\r\n\r\n但保存操作仍将继续"); } } finally { // 恢复this.SavePath this.textBox_savePath.Text = strOldSavePath; } } } byte[] baTimestamp = this.CurrentTimestamp; string strMARC = this.MarcEditor.Marc; string strFragment = ""; if (this.domXmlFragment != null && this.domXmlFragment.DocumentElement != null) strFragment = this.domXmlFragment.DocumentElement.InnerXml; // 2014/5/12 string strMarcSyntax = ""; if (this.CurrentRecord != null) strMarcSyntax = GetMarcSyntax(this.CurrentRecord.m_strSyntaxOID); // 2014/5/18 if (string.IsNullOrEmpty(this.AutoDetectedMarcSyntaxOID) == false) strMarcSyntax = GetMarcSyntax(this.AutoDetectedMarcSyntaxOID); string strComment = ""; bool bOverwrite = false; if (string.IsNullOrEmpty(this.SavePath) == false) { string strTempProtocol = ""; string strTempPath = ""; nRet = Global.ParsePath(this.SavePath, out strTempProtocol, out strTempPath, out strError); if (nRet == -1) goto ERROR1; string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(strTempPath, out strServerName, out strPurePath); if (dp2SearchForm.IsAppendRecPath(strPurePath) == false) { string strServerUrl = dp2_searchform.GetServerUrl(strServerName); strComment = "copy from " + strPurePath + "@" + strServerUrl; } } else if (string.IsNullOrEmpty(this.textBox_tempRecPath.Text) == false) { strComment = "copy from " + this.textBox_tempRecPath.Text; } string strRights = ""; // 判断是否追加 { string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(strPath, out strServerName, out strPurePath); if (dp2SearchForm.IsAppendRecPath(strPurePath) == false) bOverwrite = true; nRet = dp2_searchform.GetChannelRights( strServerName, out strRights, out strError); if (nRet == -1) goto ERROR1; } bool bForceWverifyData = StringUtil.IsInList("client_forceverifydata", strRights); bool bVerifyed = false; if (bForceWverifyData == true) { GenerateDataEventArgs e1 = new GenerateDataEventArgs(); e1.FocusedControl = this.MarcEditor; // 0: 没有发现校验错误; 1: 发现校验警告; 2: 发现校验错误 nRet = this.VerifyData(this, e1, strSavePath, true); if (nRet == 2) { strError = "MARC 记录经校验发现有错,被拒绝保存。请修改 MARC 记录后重新保存"; goto ERROR1; } bVerifyed = true; } REDO_SAVE_DP2: string strOutputPath = ""; byte[] baOutputTimestamp = null; // return: // -2 timestamp mismatch // -1 error // 0 succeed nRet = dp2_searchform.SaveMarcRecord( true, strPath, strMARC, strMarcSyntax, baTimestamp, strFragment, strComment, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; if (nRet == -2) { // 时间戳冲突了 // 装载目标记录 DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; byte[] baTargetTimestamp = null; string strOutStyle = ""; string strTargetMARC = ""; string strError1 = ""; string strOutputSavePath = ""; long lVersion = 0; LoginInfo logininfo = null; string strXmlFragment = ""; nRet = dp2_searchform.GetOneRecord( // true, "marc", //strPath, // 不能有问号? //"", // strDirection, 0, "path:" + strPath, "", out strOutputSavePath, out strTargetMARC, out strXmlFragment, out strOutStyle, out baTargetTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError1); if (nRet == -1) { strError = "保存记录时发生错误: " + strError + ",在重装入目标记录的时候又发生错误: " + strError1; goto ERROR1; } nRet = this.LoadXmlFragment(strXmlFragment, out strError1); if (nRet == -1) { strError1 = "保存记录时发生错误: " + strError + ",在重装入目标记录的时候又发生错误: " + strError1; goto ERROR1; } // TODO: 检查源和目标的MARC格式是否一致?是否前面检查过了? TwoBiblioDialog two_biblio_dlg = new TwoBiblioDialog(); GuiUtil.SetControlFont(two_biblio_dlg, this.Font); two_biblio_dlg.Text = "覆盖书目记录"; two_biblio_dlg.MessageText = "即将被覆盖的目标记录和源内容不同。\r\n\r\n请问是否确定要用源内容覆盖目标记录?"; two_biblio_dlg.LabelSourceText = "源"; two_biblio_dlg.LabelTargetText = "目标 " + strPath; two_biblio_dlg.MarcSource = strMARC; two_biblio_dlg.MarcTarget = strTargetMARC; two_biblio_dlg.ReadOnlyTarget = true; // 初始时目标MARC编辑器不让进行修改 this.MainForm.AppInfo.LinkFormState(two_biblio_dlg, "TwoBiblioDialog_state"); two_biblio_dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(two_biblio_dlg); if (two_biblio_dlg.DialogResult == DialogResult.Cancel) { strError = "放弃保存"; goto ERROR1; // return 0; // 全部放弃 } if (two_biblio_dlg.DialogResult == DialogResult.No) { strError = "放弃保存"; goto ERROR1; } if (two_biblio_dlg.EditTarget == false) strMARC = two_biblio_dlg.MarcSource; else strMARC = two_biblio_dlg.MarcTarget; baTimestamp = baTargetTimestamp; goto REDO_SAVE_DP2; } this.SavePath = dp2_searchform.CurrentProtocol + ":" + strOutputPath; this.CurrentTimestamp = baOutputTimestamp; this.BiblioChanged = false; this.MarcEditor.ClearMarcDefDom(); this.MarcEditor.RefreshNameCaption(); // 是否刷新MARC记录? // MessageBox.Show(this, "保存成功"); if (bOverwrite == true && this.LinkedSearchForm != null) { // return: // -2 不支持 // -1 error // 0 相关窗口已经销毁,没有必要刷新 // 1 已经刷新 // 2 在结果集中没有找到要刷新的记录 nRet = RefreshCachedRecord("refresh", out strError); if (nRet == -1) MessageBox.Show(this, "记录保存已经成功,但刷新相关结果集内记录时出错: " + strError); } if (this.AutoVerifyData == true && bVerifyed == false) { // API.PostMessage(this.Handle, WM_VERIFY_DATA, 0, 0); GenerateDataEventArgs e1 = new GenerateDataEventArgs(); e1.FocusedControl = this.MarcEditor; // 0: 没有发现校验错误; 1: 发现校验警告; 2: 发现校验错误 nRet = this.VerifyData(this, e1, strSavePath, true); if (nRet == 2) { strError = "MARC 记录经校验发现有错。记录已经保存。请修改 MARC 记录后重新保存"; MessageBox.Show(this, strError); } } return 0; } else if (strProtocol.ToLower() == "unioncatalog") { string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(strPath, out strServerName, out strPurePath); if (String.IsNullOrEmpty(strServerName) == true) { strError = "路径不合法: 缺乏服务器名部分"; goto ERROR1; } if (String.IsNullOrEmpty(strPurePath) == true) { strError = "路径不合法:缺乏纯路径部分"; goto ERROR1; } byte[] baTimestamp = this.CurrentTimestamp; string strMARC = this.MarcEditor.Marc; string strMarcSyntax = ""; string strMarcSyntaxOID = this.GetCurrentMarcSyntaxOID(out strError); if (String.IsNullOrEmpty(strMarcSyntaxOID) == true) { strError = "当前MARC syntax OID为空,无法判断MARC具体格式"; goto ERROR1; } if (strMarcSyntaxOID == "1.2.840.10003.5.1") strMarcSyntax = "unimarc"; if (strMarcSyntaxOID == "1.2.840.10003.5.10") strMarcSyntax = "usmarc"; string strXml = ""; nRet = MarcUtil.Marc2Xml( strMARC, strMarcSyntax, out strXml, out strError); if (nRet == -1) goto ERROR1; string strXml1 = ""; // 将机内使用的marcxml格式转化为marcxchange格式 nRet = MarcUtil.MarcXmlToXChange(strXml, null, out strXml1, out strError); if (nRet == -1) goto ERROR1; // TODO: 是否可以直接使用Z39.50属性对话框中的用户名和密码? 登录失败后才出现登录对话框 if (this.LoginInfo == null) this.LoginInfo = new dp2Catalog.LoginInfo(); bool bRedo = false; REDO_LOGIN: if (string.IsNullOrEmpty(this.LoginInfo.UserName) == true || bRedo == true) { LoginDlg login_dlg = new LoginDlg(); GuiUtil.SetControlFont(login_dlg, this.Font); if (bRedo == true) login_dlg.Comment = strError + "\r\n\r\n请重新登录"; else login_dlg.Comment = "请指定用户名和密码"; login_dlg.UserName = this.LoginInfo.UserName; login_dlg.Password = this.LoginInfo.Password; login_dlg.SavePassword = true; login_dlg.ServerUrl = strServerName; login_dlg.StartPosition = FormStartPosition.CenterScreen; login_dlg.ShowDialog(this); if (login_dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) { strError = "放弃保存"; goto ERROR1; } this.LoginInfo.UserName = login_dlg.UserName; this.LoginInfo.Password = login_dlg.Password; strServerName = login_dlg.ServerUrl; } if (this.LoginInfo.UserName.IndexOf("/") != -1) { strError = "用户名中不能出现字符 '/'"; goto ERROR1; } string strOutputTimestamp = ""; string strOutputRecPath = ""; // parameters: // strAction 动作。为"new" "change" "delete" "onlydeletebiblio"之一。"delete"在删除书目记录的同时,会自动删除下属的实体记录。不过要求实体均未被借出才能删除。 // return: // -2 登录不成功 // -1 出错 // 0 成功 nRet = UnionCatalog.UpdateRecord( null, strServerName, this.LoginInfo.UserName + "/" + this.LoginInfo.Password, dp2SearchForm.IsAppendRecPath(strPurePath) == true ? "new": "change", strPurePath, "marcxchange", strXml1, ByteArray.GetHexTimeStampString(baTimestamp), out strOutputRecPath, out strOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; if (nRet == -2) { bRedo = true; goto REDO_LOGIN; } this.CurrentTimestamp = ByteArray.GetTimeStampByteArray(strOutputTimestamp); this.SavePath = strProtocol + ":" + strOutputRecPath + "@" + strServerName; this.BiblioChanged = false; this.MarcEditor.ClearMarcDefDom(); this.MarcEditor.RefreshNameCaption(); // 是否刷新MARC记录? // MessageBox.Show(this, "保存成功"); if (dp2SearchForm.IsAppendRecPath(strPurePath) == false && this.LinkedSearchForm != null && this.LinkedSearchForm is ZSearchForm) { nRet = RefreshCachedRecord("refresh", out strError); if (nRet == -1) MessageBox.Show(this, "记录保存已经成功,但刷新相关结果集内记录时出错: " + strError); } return 0; } else if (strProtocol.ToLower() == "z3950") { strError = "目前暂不支持 Z39.50 协议的保存操作"; goto ERROR1; } else if (strProtocol.ToLower() == "amazon") { strError = "目前暂不支持 amazon 协议的保存操作"; goto ERROR1; } else { strError = "无法识别的协议名 '" + strProtocol + "'"; goto ERROR1; } } finally { this.stop.EndLoop(); this.EnableControls(true); } // return 0; ERROR1: MessageBox.Show(this, strError); return -1; }
// 保存记录 public int SaveRecord() { string strError = ""; int nRet = 0; string strLastSavePath = MainForm.LastSavePath; if (String.IsNullOrEmpty(strLastSavePath) == false) { string strOutputPath = ""; nRet = MarcDetailForm.ChangePathToAppendStyle(strLastSavePath, out strOutputPath, out strError); if (nRet == -1) { MainForm.LastSavePath = ""; // 避免下次继续出错 2011/3/4 goto ERROR1; } strLastSavePath = strOutputPath; } SaveRecordDlg dlg = new SaveRecordDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.MainForm = this.MainForm; dlg.GetDtlpSearchParam += new GetDtlpSearchParamEventHandle(dlg_GetDtlpSearchParam); dlg.GetDp2SearchParam += new GetDp2SearchParamEventHandle(dlg_GetDp2SearchParam); // dlg.RecPath = this.SavePath == "" ? MainForm.LastSavePath : this.SavePath; dlg.RecPath = this.SavePath == "" ? strLastSavePath : this.SavePath; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ActiveProtocol = "dp2library"; this.MainForm.AppInfo.LinkFormState(dlg, "SaveRecordDlg_state"); dlg.UiState = this.MainForm.AppInfo.GetString("DcForm", "SaveRecordDlg_uiState", ""); dlg.ShowDialog(this); this.MainForm.AppInfo.SetString("DcForm", "SaveRecordDlg_uiState", dlg.UiState); if (dlg.DialogResult != DialogResult.OK) return 0; MainForm.LastSavePath = dlg.RecPath; string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(dlg.RecPath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; this.EnableControls(false); try { // dp2library协议的记录保存 if (strProtocol.ToLower() == "dp2library") { dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法保存记录"; goto ERROR1; } string strXml = ""; try { strXml = this.DcEditor.Xml; } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); goto ERROR1; } // 合成<dprms:file>元素 nRet = MergeResourceIds(ref strXml, out strError); if (nRet == -1) goto ERROR1; /* if (this.binaryResControl1 != null) { XmlDocument domDc = new XmlDocument(); try { domDc.LoadXml(strXml); } catch (Exception ex) { strError = "XML数据装入DOM时出错: " + ex.Message; goto ERROR1; } // 先删除已经有的<dprms:file>元素 List<string> ids = this.binaryResControl1.GetIds(); for (int i = 0; i < ids.Count; i++) { string strID = ids[i]; if (String.IsNullOrEmpty(strID) == true) continue; XmlNode node = domDc.CreateElement("dprms", "file", DpNs.dprms); domDc.DocumentElement.AppendChild(node); DomUtil.SetAttr(node, "id", strID); } strXml = domDc.OuterXml; } * */ string strOutputPath = ""; byte[] baOutputTimestamp = null; nRet = dp2_searchform.SaveXmlRecord( strPath, strXml, this.CurrentTimestamp, out strOutputPath, out baOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; this.SavePath = strProtocol + ":" + strOutputPath; this.CurrentTimestamp = baOutputTimestamp; /* // 结果集路径为空 this.textBox_tempRecPath.Text = ""; * */ string strServerName = ""; string strLocalPath = ""; // 如果资源控件还没有设置path,或者为追加型,则补上 // TODO: 是不是干脆都作一次? if (String.IsNullOrEmpty(this.binaryResControl1.BiblioRecPath) == true || dp2SearchForm.IsAppendRecPath(this.binaryResControl1.BiblioRecPath) == true) { // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strOutputPath, out strServerName, out strLocalPath); this.binaryResControl1.BiblioRecPath = strLocalPath; } // 提交对象保存请求 // return: // -1 error // >=0 实际上载的资源对象数 nRet = this.binaryResControl1.Save( dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName)), "0", // TODO: 要替换为 server_version out strError); if (nRet == -1) MessageBox.Show(this, strError); else { MessageBox.Show(this, "保存成功"); } if (nRet >= 1) { /* bObjectSaved = true; if (strText != "") strText += " "; strText += "对象信息"; * */ // 刷新书目记录的时间戳 // LoadRecord("current"); LoadDp2Record(dp2_searchform, strOutputPath, "current", false); } this.BiblioChanged = false; return 0; } else if (strProtocol.ToLower() == "dtlp") { strError = "目前DC窗暂不支持DTLP协议的保存操作"; goto ERROR1; } else if (strProtocol.ToLower() == "z3950") { strError = "目前DC窗暂不支持Z39.50协议的保存操作"; goto ERROR1; } else { strError = "无法识别的协议名 '" + strProtocol + "'"; goto ERROR1; } } finally { this.EnableControls(true); } // return 0; ERROR1: MessageBox.Show(this, strError); return -1; }