Exemplo n.º 1
0
        /// <summary>
        /// 从节点所关联的标签集合中删除指定的标签
        /// </summary>
        /// <param name="InfoNodePath"></param>
        /// <param name="labelIDs"></param>
        public void DeleteLabelsOfInfoNodeDB(String InfoNodePath, List <int> labelIDs)
        {
            if (string.IsNullOrEmpty(InfoNodePath) || labelIDs == null || labelIDs.Count == 0)
            {
                return;
            }
            using (MyDBEntities context = new MyDBEntities(EFConnectionString))
            {
                InfoNodeDB InfoNodeObj = context.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);
                if (InfoNodeObj == null)
                {
                    return;
                }

                foreach (var label in InfoNodeObj.LabelNodeDBs.ToList())
                {
                    if (labelIDs.IndexOf(label.ID) != -1)
                    {
                        //仅删除LabelNodeAndInfoNode记录
                        InfoNodeObj.LabelNodeDBs.Remove(label);
                        //删除数据库中的label,而不仅指记录
                        //context.Entry(label).State = EntityState.Deleted;
                    }
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 连续从节点所关联的标签集合中删除指定的标签
        /// </summary>
        /// <param name="InfoNodePath"></param>
        /// <param name="labelIDs"></param>
        public void DeleteLabelsOfInfoNodeDBContinuousExecution(String InfoNodePath, List <int> labelIDs)
        {
            if (string.IsNullOrEmpty(InfoNodePath) || labelIDs == null || labelIDs.Count == 0)
            {
                return;
            }

            InfoNodeDB InfoNodeObj = _dbContext.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);

            if (InfoNodeObj == null)
            {
                return;
            }

            foreach (var label in InfoNodeObj.LabelNodeDBs.ToList())
            {
                if (labelIDs.IndexOf(label.ID) != -1)
                {
                    //保证删除LabelNodeAndInfoNode记录
                    InfoNodeObj.LabelNodeDBs.Remove(label);
                    //确保InfoNodeDB删除
                    _dbContext.Entry(label).State = EntityState.Deleted;
                }
            }
            // context.SaveChanges();
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        public int UpdateDataInfoObject(IDataInfo dataInfoObject)
        {
            InfoNodeDataInfo obj = dataInfoObject as InfoNodeDataInfo;

            if (String.IsNullOrEmpty(obj.Text) == false && obj.Text.Length > DALConfig.MaxTextFieldSize)
            {
                obj.Text = obj.Text.Substring(0, DALConfig.MaxTextFieldSize);
            }
            if (dataInfoObject == null || obj == null)
            {
                return(0);
            }
            bool       isNew = false;
            InfoNodeDB dbobj = repository.GetInfoNodeDBWithoutFileInfosByPath(obj.Path);

            if (dbobj == null)
            {
                dbobj = new InfoNodeDB();
                isNew = true;
            }
            dbobj.ModifyTime = obj.ModifyTime;
            dbobj.Text       = obj.Text;
            dbobj.Path       = obj.Path;
            dbobj.Type       = obj.IconType;
            dbobj.RTFText    = (String.IsNullOrEmpty(obj.RTFText)) ? null : Encoding.UTF8.GetBytes(obj.RTFText);
            if (isNew)
            {
                return(repository.AddInfoNodeDB(dbobj));
            }
            else
            {
                return(repository.UpdateInfoNodeDB(dbobj));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 按照Path提取相应节点所有的标签信息(是LabelInfo对象)SqlCeException: 在 WHERE、HAVING、GROUP BY、ON 或 IN 子句中不能使用 ntext 和 image 数据类型,除非将这些数据类型与 LIKE 或 IS NULL 谓词一起使用。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public ObservableCollection <DBLabelInfo> GetLabelInfosOfInfoNodeDB(String path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(null);
            }
            ObservableCollection <DBLabelInfo> labelInfos = new ObservableCollection <DBLabelInfo>();

            using (MyDBEntities context = new MyDBEntities(EFConnectionString))
            {
                var query = from item in context.InfoNodeDBs
                            where item.Path == path
                            select item;
                InfoNodeDB InfoNodeObj = query.FirstOrDefault();
                if (InfoNodeObj != null)
                {
                    foreach (var label in InfoNodeObj.LabelNodeDBs)
                    {
                        labelInfos.Add(new DBLabelInfo()
                        {
                            ModifyTime = label.ModifyTime.Value,
                            Path       = label.Path,
                            Label      = label.Label,
                            ID         = label.ID
                        });
                    }
                }
                return(labelInfos);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 从节点所关联的文件集合中删除指定的文件
        /// </summary>
        /// <param name="InfoNodePath"></param>
        /// <param name="fileIDs"></param>
        public void DeleteFilesOfInfoNodeDB(String InfoNodePath, List <int> fileIDs)
        {
            if (string.IsNullOrEmpty(InfoNodePath) || fileIDs == null || fileIDs.Count == 0)
            {
                return;
            }
            using (MyDBEntities context = new MyDBEntities(EFConnectionString))
            {
                InfoNodeDB InfoNodeObj = context.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);
                if (InfoNodeObj == null)
                {
                    return;
                }

                foreach (var file in InfoNodeObj.DiskFiles.ToList())
                {
                    if (fileIDs.IndexOf(file.ID) != -1)
                    {
                        //保证删除FileAndInfoNode记录
                        InfoNodeObj.DiskFiles.Remove(file);
                        //确保DiskFile删除
                        context.Entry(file).State = EntityState.Deleted;
                    }
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 按照Path提取相应节点所有的文件信息(是FileInfo对象)SqlCeException: 在 WHERE、HAVING、GROUP BY、ON 或 IN 子句中不能使用 ntext 和 image 数据类型,除非将这些数据类型与 LIKE 或 IS NULL 谓词一起使用。

        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public ObservableCollection <DBFileInfo> GetFileInfosOfInfoNodeDB(String path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(null);
            }
            ObservableCollection <DBFileInfo> fileInfos = new ObservableCollection <DBFileInfo>();

            using (MyDBEntities context = new MyDBEntities(EFConnectionString))
            {
                var query = from item in context.InfoNodeDBs
                            where item.Path == path
                            select item;
                InfoNodeDB InfoNodeObj = query.FirstOrDefault();
                if (InfoNodeObj != null)
                {
                    foreach (var file in InfoNodeObj.DiskFiles)
                    {
                        fileInfos.Add(new DBFileInfo()
                        {
                            AddTime  = file.AddTime.Value,
                            FilePath = file.FilePath,
                            FileSize = file.FileSize.Value,
                            ID       = file.ID
                        });
                    }
                }
                return(fileInfos);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 向数据库中添加一条记录
        /// </summary>
        /// <param name="InfoNodeObj"></param>
        /// <returns></returns>
        public int AddInfoNodeDB(InfoNodeDB InfoNodeObj)
        {
            if (InfoNodeObj == null)
            {
                return(0);
            }

            _dbContext.InfoNodeDBs.Add(InfoNodeObj);
            return(_dbContext.SaveChanges());
        }
Exemplo n.º 9
0
 /// <summary>
 /// 按照信息节点ID从数据库中提取信息节点内容
 /// 找不到返回null
 /// </summary>
 /// <param name="infoNodeID"></param>
 /// <returns></returns>
 public byte[] getInfoNodeContent(int infoNodeID)
 {
     using (MyDBEntities context = new MyDBEntities(EFConnectionString))
     {
         InfoNodeDB infoNode = context.InfoNodeDBs.FirstOrDefault(f => f.ID == infoNodeID);
         if (infoNode != null)
         {
             return(infoNode.RTFText);
         }
     }
     return(null);
 }
Exemplo n.º 10
0
        /// <summary>
        /// 新建一个InfoNode记录,不包容任何文件
        /// </summary>
        /// <param name="dataInfoObject"></param>
        /// <returns></returns>
        public int Create(IDataInfo dataInfoObject)
        {
            if (dataInfoObject == null || (dataInfoObject as InfoNodeDataInfo) == null)
            {
                return(0);
            }
            InfoNodeDB dbobj  = InfoNodeHelper.changeToInfoNodeDB(dataInfoObject as InfoNodeDataInfo);
            int        result = repository.AddInfoNodeDB(dbobj);

            //将数据库生成的ID值传回
            dataInfoObject.ID = dbobj.ID;
            return(0);
        }
Exemplo n.º 11
0
 /// <summary>
 /// 将DBInfoNodeInfo对象转换为EF可以直接保存的InfoNode对象
 /// </summary>
 /// <param name="dbInfoNodeInfo"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 public static InfoNodeDB toInfoNodeDB(DBInfoNodeInfo dbInfoNodeInfo, InfoNodeDB infoNodeObj)
 {
     if (dbInfoNodeInfo != null)
     {
         InfoNodeDB infoNode = new InfoNodeDB()
         {
             ID         = dbInfoNodeInfo.ID,
             Text       = dbInfoNodeInfo.InfoNodeHearder,
             Path       = dbInfoNodeInfo.Path,
             ModifyTime = dbInfoNodeInfo.ModifyTime,
         };
         return(infoNode);
     }
     return(null);
 }
Exemplo n.º 12
0
        public IDataInfo GetDataInfoObjectByPath(string nodePath)
        {
            InfoNodeDB dbobj = repository.GetInfoNodeDBWithoutFileInfosByPath(nodePath);
            ObservableCollection <DBFileInfo> files = repository.GetFileInfosOfInfoNodeDB(nodePath);

            ObservableCollection <DBLabelInfo> labels = repository.GetLabelInfosOfInfoNodeDB(nodePath);

            InfoNodeDataInfo InfoNodeInfo = InfoNodeHelper.changeToInfoNodeDataInfo(dbobj);

            if (InfoNodeInfo != null)
            {
                InfoNodeInfo.AttachFiles  = files;
                InfoNodeInfo.AttachLabels = labels;
            }

            return(InfoNodeInfo);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 转换为InfoNodeInfo,不理会附属文件集合
        /// </summary>
        /// <param name="dbobj"></param>
        /// <returns></returns>
        public static InfoNodeDataInfo changeToInfoNodeDataInfo(InfoNodeDB dbobj)
        {
            if (dbobj == null)
            {
                return(null);
            }
            InfoNodeDataInfo obj = new InfoNodeDataInfo()
            {
                Text       = String.IsNullOrEmpty(dbobj.Text) ? "" : dbobj.Text,
                RTFText    = dbobj.RTFText == null ? "" : Encoding.UTF8.GetString(dbobj.RTFText),
                Path       = dbobj.Path,
                ModifyTime = dbobj.ModifyTime.Value,
                ID         = dbobj.ID
            };

            return(obj);
        }
Exemplo n.º 14
0
 /// <summary>
 /// 将一个文件加入到节点的文件集合中
 /// </summary>
 /// <param name="InfoNodePath"></param>
 /// <param name="file"></param>
 public int AddFileOfInfoNodeDB(String InfoNodePath, DiskFile file)
 {
     if (string.IsNullOrEmpty(InfoNodePath) || file == null)
     {
         return(0);
     }
     using (MyDBEntities context = new MyDBEntities(EFConnectionString))
     {
         InfoNodeDB InfoNodeObj = context.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);
         if (InfoNodeObj == null)
         {
             return(0);
         }
         InfoNodeObj.DiskFiles.Add(file);
         return(context.SaveChanges());
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// 添加信息节点与标签的关联关系。
 /// </summary>
 /// <param name="InfoNodePath"></param>
 /// <param name="labelNode"></param>
 public int AddLabelOfInfoNodeDB(String InfoNodePath, LabelNodeDB labelNode)
 {
     if (string.IsNullOrEmpty(InfoNodePath) || labelNode == null)
     {
         return(0);
     }
     using (MyDBEntities context = new MyDBEntities(EFConnectionString))
     {
         InfoNodeDB InfoNodeObj = context.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);
         if (InfoNodeObj == null)
         {
             return(0);
         }
         context.LabelNodeDBs.Add(labelNode);//添加到同一上下文关系
         InfoNodeObj.LabelNodeDBs.Add(labelNode);
         return(context.SaveChanges());
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// 更新节点的信息
        /// </summary>
        /// <param name="InfoNodeObj"></param>
        public int UpdateInfoNodeDB(InfoNodeDB InfoNodeObj)
        {
            if (InfoNodeObj == null)
            {
                return(0);
            }

            InfoNodeDB InfoNodeToModify = _dbContext.InfoNodeDBs.FirstOrDefault(p => p.ID == InfoNodeObj.ID);

            if (InfoNodeToModify != null)
            {
                InfoNodeToModify.ModifyTime = InfoNodeObj.ModifyTime;
                InfoNodeToModify.Text       = InfoNodeObj.Text;
                InfoNodeToModify.RTFText    = InfoNodeObj.RTFText;
                InfoNodeToModify.Type       = InfoNodeObj.Type;
                return(_dbContext.SaveChanges());
            }

            return(0);
        }
Exemplo n.º 17
0
 /// <summary>
 /// 将多个文件追加到信息节点中
 /// 如果文件夹节点找不到,或者files为空集合,什么也不干,返回
 /// </summary>
 /// <param name="InfoNodeDBPath"></param>
 /// <param name="files"></param>
 public void AddFilesOfInfoNode(String InfoNodePath, List <DiskFile> files)
 {
     if (string.IsNullOrEmpty(InfoNodePath) || files == null || files.Count == 0)
     {
         return;
     }
     using (MyDBEntities context = new MyDBEntities(EFConnectionString))
     {
         InfoNodeDB InfoNodeObj = context.InfoNodeDBs.FirstOrDefault(p => p.Path == InfoNodePath);
         if (InfoNodeObj == null)
         {
             return;
         }
         foreach (var file in files)
         {
             InfoNodeObj.DiskFiles.Add(file);
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// 添加标签与信息节点的关联关系。
 /// </summary>
 /// <param name="LabelNodeDBPath"></param>
 /// <param name="infoNode"></param>
 public int AddInfoNodeOfLabelNodeDB(String LabelNodeDBPath, InfoNodeDB infoNode)
 {
     if (string.IsNullOrEmpty(LabelNodeDBPath) || infoNode == null)
     {
         return(0);
     }
     using (MyDBEntities context = new MyDBEntities(EFConnectionString))
     {
         LabelNodeDB LabelNodeObj = context.LabelNodeDBs.FirstOrDefault(p => p.Path == LabelNodeDBPath);
         if (LabelNodeObj == null)
         {
             return(0);
         }
         //由于infoNode是之前从数据库中提取出来的实体数据,而不是新建的数据,所以,infoNode在EF中已经被标记有上下文,
         //通过引用赋值方式,并不能消除此上下文标记。此时如果需要在当前上下文中使用,必须先将它加入当前上下文中。
         //这种方式添加的关联会复制一份数据,不推荐。
         context.InfoNodeDBs.Add(infoNode);
         //以上。
         LabelNodeObj.InfoNodeDBs.Add(infoNode);
         return(context.SaveChanges());
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// 转换为InfoNode对象,不理会附属文件集合
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static InfoNodeDB changeToInfoNodeDB(InfoNodeDataInfo obj)
        {
            if (obj == null)
            {
                return(null);
            }
            //注意数据库中nvarchar最大允许4000个字符
            if (obj.Text != null && obj.Text.Length > DALConfig.MaxTextFieldSize)
            {
                obj.Text = obj.Text.Substring(0, DALConfig.MaxTextFieldSize);
            }

            InfoNodeDB dbObj = new InfoNodeDB()
            {
                ModifyTime = obj.ModifyTime,
                Path       = obj.Path,
                RTFText    = String.IsNullOrEmpty(obj.RTFText) ? null : Encoding.UTF8.GetBytes(obj.RTFText), // RTFText是真正内容
                Text       = String.IsNullOrEmpty(obj.Text) ? "" : obj.Text,                                 //Text该属性仅用于在数据库中查找文本
                Type       = obj.IconType,
                ID         = obj.ID
            };

            return(dbObj);
        }
Exemplo n.º 20
0
 /// <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;
 }