コード例 #1
0
ファイル: ManagerForm.cs プロジェクト: paopaofeng/dp2
        // 修改一个节点的定义
        private void toolStripButton_opacBrowseFormats_modify_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

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

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

            if (current_treenode.Parent == null)
            {
                // 库名节点


                // 当前已经存在的数据库名都是需要排除的
                List<string> existing_dbnames = new List<string>();
                for (int i = 0; i < this.treeView_opacBrowseFormats.Nodes.Count; i++)
                {
                    string strDatabaseName = this.treeView_opacBrowseFormats.Nodes[i].Text;
                    existing_dbnames.Add(strDatabaseName);
                }

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

                dlg.Text = "修改数据库名";
                dlg.ManagerForm = this;
                dlg.DatabaseName = current_treenode.Text;
                dlg.ExcludingDbNames = existing_dbnames;
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog(this);

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

                current_treenode.Text = dlg.DatabaseName;

                // 确保展开
                if (current_treenode.Parent != null)
                    current_treenode.Parent.Expand();

                // 需要立即向服务器提交修改
                nRet = SubmitOpacBrowseFormatDef(out strError);
                if (nRet == -1)
                {
                    current_treenode.ImageIndex = 2;    // 表示未能提交的定义变化请求
                    goto ERROR1;
                }
            }
            else
            {
                // 格式节点

                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 = "XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }


                // 显示格式
                OpacBrowseFormatDialog dlg = new OpacBrowseFormatDialog();
                MainForm.SetControlFont(dlg, this.Font, false);

                dlg.Text = "请指定显示格式的属性";
                // dlg.FormatName = DomUtil.GetAttr(dom.DocumentElement, "name");
                dlg.CaptionsXml = dom.DocumentElement.InnerXml; // 2009/6/27
                dlg.FormatType = DomUtil.GetAttr(dom.DocumentElement, "type");
                dlg.ScriptFile = DomUtil.GetAttr(dom.DocumentElement, "scriptfile");
                dlg.FormatStyle = DomUtil.GetAttr(dom.DocumentElement, "style");
                dlg.StartPosition = FormStartPosition.CenterScreen;
                dlg.ShowDialog(this);

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

                /*
                string strDisplayText = dlg.FormatName;
                DomUtil.SetAttr(dom.DocumentElement, "name", dlg.FormatName);

                if (String.IsNullOrEmpty(dlg.FormatType) == false)
                {
                    strDisplayText += " type=" + dlg.FormatType;
                    DomUtil.SetAttr(dom.DocumentElement, "type", dlg.FormatType);
                }

                if (String.IsNullOrEmpty(dlg.ScriptFile) == false)
                {
                    strDisplayText += " scriptfile=" + dlg.ScriptFile;
                    DomUtil.SetAttr(dom.DocumentElement, "scriptfile", dlg.ScriptFile);
                }

                if (String.IsNullOrEmpty(dlg.FormatStyle) == false)
                {
                    strDisplayText += " style=" + dlg.FormatStyle;
                    DomUtil.SetAttr(dom.DocumentElement, "style", dlg.FormatStyle);
                }
                 * */

                // 2009/6/27
                if (String.IsNullOrEmpty(dlg.CaptionsXml) == false)
                    dom.DocumentElement.InnerXml = dlg.CaptionsXml;

                // 2009/6/27
                current_treenode.Text = GetFormatDisplayString(dom.DocumentElement);

                current_treenode.Tag = dom.DocumentElement.OuterXml;

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


                // 需要立即向服务器提交修改
                nRet = SubmitOpacBrowseFormatDef(out strError);
                if (nRet == -1)
                {
                    current_treenode.ImageIndex = 2;    // 表示未能提交的定义变化请求
                    goto ERROR1;
                }
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
コード例 #2
0
ファイル: ManagerForm.cs プロジェクト: paopaofeng/dp2
        // 插入显示格式节点(后插)
        private void toolStripMenuItem_opacBrowseFormats_insertBrowseFormatNode_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

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

            if (current_treenode == null)
            {
                MessageBox.Show(this, "尚未选定库名或格式名节点,因此无法插入新的显示格式节点");
                return;
            }

            int index = -1;

            Debug.Assert(current_treenode != null, "");

            // 如果是第一级的节点,则理解为插入到它的儿子的尾部
            if (current_treenode.Parent == null)
            {
                Debug.Assert(current_treenode != null, "");

                index = current_treenode.Nodes.Count;
            }
            else
            {
                index = current_treenode.Parent.Nodes.IndexOf(current_treenode);

                Debug.Assert(index != -1, "");

                index++;

                current_treenode = current_treenode.Parent; 
            }

            // 至此,current_treenode为数据库类型的节点了


            // 新的显示格式
            OpacBrowseFormatDialog dlg = new OpacBrowseFormatDialog();
            MainForm.SetControlFont(dlg, this.Font, false);

            // TODO: 如果数据库为书目库,则type应当预设为"biblio"
            dlg.Text = "请指定显示格式的属性";
            // dlg.FormatName = "";
            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

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

            XmlDocument dom = new XmlDocument();
            dom.LoadXml("<format />");

            /*
            string strDisplayText = dlg.FormatName;
            DomUtil.SetAttr(dom.DocumentElement, "name", dlg.FormatName);

            if (String.IsNullOrEmpty(dlg.FormatType) == false)
            {
                strDisplayText += " type=" + dlg.FormatType;
                DomUtil.SetAttr(dom.DocumentElement, "type", dlg.FormatType);
            }

            if (String.IsNullOrEmpty(dlg.ScriptFile) == false)
            {
                strDisplayText += " scriptfile=" + dlg.ScriptFile;
                DomUtil.SetAttr(dom.DocumentElement, "scriptfile", dlg.ScriptFile);
            }

            if (String.IsNullOrEmpty(dlg.FormatStyle) == false)
            {
                strDisplayText += " style=" + dlg.FormatStyle;
                DomUtil.SetAttr(dom.DocumentElement, "style", dlg.FormatStyle);
            }
             * */

            // 2009/6/27
            if (String.IsNullOrEmpty(dlg.CaptionsXml) == false)
                dom.DocumentElement.InnerXml = dlg.CaptionsXml;

            TreeNode new_treenode = new TreeNode(GetFormatDisplayString(dom.DocumentElement), 1, 1);
            new_treenode.Tag = dom.DocumentElement.OuterXml;

            current_treenode.Nodes.Insert(index, new_treenode);

            this.treeView_opacBrowseFormats.SelectedNode = new_treenode;

            // 需要立即向服务器提交修改
            nRet = SubmitOpacBrowseFormatDef(out strError);
            if (nRet == -1)
            {
                new_treenode.ImageIndex = 2;    // 表示未能提交的新插入节点请求
                goto ERROR1;
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }