/// <summary>
        /// 转换为FolderInfo,不理会附属文件集合
        /// </summary>
        /// <param name="dbobj"></param>
        /// <returns></returns>
        public static FolderInfo changeToFolderInfo(FolderDB dbobj)
        {
            if (dbobj == null)
            {
                return null;
            }
            FolderInfo obj = new FolderInfo()
            {
                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;
        }
        /// <summary>
        /// 转换为FolderDB对象,不理会附属文件集合
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static FolderDB changeToFolderDB(FolderInfo 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);
            }

            FolderDB dbObj = new FolderDB()
            {
                ModifyTime = obj.ModifyTime,
                Path = obj.Path,
                RTFText = String.IsNullOrEmpty(obj.RTFText) ? null : Encoding.UTF8.GetBytes(obj.RTFText),
                Text = String.IsNullOrEmpty(obj.Text) ? "" : obj.Text,
                ID = obj.ID
            };

            return dbObj;
        }
示例#3
0
        public int UpdateDataInfoObject(IDataInfo dataInfoObject)
        {
            FolderInfo obj = dataInfoObject as FolderInfo;
            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;
            FolderDB dbobj = repository.GetFolderDBWithoutFileInfosByPath(obj.Path);
            if (dbobj == null)
            {
                dbobj = new FolderDB();
                isNew = true;

            }
            dbobj.ModifyTime = obj.ModifyTime;
            dbobj.Text = obj.Text;
            dbobj.Path = obj.Path;
            dbobj.RTFText = (String.IsNullOrEmpty(obj.RTFText)) ? null : Encoding.UTF8.GetBytes(obj.RTFText);
            if (isNew)
            {
                return repository.AddFolderDB(dbobj);
            }
            else
            {

                return repository.UpdateFolderDB(dbobj);

            }
        }