示例#1
0
        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件</param>
        /// <param name="category">文件分类</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态</param>
        /// <returns>主键</returns>
        private string Add(string folderId, string fileName, string file, byte[] byteFile, string description, bool enabled, out string statusCode)
        {
            statusCode = string.Empty;
            BaseFileEntity fileEntity = new BaseFileEntity();

            fileEntity.FolderId    = folderId;
            fileEntity.FileName    = fileName;
            fileEntity.Contents    = byteFile;
            fileEntity.Description = description;
            fileEntity.Enabled     = enabled ? 1:0;
            string returnValue = string.Empty;

            // 检查是否重复
            if (this.Exists(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, fileEntity.FolderId), new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileEntity.FileName)))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                returnValue = this.AddEntity(fileEntity);
                // 运行成功
                statusCode = StatusCode.OKAdd.ToString();
            }
            return(returnValue);
        }
示例#2
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="fileEntity">文件夹的基类表结构定义</param>
        /// <param name="statusCode">状态返回码</param>
        /// <returns>影响行数</returns>
        public int Update(BaseFileEntity fileEntity, out string statusCode)
        {
            int returnValue = 0;

            //if (DbLogic.IsModifed(DbHelper, BaseFolderEntity.TableName, fileEntity.Id, fileEntity.ModifiedUserId, fileEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    statusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{
            // 检查文件夹名是否重复
            if (this.Exists(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, fileEntity.FolderId), new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileEntity.FileName), fileEntity.Id))
            {
                // 文件夹名已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                returnValue = this.UpdateEntity(fileEntity);
                if (returnValue == 1)
                {
                    // 运行成功
                    statusCode = StatusCode.OKUpdate.ToString();
                }
                else
                {
                    statusCode = StatusCode.ErrorDeleted.ToString();
                }
            }
            //}
            return(returnValue);
        }
示例#3
0
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>数据权限</returns>
        public BaseFileEntity GetEntity(string id)
        {
            string sqlQuery = string.Empty;

            sqlQuery = " SELECT " + BaseFileEntity.FieldId
                       + "        ," + BaseFileEntity.FieldFolderId
                       + "        ," + BaseFileEntity.FieldFileName
                       + "        ," + BaseFileEntity.FieldFilePath
                       + "        ," + BaseFileEntity.FieldFileSize
                       + "        ," + BaseFileEntity.FieldReadCount
                       + "        ," + BaseFileEntity.FieldDescription
                       + "        ," + BaseFileEntity.FieldEnabled
                       + "        ," + BaseFileEntity.FieldDeletionStateCode
                       + "        ," + BaseFileEntity.FieldSortCode
                       + "        ," + BaseFileEntity.FieldCreateUserId
                       + "        ," + BaseFileEntity.FieldCreateBy
                       + "        ," + BaseFileEntity.FieldCreateOn
                       + "        ," + BaseFileEntity.FieldModifiedUserId
                       + "        ," + BaseFileEntity.FieldModifiedBy
                       + "        ," + BaseFileEntity.FieldModifiedOn
                       + " FROM " + this.CurrentTableName
                       + " WHERE " + BaseFileEntity.FieldId + " = " + DbHelper.GetParameter(BaseFileEntity.FieldId);
            DataTable dataTable = new DataTable(BaseFileEntity.TableName);

            DbHelper.Fill(dataTable, sqlQuery, new IDbDataParameter[] { DbHelper.MakeParameter(BaseFileEntity.FieldId, id) });
            BaseFileEntity fileEntity = new BaseFileEntity(dataTable);

            return(fileEntity);
        }
