Пример #1
0
        // 插入<group>类型节点。一级节点。
        private void toolStripMenuItem_zhongcihao_insert_group_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            // 当前节点
            TreeNode current_treenode = this.treeView_zhongcihao.SelectedNode;

            // 如果不是根级的节点,则向上找到根级别
            if (current_treenode != null && current_treenode.Parent != null)
            {
                current_treenode = current_treenode.Parent;
            }

            // 插入点
            int index = this.treeView_zhongcihao.Nodes.IndexOf(current_treenode);
            if (index == -1)
                index = this.treeView_zhongcihao.Nodes.Count;
            else
                index++;

            List<string> used_dbnames = GetAllUsedZhongcihaoDbName(null);

            // 询问<group>名
            ZhongcihaoGroupDialog dlg = new ZhongcihaoGroupDialog();
            MainForm.SetControlFont(dlg, this.Font, false);

            dlg.Text = "请指定组特性";
            dlg.AllZhongcihaoDatabaseInfoXml = GetAllZhongcihaoDbInfoXml();
            dlg.ExcludingDbNames = used_dbnames;
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

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

            /* 已经在ZhongcihaoGroupDialog对话框中检查过了
            // 检查对话框中得到的种次号库,是不是被别处用过的种次号库?
            if (used_dbnames.IndexOf(dlg.ZhongcihaoDbName) != -1)
            {
                strError = "您所指定的种次号库 '" + dlg.ZhongcihaoDbName + "' 已经被其他组使用过了。放弃创建组。";
                goto ERROR1;
            }
             * */


            // 检查所指定的种次号库是否存在。如果不存在,提醒创建它

            // 检查指定名字的种次号库是否已经创建
            // return:
            //      -2  所指定的种次号库名字,实际上是一个已经存在的其他类型的库名
            //      -1  error
            //      0   还没有创建
            //      1   已经创建
            nRet = CheckZhongcihaoDbCreated(dlg.ZhongcihaoDbName,
                out strError);
            if (nRet == -1)
                goto ERROR1;
            if (nRet == -2)
                goto ERROR1;
            if (nRet == 0)
            {
                string strComment = "种次号库 '" + dlg.ZhongcihaoDbName + "' 尚未创建。按确定按钮可创建它。";
                // return:
                //      -1  errpr
                //      0   cancel
                //      1   created
                nRet = CreateSimpleDatabase("zhongcihao",
                    dlg.ZhongcihaoDbName,
                    strComment);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 0)
                    return;
                Debug.Assert(nRet == 1, "");
            }

            XmlDocument dom = new XmlDocument();
            dom.LoadXml("<group />");
            DomUtil.SetAttr(dom.DocumentElement, "name", dlg.GroupName);
            DomUtil.SetAttr(dom.DocumentElement, "zhongcihaodb", dlg.ZhongcihaoDbName);

            string strGroupCaption = MakeZhongcihaoGroupNodeName(dlg.GroupName, dlg.ZhongcihaoDbName);

            TreeNode new_treenode = new TreeNode(strGroupCaption, TYPE_ZHONGCIHAO_GROUP, TYPE_ZHONGCIHAO_GROUP);
            new_treenode.Tag = dom.OuterXml;
            this.treeView_zhongcihao.Nodes.Insert(index, new_treenode);

            this.treeView_zhongcihao.SelectedNode = new_treenode;

            this.ZhongcihaoChanged = true;


            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #2
