/// <summary> /// 添加关联的InfoNode,并传回ID /// </summary> /// <param name="infoNodeInfo"></param> /// <param name="infoNodeContent"></param> public void AddInfoNodeAssociation(string nodePath, DBInfoNodeInfo infoNodeInfo, InfoNodeDB infoNode) { //InfoNodeDB infoNode = DBInfoNodeInfo.toInfoNodeDB(infoNodeInfo, infoNodeContent); repository.AddInfoNodeOfLabelNodeDB(nodePath, infoNode); //将ID传回 infoNodeInfo.ID = infoNode.ID; }
/// <summary> /// 给标签节点添加信息节点关联,当用户在树中删除标签节点时,标签节点及其关联的“信息节点关联关系”会删除,但不会删除信息节点本身。 private void AddInfoNodeToLabel() { //var dataObj = labeltree.SelectedItem.NodeData.DataItem as LabelNodeDataInfo; 如此获得的数据对象不是数据库信息选项卡中的标签节点的数据对象 //var accessObj = labeltree.SelectedItem.NodeData.AccessObject as LabelNodeAccess; string labelnodePath = labeltree.SelectedItem.NodeData.DataItem.Path; //查找节点 TreeViewIconsItem nodeNeedToAddInfoNode = curDbInfoTab.LabelViewObj.SuperTree.Nodes.FirstOrDefault(n => n.Path == labelnodePath); var dataObj = nodeNeedToAddInfoNode.NodeData.DataItem as LabelNodeDataInfo; var accessObj = nodeNeedToAddInfoNode.NodeData.AccessObject as LabelNodeAccess; DBInfoNodeInfo infoNodeInfo = new DBInfoNodeInfo() { ModifyTime = DateTime.Now, //Path= curDbInfoTab.CurrentTreeView.SelectedItem.NodeData.DataItem.Path Path = InfoNodeDataInfoObj.Path }; //不加入重复的信息节点 if (dataObj.AttachInfoNodeInfos.IndexOf(infoNodeInfo) == -1) { //创建连接字符串 String EFConnectionString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath); InfoNodeRepository repository = new InfoNodeRepository(EFConnectionString); //InfoNodeDataInfo obj = SelectedInfoNodeDataObj.DataItem as InfoNodeDataInfo; InfoNodeDB dbobj = repository.GetInfoNodeDBWithoutFileInfosByPath(InfoNodeDataInfoObj.Path); //给标签节点添加标签节点与信息节点的关联 accessObj.AddInfoNodeAssociation(dataObj.Path, infoNodeInfo, dbobj); dataObj.AttachInfoNodeInfos.Add(infoNodeInfo); } }
private void dgFiles_mouseDoubleClick(object sender, MouseButtonEventArgs e) { if (e.OriginalSource is TextBlock) { DBInfoNodeInfo info = dgFiles.SelectedItem as DBInfoNodeInfo; LoadInfoNodeControlEventManager loadInfoNodeControlEventManager = new LoadInfoNodeControlEventManager(); loadInfoNodeControlEventManager.RaiseEvent(info.Path); } }
private void CreateAssociation() { //创建连接字符串 String EFConnectionString = DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath); string labelnodePath = labeltree.SelectedItem.NodeData.DataItem.Path; string infoNodePath = InfoNodeDataInfoObj.Path; //创建多对多关联时,对信息节点与标签节点在数据库中均存在的,不能直接修改数据库表或实体类,而应该修改关联关系 using (MyDBEntities context = new MyDBEntities(EFConnectionString)) { var infoNode = context.InfoNodeDBs.FirstOrDefault(p => p.Path == infoNodePath); var labelNode = context.LabelNodeDBs.FirstOrDefault(p => p.Path == labelnodePath); if (infoNode != null && labelNode != null) { infoNode.LabelNodeDBs.Add(labelNode); labelNode.InfoNodeDBs.Add(infoNode); //context.LabelNodeDBs.Add(labelNode);//不能再添加了否则数据库中会多出一个ID不同的labelNode // context.InfoNodeDBs.Add(infoNode);//不能再添加了否则数据库中会多出一个ID不同的infoNode int r = context.SaveChanges(); //给标签添加信息绑定 DBInfoNodeInfo infoNodeInfo = new DBInfoNodeInfo() { ID = infoNode.ID, ModifyTime = DateTime.Now, Path = InfoNodeDataInfoObj.Path }; //查找节点 TreeViewIconsItem nodeNeedToAddInfoNode = curDbInfoTab.LabelViewObj.SuperTree.Nodes.FirstOrDefault(n => n.Path == labelnodePath); var dataObj = nodeNeedToAddInfoNode.NodeData.DataItem as LabelNodeDataInfo; //不加入重复的信息节点 if (dataObj.AttachInfoNodeInfos.IndexOf(infoNodeInfo) == -1) { dataObj.AttachInfoNodeInfos.Add(infoNodeInfo); } //给信息添加标签绑定 DBLabelInfo labelInfo = new DBLabelInfo() { ID = labelNode.ID, ModifyTime = DateTime.Now, Path = labelnodePath, // Label = selectedlabel }; if (InfoNodeDataInfoObj.AttachLabels.IndexOf(labelInfo) == -1) { InfoNodeDataInfoObj.AttachLabels.Add(labelInfo); } } } }