示例#4
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>文件</returns>
        public byte[] Downloads(BaseUserInfo userInfo, string id)
        {
            byte[] result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                if (BaseSystemInfo.UploadStorageMode == "Disk")
                {
                    manager.UpdateReadCount(id);                    // 阅读次数要加一
                    BaseFileEntity entity = manager.GetObject(id);

                    System.IO.FileStream fs = null;
                    //建立二进制读取
                    System.IO.BinaryReader br = null;
                    fs     = new FileStream(entity.FilePath + entity.FileName, System.IO.FileMode.Open);
                    br     = new BinaryReader((Stream)fs);
                    result = br.ReadBytes((int)fs.Length);
                    br.Close();
                    fs.Close();
                }
                else
                {
                    result = manager.Download(id);
                }
            });
            return(result);
        }
示例#5
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseFileEntity GetObject(BaseUserInfo userInfo, string id)
        {
            BaseFileEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                entity      = manager.GetObject(id);
            });
            return(entity);
        }
示例#6
0
        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="newName">新名称</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Rename(BaseUserInfo userInfo, string id, string newName, bool enabled, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            statusCode    = string.Empty;
            statusMessage = string.Empty;

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileEntity  fileEntity  = new BaseFileEntity();
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    DataTable       dataTable   = fileManager.GetDataTableById(id);
                    fileEntity.GetSingle(dataTable);
                    fileEntity.FileName = newName;
                    fileEntity.Enabled  = enabled ? 1 : 0;
                    returnValue         = fileManager.Update(fileEntity, out statusCode);
                    statusMessage       = fileManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(returnValue);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseFileEntity entity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseFileEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseFileEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseFileEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseFileEntity.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
示例#8
0
        /// <summary>
        /// 分段上传文件 ,2012-10-14 HJC Add 暂时支持SQL数据库
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="length"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public string UplaodeByBlockUpdate(string Id, int length, byte[] file)
        {
            string result = string.Empty;

            string         commandText;
            BaseFileEntity entity = new BaseFileEntity();

            commandText  = "declare @content varbinary(16) ";
            commandText += string.Format("SELECT @content=textptr({0}) from {1} where {2} = {3}", BaseFileEntity.FieldContents, BaseFileEntity.TableName, BaseFileEntity.FieldId, Id);
            commandText += string.Format(" updatetext {0}.{1} @content @length 0 @block", BaseFileEntity.TableName, BaseFileEntity.FieldContents);
            IDbDataParameter[] dbParameters = new IDbDataParameter[2];
            dbParameters[0] = DbHelper.MakeParameter("block", file);
            dbParameters[1] = DbHelper.MakeParameter("length", length);
            dbHelper.ExecuteNonQuery(commandText, dbParameters);

            return(result);
        }
示例#9
0
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="result">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dt)
        {
            int            result = 0;
            BaseFileEntity entity = new BaseFileEntity();

            foreach (DataRow dr in dt.Rows)
            {
                // 删除状态
                if (dr.RowState == DataRowState.Deleted)
                {
                    string id = dr[BaseFileEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        result += this.Delete(id);
                    }
                }
                // 被修改过
                if (dr.RowState == DataRowState.Modified)
                {
                    string id = dr[BaseFileEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        entity.GetFrom(dr);
                        // 判断是否允许编辑
                        result += this.UpdateObject(entity);
                    }
                }
                // 添加状态
                if (dr.RowState == DataRowState.Added)
                {
                    entity.GetFrom(dr);
                    result += this.AddObject(entity).Length > 0 ? 1 : 0;
                }
                if (dr.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dr.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            return(result);
        }
示例#10
0
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dataTable)
        {
            int            returnValue = 0;
            BaseFileEntity fileEntity  = new BaseFileEntity();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                // 删除状态
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    string id = dataRow[BaseFileEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        returnValue += this.Delete(id);
                    }
                }
                // 被修改过
                if (dataRow.RowState == DataRowState.Modified)
                {
                    string id = dataRow[BaseFileEntity.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        fileEntity.GetFrom(dataRow);
                        // 判断是否允许编辑
                        returnValue += this.UpdateEntity(fileEntity);
                    }
                }
                // 添加状态
                if (dataRow.RowState == DataRowState.Added)
                {
                    fileEntity.GetFrom(dataRow);
                    returnValue += this.AddEntity(fileEntity).Length > 0 ? 1 : 0;
                }
                if (dataRow.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dataRow.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            return(returnValue);
        }
示例#11
0
        /// <summary>
        /// 分块上传文件添加
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="fileName"></param>
        /// <param name="file"></param>
        /// <param name="filesize"></param>
        /// <param name="enabled"></param>
        /// <returns></returns>
        public string UplaodeByBlock(string folderId, string filePath, string fileName, byte[] file, int filesize, bool enabled)
        {
            // 检查是否已经存在
            //string result = this.GetId(new KeyValuePair<string, object>(BaseFileEntity.FieldFolderId, folderId), new KeyValuePair<string, object>(BaseFileEntity.FieldFileName, fileName));
            // 检查是否已经存在,加入删除状态为0的条件
            List <KeyValuePair <string, object> > parametersList = new List <KeyValuePair <string, object> >();

            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, folderId));
            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileName));
            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldDeletionStateCode, 0));
            string result = this.GetId(parametersList);

            if (!String.IsNullOrEmpty(result))
            {
                // 更新数据
                this.UpdateFile(result, fileName, file);
                //在能够真实模仿C/S中的提示确定信息对话框的B/S版本出来之前,先做如下处理:前面的文件有重复的,打删除标志来处理,因为客户不会闲着没事,老传文件,且服务器都是几百个G的空间
                // 删除数据
                BaseFileManager manager        = new BaseFileManager();
                int             intReturnValue = manager.SetDeleted(result);
                // 添加数据
                BaseFileEntity entity = new BaseFileEntity();
                entity.FolderId = folderId;
                entity.FilePath = filePath;
                entity.FileName = fileName;
                entity.Contents = file;
                entity.FileSize = filesize;
                entity.Enabled  = enabled ? 1 : 0;
                result          = this.AddObject(entity);
            }
            else
            {
                // 添加数据
                BaseFileEntity entity = new BaseFileEntity();
                entity.FolderId = folderId;
                entity.FilePath = filePath;
                entity.FileName = fileName;
                entity.Contents = file;
                entity.FileSize = filesize;
                entity.Enabled  = enabled ? 1:0;
                result          = this.AddObject(entity);
            }
            return(result);
        }