0
        // 修改一个节点的定义
        private void toolStripButton_zhongcihao_modify_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            // 当前节点
            TreeNode current_treenode = this.treeView_zhongcihao.SelectedNode;

            if (current_treenode == null)
            {
                MessageBox.Show(this, "尚未选定要修改的节点");
                return;
            }

            if (current_treenode.ImageIndex == TYPE_ZHONGCIHAO_GROUP)
            {
                // 组节点


                string strXml = (string)current_treenode.Tag;
                if (String.IsNullOrEmpty(strXml) == true)
                {
                    strError = "节点 " + current_treenode.Text + " 没有Tag定义";
                    goto ERROR1;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strXml);
                }
                catch (Exception ex)
                {
                    strError = "<group>节点的XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }

                string strGroupName = DomUtil.GetAttr(dom.DocumentElement,
                    "name");
                string strZhongcihaoDbName = DomUtil.GetAttr(dom.DocumentElement,
                    "zhongcihaodb");

                List<string> used_dbnames = GetAllUsedZhongcihaoDbName(current_treenode);

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

                dlg.Text = "修改组特性";
                dlg.ZhongcihaoDbName = strZhongcihaoDbName;
                dlg.GroupName = strGroupName;
                dlg.AllZhongcihaoDatabaseInfoXml = GetAllZhongcihaoDbInfoXml();
                dlg.ExcludingDbNames = used_dbnames;
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog(this);

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

                DomUtil.SetAttr(dom.DocumentElement, "name", dlg.GroupName);
                DomUtil.SetAttr(dom.DocumentElement, "zhongcihaodb", dlg.ZhongcihaoDbName);

                current_treenode.Text = MakeZhongcihaoGroupNodeName(dlg.GroupName, dlg.ZhongcihaoDbName);
                current_treenode.Tag = dom.DocumentElement.OuterXml;    // 2009/3/3

                // 确保展开
                // current_treenode.Parent.Expand();

                this.ZhongcihaoChanged = true;

            }
            else if (current_treenode.ImageIndex == TYPE_ZHONGCIHAO_DATABASE)
            {
                // 书目库节点

                string strXml = (string)current_treenode.Tag;

                if (String.IsNullOrEmpty(strXml) == true)
                {
                    strError = "节点 " + current_treenode.Text + " 没有Tag定义";
                    goto ERROR1;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strXml);
                }
                catch (Exception ex)
                {
                    strError = "<database>节点的XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }

                string strDatabaseName = DomUtil.GetAttr(dom.DocumentElement,
                    "name");

                List<string> used_dbnames = Zhongcihao_GetAllUsedBiblioDbName(current_treenode);
                
                // 新的书目库名
                GetOpacMemberDatabaseNameDialog dlg = new GetOpacMemberDatabaseNameDialog();
                MainForm.SetControlFont(dlg, this.Font, false);

                dlg.Text = "修改书目库名";
                dlg.SelectedDatabaseName = strDatabaseName;
                dlg.AllDatabaseInfoXml = GetAllBiblioDbInfoXml();
                dlg.ExcludingDbNames = used_dbnames;
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog(this);

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

                // 检查对话框中得到的书目库名,是不是被别处用过的书目库名?
                if (used_dbnames.IndexOf(dlg.SelectedDatabaseName) != -1)
                {
                    strError = "您所指定的书目库 '" + dlg.SelectedDatabaseName + "' 已经被其他数据库节点使用过了。放弃本次修改数据库节点操作。";
                    goto ERROR1;
                }

                // 检查指定名字的书目库是否已经创建
                // return:
                //      -2  所指定的书目库名字,实际上是一个已经存在的其他类型的库名
                //      -1  error
                //      0   还没有创建
                //      1   已经创建
                nRet = CheckBiblioDbCreated(dlg.SelectedDatabaseName,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == -2)
                    goto ERROR1;
                if (nRet == 0)
                {
                    strError = "书目库 '" + dlg.SelectedDatabaseName + "' 尚未创建。请先创建它,再来修改数据库节点。";
                    goto ERROR1;
                }

                // 获得数据库syntax
                string strSyntax = "";
                // 获得书目库的syntax
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = GetBiblioSyntax(dlg.SelectedDatabaseName,
                    out strSyntax,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 0)
                {
                    strError = "在调用GetBiblioSyntax()过程中,发现并不存在书目库 '" + dlg.SelectedDatabaseName + "' 的定义";
                    goto ERROR1;
                }

                string strPrefix = "";
                string strUri = "";
                if (strSyntax == "unimarc")
                    strUri = Ns.unimarcxml;
                else if (strSyntax == "usmarc")
                    strUri = Ns.usmarcxml;
                else
                {
                    nRet = ExistingPrefix(strSyntax, out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 1)
                        strPrefix = strSyntax;
                    Debug.Assert(nRet == 0, "");
                    if (nRet == 0)
                    {
                        strError = "目前名字表中尚未定义书目库格式 '" + strSyntax + "' 所对应的namespace URI,所以无法创建该格式的书目库节点";
                        goto ERROR1;
                    }
                }


                if (String.IsNullOrEmpty(strPrefix) == true)
                {
                    // 根据名字空间URI查找对应的prefix
                    // return:
                    //      -1  error
                    //      0   not found
                    //      1   found
                    nRet = FindNamespacePrefix(strUri,
                        out strPrefix,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        strError = "在名字表中没有找到与namespace URI '" + strUri + "' (来源于书目库格式 '" + strSyntax + "') 对应的prefix,无法创建该格式的书目库节点";
                        goto ERROR1;
                    }
                    Debug.Assert(nRet == 1, "");
                }

                DomUtil.SetAttr(dom.DocumentElement, "name", dlg.SelectedDatabaseName);
                DomUtil.SetAttr(dom.DocumentElement, "leftfrom", "索取类号");

                if (strSyntax == "unimarc")
                {
                    DomUtil.SetAttr(dom.DocumentElement,
                                        "rightxpath",
                                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='905']/" + strPrefix + ":subfield[@code='e']/text()");
                    DomUtil.SetAttr(dom.DocumentElement,
                        "titlexpath",
                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='200']/" + strPrefix + ":subfield[@code='a']/text()");
                    DomUtil.SetAttr(dom.DocumentElement,
                        "authorxpath",
                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='200']/" + strPrefix + ":subfield[@code='f' or @code='g']/text()");
                }
                else if (strSyntax == "usmarc")
                {
                    DomUtil.SetAttr(dom.DocumentElement,
                        "rightxpath",
                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='905']/" + strPrefix + ":subfield[@code='e']/text()");
                    DomUtil.SetAttr(dom.DocumentElement,
                        "titlexpath",
                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='245']/" + strPrefix + ":subfield[@code='a']/text()");
                    DomUtil.SetAttr(dom.DocumentElement,
                        "authorxpath",
                        "//" + strPrefix + ":record/" + strPrefix + ":datafield[@tag='245']/" + strPrefix + ":subfield[@code='c']/text()");
                }
                else
                {
                    strError = "目前暂时不能处理syntax为 '" + strSyntax + "' 的书目库节点修改...";
                    goto ERROR1;
                }


                string strDisplayText = MakeZhongcihaoDatabaseNodeName(dlg.SelectedDatabaseName);

                current_treenode.Text = strDisplayText;
                current_treenode.Tag = dom.DocumentElement.OuterXml;

                // 确保展开
                current_treenode.Parent.Expand();

                this.ZhongcihaoChanged = true;
            }
            else if (current_treenode.ImageIndex == TYPE_ZHONGCIHAO_NSTABLE)
            {
                // 名字表节点
                string strXml = (string)current_treenode.Tag;
                if (String.IsNullOrEmpty(strXml) == true)
                {
                    strError = "节点 " + current_treenode.Text + " 没有Tag定义";
                    goto ERROR1;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strXml);
                }
                catch (Exception ex)
                {
                    strError = "<nstable>节点的XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }

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

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

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

                dom = new XmlDocument();
                try
                {
                    dom.LoadXml(dlg.XmlString);
                }
                catch (Exception ex)
                {
                    strError = "修改后的的XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }

                string strNstableName = DomUtil.GetAttr(dom.DocumentElement, "name");

                current_treenode.Text = MakeZhongcihaoNstableNodeName(strNstableName);
                current_treenode.Tag = dlg.XmlString;

                // 确保展开
                current_treenode.Parent.Expand();

                this.ZhongcihaoChanged = true;
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #3
0
        // 插入<group>类型节点
        private void toolStripMenuItem_zhongcihao_insert_group_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            // 当前节点
            TreeNode current_treenode = this.treeView_zhongcihao.SelectedNode;

            // 如果不是根级的节点,则向上找到根级别
            if (current_treenode != null && current_treenode.Parent != null)
            {
                current_treenode = current_treenode.Parent;
            }

            // 插入点
            int index = this.treeView_zhongcihao.Nodes.IndexOf(current_treenode);
            if (index == -1)
                index = this.treeView_zhongcihao.Nodes.Count;
            else
                index++;

            // 询问<group>名
            ZhongcihaoGroupDialog dlg = new ZhongcihaoGroupDialog();

            dlg.Text = "请指定组特性";
            dlg.AllZhongcihaoDatabaseInfoXml = GetAllZhongcihaoDbInfoXml();
            dlg.ExcludingDbNames = GetAllUsedZhongcihaoDbName();
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

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

            // 检查所指定的种次号库是否存在。如果不存在,提醒创建它

                    // 检查指定名字的种次号库是否已经创建
        // return:
        //      -2  所指定的种次号库名字,实际上是一个已经存在的其他类型的库名
        //      -1  error
        //      0   还没有创建
        //      1   已经创建
            nRet = CheckZhongcihaoDbCreated(dlg.ZhongcihaoDbName,
                out strError);
            if (nRet == -1)
                goto ERROR1;
            if (nRet == -2)
                goto ERROR1;
            if (nRet == 0)
            {
                string strComment = "种次号库 '" + dlg.ZhongcihaoDbName + "' 尚未创建。请创建它。";
                // return:
                //      -1  errpr
                //      0   cancel
                //      1   created
                nRet = CreateSimpleDatabase("zhongcihao",
                    dlg.ZhongcihaoDbName,
                    strComment);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 0)
                    return;
                Debug.Assert(nRet == 1, "");
            }

            XmlDocument dom = new XmlDocument();
            dom.LoadXml("<group />");
            DomUtil.SetAttr(dom.DocumentElement, "name", dlg.GroupName);
            DomUtil.SetAttr(dom.DocumentElement, "zhongcihaodb", dlg.ZhongcihaoDbName);

            TreeNode new_treenode = new TreeNode(dlg.GroupName, TYPE_GROUP, TYPE_GROUP);
            new_treenode.Tag = dom.OuterXml;
            this.treeView_zhongcihao.Nodes.Insert(index, new_treenode);

            this.treeView_zhongcihao.SelectedNode = new_treenode;

            /*
            // 需要立即向服务器提交修改
            nRet = SubmitZhongcihaoDef(out strError);
            if (nRet == -1)
            {
                new_treenode.ImageIndex = TYPE_ERROR;    // 表示未能提交的新插入节点请求
                goto ERROR1;
            }*/

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