示例#1
0
        // 保存到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;
        }
示例#2
0
        private void button_findServerName_Click(object sender, EventArgs e)
        {
            GetDp2ResDlg dlg = new GetDp2ResDlg();
            GuiUtil.SetControlFont(dlg, this.Font);

            dlg.dp2Channels = this.Channels;
            dlg.Servers = this.MainForm.Servers;
            dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_SERVER };
            dlg.Path = this.textBox_serverName.Text;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return;

            this.textBox_serverName.Text = dlg.Path;
        }
示例#3
0
        // dp2library协议下 装载模板
        // parameters:
        //      strPath dp2library协议内路径。例如 中文图书/1@本地服务器
        public int LoadDp2libraryTemplate(string strPath)
        {
            try
            {
                string strError = "";
                int nRet = 0;

                // 按住 Shift 使用本功能,可重新出现对话框
                bool bShift = (Control.ModifierKeys == Keys.Shift);

                /*
                if (this.BiblioChanged == true
                    || this.ObjectChanged == true)
                {
                    // 警告尚未保存
                    DialogResult result = MessageBox.Show(this,
                        "当前有 " + GetCurrentChangedPartName() + " 被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要装载新内容? ",
                        "MarcDetailForm",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2);
                    if (result == DialogResult.No)
                        return 0;
                }*/


                dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                if (dp2_searchform == null)
                {
                    strError = "没有连接的或者打开的dp2检索窗,无法装载模板";
                    goto ERROR1;
                }

                string strSelectedDbName = this.MainForm.AppInfo.GetString(
         "entity_form",
         "selected_dbname_for_loadtemplate",
         "");
                SelectedTemplate selected = this.selected_templates.Find(strSelectedDbName);


                string strServerName = "";
                string strLocalPath = "";

                string strBiblioDbName = "";

                // 解析记录路径。
                // 记录路径为如下形态 "中文图书/1 @服务器"
                dp2SearchForm.ParseRecPath(string.IsNullOrEmpty(strSelectedDbName) == false ? strSelectedDbName : strPath,
                    out strServerName,
                    out strLocalPath);

                strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath);


                /*
                if (this.LinkedSearchForm != null
                    && strProtocol != this.LinkedSearchForm.CurrentProtocol)
                {
                    strError = "检索窗的协议已经发生改变";
                    goto ERROR1;
                }*/

                string strStartPath = "";

                if (String.IsNullOrEmpty(strServerName) == false
                    && String.IsNullOrEmpty(strBiblioDbName) == false)
                    strStartPath = strServerName + "/" + strBiblioDbName;
                else if (String.IsNullOrEmpty(strServerName) == false)
                    strStartPath = strServerName;

                GetDp2ResDlg dbname_dlg = new GetDp2ResDlg();
                GuiUtil.SetControlFont(dbname_dlg, this.Font);
                if (selected != null)
                {
                    dbname_dlg.NotAsk = selected.NotAskDbName;
                    dbname_dlg.AutoClose = (bShift == true ? false : selected.NotAskDbName);
                }
                dbname_dlg.EnableNotAsk = true;

                dbname_dlg.Text = "装载书目模板 -- 请选择目标数据库";
                dbname_dlg.dp2Channels = dp2_searchform.Channels;
                dbname_dlg.Servers = this.MainForm.Servers;
                dbname_dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_DB };
                dbname_dlg.Path = strStartPath;

                if (this.IsValid() == false)
                    return -1;
                    dbname_dlg.ShowDialog(this);    ////


                if (dbname_dlg.DialogResult != DialogResult.OK)
                    return 0;

                // 记忆
                this.MainForm.AppInfo.SetString(
                    "entity_form",
                    "selected_dbname_for_loadtemplate",
                    CanonicalizePath(dbname_dlg.Path));

                selected = this.selected_templates.Find(CanonicalizePath(dbname_dlg.Path));   // 

                // 将目标路径拆分为两个部分
                nRet = dbname_dlg.Path.IndexOf("/");
                if (nRet == -1)
                {
                    Debug.Assert(false, "");
                    strServerName = dbname_dlg.Path;
                    strBiblioDbName = "";
                    strError = "所选择目标(数据库)路径 '" + dbname_dlg.Path + "' 格式不正确";
                    goto ERROR1;
                }
                else
                {
                    strServerName = dbname_dlg.Path.Substring(0, nRet);
                    strBiblioDbName = dbname_dlg.Path.Substring(nRet + 1);

                    // 检查所选数据库的syntax,必须为marc

                    string strSyntax = "";
                    // 获得一个数据库的数据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 temp_dlg = new SelectRecordTemplateDlg();
                GuiUtil.SetControlFont(temp_dlg, this.Font);

                temp_dlg.Text = "请选择新记录模板 -- " + dbname_dlg.Path;

                string strSelectedTemplateName = "";
                bool bNotAskTemplateName = false;
                if (selected != null)
                {
                    strSelectedTemplateName = selected.TemplateName;
                    bNotAskTemplateName = selected.NotAskTemplateName;
                }

                temp_dlg.SelectedName = strSelectedTemplateName;
                temp_dlg.AutoClose = (bShift == true ? false : bNotAskTemplateName);
                temp_dlg.NotAsk = bNotAskTemplateName;
                temp_dlg.EnableNotAsk = true;    // 2015/5/11

                nRet = temp_dlg.Initial(
                    false,  // true 表示也允许删除
                    strCode,
                    out strError);
                if (nRet == -1)
                {
                    strError = "装载配置文件 '" + strCfgFilePath + "' 发生错误: " + strError;
                    goto ERROR1;
                }

                temp_dlg.ap = this.MainForm.AppInfo;
                temp_dlg.ApCfgTitle = "marcdetailform_selecttemplatedlg";
                if (this.IsValid() == false)
                    return -1;
                    temp_dlg.ShowDialog(this);  ////


                if (temp_dlg.DialogResult != DialogResult.OK)
                    return 0;

                // 记忆本次的选择,下次就不用再进入本对话框了
                this.selected_templates.Set(CanonicalizePath(dbname_dlg.Path),
                    dbname_dlg.NotAsk,
                    temp_dlg.SelectedName,
                    temp_dlg.NotAsk);

                string strMarcSyntax = "";
                string strOutMarcSyntax = "";
                string strRecord = "";

                // 从数据记录中获得MARC格式
                nRet = MarcUtil.Xml2Marc(temp_dlg.SelectedRecordXml,
                    true,
                    strMarcSyntax,
                    out strOutMarcSyntax,
                    out strRecord,
                    out strError);
                if (nRet == -1)
                {
                    strError = "XML转换到MARC记录时出错: " + strError;
                    goto ERROR1;
                }
                this.SavePath = "dp2library" + ":" + strBiblioDbName + "/?" + "@" + strServerName;

                if (this.IsValid() == false)
                    return -1;

                this.MarcEditor.ClearMarcDefDom();
                this.MarcEditor.Marc = strRecord;   ////
                this.CurrentTimestamp = baCfgOutputTimestamp;

                this.ObjectChanged = false;
                this.BiblioChanged = false;

                DisplayHtml(strRecord, GetSyntaxOID(strOutMarcSyntax));

                this.LinkedSearchForm = null;  // 切断和原来关联的检索窗的联系。这样就没法前后翻页了
                return 0;
            ERROR1:
                MessageBox.Show(this, strError);
                return -1;
            }
            catch (System.ObjectDisposedException)
            {
                return -1;
            }
        }
