Exemplo n.º 1
0
        // 删除记录
        // TODO: 需要增加对dp2和UnionCatalog协议的删除功能
        public int DeleteRecord()
        {
            string strError = "";

            if (String.IsNullOrEmpty(this.SavePath) == true)
            {
                strError = "缺乏保存路径";
                goto ERROR1;
            }

            string strProtocol = "";
            string strPath = "";
            int nRet = Global.ParsePath(this.SavePath,
                out strProtocol,
                out strPath,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            string strChangedWarning = "";

            if (this.ObjectChanged == true
                || this.BiblioChanged == true)
            {
                strChangedWarning = "当前有 "
                    + GetCurrentChangedPartName()
                    // strChangedWarning
                + " 被修改过。\r\n\r\n";
            }

            string strText = strChangedWarning;

            strText += "确实要删除书目记录 \r\n" + strPath + " ";

            /*
            int nObjectCount = this.binaryResControl1.ObjectCount;
            if (nObjectCount != 0)
                strText += "和从属的 " + nObjectCount.ToString() + " 个对象";
             * */

            strText += " ?";

            // 警告删除
            DialogResult result = MessageBox.Show(this,
                strText,
                "MarcDetailForm",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);
            if (result != DialogResult.Yes)
            {
                return 0;
            }

            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 strOutputPath = "";
                    // byte[] baOutputTimestamp = null;
                    nRet = dtlp_searchform.DeleteMarcRecord(
                        strPath,
                        this.CurrentTimestamp,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;

                    MessageBox.Show(this, "删除成功");
                    return 1;
                }
                // dp2library协议的记录删除
                else if (strProtocol.ToLower() == "dp2library")
                {

                    dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

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



                    // string strOutputPath = "";
                    byte[] baOutputTimestamp = null;
                    // 删除一条MARC/XML记录
                    // parameters:
                    //      strSavePath 内容为"中文图书/1@本地服务器"。没有协议名部分。
                    // return:
                    //      -1  error
                    //      0   suceed
                    nRet = dp2_searchform.DeleteOneRecord(
                        strPath,
                        this.CurrentTimestamp,
                        out baOutputTimestamp,
                        out strError);
                    this.CurrentTimestamp = baOutputTimestamp;  // 即便发生错误,也要更新时间戳,以便后面继续删除
                    if (nRet == -1)
                        goto ERROR1;

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

                    MessageBox.Show(this, "删除成功");
                    // TODO: ZSearchForm中的记录是否也要清除?

                    if (this.LinkedSearchForm != null
    && this.LinkedSearchForm is ZSearchForm)
                    {
                        nRet = RefreshCachedRecord("delete",
                            out strError);
                        if (nRet == -1)
                            MessageBox.Show(this, "记录删除已经成功,但刷新相关结果集内记录时出错: " + strError);
                    }

                    return 1;
                }
                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;

                    // 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,
                        "delete",
                        strPurePath,
                        "", // format
                        null,
                        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.BiblioChanged = false;
                    this.ObjectChanged = false;

                    MessageBox.Show(this, "删除成功");

                    if (this.LinkedSearchForm != null
    && this.LinkedSearchForm is ZSearchForm)
                    {
                        nRet = RefreshCachedRecord("delete",
                            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;
        }
Exemplo n.º 2
0
        // GCAT通道登录 旧的方式
        public void gcat_channel_BeforeLogin(object sender,
            DigitalPlatform.GcatClient.BeforeLoginEventArgs e)
        {
            string strUserName = (string)this.DetailForm.MainForm.ParamTable["author_number_account_username"];
            string strPassword = (string)this.DetailForm.MainForm.ParamTable["author_number_account_password"];

            if (String.IsNullOrEmpty(strUserName) == true)
            {
                strUserName = "******";
                strPassword = "";
            }

            // 直接试探
            if (!(e.UserName == strUserName && e.Failed == true)
                && strUserName != "")
            {
                e.UserName = strUserName;
                e.Password = strPassword;
                return;
            }

            LoginDlg dlg = new LoginDlg();
            GuiUtil.SetControlFont(dlg, this.DetailForm.MainForm.Font);

            if (e.Failed == true)
                dlg.textBox_comment.Text = "登录失败。加著者号码功能需要重新登录";
            else
                dlg.textBox_comment.Text = "加著者号码功能需要登录";

            dlg.textBox_serverAddr.Text = e.GcatServerUrl;
            dlg.textBox_userName.Text = strUserName;
            dlg.textBox_password.Text = strPassword;
            dlg.checkBox_savePassword.Checked = true;

            dlg.textBox_serverAddr.Enabled = false;
            dlg.TopMost = true; // 2009/11/12 因为ShowDialog(null),为了防止对话框被放在非顶部
            dlg.ShowDialog(null);
            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Cancel = true;    // 2009/11/12 如果缺这一句,会造成Cancel后仍然重新弹出登录对话框
                return;
            }

            strUserName = dlg.textBox_userName.Text;
            strPassword = dlg.textBox_password.Text;

            e.UserName = strUserName;
            e.Password = strPassword;

            this.DetailForm.MainForm.ParamTable["author_number_account_username"] = strUserName;
            this.DetailForm.MainForm.ParamTable["author_number_account_password"] = strPassword;
        }
Exemplo n.º 3
0
        // 保存记录
        // 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;
        }
Exemplo n.º 4
0
        void channels_AskAccountInfo(object sender, AskAccountInfoEventArgs e)
        {
            e.Owner = this;

            LoginDlg dlg = new LoginDlg();
            GuiUtil.AutoSetDefaultFont(dlg);

            dlg.textBox_serverAddr.Text = this.textBox_kernelUrl.Text;
            dlg.textBox_serverAddr.ReadOnly = true;
            dlg.textBox_comment.Text = e.Comment;
            dlg.textBox_userName.Text = this.ManagerUserName;
            dlg.textBox_password.Text = this.ManagerPassword;
            dlg.checkBox_savePassword.Checked = this.SavePassword;
            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Result = 0;
                return;
            }

            this.ManagerPassword = dlg.textBox_userName.Text;

            if (dlg.checkBox_savePassword.Checked == true)
                this.ManagerPassword = dlg.textBox_password.Text;
            else
                this.ManagerPassword = "";

            e.UserName = dlg.textBox_userName.Text;
            e.Password = dlg.textBox_password.Text;

            e.Result = 1;
        }