示例#12
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseFileEntity entity)
 {
     sqlBuilder.SetValue(BaseFileEntity.FieldFolderId, entity.FolderId);
     sqlBuilder.SetValue(BaseFileEntity.FieldFileName, entity.FileName);
     sqlBuilder.SetValue(BaseFileEntity.FieldFilePath, entity.FilePath);
     sqlBuilder.SetValue(BaseFileEntity.FieldContents, entity.Contents);
     if (entity.Contents != null && (entity.FileSize == null || entity.FileSize == 0))
     {
         sqlBuilder.SetValue(BaseFileEntity.FieldFileSize, entity.Contents.Length);
     }
     else
     {
         sqlBuilder.SetValue(BaseFileEntity.FieldFileSize, entity.FileSize);
     }
     sqlBuilder.SetValue(BaseFileEntity.FieldReadCount, entity.ReadCount);
     sqlBuilder.SetValue(BaseFileEntity.FieldDeletionStateCode, entity.DeletionStateCode);
     sqlBuilder.SetValue(BaseFileEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseFileEntity.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(BaseFileEntity.FieldSortCode, entity.SortCode);
     SetObjectExpand(sqlBuilder, entity);
 }
示例#13
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="BaseFileEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseFileEntity fileEntity)
 {
     sqlBuilder.SetValue(BaseFileEntity.FieldFolderId, fileEntity.FolderId);
     sqlBuilder.SetValue(BaseFileEntity.FieldFileName, fileEntity.FileName);
     sqlBuilder.SetValue(BaseFileEntity.FieldFilePath, fileEntity.FilePath);
     sqlBuilder.SetValue(BaseFileEntity.FieldContents, fileEntity.Contents);
     if (fileEntity.Contents != null)
     {
         sqlBuilder.SetValue(BaseFileEntity.FieldFileSize, fileEntity.Contents.Length);
     }
     else
     {
         sqlBuilder.SetValue(BaseFileEntity.FieldFileSize, fileEntity.FileSize);
     }
     sqlBuilder.SetValue(BaseFileEntity.FieldReadCount, fileEntity.ReadCount);
     sqlBuilder.SetValue(BaseFileEntity.FieldDeletionStateCode, fileEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseFileEntity.FieldDescription, fileEntity.Description);
     sqlBuilder.SetValue(BaseFileEntity.FieldEnabled, fileEntity.Enabled);
     sqlBuilder.SetValue(BaseFileEntity.FieldSortCode, fileEntity.SortCode);
     SetEntityExpand(sqlBuilder, fileEntity);
 }
示例#14
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseFileEntity GetEntity(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            BaseFileEntity fileEntity = null;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    fileEntity = fileManager.GetEntity(id);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.FileService_GetEntity, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(fileEntity);
        }
示例#15
0
        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="newName">新名称</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Rename(BaseUserInfo userInfo, string id, string newName, bool enabled, out string statusCode, out string statusMessage)
        {
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            int    result        = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                BaseFileEntity fileEntity = new BaseFileEntity();
                var manager = new BaseFileManager(dbHelper, userInfo);
                var dt      = manager.GetDataTableById(id);
                fileEntity.GetSingle(dt);
                fileEntity.FileName = newName;
                fileEntity.Enabled  = enabled ? 1 : 0;
                result        = manager.Update(fileEntity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
示例#16
0
        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件</param>
        /// <param name="category">文件分类</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态</param>
        /// <returns>主键</returns>
        public string Add(BaseFileEntity fileEntity, out string statusCode)
        {
            statusCode = string.Empty;
            string returnValue = string.Empty;
            // 检查是否重复
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, fileEntity.FolderId));
            parameters.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileEntity.FileName));
            parameters.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldDeletionStateCode, 0));

            if (this.Exists(parameters))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                returnValue = this.AddEntity(fileEntity);
                // 运行成功
                statusCode = StatusCode.OKAdd.ToString();
            }
            return(returnValue);
        }
