Esempio n. 1
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;

        }
Esempio n. 2
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")
                    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;
        }