Example #1
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 #2
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 #3
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 #4
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);
            }
        }