示例#17
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseFileEntity entity)
        {
            string sequence = string.Empty;

            sequence = entity.Id;
            if (entity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence        = sequenceManager.Increment(this.CurrentTableName);
                entity.SortCode = int.Parse(sequence);
            }
            if (entity.Id is string)
            {
                this.Identity = false;
            }
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseFileEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseFileEntity.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && DbHelper.CurrentDbType == CurrentDbType.Oracle)
                {
                    sqlBuilder.SetFormula(BaseFileEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                }
                else
                {
                    if (this.Identity && DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        if (string.IsNullOrEmpty(entity.Id))
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.Increment(this.CurrentTableName);
                            }
                            entity.Id = sequence;
                        }
                        sqlBuilder.SetValue(BaseFileEntity.FieldId, entity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseFileEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseFileEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseFileEntity.FieldCreateOn);
            // 这里主要是为了列表里的数据库更好看
            sqlBuilder.SetValue(BaseFileEntity.FieldModifiedUserId, entity.ModifiedUserId);
            sqlBuilder.SetValue(BaseFileEntity.FieldModifiedBy, entity.ModifiedBy);
            sqlBuilder.SetValue(BaseFileEntity.FieldModifiedOn, entity.ModifiedOn);
            if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
示例#18
0
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseFileEntity entity);
示例#19
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="fileEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseFileEntity fileEntity)
 {
     return(this.AddEntity(fileEntity));
 }
示例#20
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(BaseFileEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddObject(entity));
 }
示例#21
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseFileEntity entity)
 {
     return(this.AddObject(entity));
 }
