Esempio n. 1
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            DataTable dataTable = new DataTable(BaseModuleEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFolderManager folderManager = new BaseFolderManager(dbHelper, userInfo);
                    // 检查相应的系统必备文件夹
                    folderManager.FolderCheck();
                    if (userInfo.IsAdministrator)
                    {
                        dataTable = folderManager.GetDataTable(BaseFolderEntity.FieldSortCode);
                    }
                    else
                    {
                        // 数据权限部分,部门的权限部分。
                        BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
                        string[] ids = permissionScopeManager.GetOrganizeIds(userInfo.Id, "Resource.ManagePermission");
                        // 获取安全等级,比自己小的。
                        string commandText = string.Format(@"SELECT *
                                                               FROM BaseFolder
                                                              WHERE (DeletionStateCode = 0
                                                                    AND Enabled = 1
                                                                    AND (IsPublic = 1
                                                                         OR Id = 'UserSpace'
                                                                         OR Id = 'CompanyFile'
                                                                         OR Id = '{0}'
                                                                         OR Id = '{1}'
                                                                         OR Id = '{2}'
                                                                         OR CreateUserId = '{3}')) ", userInfo.Id, userInfo.DepartmentId, userInfo.CompanyId, userInfo.Id);
                        if (ids != null && ids.Length > 0)
                        {
                            commandText += " OR ID IN (" + BaseBusinessLogic.ObjectsToList(ids) + ") ";
                        }
                        dataTable = folderManager.Fill(commandText);
                    }
                    dataTable.DefaultView.Sort = BaseFolderEntity.FieldSortCode;
                    dataTable.TableName = BaseFolderEntity.TableName;
                    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 dataTable;
        }
Esempio n. 2
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;
        }