Example #1
0
        // return:
        //      -1  出错
        //      0   没有必要保存
        //      1   成功保存
        int SaveTemplateChange(SelectRecordTemplateDlg tempdlg,
            string strBiblioDbName,
            byte[] baTimestamp,
            out string strError)
        {
            strError = "";

            if (tempdlg.Changed == false    // DOM 内容没有变化
                && tempdlg.textBox_name.Text == "")	// 没有选定要保存的模板名
                return 0;


            // 获得书目记录XML格式
            string strXmlBody = "";
            int nRet = this.GetBiblioXml(
                strBiblioDbName,
                false,  // 不要包含资源ID
                out strXmlBody,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            // 修改配置文件内容
            if (tempdlg.textBox_name.Text != "")
            {
                // 替换或者追加一个记录
                nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text,
                    strXmlBody,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
            }

            string strOutputXml = tempdlg.OutputXml;

            // Debug.Assert(false, "");
            nRet = SaveCfgFile(strBiblioDbName,
                "template",
                strOutputXml,
                baTimestamp,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            return 1;
        ERROR1:
            return -1;
        }
Example #2
0
        // 装载书目模板
        // return:
        //      -1  error
        //      0   放弃
        //      1   成功装载
        /// <summary>
        /// 装载书目模板
        /// </summary>
        /// <param name="bAutoSave">是否自动保存窗口内先前的修改</param>
        /// <returns>
        /// <para>-1: 出错</para>
        /// <para>0: 放弃</para>
        /// <para>1: 成功装载</para>
        /// </returns>
        public int LoadBiblioTemplate(bool bAutoSave = true)
        {
            int nRet = 0;

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

            if (this.BiblioChanged == true
                || this.EntitiesChanged == true
                || this.IssuesChanged == true
                || this.OrdersChanged == true
                || this.CommentsChanged == true
                || this.ObjectChanged == true)
            {
                // 2008/6/25
                if (this.checkBox_autoSavePrev.Checked == true
                    && bAutoSave == true)
                {
                    nRet = this.DoSaveAll();
                    if (nRet == -1)
                        return -1;
                }
                else
                {

                    DialogResult result = MessageBox.Show(this,
                        "装载编目模板前,发现当前窗口中已有 " + GetCurrentChangedPartName() + " 修改后未来得及保存。是否要继续装载编目模板到窗口中(这样将丢失先前修改的内容)?\r\n\r\n(是)继续装载编目模板 (否)不装载编目模板",
                        "EntityForm",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2);
                    if (result != DialogResult.Yes)
                    {
                        MessageBox.Show(this, "装载编目模板操作被放弃...");
                        return 0;
                    }
                }
            }

            string strSelectedDbName = this.MainForm.AppInfo.GetString(
                "entity_form",
                "selected_dbname_for_loadtemplate",
                "");

            SelectedTemplate selected = this.selected_templates.Find(strSelectedDbName);

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

            dbname_dlg.EnableNotAsk = true;
            dbname_dlg.DbName = strSelectedDbName;
            dbname_dlg.MainForm = this.MainForm;

            dbname_dlg.Text = "装载书目模板 -- 请选择目标编目库名";
            //  dbname_dlg.StartPosition = FormStartPosition.CenterScreen;

            this.MainForm.AppInfo.LinkFormState(dbname_dlg, "entityform_load_template_GetBiblioDbNameDlg_state");
            dbname_dlg.ShowDialog(this);
            // this.MainForm.AppInfo.UnlinkFormState(dbname_dlg);

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

            string strBiblioDbName = dbname_dlg.DbName;
            // 记忆
            this.MainForm.AppInfo.SetString(
                "entity_form",
                "selected_dbname_for_loadtemplate",
                strBiblioDbName);

            selected = this.selected_templates.Find(strBiblioDbName);

            this.BiblioRecPath = dbname_dlg.DbName + "/?";	// 为了追加保存

            // 下载配置文件
            string strContent = "";
            string strError = "";

            // string strCfgFilePath = respath.Path + "/cfgs/template";
            byte[] baCfgOutputTimestamp = null;
            // return:
            //      -1  error
            //      0   not found
            //      1   found
            nRet = GetCfgFileContent(strBiblioDbName,
                "template",
                out strContent,
                out baCfgOutputTimestamp,
                out strError);
            if (nRet == -1 || nRet == 0)
            {
                this.BiblioTimestamp = null;
                goto ERROR1;
            }

            // MessageBox.Show(this, strContent);

            SelectRecordTemplateDlg select_temp_dlg = new SelectRecordTemplateDlg();
            MainForm.SetControlFont(select_temp_dlg, this.Font, false);

            select_temp_dlg.Text = "请选择新书目记录模板 -- 来自书目库 '" + strBiblioDbName + "'";
            string strSelectedTemplateName = "";
            bool bNotAskTemplateName = false;
            if (selected != null)
            {
                strSelectedTemplateName = selected.TemplateName;
                bNotAskTemplateName = selected.NotAskTemplateName;
            }

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

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

            this.MainForm.AppInfo.LinkFormState(select_temp_dlg, "entityform_load_template_SelectTemplateDlg_state");
            select_temp_dlg.ShowDialog(this);
            // this.MainForm.AppInfo.UnlinkFormState(select_temp_dlg);

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

            if (select_temp_dlg.Changed == true)
            {
                // return:
                //      -1  出错
                //      0   没有必要保存
                //      1   成功保存
                nRet = SaveTemplateChange(select_temp_dlg,
                    strBiblioDbName,
                    baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                this.MainForm.StatusBarMessage = "修改模板成功。";
                return 1;
            }

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

            this.BiblioTimestamp = null;
            // this.m_strMetaData = "";	// 记忆XML记录的元数据

            this.BiblioOriginPath = ""; // 保存从数据库中来的原始path

            // this.TimeStamp = baTimeStamp;

            // this.Text = respath.ReverseFullPath; // 窗口标题

            // return:
            //      -1  error
            //      0   空的记录
            //      1   成功
            nRet = SetBiblioRecordToMarcEditor(select_temp_dlg.SelectedRecordXml,
                out strError);
            if (nRet == -1)
                goto ERROR1;

#if NO
            Global.SetHtmlString(this.webBrowser_biblioRecord,
                "(空白)");
#endif
            this.m_webExternalHost_biblio.SetHtmlString("(空白)",
    "entityform_error");

            // 对象tabpage清空 2009/1/5 
            this.binaryResControl1.Clear();

            // 册tabpage是否显示
            string strItemDbName = this.MainForm.GetItemDbName(strBiblioDbName);
            if (String.IsNullOrEmpty(strItemDbName) == false)
            {
                this.EnableItemsPage(true);
            }
            else
            {
                this.EnableItemsPage(false);
            }

            this.entityControl1.ClearItems();

            // 期tabpage是否显示
            string strIssueDbName = this.MainForm.GetIssueDbName(strBiblioDbName);
            if (String.IsNullOrEmpty(strIssueDbName) == false)
            {
                this.EnableIssuesPage(true);
            }
            else
            {
                this.EnableIssuesPage(false);
            }

            this.issueControl1.ClearItems();

            // 订购tabpage是否显示
            string strOrderDbName = this.MainForm.GetOrderDbName(strBiblioDbName);
            if (String.IsNullOrEmpty(strOrderDbName) == false) // 仅在当前书目库有对应的采购库时,才装入采购记录
            {
                if (String.IsNullOrEmpty(strIssueDbName) == false)
                    this.orderControl1.SeriesMode = true;
                else
                    this.orderControl1.SeriesMode = false;

                this.EnableOrdersPage(true);
            }
            else
            {
                this.EnableOrdersPage(false);
            }

            this.orderControl1.ClearItems();

            // 评注tabpage是否显示
            string strCommentDbName = this.MainForm.GetCommentDbName(strBiblioDbName);
            if (String.IsNullOrEmpty(strCommentDbName) == false)
            {
                this.EnableCommentsPage(true);
            }
            else
            {
                this.EnableCommentsPage(false);
            }

            this.commentControl1.ClearItems();

            // 2007/11/5 
            this.DeletedMode = false;

            this.BiblioChanged = false;

            // ****
            this.toolStripButton_marcEditor_save.Enabled = true;

            // 用模板的时候,无论如何ReadOnly都是false
            if (this.m_marcEditor.ReadOnly == true)
                this.m_marcEditor.ReadOnly = false;

            // 2008/11/30 
            SwitchFocus(MARC_EDITOR);
            if (dbname_dlg.NotAsk == true || select_temp_dlg.NotAsk == true)
            {
                this.MainForm.StatusBarMessage = "自动从书目库 " + strBiblioDbName + " 中装入名为 " + select_temp_dlg.SelectedName + " 的新书目记录模板。如要重新出现装载对话框,请按住Shift键再点“装载书目模板”按钮...";
            }
            return 1;
        ERROR1:
            MessageBox.Show(this, strError);
            return -1;
        }
Example #3
0
        // 
        /// <summary>
        /// 保存当前窗口内记录到模板配置文件
        /// </summary>
        public void SaveBiblioToTemplate()
        {
            // 获得路径行中已经有的书目库名
            string strBiblioDbName = Global.GetDbName(this.BiblioRecPath);

            GetDbNameDlg dlg = new GetDbNameDlg();
            MainForm.SetControlFont(dlg, this.Font, false);

            dlg.DbName = strBiblioDbName;
            dlg.MainForm = this.MainForm;
            dlg.Text = "请选择目标编目库名";
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

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

            strBiblioDbName = dlg.DbName;


            // 下载模板配置文件
            string strContent = "";
            string strError = "";

            // string strCfgFilePath = respath.Path + "/cfgs/template";
            byte[] baTimestamp = null;

            // return:
            //      -1  error
            //      0   not found
            //      1   found
            int nRet = GetCfgFileContent(strBiblioDbName,
                "template",
                out strContent,
                out baTimestamp,
                out strError);
            if (nRet == -1 || nRet == 0)
            {
                goto ERROR1;
            }

            SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg();
            MainForm.SetControlFont(tempdlg, this.Font, false);
            nRet = tempdlg.Initial(
                true,   // 允许修改
                strContent,
                out strError);
            if (nRet == -1)
                goto ERROR1;


            tempdlg.Text = "请选择要修改的模板记录";
            tempdlg.CheckNameExist = false;	// 按OK按钮时不警告"名字不存在",这样允许新建一个模板
            //tempdlg.ap = this.MainForm.applicationInfo;
            //tempdlg.ApCfgTitle = "detailform_selecttemplatedlg";
            tempdlg.ShowDialog(this);

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

            // return:
            //      -1  出错
            //      0   没有必要保存
            //      1   成功保存
            nRet = SaveTemplateChange(tempdlg,
                strBiblioDbName,
                baTimestamp,
                out strError);
            if (nRet == -1)
                goto ERROR1;

#if NO
            // 获得书目记录XML格式
            string strXmlBody = "";
            nRet = this.GetBiblioXml(
                strBiblioDbName,
                false,  // 不要包含资源ID
                out strXmlBody,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            // 修改配置文件内容
            if (tempdlg.textBox_name.Text != "")
            {
                // 替换或者追加一个记录
                nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text,
                    strXmlBody,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }

            if (tempdlg.Changed == false)	// 没有必要保存回去
                return;

            string strOutputXml = tempdlg.OutputXml;

            // Debug.Assert(false, "");
            nRet = SaveCfgFile(strBiblioDbName,
                "template",
                strOutputXml,
                baTimestamp,
                out strError);
            if (nRet == -1)
                goto ERROR1;
#endif

            this.MainForm.StatusBarMessage = "修改模板成功。";
            return;

        ERROR1:
            MessageBox.Show(this, strError);
        }
Example #4
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;
        }
Example #5
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;
            }
        }
Example #6
0
        // 装载读者记录模板
        // return:
        //      -1  error
        //      0   放弃
        //      1   成功装载
        /// <summary>
        /// 装载读者记录模板
        /// </summary>
        /// <returns>-1: 出错; 0: 放弃; 1: 成功</returns>
        public int LoadReaderTemplateFromServer()
        {
            this.EnableControls(false);

            try
            {

                int nRet = 0;
                string strError = "";

                bool bShift = (Control.ModifierKeys == Keys.Shift);

                if (this.ReaderXmlChanged == true
                    || this.ObjectChanged == true)
                {
                    // 警告尚未保存
                    DialogResult result = MessageBox.Show(this,
        "当前有信息被修改后尚未保存。若此时若创建新读者信息,现有未保存信息将丢失。\r\n\r\n确实要创建新读者信息? ",
        "ReaderInfoForm",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button2);
                    if (result != DialogResult.Yes)
                        return 0;
                }

                this.binaryResControl1.Clear();
                this.ObjectChanged = false; // 2013/10/17

                nRet = this.readerEditControl1.SetData("<root />",
         "",
         null,
         out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.readerEditControl1.Changed = false;

                string strSelectedDbName = this.MainForm.AppInfo.GetString(
                    "readerinfo_form",
                    "selected_dbname_for_loadtemplate",
                    "");

                SelectedTemplate selected = this.selected_templates.Find(strSelectedDbName);

                GetDbNameDlg dbname_dlg = new GetDbNameDlg();
                MainForm.SetControlFont(dbname_dlg, this.Font, false);
                dbname_dlg.DbType = "reader";
                if (selected != null)
                {
                    dbname_dlg.NotAsk = selected.NotAskDbName;
                    dbname_dlg.AutoClose = (bShift == true ? false : selected.NotAskDbName);
                }

                dbname_dlg.EnableNotAsk = true;
                dbname_dlg.DbName = strSelectedDbName;
                dbname_dlg.MainForm = this.MainForm;

                dbname_dlg.Text = "装载读者记录模板 -- 请选择目标读者库名";
                //  dbname_dlg.StartPosition = FormStartPosition.CenterScreen;

                this.MainForm.AppInfo.LinkFormState(dbname_dlg, "readerinfoformm_load_template_GetBiblioDbNameDlg_state");
                dbname_dlg.ShowDialog(this);
                this.MainForm.AppInfo.UnlinkFormState(dbname_dlg);

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

                string strReaderDbName = dbname_dlg.DbName;
                // 记忆
                this.MainForm.AppInfo.SetString(
                    "readerinfo_form",
                    "selected_dbname_for_loadtemplate",
                    strReaderDbName);

                selected = this.selected_templates.Find(strReaderDbName);

                this.readerEditControl1.RecPath = dbname_dlg.DbName + "/?";	// 为了追加保存
                this.readerEditControl1.Changed = false;

                // 下载配置文件
                string strContent = "";

                // string strCfgFilePath = respath.Path + "/cfgs/template";
                byte[] baCfgOutputTimestamp = null;
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = GetCfgFileContent(strReaderDbName + "/cfgs/template",
                    out strContent,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == 0)
                {
                    MessageBox.Show(this, strError + "\r\n\r\n将改用位于本地的 “选项/读者信息缺省值” 来刷新记录");

                    // 如果template文件不存在,则找本地配置的模板
                    string strNewDefault = this.MainForm.AppInfo.GetString(
    "readerinfoform_optiondlg",
    "newreader_default",
    "<root />");
                    nRet = this.readerEditControl1.SetData(strNewDefault,
                         "",
                         null,
                         out strError);
                    if (nRet == -1)
                        MessageBox.Show(this, strError);

                    // this.ClearCardPhoto();
                    this.binaryResControl1.Clear();
                    this.ObjectChanged = false; // 2013/10/17

#if NO
                    Global.ClearHtmlPage(this.webBrowser_readerInfo,
                        this.MainForm.DataDir);
#endif
                    ClearReaderHtmlPage();

                    
                    /*
                    this.SetXmlToWebbrowser(this.webBrowser_xml,
                        strNewDefault);
                     * */
                    Global.SetXmlToWebbrowser(this.webBrowser_xml,
    this.MainForm.DataDir,
    "xml",
    strNewDefault);

                    this.m_strSetAction = "new";
                    // this.m_strLoadSource = "local";
                    return -1;
                }
                if (nRet == -1 || nRet == 0)
                {
                    this.readerEditControl1.Timestamp = null;
                    goto ERROR1;
                }

                // MessageBox.Show(this, strContent);

                SelectRecordTemplateDlg select_temp_dlg = new SelectRecordTemplateDlg();
                MainForm.SetControlFont(select_temp_dlg, this.Font, false);

                select_temp_dlg.Text = "请选择新读者记录模板 -- 来自库 '" + strReaderDbName + "'";
                string strSelectedTemplateName = "";
                bool bNotAskTemplateName = false;
                if (selected != null)
                {
                    strSelectedTemplateName = selected.TemplateName;
                    bNotAskTemplateName = selected.NotAskTemplateName;
                }

                select_temp_dlg.SelectedName = strSelectedTemplateName;
                select_temp_dlg.AutoClose = (bShift == true ? false : bNotAskTemplateName);
                select_temp_dlg.NotAsk = bNotAskTemplateName;

                nRet = select_temp_dlg.Initial(
                    false,
                    strContent,
                    out strError);
                if (nRet == -1)
                {
                    strError = "装载配置文件 '" + "template" + "' 发生错误: " + strError;
                    goto ERROR1;
                }

                this.MainForm.AppInfo.LinkFormState(select_temp_dlg, "readerinfoform_load_template_SelectTemplateDlg_state");
                select_temp_dlg.ShowDialog(this);
                this.MainForm.AppInfo.UnlinkFormState(select_temp_dlg);

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

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

                this.readerEditControl1.Timestamp = null;

                // this.BiblioOriginPath = ""; // 保存从数据库中来的原始path


                nRet = this.readerEditControl1.SetData(
        select_temp_dlg.SelectedRecordXml,
        dbname_dlg.DbName + "/?",
        null,
        out strError);
                if (nRet == -1)
                    goto ERROR1;

                /*
                this.SetXmlToWebbrowser(this.webBrowser_xml,
                    select_temp_dlg.SelectedRecordXml);
                 * */
                Global.SetXmlToWebbrowser(this.webBrowser_xml,
this.MainForm.DataDir,
"xml",
select_temp_dlg.SelectedRecordXml);

                this.m_strSetAction = "new";
                // this.m_strLoadSource = "server";

#if NO
                Global.ClearHtmlPage(this.webBrowser_readerInfo,
                    this.MainForm.DataDir);
#endif
                ClearReaderHtmlPage();

                this.readerEditControl1.Changed = false;
                return 1;
            ERROR1:
                MessageBox.Show(this, strError);
                return -1;
            }
            finally
            {
                this.EnableControls(true);
            }
        }
Example #7
0
        // 
        /// <summary>
        /// 保存当前窗口内记录到模板配置文件
        /// </summary>
        public void SaveReaderToTemplate()
        {
            this.EnableControls(false);

            try
            {

                // 获得路径行中已经有的读者库名
                string strReaderDbName = Global.GetDbName(this.readerEditControl1.RecPath);

                GetDbNameDlg dlg = new GetDbNameDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.DbType = "reader";
                dlg.DbName = strReaderDbName;
                dlg.MainForm = this.MainForm;
                dlg.Text = "请选择目标读者库名";
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog(this);

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

                strReaderDbName = dlg.DbName;


                // 下载模板配置文件
                string strContent = "";
                string strError = "";

                byte[] baTimestamp = null;

                // return:
                //      -1  error
                //      0   not found
                //      1   found
                int nRet = GetCfgFileContent(strReaderDbName + "/cfgs/template",
                    out strContent,
                    out baTimestamp,
                    out strError);
                if (nRet == -1 || nRet == 0)
                {
                    goto ERROR1;
                }

                SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg();
                MainForm.SetControlFont(tempdlg, this.Font, false);
                nRet = tempdlg.Initial(
                    true,
                    strContent, out strError);
                if (nRet == -1)
                    goto ERROR1;


                tempdlg.Text = "请选择要修改的模板记录";
                tempdlg.CheckNameExist = false;	// 按OK按钮时不警告"名字不存在",这样允许新建一个模板
                //tempdlg.ap = this.MainForm.applicationInfo;
                //tempdlg.ApCfgTitle = "detailform_selecttemplatedlg";
                tempdlg.ShowDialog(this);

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

                string strNewXml = "";
                nRet = this.readerEditControl1.GetData(
                    out strNewXml,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 需要消除password/displayName元素内容
                {
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strNewXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载XML到DOM出错: " + ex.Message;
                        goto ERROR1;
                    }
                    DomUtil.SetElementText(dom.DocumentElement,
                        "password", "");
                    DomUtil.SetElementText(dom.DocumentElement,
                        "displayName", "");

                    strNewXml = dom.OuterXml;
                }

                // 修改配置文件内容
                if (tempdlg.textBox_name.Text != "")
                {
                    // 替换或者追加一个记录
                    nRet = tempdlg.ReplaceRecord(tempdlg.textBox_name.Text,
                        strNewXml,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }

                if (tempdlg.Changed == false)	// 没有必要保存回去
                    return;

                string strOutputXml = tempdlg.OutputXml;

                // Debug.Assert(false, "");
                nRet = SaveCfgFile(strReaderDbName + "/cfgs/template",
                    strOutputXml,
                    baTimestamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                this.MainForm.StatusBarMessage = "修改模板成功。";
                return;

            ERROR1:
                MessageBox.Show(this, strError);
            }
            finally
            {
                this.EnableControls(true);
            }
        }
Example #8
0
        // 装载模板
        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;
        }