示例#22
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(BaseFileEntity entity)
 {
     return(this.UpdateObject(entity));
 }
示例#23
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件内容</param>
        /// <param name="toUserId">发送给谁主键</param>
        /// <returns>文件主键</returns>
        public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFolderEntity  folderEntity  = new BaseFolderEntity();
                    BaseFolderManager folderManager = new BaseFolderManager(dbHelper, userInfo);
                    // 检查相应的系统必备文件夹
                    folderManager.FolderCheck();
                    BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetEntity(toUserId);
                    if (!string.IsNullOrEmpty(userEntity.Id))
                    {
                        // 04:判断发送者的空间是否存在?
                        // 05:判断已收文件夹是否存在?
                        if (!folderManager.Exists(userEntity.Id.ToString()))
                        {
                            folderEntity.FolderName        = userEntity.RealName + AppMessage.FileService_File;
                            folderEntity.ParentId          = "UserSpace";
                            folderEntity.Id                = userEntity.Id.ToString();
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        // 06:判断来自谁的文件夹是否存在?
                        // 07:判断发给谁的文件夹是否存在?
                        if (!folderManager.Exists(toUserId + "_Receive"))
                        {
                            folderEntity.FolderName        = AppMessage.FileService_ReceiveFile;
                            folderEntity.ParentId          = toUserId;
                            folderEntity.Id                = toUserId + "_Receive";
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId))
                        {
                            folderEntity.FolderName        = userEntity.RealName + "(" + userEntity.UserName + ")";
                            folderEntity.ParentId          = userInfo.Id + "_Send";
                            folderEntity.Id                = userInfo.Id + "_Send_" + toUserId;
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id))
                        {
                            folderEntity.FolderName        = userInfo.RealName + "(" + userInfo.UserName + ")";
                            folderEntity.ParentId          = toUserId + "_Receive";
                            folderEntity.Id                = toUserId + "_Receive_" + userInfo.Id;
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        // 08:已发送文件夹多一个文件。
                        // 09:已接收文件夹多一个文件。
                        BaseFileEntity fileEntity = new BaseFileEntity();
                        fileEntity.FileName  = fileName;
                        fileEntity.Contents  = file;
                        fileEntity.Enabled   = 1;
                        fileEntity.ReadCount = 0;
                        fileEntity.FolderId  = userInfo.Id + "_Send_" + toUserId;
                        // 把修改人显示出来
                        fileEntity.ModifiedBy     = userInfo.RealName;
                        fileEntity.ModifiedUserId = userInfo.Id;
                        fileEntity.ModifiedOn     = DateTime.Now;
                        BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                        fileManager.AddEntity(fileEntity);
                        fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id;
                        returnValue         = fileManager.AddEntity(fileEntity);
                        // string webHostUrl = BaseSystemInfo.WebHostUrl;
                        // if (string.IsNullOrEmpty(webHostUrl))
                        // {
                        //    webHostUrl = "WebHostUrl";
                        // }
                        // 10:应该还发一个短信提醒一下才对。
                        BaseMessageEntity messageEntity = new BaseMessageEntity();
                        messageEntity.Id           = Guid.NewGuid().ToString();
                        messageEntity.CategoryCode = MessageCategory.Send.ToString();
                        messageEntity.FunctionCode = MessageFunction.Message.ToString();
                        messageEntity.ObjectId     = returnValue;
                        messageEntity.ReceiverId   = toUserId;
                        // target=\"_blank\"
                        messageEntity.Contents          = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + returnValue + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile;
                        messageEntity.IsNew             = (int)MessageStateCode.New;
                        messageEntity.ReadCount         = 0;
                        messageEntity.DeletionStateCode = 0;
                        messageEntity.Enabled           = 1;
                        BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo);
                        returnValue = messageManager.Add(messageEntity);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }
示例#24
0
 partial void SetEntityExpand(SQLBuilder sqlBuilder, BaseFileEntity fileEntity);
