// return: // -1 出错 // 0 没有必要保存 // 1 成功保存 int SaveTemplateChange(SelectRecordTemplateDlg tempdlg, string strBiblioDbName, byte[] baTimestamp, out string strError) { strError = ""; if (tempdlg.Changed == false // DOM 内容没有变化 && tempdlg.textBox_name.Text == "") // 没有选定要保存的模板名 return 0; // 获得书目记录XML格式 string strXmlBody = ""; int nRet = this.GetBiblioXml( strBiblioDbName, false, // 不要包含资源ID out strXmlBody, out strError); if (nRet == -1) goto ERROR1; // 修改配置文件内容 if (tempdlg.textBox_name.Text != "") { // 替换或者追加一个记录 nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text, strXmlBody, out strError); if (nRet == -1) goto ERROR1; } string strOutputXml = tempdlg.OutputXml; // Debug.Assert(false, ""); nRet = SaveCfgFile(strBiblioDbName, "template", strOutputXml, baTimestamp, out strError); if (nRet == -1) goto ERROR1; return 1; ERROR1: return -1; }
// 保存到dp2library模板 public int SaveToDp2libraryTemplate(string strPath) { string strError = ""; int nRet = 0; dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法保存当前内容到模板"; goto ERROR1; } string strServerName = ""; string strLocalPath = ""; string strBiblioDbName = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strServerName, out strLocalPath); strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath); string strStartPath = ""; if (String.IsNullOrEmpty(strServerName) == false && String.IsNullOrEmpty(strBiblioDbName) == false) strStartPath = strServerName + "/" + strBiblioDbName; else if (String.IsNullOrEmpty(strServerName) == false) strStartPath = strServerName; GetDp2ResDlg dlg = new GetDp2ResDlg(); GuiUtil.SetControlFont(dlg, this.Font); dlg.Text = "请选择目标数据库"; dlg.dp2Channels = dp2_searchform.Channels; dlg.Servers = this.MainForm.Servers; dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_DB }; dlg.Path = strStartPath; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return 0; string strSyntax = ""; nRet = dlg.Path.IndexOf("/"); if (nRet == -1) { strServerName = dlg.Path; strBiblioDbName = ""; strError = "未选择目标数据库"; goto ERROR1; } else { strServerName = dlg.Path.Substring(0, nRet); strBiblioDbName = dlg.Path.Substring(nRet + 1); // 检查所选数据库的syntax,必须为dc // 获得一个数据库的数据syntax // parameters: // stop 如果!=null,表示使用这个stop,它已经OnStop += // 如果==null,表示会自动使用this.stop,并自动OnStop+= // return: // -1 error // 0 not found // 1 found nRet = dp2_searchform.GetDbSyntax( null, strServerName, strBiblioDbName, out strSyntax, out strError); if (nRet == -1) { strError = "获取书目库 '" + strBiblioDbName + "的数据格式时发生错误: " + strError; goto ERROR1; } if (strSyntax != "unimarc" && strSyntax != "usmarc") { strError = "所选书目库 '" + strBiblioDbName + "' 不是MARC格式的数据库"; goto ERROR1; } } // 然后获得cfgs/template配置文件 string strCfgFilePath = strBiblioDbName + "/cfgs/template" + "@" + strServerName; string strCode = ""; byte[] baCfgOutputTimestamp = null; // return: // -1 error // 0 not found // 1 found nRet = dp2_searchform.GetCfgFile(strCfgFilePath, out strCode, out baCfgOutputTimestamp, out strError); if (nRet == -1 || nRet == 0) goto ERROR1; SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg(); GuiUtil.SetControlFont(tempdlg, this.Font); nRet = tempdlg.Initial(true, strCode, out strError); if (nRet == -1) goto ERROR1; tempdlg.Text = "请选择要修改的模板记录"; tempdlg.CheckNameExist = false; // 按OK按钮时不警告"名字不存在",这样允许新建一个模板 tempdlg.ap = this.MainForm.AppInfo; tempdlg.ApCfgTitle = "marcdetailform_selecttemplatedlg"; tempdlg.ShowDialog(this); if (tempdlg.DialogResult != DialogResult.OK) return 0; // 修改配置文件内容 if (tempdlg.textBox_name.Text != "") { string strXml = ""; /* nRet = dp2SearchForm.GetBiblioXml( strSyntax, this.MarcEditor.Marc, out strXml, out strError); * */ // 2008/5/16 changed nRet = MarcUtil.Marc2Xml( this.MarcEditor.Marc, strSyntax, out strXml, out strError); if (nRet == -1) goto ERROR1; // 替换或者追加一个记录 nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text, strXml, out strError); if (nRet == -1) { goto ERROR1; } } if (tempdlg.Changed == false) // 没有必要保存回去 return 0; string strOutputXml = tempdlg.OutputXml; nRet = dp2_searchform.SaveCfgFile( strCfgFilePath, strOutputXml, baCfgOutputTimestamp, out strError); if (nRet == -1) goto ERROR1; MessageBox.Show(this, "修改模板 '"+strCfgFilePath+"' 成功"); return 0; ERROR1: MessageBox.Show(this, strError); return -1; }
// /// <summary> /// 保存当前窗口内记录到模板配置文件 /// </summary> public void SaveBiblioToTemplate() { // 获得路径行中已经有的书目库名 string strBiblioDbName = Global.GetDbName(this.BiblioRecPath); GetDbNameDlg dlg = new GetDbNameDlg(); MainForm.SetControlFont(dlg, this.Font, false); dlg.DbName = strBiblioDbName; dlg.MainForm = this.MainForm; dlg.Text = "请选择目标编目库名"; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; strBiblioDbName = dlg.DbName; // 下载模板配置文件 string strContent = ""; string strError = ""; // string strCfgFilePath = respath.Path + "/cfgs/template"; byte[] baTimestamp = null; // return: // -1 error // 0 not found // 1 found int nRet = GetCfgFileContent(strBiblioDbName, "template", out strContent, out baTimestamp, out strError); if (nRet == -1 || nRet == 0) { goto ERROR1; } SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg(); MainForm.SetControlFont(tempdlg, this.Font, false); nRet = tempdlg.Initial( true, // 允许修改 strContent, out strError); if (nRet == -1) goto ERROR1; tempdlg.Text = "请选择要修改的模板记录"; tempdlg.CheckNameExist = false; // 按OK按钮时不警告"名字不存在",这样允许新建一个模板 //tempdlg.ap = this.MainForm.applicationInfo; //tempdlg.ApCfgTitle = "detailform_selecttemplatedlg"; tempdlg.ShowDialog(this); if (tempdlg.DialogResult != DialogResult.OK) return; // return: // -1 出错 // 0 没有必要保存 // 1 成功保存 nRet = SaveTemplateChange(tempdlg, strBiblioDbName, baTimestamp, out strError); if (nRet == -1) goto ERROR1; #if NO // 获得书目记录XML格式 string strXmlBody = ""; nRet = this.GetBiblioXml( strBiblioDbName, false, // 不要包含资源ID out strXmlBody, out strError); if (nRet == -1) goto ERROR1; // 修改配置文件内容 if (tempdlg.textBox_name.Text != "") { // 替换或者追加一个记录 nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text, strXmlBody, out strError); if (nRet == -1) { goto ERROR1; } } if (tempdlg.Changed == false) // 没有必要保存回去 return; string strOutputXml = tempdlg.OutputXml; // Debug.Assert(false, ""); nRet = SaveCfgFile(strBiblioDbName, "template", strOutputXml, baTimestamp, out strError); if (nRet == -1) goto ERROR1; #endif this.MainForm.StatusBarMessage = "修改模板成功。"; return; ERROR1: MessageBox.Show(this, strError); }
// /// <summary> /// 保存当前窗口内记录到模板配置文件 /// </summary> public void SaveReaderToTemplate() { this.EnableControls(false); try { // 获得路径行中已经有的读者库名 string strReaderDbName = Global.GetDbName(this.readerEditControl1.RecPath); GetDbNameDlg dlg = new GetDbNameDlg(); MainForm.SetControlFont(dlg, this.Font, false); dlg.DbType = "reader"; dlg.DbName = strReaderDbName; dlg.MainForm = this.MainForm; dlg.Text = "请选择目标读者库名"; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; strReaderDbName = dlg.DbName; // 下载模板配置文件 string strContent = ""; string strError = ""; byte[] baTimestamp = null; // return: // -1 error // 0 not found // 1 found int nRet = GetCfgFileContent(strReaderDbName + "/cfgs/template", out strContent, out baTimestamp, out strError); if (nRet == -1 || nRet == 0) { goto ERROR1; } SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg(); MainForm.SetControlFont(tempdlg, this.Font, false); nRet = tempdlg.Initial( true, strContent, out strError); if (nRet == -1) goto ERROR1; tempdlg.Text = "请选择要修改的模板记录"; tempdlg.CheckNameExist = false; // 按OK按钮时不警告"名字不存在",这样允许新建一个模板 //tempdlg.ap = this.MainForm.applicationInfo; //tempdlg.ApCfgTitle = "detailform_selecttemplatedlg"; tempdlg.ShowDialog(this); if (tempdlg.DialogResult != DialogResult.OK) return; string strNewXml = ""; nRet = this.readerEditControl1.GetData( out strNewXml, out strError); if (nRet == -1) goto ERROR1; // 需要消除password/displayName元素内容 { XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strNewXml); } catch (Exception ex) { strError = "装载XML到DOM出错: " + ex.Message; goto ERROR1; } DomUtil.SetElementText(dom.DocumentElement, "password", ""); DomUtil.SetElementText(dom.DocumentElement, "displayName", ""); strNewXml = dom.OuterXml; } // 修改配置文件内容 if (tempdlg.textBox_name.Text != "") { // 替换或者追加一个记录 nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text, strNewXml, out strError); if (nRet == -1) { goto ERROR1; } } if (tempdlg.Changed == false) // 没有必要保存回去 return; string strOutputXml = tempdlg.OutputXml; // Debug.Assert(false, ""); nRet = SaveCfgFile(strReaderDbName + "/cfgs/template", strOutputXml, baTimestamp, out strError); if (nRet == -1) goto ERROR1; this.MainForm.StatusBarMessage = "修改模板成功。"; return; ERROR1: MessageBox.Show(this, strError); } finally { this.EnableControls(true); } }