示例#4
0
        // 查重
        // parameters:
        //      strSender   触发命令的来源 "toolbar" "ctrl_d"
        public int SearchDup(string strSender)
        {
            string strError = "";
            int nRet = 0;

            Debug.Assert(strSender == "toolbar" || strSender == "ctrl_d","");

            string strStartPath = this.SavePath;

            // 检查当前通讯协议
            string strProtocol = "";
            string strPath = "";

            if (String.IsNullOrEmpty(strStartPath) == false)
            {
                nRet = Global.ParsePath(strStartPath,
                    out strProtocol,
                    out strPath,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (strProtocol != "dp2library"
                    && strProtocol != "dtlp")
                    strStartPath = "";  // 迫使重新选择起点路径
            }
            else
            {
                // 选择协议
                SelectProtocolDialog protocol_dlg = new SelectProtocolDialog();
                GuiUtil.SetControlFont(protocol_dlg, this.Font);

                protocol_dlg.Protocols = new List<string>();
                protocol_dlg.Protocols.Add("dp2library");
                protocol_dlg.Protocols.Add("dtlp");
                protocol_dlg.StartPosition = FormStartPosition.CenterScreen;

                protocol_dlg.ShowDialog(this);

                if (protocol_dlg.DialogResult != DialogResult.OK)
                    return 0;

                strProtocol = protocol_dlg.SelectedProtocol;
            }




            this.EnableControls(false);
            try
            {

                // dtlp协议的查重
                if (strProtocol.ToLower() == "dtlp")
                {
                    // TODO: 如果起始路径为空,需要从系统配置中得到一个缺省的起始路径

                    DtlpSearchForm dtlp_searchform = this.GetDtlpSearchForm();

                    if (dtlp_searchform == null)
                    {
                        strError = "没有连接的或者打开的DTLP检索窗,无法进行查重";
                        goto ERROR1;
                    }

                    // 打开查重窗口
                    DtlpDupForm form = new DtlpDupForm();

                    // form.MainForm = this.MainForm;
                    form.MdiParent = this.MainForm;
                    form.LoadDetail -= new LoadDetailEventHandler(dtlpdupform_LoadDetail);
                    form.LoadDetail += new LoadDetailEventHandler(dtlpdupform_LoadDetail);

                    string strCfgFilename = this.MainForm.DataDir + "\\dtlp_dup.xml";
                    nRet = form.Initial(strCfgFilename,
                        this.MainForm.stopManager,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        // 配置文件不存在对于编辑配置文件的界面无大碍,但是对查重却影响深远 -- 无法查重
                        strError = "配置文件 " + strCfgFilename + " 不存在。请利用主菜单“帮助/系统参数配置”命令,出现对话框后选“DTLP协议”属性页,按“查重方案配置”进行配置。";
                        goto ERROR1;
                    }


                    form.RecordPath = strPath;
                    form.ProjectName = "{default}"; // "<默认>"
                    form.MarcRecord = this.MarcEditor.Marc;
                    form.DtlpChannel = dtlp_searchform.DtlpChannel;

                    form.AutoBeginSearch = true;

                    form.Show();

                    return 0;
                }
                else if (strProtocol.ToLower() == "dp2library")
                {
                        dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                        if (dp2_searchform == null)
                        {
                            strError = "没有连接的或者打开的dp2检索窗,无法进行查重";
                            goto ERROR1;
                        } 
                    if (String.IsNullOrEmpty(strStartPath) == true)
                    {
                        /*
                        strError = "当前记录路径为空,无法进行查重";
                        goto ERROR1;
                         * */


                        string strDefaultStartPath = this.MainForm.DefaultSearchDupStartPath;

                        // 如果缺省起点路径定义为空,或者按下Control键强制要求出现对话框
                        if (String.IsNullOrEmpty(strDefaultStartPath) == true
                            || (Control.ModifierKeys == Keys.Control && strSender == "toolbar"))
                        {
                            // 变为正装形态
                            if (String.IsNullOrEmpty(strDefaultStartPath) == false)
                                strDefaultStartPath = Global.GetForwardStyleDp2Path(strDefaultStartPath);

                            // 临时指定一个dp2library服务器和数据库
                            GetDp2ResDlg dlg = new GetDp2ResDlg();
                            GuiUtil.SetControlFont(dlg, this.Font);

                            dlg.Text = "请指定一个 dp2library 数据库,以作为模拟的查重起点";
                            dlg.dp2Channels = dp2_searchform.Channels;
                            dlg.Servers = this.MainForm.Servers;
                            dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_DB };
                            dlg.Path = strDefaultStartPath;  // 采用遗留的上次用过的路径

                            this.MainForm.AppInfo.LinkFormState(dlg,
                                "searchdup_selectstartpath_dialog_state");

                            dlg.ShowDialog(this);

                            this.MainForm.AppInfo.UnlinkFormState(dlg);

                            if (dlg.DialogResult != DialogResult.OK)
                                return 0;

                            strDefaultStartPath = Global.GetBackStyleDp2Path(dlg.Path + "/?");

                            // 重新设置到系统参数中
                            this.MainForm.DefaultSearchDupStartPath = strDefaultStartPath;
                        }

                        // strProtocol = "dp2library";
                        strPath = strDefaultStartPath;
                    }


                        //// 
                        /*
                        dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                        if (dp2_searchform == null)
                        {
                            strError = "没有连接的或者打开的dp2检索窗,无法进行查重";
                            goto ERROR1;
                        }*/

                    // 将strPath解析为server url和local path两个部分
                    string strServerName = "";
                    string strPurePath = "";
                    dp2SearchForm.ParseRecPath(strPath,
                        out strServerName,
                        out strPurePath);

                    /*
                    // 获得server url

                    string strServerUrl = dp2_searchform.GetServerUrl(strServerName);
                    if (strServerUrl == null)
                    {
                        strError = "未能找到名为 '" + strServerName + "' 的服务器";
                        goto ERROR1;
                    }
                    */

                    string strDbName = dp2SearchForm.GetDbName(strPurePath);
                    string strSyntax = "";


                    // 获得一个数据库的数据syntax
                    // parameters:
                    //      stop    如果!=null,表示使用这个stop,它已经OnStop +=
                    //              如果==null,表示会自动使用this.stop,并自动OnStop+=
                    // return:
                    //      -1  error
                    //      0   not found
                    //      1   found
                    nRet = dp2_searchform.GetDbSyntax(null, // this.stop, bug!!!
                        strServerName,
                        strDbName,
                        out strSyntax,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    if (String.IsNullOrEmpty(strSyntax) == true)
                        strSyntax = "unimarc";

                    string strXml = "";
                    // 获得书目记录的XML格式
                    // parameters:
                    //      strMarcSyntax 要创建的XML记录的marcsyntax。
                    /*
                    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;


                    // 打开查重窗口
                    dp2DupForm form = new dp2DupForm();

                    form.MainForm = this.MainForm;
                    form.MdiParent = this.MainForm;

                    form.LibraryServerName = strServerName;
                    form.ProjectName = "<默认>";
                    form.XmlRecord = strXml;
                    form.RecordPath = strPurePath;

                    form.AutoBeginSearch = true;

                    form.Show();

                    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.EnableControls(true);
            }

        ERROR1:
            MessageBox.Show(this, strError);
            return -1;

        }
示例#5
0
        // 获得缺省查重起点路径
        private void button_dp2library_searchDup_findDefaultStartPath_Click(object sender, EventArgs e)
        {
            string strError = "";

            dp2SearchForm dp2_searchform = this.MainForm.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "无法获得打开的 dp2检索窗,无法获得 dp2library 数据库名";
                goto ERROR1;
            }

            string strDefaultStartPath = Global.GetForwardStyleDp2Path(this.textBox_dp2library_searchDup_defaultStartPath.Text);

            // 临时指定一个dp2library服务器和数据库
            GetDp2ResDlg dlg = new GetDp2ResDlg();
            GuiUtil.SetControlFont(dlg, this.Font);

            dlg.Text = "请指定一个 dp2library 数据库,以作为模拟的查重起点";
            dlg.dp2Channels = dp2_searchform.Channels;
            dlg.Servers = this.MainForm.Servers;
            dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_DB };
            dlg.Path = strDefaultStartPath;

            this.MainForm.AppInfo.LinkFormState(dlg,
                "searchdup_selectstartpath_dialog_state");

            dlg.ShowDialog(this);

            this.MainForm.AppInfo.UnlinkFormState(dlg);

            if (dlg.DialogResult != DialogResult.OK)
                return;

            strDefaultStartPath = Global.GetBackStyleDp2Path(dlg.Path + "/?");


            this.textBox_dp2library_searchDup_defaultStartPath.Text = strDefaultStartPath;
            return;

        ERROR1:
            MessageBox.Show(this, strError);
        }
示例#6
0
文件: DcForm.cs 项目: renyh1013/dp2
        // 查重
        // parameters:
        //      strSender   触发命令的来源 "toolbar" "ctrl_d"
        public int SearchDup(string strSender)
        {
            string strError = "";
            int nRet = 0;

            Debug.Assert(strSender == "toolbar" || strSender == "ctrl_d", "");

            string strStartPath = this.SavePath;

            // 检查当前通讯协议
            string strProtocol = "";
            string strPath = "";

            if (String.IsNullOrEmpty(strStartPath) == false)
            {
                nRet = Global.ParsePath(strStartPath,
                    out strProtocol,
                    out strPath,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (strProtocol != "dp2library")
                    strStartPath = "";  // 迫使重新选择起点路径
            }

            if (String.IsNullOrEmpty(strStartPath) == true)
            {
                /*
                strError = "当前记录路径为空,无法进行查重";
                goto ERROR1;
                 * */
                dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                if (dp2_searchform == null)
                {
                    strError = "没有连接的或者打开的dp2检索窗,无法进行查重";
                    goto ERROR1;
                }

                string strDefaultStartPath = this.MainForm.DefaultSearchDupStartPath;

                // 如果缺省起点路径定义为空,或者按下Control键强制要求出现对话框
                if (String.IsNullOrEmpty(strDefaultStartPath) == true
                    || (Control.ModifierKeys == Keys.Control && strSender == "toolbar"))
                {
                    // 变为正装形态
                    if (String.IsNullOrEmpty(strDefaultStartPath) == false)
                        strDefaultStartPath = Global.GetForwardStyleDp2Path(strDefaultStartPath);

                    // 临时指定一个dp2library服务器和数据库
                    GetDp2ResDlg dlg = new GetDp2ResDlg();
                    GuiUtil.SetControlFont(dlg, this.Font);

                    dlg.Text = "请指定一个dp2library数据库,以作为模拟的查重起点";
                    dlg.dp2Channels = dp2_searchform.Channels;
                    dlg.Servers = this.MainForm.Servers;
                    dlg.EnabledIndices = new int[] { dp2ResTree.RESTYPE_DB };
                    dlg.Path = strDefaultStartPath;  // 采用遗留的上次用过的路径

                    this.MainForm.AppInfo.LinkFormState(dlg,
                        "searchdup_selectstartpath_dialog_state");

                    dlg.ShowDialog(this);

                    this.MainForm.AppInfo.UnlinkFormState(dlg);

                    if (dlg.DialogResult != DialogResult.OK)
                        return 0;

                    strDefaultStartPath = Global.GetBackStyleDp2Path(dlg.Path + "/?");

                    // 重新设置到系统参数中
                    this.MainForm.DefaultSearchDupStartPath = strDefaultStartPath;
                }

                strProtocol = "dp2library";
                strPath = strDefaultStartPath;
            }

            this.EnableControls(false);
            try
            {
                // dtlp协议的记录保存
                if (strProtocol.ToLower() == "dtlp")
                {
                    strError = "目前暂不支持DTLP协议的查重操作";
                    goto ERROR1;
                }
                else if (strProtocol.ToLower() == "dp2library")
                {
                    dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                    if (dp2_searchform == null)
                    {
                        strError = "没有连接的或者打开的dp2检索窗,无法进行查重";
                        goto ERROR1;
                    }

                    // 将strPath解析为server url和local path两个部分
                    string strServerName = "";
                    string strPurePath = "";
                    dp2SearchForm.ParseRecPath(strPath,
                        out strServerName,
                        out strPurePath);

                    string strDbName = dp2SearchForm.GetDbName(strPurePath);
                    string strSyntax = "";

                    // 获得一个数据库的数据syntax
                    // parameters:
                    //      stop    如果!=null,表示使用这个stop,它已经OnStop +=
                    //              如果==null,表示会自动使用this.stop,并自动OnStop+=
                    // return:
                    //      -1  error
                    //      0   not found
                    //      1   found
                    nRet = dp2_searchform.GetDbSyntax(null, // this.stop, BUG!!!
                        strServerName,
                        strDbName,
                        out strSyntax,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    if (String.IsNullOrEmpty(strSyntax) == true)
                        strSyntax = "unimarc";

                    // 获得书目记录的XML格式
                    string strXml = "";

                    try
                    {
                        strXml = this.DcEditor.Xml;
                    }
                    catch (Exception ex)
                    {
                        strError = ExceptionUtil.GetAutoText(ex);
                        goto ERROR1;
                    }

                    // 打开查重窗口
                    dp2DupForm form = new dp2DupForm();

                    form.MainForm = this.MainForm;
                    form.MdiParent = this.MainForm;

                    form.LibraryServerName = strServerName;
                    form.ProjectName = "<默认>";
                    form.XmlRecord = strXml;
                    form.RecordPath = strPurePath;

                    form.AutoBeginSearch = true;

                    form.Show();
                    return 0;
                }
                else if (strProtocol.ToLower() == "z3950")
                {
                    strError = "目前暂不支持Z39.50协议的保存操作";
                    goto ERROR1;
                }
                else
                {
                    strError = "无法识别的协议名 '" + strProtocol + "'";
                    goto ERROR1;
                }
            }
            finally
            {
                this.EnableControls(true);
            }

        ERROR1:
            MessageBox.Show(this, strError);
            return -1;
        }
示例#7
0
文件: DcForm.cs 项目: renyh1013/dp2
        // 装载模板
        public int LoadTemplate()
        {
            string strError = "";
            int nRet = 0;

            if (this.BiblioChanged == true
                || this.ObjectChanged == true)
            {
                // 警告尚未保存
                DialogResult result = MessageBox.Show(this,
                    "当前有 " + GetCurrentChangedPartName() + " 被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要装载新内容? ",
                    "DcForm",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                    return 0;
            }


            dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "没有连接的或者打开的dp2检索窗,无法装载模板";
                goto ERROR1;
            }

            string strProtocol = "";
            string strPath = "";

            string strServerName = "";
            string strLocalPath = "";

            string strBiblioDbName = "";

            if (String.IsNullOrEmpty(this.SavePath) == false)
            {
                // 分离出各个部分
                nRet = Global.ParsePath(this.SavePath,
                    out strProtocol,
                    out strPath,
                    out strError);
                if (nRet == -1)
                {
                    strError = "解析路径 '" + this.SavePath + "' 字符串过程中发生错误: " + strError;
                    goto ERROR1;
                }

                if (strProtocol == "dp2library")
                {
                    // 解析记录路径。
                    // 记录路径为如下形态 "中文图书/1 @服务器"
                    dp2SearchForm.ParseRecPath(strPath,
                        out strServerName,
                        out strLocalPath);

                    strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath);
                }
                else
                {
                    strProtocol = "dp2library";
                    strPath = "";
                }
            }
            else
            {
                strProtocol = "dp2library";
            }

            /*
            if (this.LinkedSearchForm != null
                && strProtocol != this.LinkedSearchForm.CurrentProtocol)
            {
                strError = "检索窗的协议已经发生改变";
                goto ERROR1;
            }*/

            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;

            // 将目标路径拆分为两个部分
            nRet = dlg.Path.IndexOf("/");
            if (nRet == -1)
            {
                Debug.Assert(false, "");
                strServerName = dlg.Path;
                strBiblioDbName = "";
                strError = "所选择目标(数据库)路径 '" + dlg.Path + "' 格式不正确";
                goto ERROR1;
            }
            else
            {
                strServerName = dlg.Path.Substring(0, nRet);
                strBiblioDbName = dlg.Path.Substring(nRet + 1);

                // 检查所选数据库的syntax,必须为dc

                string strSyntax = "";
                // 获得一个数据库的数据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 != "dc")
                {
                    strError = "所选书目库 '" + strBiblioDbName + "' 不是DC格式的数据库";
                    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(false,
                strCode,
                out strError);
            if (nRet == -1)
            {
                strError = "装载配置文件 '" + strCfgFilePath + "' 发生错误: " + strError;
                goto ERROR1;
            }

            tempdlg.ap = this.MainForm.AppInfo;
            tempdlg.ApCfgTitle = "dcform_selecttemplatedlg";
            tempdlg.ShowDialog(this);

            if (tempdlg.DialogResult != DialogResult.OK)
                return 0;

            // 获得cfgs\dcdef
            string strCfgFileName = "dcdef";

            string strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName;

            // 和以前的不同,才有必要重新载入
            if (this.DcCfgFilename != strCfgPath)
            {
                strCode = "";
                // byte[] baCfgOutputTimestamp = null;
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = dp2_searchform.GetCfgFile(strCfgPath,
                    out strCode,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1 || nRet == 0)
                    goto ERROR1;

                nRet = this.DcEditor.LoadCfgCode(strCode,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.DcCfgFilename = strCfgPath;
            }

            // 接着装入对象资源
            {
                this.binaryResControl1.Clear();
                // this.binaryResControl1.Channel = dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName));
                this.binaryResControl1.BiblioRecPath = strBiblioDbName + "/?";
            }

            this.DcEditor.Xml = tempdlg.SelectedRecordXml;
            this.CurrentTimestamp = null;   // baCfgOutputTimestamp;

            this.SavePath = strProtocol + ":" + strBiblioDbName + "/?" + "@" + strServerName;

            this.ObjectChanged = false;
            this.BiblioChanged = false;

            this.LinkedSearchForm = null;  // 切断和原来关联的检索窗的联系。这样就没法前后翻页了
            return 0;
        ERROR1:
            MessageBox.Show(this, strError);
            return -1;
        }