Exemplo n.º 1
0
        private void toolStripButton_arrangement_modify_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

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

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

            if (current_treenode.ImageIndex == TYPE_ARRANGEMENT_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 strArrangementName = DomUtil.GetAttr(dom.DocumentElement,
                    "name");
                string strClassType = DomUtil.GetAttr(dom.DocumentElement,
                    "classType");
                string strQufenhaoType = DomUtil.GetAttr(dom.DocumentElement,
                    "qufenhaoType");
                string strZhongcihaoDbName = DomUtil.GetAttr(dom.DocumentElement,
                    "zhongcihaodb");
                string strCallNumberStyle = DomUtil.GetAttr(dom.DocumentElement,
    "callNumberStyle");

                List<string> used_dbnames = GetArrangementAllUsedZhongcihaoDbName(current_treenode);

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

                dlg.Text = "修改排架体系特性";
                dlg.ArrangementName = strArrangementName;
                dlg.ClassType = strClassType;
                dlg.QufenhaoType = strQufenhaoType;
                dlg.ZhongcihaoDbName = strZhongcihaoDbName;
                dlg.CallNumberStyle = strCallNumberStyle;
                dlg.AllZhongcihaoDatabaseInfoXml = GetAllZhongcihaoDbInfoXml();
                dlg.ExcludingDbNames = used_dbnames;
                dlg.StartPosition = FormStartPosition.CenterScreen;
            REDO_INPUT:
                dlg.ShowDialog(this);

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

                // 检查排架体系节点名是否重复
                nRet = CheckArrangementNameDup(dlg.ArrangementName,
                    current_treenode,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;
                if (nRet == 1)
                {
                    MessageBox.Show(this, "排架体系名 '" + dlg.ArrangementName + "' 已经存在,无法重复创建,请修改");
                    goto REDO_INPUT;
                }

                DomUtil.SetAttr(dom.DocumentElement, "name", dlg.ArrangementName);
                DomUtil.SetAttr(dom.DocumentElement, "classType", dlg.ClassType);
                DomUtil.SetAttr(dom.DocumentElement, "qufenhaoType", dlg.QufenhaoType);
                DomUtil.SetAttr(dom.DocumentElement, "zhongcihaodb", dlg.ZhongcihaoDbName);
                DomUtil.SetAttr(dom.DocumentElement, "callNumberStyle", dlg.CallNumberStyle);

                current_treenode.Text = MakeArrangementGroupNodeName(
                    dlg.ArrangementName,
                    dlg.ClassType,
                    dlg.QufenhaoType,
                    dlg.ZhongcihaoDbName,
                    dlg.CallNumberStyle);
                current_treenode.Tag = dom.DocumentElement.OuterXml;

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

                this.ArrangementChanged = true;

            }
            else if (current_treenode.ImageIndex == TYPE_ARRANGEMENT_LOCATION)
            {
                // 馆藏地点节点
                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 = "<location>节点的XML装入DOM时出错: " + ex.Message;
                    goto ERROR1;
                }

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

                List<string> used_locationnames = this.GetArrangementAllUsedLocationName(current_treenode);

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

                dlg.Text = "修改馆藏地点名";
                if (this.Channel != null)
                    dlg.LibraryCodeList = this.Channel.LibraryCodeList;
                dlg.LocationString = strLocationName;
                dlg.ExcludingLocationNames = used_locationnames;
                dlg.StartPosition = FormStartPosition.CenterScreen;

                dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable);
                dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable);

                dlg.ShowDialog(this);

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

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

                DomUtil.SetAttr(dom.DocumentElement, "name", dlg.LocationString);

                string strDisplayText = MakeArrangementLocationNodeName(dlg.LocationString);

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

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

                this.ArrangementChanged = true;
            }
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Exemplo n.º 2
0
        private void toolStripMenuItem_arrangement_insert_group_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

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

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

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

            List<string> used_dbnames = GetArrangementAllUsedZhongcihaoDbName(null);

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

            dlg.Text = "请指定排架体系特性";
            dlg.AllZhongcihaoDatabaseInfoXml = GetAllZhongcihaoDbInfoXml();
            dlg.ExcludingDbNames = used_dbnames;
            dlg.StartPosition = FormStartPosition.CenterScreen;
        REDO_INPUT:
            dlg.ShowDialog(this);

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

            // 检查排架体系节点名是否重复
            nRet = CheckArrangementNameDup(dlg.ArrangementName,
                null,
                out strError);
            if (nRet == -1)
                goto ERROR1;
            if (nRet == 1)
            {
                MessageBox.Show(this, "排架体系名 '" + dlg.ArrangementName + "' 已经存在,无法重复创建,请修改");
                goto REDO_INPUT;
            }

            // 检查所指定的种次号库是否存在。如果不存在,提醒创建它
            if (String.IsNullOrEmpty(dlg.ZhongcihaoDbName) == false)
            {
                // 检查指定名字的种次号库是否已经创建
                // 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.ArrangementName);
            DomUtil.SetAttr(dom.DocumentElement, "classType", dlg.ClassType);
            DomUtil.SetAttr(dom.DocumentElement, "qufenhaoType", dlg.QufenhaoType);
            DomUtil.SetAttr(dom.DocumentElement, "zhongcihaodb", dlg.ZhongcihaoDbName);
            DomUtil.SetAttr(dom.DocumentElement, "callNumberStyle", dlg.CallNumberStyle);

            string strGroupCaption = MakeArrangementGroupNodeName(
                dlg.ArrangementName,
                dlg.ClassType,
                dlg.QufenhaoType,
                dlg.ZhongcihaoDbName,
                dlg.CallNumberStyle);

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

            this.treeView_arrangement.SelectedNode = new_treenode;

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