private void tsm_SaveAll_Click(object sender, EventArgs e) { //保存前收集当前节点的数据 this._collectDataNode = this._bindDataNode; if (!this.DataCollect()) return; foreach (IProject proj in this._projectList) { proj.ToFile(); OutPut.OutPutMsg("保存项目【" + proj.ProjName + "】成功!"); } foreach (IProject proj in this._projectList) { proj.Load(); //AbstractPlatformComponent projComponent = proj as AbstractPlatformComponent; //projComponent.from(null); } //重新保存后需要重新绑定数据 if (this._currentProj != null) { foreach (AbstractPlatformComponent proj in this._projectList) { AbstractPlatformComponent projComponent = this._currentProj as AbstractPlatformComponent; if (projComponent.Guid == proj.Guid) { this._currentProj = null; this._currentProj = proj as IProject; break; } } } DataBind(); }
private void AddProjNode(IProject proj) { AbstractPlatformComponent projComponent = proj as AbstractPlatformComponent; ComponentTreeNode projNode = null; //先添加根节点 if (proj.ProjType == ProjectTypeEnum.BEProj) { projNode = new ComponentTreeNode(NodeType.BEProj, projComponent.Guid); projNode.ImageIndex = projNode.SelectedImageIndex = 0; projNode.Text = proj.ProjName; } else if (proj.ProjType == ProjectTypeEnum.BPProj) { projNode = new ComponentTreeNode(NodeType.BPProj, projComponent.Guid); projNode.ImageIndex = projNode.SelectedImageIndex = 0; projNode.Text = proj.ProjName; } this.tvProject.Nodes.Add(projNode); //增加引用节点 ComponentTreeNode refrenceNode = new ComponentTreeNode(NodeType.Refrence, string.Empty); refrenceNode.Text = "引用"; refrenceNode.ImageIndex = refrenceNode.SelectedImageIndex = 6; projNode.Nodes.Add(refrenceNode); foreach (ProjectRefrence pr in proj.RefrenceList) { ComponentTreeNode rootNode = projNode; ComponentTreeNode refrenceDllNode = new ComponentTreeNode(NodeType.RefrenceDll, pr.Guid); refrenceDllNode.ImageIndex = refrenceDllNode.SelectedImageIndex = 8; refrenceDllNode.Text = pr.Name; refrenceNode.Nodes.Add(refrenceDllNode); } //增加文件夹节点 foreach (Floder floder in proj.FloderList) { ComponentTreeNode rootNode = projNode; if (!string.IsNullOrEmpty(floder.PGuid)) { rootNode = findNode(rootNode, floder.PGuid); if (rootNode == null) throw new Exception("Guid:" + floder.PGuid + "的树节点对象没有找到"); } ComponentTreeNode floderNode = new ComponentTreeNode(NodeType.Floder, floder.Guid); floderNode.ImageIndex = floderNode.SelectedImageIndex = 3; floderNode.Text = floder.Name; rootNode.Nodes.Add(floderNode); } //增加实体节点 if (proj.ProjType == ProjectTypeEnum.BEProj) { foreach (BEEntity entity in proj.EntityList) { ComponentTreeNode entityNode = new ComponentTreeNode(NodeType.BEEntity, entity.Guid); entityNode.ImageIndex = entityNode.SelectedImageIndex = 1; entityNode.Text = entity.Name; ComponentTreeNode rootNode = projNode; if (!string.IsNullOrEmpty(entity.FloderGuid)) { rootNode = findNode(projNode, entity.FloderGuid); if (rootNode == null) throw new Exception("Guid:" + entity.FloderGuid + "的树节点对象没有找到"); } rootNode.Nodes.Add(entityNode); } } //增加实体节点 if (proj.ProjType == ProjectTypeEnum.BPProj) { foreach (BPEntity entity in proj.EntityList) { ComponentTreeNode entityNode = new ComponentTreeNode(NodeType.BPEntity, entity.Guid); entityNode.ImageIndex = entityNode.SelectedImageIndex = 2; entityNode.Text = entity.Name; ComponentTreeNode rootNode = projNode; if (!string.IsNullOrEmpty(entity.FloderGuid)) { rootNode = findNode(projNode, entity.FloderGuid); if (rootNode == null) throw new Exception("Guid:" + entity.FloderGuid + "的树节点对象没有找到"); } rootNode.Nodes.Add(entityNode); } } //增加DTO实体节点 foreach (DTOEntity entity in proj.DTOList) { ComponentTreeNode entityNode = new ComponentTreeNode(NodeType.DTOEntity, entity.Guid); entityNode.ImageIndex = entityNode.SelectedImageIndex = 5; entityNode.Text = entity.Name; ComponentTreeNode rootNode = projNode; if (!string.IsNullOrEmpty(entity.FloderGuid)) { rootNode = findNode(projNode, entity.FloderGuid); if (rootNode == null) throw new Exception("Guid:" + entity.FloderGuid + "的树节点对象没有找到"); } rootNode.Nodes.Add(entityNode); } //增加DTO实体节点 foreach (EnumEntity entity in proj.EnumList) { ComponentTreeNode entityNode = new ComponentTreeNode(NodeType.EnumEntity, entity.Guid); entityNode.ImageIndex = entityNode.SelectedImageIndex = 9; entityNode.Text = entity.Name; ComponentTreeNode rootNode = projNode; if (!string.IsNullOrEmpty(entity.FloderGuid)) { rootNode = findNode(projNode, entity.FloderGuid); if (rootNode == null) throw new Exception("Guid:" + entity.FloderGuid + "的树节点对象没有找到"); } rootNode.Nodes.Add(entityNode); } this._currentProj = proj; this._currentProjNode = projNode; this._bindDataNode = this._currentProjNode; this.DataBind(); this.tvProject.SelectedNode = this._currentProjNode; }
private void treeView1_DragDrop(object sender, DragEventArgs e) { TreeNode node = null; if (e.Data.GetDataPresent(typeof(MetaDataTreeNode))) { node = (MetaDataTreeNode)(e.Data.GetData(typeof(MetaDataTreeNode))); } else if (e.Data.GetDataPresent(typeof(ComponentTreeNode))) { node = (ComponentTreeNode)(e.Data.GetData(typeof(ComponentTreeNode))); } else { Array aryFiles = ((System.Array)e.Data.GetData(DataFormats.FileDrop)); if (aryFiles != null) { foreach (string file in aryFiles) { LoadProj(file); } } return; } pos.X = e.X; pos.Y = e.Y; pos = tvProject.PointToClient(pos); ComponentTreeNode dropNode = this.tvProject.GetNodeAt(pos) as ComponentTreeNode; if (dropNode == null) dropNode = this._currentProjNode; if (node is MetaDataTreeNode) { ComponentTreeNode rootNode = GetRootNode(dropNode); ComponentTreeNode refrenceNode = rootNode.Nodes[0] as ComponentTreeNode; MetaDataTreeNode dragNode = node as MetaDataTreeNode; //如果dll已经引用则不需要引用 foreach (ComponentTreeNode subNode in refrenceNode.Nodes) { if (subNode.Text == dragNode.Text) return; } ComponentTreeNode newNode = new ComponentTreeNode(NodeType.RefrenceDll, Guid.NewGuid().ToString()); newNode.RefType = dragNode.RefType; newNode.Text = dragNode.Text; newNode.FileName = dragNode.FileName; newNode.ImageIndex = newNode.SelectedImageIndex = 8; refrenceNode.Nodes.Add(newNode); refrenceNode.Expand(); this.tvProject.SelectedNode = refrenceNode; IProject currentProj = this.GetProject(rootNode.Guid); ProjectRefrence projRefrence = new ProjectRefrence(currentProj, newNode.Guid, this.getRelativePath(dragNode.FilePath)); projRefrence.RefProjName = newNode.FileName; projRefrence.RefrenceType = newNode.RefType; projRefrence.Code = projRefrence.Name = newNode.Text; currentProj.RefrenceList.Add(projRefrence); } else if (node is ComponentTreeNode) { ComponentTreeNode dragNode = node as ComponentTreeNode; // 如果目标节点不存在,即拖拽的位置不存在节点,那么就将被拖拽节点放在根节点之下 if (node is ComponentTreeNode) { if (dragNode.NodeType == NodeType.BEProj || dragNode.NodeType == NodeType.BPProj) { return; } } //不能将节点拖拽到实体节点上 if (dropNode.NodeType == NodeType.BEEntity || dropNode.NodeType == NodeType.BPEntity || dropNode.NodeType == NodeType.Refrence || dropNode.NodeType == NodeType.RefrenceDll || dropNode.NodeType == NodeType.EnumEntity) { return; } ComponentTreeNode rootNode = GetRootNode(dropNode); //不能够跨项目进行拖拽 AbstractPlatformComponent currentProj = this._currentProj as AbstractPlatformComponent; if (rootNode.Guid != currentProj.Guid) { return; } // 1.目标节点不是空。2.目标节点不是被拖拽接点的字节点。3.目标节点不是被拖拽节点本身 if (dropNode != null && dropNode.Parent != node && dropNode != node) { // 将被拖拽节点从原来位置删除。 node.Remove(); // 在目标节点下增加被拖拽节点 dropNode.Nodes.Add(dragNode); } if (dropNode.NodeType == NodeType.BEProj || dropNode.NodeType == NodeType.BPProj) { if (dragNode.NodeType == NodeType.BEEntity) { BEEntity entity = this._currentProj.Get(dragNode.Guid) as BEEntity; if (entity != null) { entity.FloderGuid = string.Empty; } } else if (dragNode.NodeType == NodeType.BPEntity) { BPEntity entity = this._currentProj.Get(dragNode.Guid) as BPEntity; if (entity != null) { entity.FloderGuid = string.Empty; } } else if (dragNode.NodeType == NodeType.DTOEntity) { DTOEntity entity = this._currentProj.Get(dragNode.Guid) as DTOEntity; if (entity != null) { entity.FloderGuid = string.Empty; } } else if (dragNode.NodeType == NodeType.EnumEntity) { EnumEntity entity = this._currentProj.Get(dragNode.Guid) as EnumEntity; if (entity != null) { entity.FloderGuid = string.Empty; } } else if (dragNode.NodeType == NodeType.Floder) { Floder floder = this._currentProj.GetFloder(dragNode.Guid); floder.PGuid = string.Empty; } } else if (dropNode.NodeType == NodeType.Floder) { if (dragNode.NodeType == NodeType.BEEntity) { BEEntity entity = this._currentProj.Get(dragNode.Guid) as BEEntity; if (entity != null) { entity.FloderGuid = dropNode.Guid; } } else if (dragNode.NodeType == NodeType.BPEntity) { BPEntity entity = this._currentProj.Get(dragNode.Guid) as BPEntity; if (entity != null) { entity.FloderGuid = dropNode.Guid; } } else if (dragNode.NodeType == NodeType.DTOEntity) { DTOEntity entity = this._currentProj.Get(dragNode.Guid) as DTOEntity; if (entity != null) { entity.FloderGuid = dropNode.Guid; } } else if (dragNode.NodeType == NodeType.EnumEntity) { EnumEntity entity = this._currentProj.Get(dragNode.Guid) as EnumEntity; if (entity != null) { entity.FloderGuid = dropNode.Guid; } } else if (dragNode.NodeType == NodeType.Floder) { Floder floder = this._currentProj.GetFloder(dragNode.Guid); floder.PGuid = dropNode.Guid; } } } }
private static ComponentTreeNode GetRootNode(ComponentTreeNode node) { ComponentTreeNode ctn = node; while (true) { if (ctn == null) break; if (ctn.NodeType == NodeType.BEProj || ctn.NodeType == NodeType.BPProj) { break; } ctn = ctn.Parent as ComponentTreeNode; } return ctn; }
/// <summary> /// 移除项目 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsm_RemoveProject_Click(object sender, EventArgs e) { if (this._currentProj != null) { if (MessageBox.Show("移除当前项目“" + this._currentProj.ProjName + "”,是否保存?", "移除", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { this._collectDataNode = this._bindDataNode; this.DataCollect(); this._currentProj.ToFile(); } this._projectList.Remove(this._currentProj); this.tvProject.Nodes.Remove(this._currentProjNode); this._currentProj = null; this._currentProjNode = null; this._bindDataNode = null; if (this._projectList == null || this._projectList.Count == 0) { this.tbNameSpace.Text = string.Empty; this.tbNameSpace.Enabled = false; } else { ComponentTreeNode node = this.GetRootNode(this._projectList[0].Guid); if (node != null) { this.tvProject.Focus(); this.tvProject.SelectedNode = node; } } } }
/// <summary> /// 新增分类 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsm_AddFloder_Click(object sender, EventArgs e) { if (this._bindDataNode == null) { MessageBox.Show("请选择你要添加分类的父节点"); return; } if (this._bindDataNode.NodeType == NodeType.BEProj || this._bindDataNode.NodeType == NodeType.BPProj || this._bindDataNode.NodeType == NodeType.Floder) { if (this._currentProj != null) { ComponentTreeNode tn = new ComponentTreeNode(NodeType.Floder, Guid.NewGuid().ToString()); tn.Text = "新增分类"; tn.ImageIndex = tn.SelectedImageIndex = 3; this._bindDataNode.Nodes.Add(tn); Floder floder = new Floder(this._currentProj, tn.Guid); floder.Name = tn.Text; if (this._bindDataNode.NodeType == NodeType.Floder) { floder.PGuid = this._bindDataNode.Guid; } this._currentProj.FloderList.Add(floder); this.tvProject.SelectedNode = tn; } } }
/// <summary> /// 新增DTO /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsm_AddDTOEntity_Click(object sender, EventArgs e) { if (this._currentProjNode == null) { MessageBox.Show("请选择一个工程"); } else { ComponentTreeNode tn = new ComponentTreeNode(NodeType.DTOEntity, Guid.NewGuid().ToString()); tn.Text = "新增DTO"; tn.ImageIndex = tn.SelectedImageIndex = 5; DTOEntity entity = new DTOEntity(this._currentProj, tn.Guid, string.Empty); if (this._bindDataNode.NodeType == NodeType.Floder) { entity.FloderGuid = this._bindDataNode.Guid; } entity.Code = string.Empty; entity.Name = tbDisplayName.Text; if (this._bindDataNode.NodeType == NodeType.Floder) { entity.FloderGuid = this._bindDataNode.Guid; } this._currentProj.DTOList.Add(entity); this._bindDataNode.Nodes.Add(tn); this.tvProject.SelectedNode = tn; } }
/// <summary> /// 新增BP /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsm_AddBPEntity_Click(object sender, EventArgs e) { if (this._currentProjNode == null || this._currentProjNode.NodeType != NodeType.BPProj) { MessageBox.Show("请选择一个BP工程"); } else { ComponentTreeNode tn = new ComponentTreeNode(NodeType.BPEntity, Guid.NewGuid().ToString()); tn.Text = "新增BP"; tn.ImageIndex = tn.SelectedImageIndex = 2; BPEntity entity = new BPEntity(this._currentProj as BPProj, tn.Guid, string.Empty); if (this._bindDataNode.NodeType == NodeType.Floder) { entity.FloderGuid = this._bindDataNode.Guid; } entity.Code = string.Empty; entity.Name = string.Empty; if (this._bindDataNode.NodeType == NodeType.Floder) { entity.FloderGuid = this._bindDataNode.Guid; } entity.ReturnName = entity.ReturnProxyName = "void"; entity.ReturnGuid = string.Empty; this._currentProj.EntityList.Add(entity); this._bindDataNode.Nodes.Add(tn); this.groupBox3.Enabled = true; this.dataGridView1.Rows.Clear(); this.tvProject.SelectedNode = tn; } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { ComponentTreeNode node = e.Node as ComponentTreeNode; this._collectDataNode = this._bindDataNode; if (node != null) { if (this.DataCollect()) { this.btnInhert.Enabled = true; this.btnClearInhert.Enabled = true; this.dataGridView1.Columns[3].Visible = true; this.dataGridView1.Columns[4].Visible = true; this.dataGridView1.Columns[5].Visible = true; this.dataGridView1.Columns[6].Visible = false; this.dataGridView1.Columns[7].Visible = false; this.dataGridView1.Columns[8].Visible = false; this.dataGridView1.Columns[9].Visible = false; this.dataGridView1.Columns[10].Visible = false; if (node.NodeType == NodeType.BEProj || node.NodeType == NodeType.BPProj) { if (this._currentProjNode == null || this._currentProjNode.Guid != node.Guid) { this._searchIndex = 0; this._currentProjNode = node; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == node.Guid) { this._currentProj = proj; break; } } this.groupBox3.Enabled = false; this.tbNameSpace.ReadOnly = false; this.tbCode.Text = string.Empty; this.tbDisplayName.Text = string.Empty; this.tbTableName.Text = string.Empty; this.tbInhertClass.Text = string.Empty; this.tbInhertGuid.Text = string.Empty; this.dataGridView1.Rows.Clear(); } else if (node.NodeType == NodeType.BEEntity) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == this._currentProjNode.Guid) { this._currentProj = proj; break; } } this.dataGridView1.Columns[7].Visible = true; this.dataGridView1.Columns[9].Visible = true; this.dataGridView1.Columns[10].Visible = true; this.groupBox3.Enabled = true; this.tbNameSpace.ReadOnly = true; this.tbTableName.ReadOnly = false; } else if (node.NodeType == NodeType.DTOEntity) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == this._currentProjNode.Guid) { this._currentProj = proj; break; } } this.dataGridView1.Columns[9].Visible = true; this.groupBox3.Enabled = true; this.tbTableName.Text = string.Empty; this.tbNameSpace.ReadOnly = true; this.tbTableName.ReadOnly = true; } else if (node.NodeType == NodeType.EnumEntity) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == this._currentProjNode.Guid) { this._currentProj = proj; break; } } this.groupBox3.Enabled = true; this.tbTableName.Text = string.Empty; this.tbInhertClass.Text = string.Empty; this.tbInhertGuid.Text = string.Empty; this.tbNameSpace.ReadOnly = true; this.tbTableName.ReadOnly = true; this.btnInhert.Enabled = false; this.btnClearInhert.Enabled = false; this.dataGridView1.Columns[3].Visible = false; this.dataGridView1.Columns[4].Visible = false; this.dataGridView1.Columns[5].Visible = false; this.dataGridView1.Columns[6].Visible = false; this.dataGridView1.Columns[8].Visible = true; } else if (node.NodeType == NodeType.BPEntity) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == this._currentProjNode.Guid) { this._currentProj = proj; break; } } this.groupBox3.Enabled = true; this.tbTableName.Text = string.Empty; this.tbNameSpace.ReadOnly = true; this.tbTableName.ReadOnly = true; } else if (node.NodeType == NodeType.Floder) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == this._currentProjNode.Guid) { this._currentProj = proj; break; } } this.groupBox3.Enabled = false; this.tbNameSpace.ReadOnly = true; this.tbCode.Text = string.Empty; this.tbDisplayName.Text = string.Empty; this.tbTableName.Text = string.Empty; this.tbInhertClass.Text = string.Empty; this.tbInhertGuid.Text = string.Empty; this.dataGridView1.Rows.Clear(); } else if (node.NodeType == NodeType.Refrence || node.NodeType == NodeType.RefrenceDll) { ComponentTreeNode rootNode = GetRootNode(node); if (this._currentProjNode == null || this._currentProjNode.Guid != rootNode.Guid) { this._searchIndex = 0; this._currentProjNode = rootNode; } foreach (IProject proj in this._projectList) { AbstractPlatformComponent componentProj = proj as AbstractPlatformComponent; if (componentProj.Guid == node.Guid) { this._currentProj = proj; break; } } this.groupBox3.Enabled = false; this.tbNameSpace.ReadOnly = true; this.tbCode.Text = string.Empty; this.tbDisplayName.Text = string.Empty; this.tbTableName.Text = string.Empty; this.tbInhertClass.Text = string.Empty; this.tbInhertGuid.Text = string.Empty; this.dataGridView1.Rows.Clear(); } } } if (node.NodeType == NodeType.Floder) { if (node.IsExpanded) { node.ImageIndex = 4; node.SelectedImageIndex = 4; } else { node.ImageIndex = 3; node.SelectedImageIndex = 3; } } this._bindDataNode = node; DataBind(); this._collectDataNode = node; }