Exemplo n.º 5
0
        // 获得缺省帐户信息
        // return:
        //		2	already login succeed
        //		1	dialog return OK
        //		0	dialog return Cancel
        //		-1	other error
        public void OnAskAccountInfo(object sender,
            AskAccountInfoEventArgs e)
        {
            bool bFirst = true;

            bool bAutoLogin = (e.LoginStyle & LoginStyle.AutoLogin) == LoginStyle.AutoLogin;
            bool bFillDefault = (e.LoginStyle & LoginStyle.FillDefaultInfo) == LoginStyle.FillDefaultInfo;

            e.Owner = this.ownerForm;
            e.UserName = "";
            e.Password = "";

            LoginDlg dlg = new LoginDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

            Server server = this[e.Url];

            dlg.textBox_serverAddr.Text = e.Url;
            if (bFillDefault == true)
            {
                if (server != null)
                {
                    dlg.textBox_userName.Text = (server.DefaultUserName == "" ? "public" : server.DefaultUserName);
                    dlg.textBox_password.Text = server.DefaultPassword;
                    dlg.checkBox_savePassword.Checked = server.SavePassword;
                }
                else
                {
                    dlg.textBox_userName.Text = "public";
                    dlg.textBox_password.Text = "";
                    dlg.checkBox_savePassword.Checked = false;
                }
            }

            if (e.Comment != null)
                dlg.textBox_comment.Text = e.Comment;

        DOLOGIN:
            if (e.Channels != null)
            {
                if (bAutoLogin == false && bFirst == true)
                    goto REDOINPUT;

                // 找到Channel
                RmsChannel channel = e.Channel; // 2013/2/14
                if (channel == null)
                    channel = e.Channels.GetChannel(dlg.textBox_serverAddr.Text);

                Debug.Assert(channel != null, "Channels.GetChannel()异常...");

                string strError;
                // 登录
                int nRet = channel.Login(dlg.textBox_userName.Text,
                    dlg.textBox_password.Text,
                    out strError);

                if (nRet != 1)
                {
                    strError = "以用户名 '" + dlg.textBox_userName.Text + "' 登录到 '" + dlg.textBox_serverAddr.Text + "' 失败: " + strError;

                    if (this.ownerForm != null)
                    {
                        MessageBox.Show(this.ownerForm, strError);
                    }
                    else
                    {
                        e.ErrorInfo = strError;
                        e.Result = -1;
                    }

                    goto REDOINPUT;
                }
                else // 登录成功
                {
                    if (String.Compare(e.Url, dlg.textBox_serverAddr.Text, true) != 0)
                    {
                        // 创建一个新的Server对象
                        // return:
                        //		-1	出错
                        //		0	加入了
                        //		1	发现重复,没有加入
                        nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1);
                        if (nRet == 0)
                            e.Url = channel.Url;
                    }

                    server = this[dlg.textBox_serverAddr.Text];

                    if (server == null) // 2006/8/19 add
                    {
                        // 创建一个新的Server对象
                        // return:
                        //		-1	出错
                        //		0	加入了
                        //		1	发现重复,没有加入
                        nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1);
                        if (nRet == 0)
                            e.Url = channel.Url;

                        server = this[dlg.textBox_serverAddr.Text];

                    }

                    Debug.Assert(server != null, "此时server不可能为null");

                    server.DefaultUserName = dlg.textBox_userName.Text;
                    server.DefaultPassword = dlg.textBox_password.Text;
                    server.SavePassword = dlg.checkBox_savePassword.Checked;
                    this.m_bChanged = true;

                    e.Result = 2;
                    return;
                }
            }


        REDOINPUT:
            bFirst = false;

            dlg.ShowDialog(ownerForm);

            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Result = 0;
                return;
            }

            if (e.Channels == null)
            {
                e.UserName = dlg.textBox_userName.Text;
                e.Password = dlg.textBox_password.Text;

                e.Result = 1;
                return;
            }


            goto DOLOGIN;
        }