示例#25
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件内容</param>
        /// <param name="toUserId">发送给谁主键</param>
        /// <returns>文件主键</returns>
        public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId)
        {
            string result = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                BaseFolderEntity folderEntity = new BaseFolderEntity();
                var folderManager             = new BaseFolderManager(dbHelper, userInfo);
                // 检查相应的系统必备文件夹
                folderManager.FolderCheck();
                BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetObject(toUserId);
                if (!string.IsNullOrEmpty(userEntity.Id))
                {
                    // 04:判断发送者的空间是否存在?
                    // 05:判断已收文件夹是否存在?
                    if (!folderManager.Exists(userEntity.Id))
                    {
                        folderEntity.FolderName        = userEntity.RealName + AppMessage.FileService_File;
                        folderEntity.ParentId          = "UserSpace";
                        folderEntity.Id                = userEntity.Id;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    // 06:判断来自谁的文件夹是否存在?
                    // 07:判断发给谁的文件夹是否存在?
                    if (!folderManager.Exists(toUserId + "_Receive"))
                    {
                        folderEntity.FolderName        = AppMessage.FileService_ReceiveFile;
                        folderEntity.ParentId          = toUserId;
                        folderEntity.Id                = toUserId + "_Receive";
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId))
                    {
                        folderEntity.FolderName        = userEntity.RealName + "(" + userEntity.UserName + ")";
                        folderEntity.ParentId          = userInfo.Id + "_Send";
                        folderEntity.Id                = userInfo.Id + "_Send_" + toUserId;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id))
                    {
                        folderEntity.FolderName        = userInfo.RealName + "(" + userInfo.UserName + ")";
                        folderEntity.ParentId          = toUserId + "_Receive";
                        folderEntity.Id                = toUserId + "_Receive_" + userInfo.Id;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    // 08:已发送文件夹多一个文件。
                    // 09:已接收文件夹多一个文件。
                    BaseFileEntity fileEntity = new BaseFileEntity();
                    fileEntity.FileName       = fileName;
                    fileEntity.Contents       = file;
                    fileEntity.Enabled        = 1;
                    fileEntity.ReadCount      = 0;
                    fileEntity.FolderId       = userInfo.Id + "_Send_" + toUserId;
                    // 把修改人显示出来
                    fileEntity.ModifiedBy     = userInfo.RealName;
                    fileEntity.ModifiedUserId = userInfo.Id;
                    fileEntity.ModifiedOn     = DateTime.Now;
                    var fileManager           = new BaseFileManager(dbHelper, userInfo);
                    fileManager.AddObject(fileEntity);
                    fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id;
                    result = fileManager.AddObject(fileEntity);
                    // string webHostUrl = BaseSystemInfo.WebHost;
                    // if (string.IsNullOrEmpty(webHostUrl))
                    // {
                    //    webHostUrl = "WebHostUrl";
                    // }
                    // 10:应该还发一个短信提醒一下才对。
                    BaseMessageEntity messageEntity = new BaseMessageEntity();
                    //messageEntity.Id = Guid.NewGuid().ToString("N");
                    messageEntity.CategoryCode = MessageCategory.Send.ToString();
                    messageEntity.FunctionCode = MessageFunction.Message.ToString();
                    messageEntity.ObjectId     = result;
                    messageEntity.ReceiverId   = toUserId;
                    // target=\"_blank\"
                    messageEntity.Contents          = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + result + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile;
                    messageEntity.IsNew             = (int)MessageStateCode.New;
                    messageEntity.ReadCount         = 0;
                    messageEntity.DeletionStateCode = 0;
                    var messageManager      = new BaseMessageManager(dbHelper, userInfo);
                    messageManager.Identity = true;
                    result = messageManager.Add(messageEntity);
                }
            });
            return(result);
        }
示例#26
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="BaseFileEntity">实体</param>
 public int Update(BaseFileEntity fileEntity)
 {
     return(this.UpdateEntity(fileEntity));
 }