コード例 #1
0
ファイル: DatabaseObjectTree.cs プロジェクト: renyh1013/dp2
        // 创建新对象
        void DoNewObject(bool bInsertAsChild)
        {
            NewObjectDlg dlg = new NewObjectDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

            dlg.Type = ResTree.RESTYPE_FILE;
            dlg.ShowDialog(this);

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

            string strPath = "";
            string strError = "";

            DatabaseObject obj = new DatabaseObject();
            obj.Name = dlg.textBox_objectName.Text;
            obj.Type = dlg.Type;
            obj.Changed = true;

            TreeNode node = new TreeNode(obj.Name, obj.Type, obj.Type);

            TreeNode nodeParent = null;

            if (bInsertAsChild == false)
            {
                // 插入同级


                // 查重
                TreeNode nodeDup = TreeViewUtil.FindNodeByText((TreeView)this,
                    this.SelectedNode != null ? this.SelectedNode.Parent : null,
                    dlg.textBox_objectName.Text);
                if (nodeDup != null)
                {
                    strError = "同名对象已经存在。放弃操作。";
                    goto ERROR1;
                }

                if (this.SelectedNode == null)
                {
                    strError = "尚未选择基准对象";
                    goto ERROR1;
                }

                nodeParent = this.SelectedNode.Parent;
                if (nodeParent == null)
                    nodeParent = this.Nodes[0];

            }
            else
            {
                // 插入下级

                // 查重
                TreeNode nodeDup = TreeViewUtil.FindNodeByText((TreeView)this,
                    this.SelectedNode,
                    dlg.textBox_objectName.Text);
                if (nodeDup != null)
                {
                    strError = "同名对象已经存在。放弃操作。";
                    goto ERROR1;
                }

                nodeParent = this.SelectedNode;
                if (nodeParent == null)
                    nodeParent = this.Nodes[0];

            }

            nodeParent.Nodes.Add(node);

            strPath = TreeViewUtil.GetPath(nodeParent, '/');
            DatabaseObject objParent = this.Root.LocateObject(strPath);
            if (objParent == null)
            {
                strError = "路径为 '" + strPath + "' 的内存对象没有找到...";
                goto ERROR1;
            }

            obj.Parent = objParent;
            objParent.Children.Add(obj);

            strPath = TreeViewUtil.GetPath(node, '/');

            // 把修改记录到日志
            ObjEvent objevent = new ObjEvent();
            objevent.Obj = obj;
            objevent.Oper = ObjEventOper.New;
            objevent.Path = strPath;
            this.Log.Add(objevent);

            /*
            int nRet = NewServerSideObject(strPath,
                dlg.Type,
                null,
                null,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            // 刷新?
            FillAll(null);
            */

            return;
        ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
コード例 #2
0
ファイル: ResTree.cs プロジェクト: paopaofeng/dp2
        int NewServerSideObject(int nType,
            out string strError)
        {
            strError = "";
            if (this.SelectedNode == null)
            {
                strError = "尚未选择基准节点";
                goto ERROR1;
            }

            if (this.SelectedNode.ImageIndex != ResTree.RESTYPE_SERVER
                && this.SelectedNode.ImageIndex != ResTree.RESTYPE_DB
                && this.SelectedNode.ImageIndex != ResTree.RESTYPE_FOLDER)
            {
                strError = "只能在服务器、数据库、目录对象之下创建新目录";
                goto ERROR1;
            }

            NewObjectDlg dlg = new NewObjectDlg();
            dlg.Font = GuiUtil.GetDefaultFont();
            dlg.Type = nType;
            dlg.ShowDialog(this);

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

            ResPath respath = new ResPath(this.SelectedNode);

            string strPath = "";
            if (respath.Path == "")
                strPath = dlg.textBox_objectName.Text;
            else
                strPath = respath.Path + "/" + dlg.textBox_objectName.Text;

            int nRet = NewServerSideObject(
                respath.Url,
                strPath,
                dlg.Type,
                null,
                null,   // byte[] baTimeStamp,
                out strError);

            return nRet;
        ERROR1:
            return -1;
        }