Exemplo n.º 6
0
        void channelArray_AskAccountInfo(object sender,
            AskDtlpAccountInfoEventArgs e)
        {
            e.Owner = null;
            e.UserName = "";
            e.Password = "";

            LoginDlg dlg = new LoginDlg();
            GuiUtil.SetControlFont(dlg, this.Font);

            AccountItem item = (AccountItem)AccountTable[e.Path];
            if (item == null)
            {
                item = new AccountItem();
                AccountTable.Add(e.Path, item);

                // 从配置文件中得到缺省账户
                item.UserName = MainForm.AppInfo.GetString(
                    "preference",
                    "defaultUserName",
                    "public");
                item.Password = MainForm.AppInfo.GetString(
                    "preference",
                    "defaultPassword",
                    "");
            }

            dlg.textBox_serverAddr.Text = e.Path;
            dlg.textBox_userName.Text = item.UserName;
            dlg.textBox_password.Text = item.Password;

            // 先登录一次再说
            {
                byte[] baResult = null;
                int nRet = e.Channel.API_ChDir(dlg.textBox_userName.Text,
                    dlg.textBox_password.Text,
                    e.Path,
                    out baResult);

                // 登录成功
                if (nRet > 0)
                {
                    e.Result = 2;
                    return;
                }
            }


            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == DialogResult.OK)
            {
                item.UserName = dlg.textBox_userName.Text;
                item.Password = dlg.textBox_password.Text;

                e.UserName = dlg.textBox_userName.Text;
                e.Password = dlg.textBox_password.Text;
                e.Owner = this;
                e.Result = 1;
                return;
            }

            e.Result = 0;
            return;
        }
Exemplo n.º 7
0
        void channelArray_AskAccountInfo(object sender, AskDtlpAccountInfoEventArgs e)
        {
            e.Owner = null;
            e.UserName = "";
            e.Password = "";

            LoginDlg dlg = new LoginDlg();

            dlg.textBox_serverAddr.Text = e.Path;
            dlg.textBox_userName.Text = this.textBox_dtlpUserName.Text;
            dlg.textBox_password.Text = this.textBox_dtlpPassword.Text;

            // 先登录一次再说
            {
                byte[] baResult = null;
                int nRet = e.Channel.API_ChDir(this.textBox_dtlpUserName.Text,
                    this.textBox_dtlpPassword.Text,
                    e.Path,
                    out baResult);

                // 登录成功
                if (nRet > 0)
                {
                    e.Result = 2;
                    return;
                }
            }


            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == DialogResult.OK)
            {
                this.textBox_dtlpUserName.Text = dlg.textBox_userName.Text;
                this.textBox_dtlpPassword.Text = dlg.textBox_password.Text;

                e.UserName = dlg.textBox_userName.Text;
                e.Password = dlg.textBox_password.Text;
                e.Owner = this;
                e.Result = 1;
                return;
            }

            e.Result = 0;
            return;
        }