Beispiel #1
0
        public override void GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files)
        {
            files       = null;
            directories = null;

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_GetDiskFiles";
                query.CommandType = CommandType.StoredProcedure;

                query.CreateParameter("@UserID", userID, SqlDbType.Int);
                query.CreateParameter("@DirectoryID", directoryID, SqlDbType.Int);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    directories = new DiskDirectoryCollection(reader);

                    if (reader.NextResult())
                    {
                        files = new DiskFileCollection(reader);
                    }
                }
            }

            if (files == null)
            {
                files = new DiskFileCollection();
            }

            if (directories == null)
            {
                directories = new DiskDirectoryCollection();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_Request.IsClick("search"))
            {
                Search();
            }
            else if (_Request.IsClick("delete"))
            {
                Delete();
            }

            m_diskFileList = DiskBO.Instance.AdminSearchFiles(MyUserID, Filter, _Request.Get <int>("page", Method.Get, 1));
            WaitForFillSimpleUsers <DiskFile>(m_diskFileList);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_Request.IsClick("search"))
            {
                Search();
            }
            else if (_Request.IsClick("delete"))
            {
                Delete();
            }

            m_diskFileList = DiskBO.Instance.AdminSearchFiles(MyUserID, Filter,  _Request.Get<int>("page", Method.Get, 1));
            WaitForFillSimpleUsers<DiskFile>(m_diskFileList);
        }
Beispiel #4
0
        public override DiskFileCollection AdminSearchFiles(DiskFileFilter filter, IEnumerable <Guid> exculdeRoles, int pageIndex)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder builder = new StringBuilder();

                if (filter.UserID != null)
                {
                    builder.Append(" AND UserID = @UserID");
                    query.CreateParameter <int>("@UserID", filter.UserID.Value, SqlDbType.Int);
                }

                if (filter.Username != null)
                {
                    builder.Append(" AND UserID IN (SELECT UserID FROM bx_Users WHERE Username LIKE '%' + @Username + '%')");
                    query.CreateParameter <string>("@Username", filter.Username, SqlDbType.NVarChar, 50);
                }

                if (filter.DirectoryName != null)
                {
                    builder.Append(" AND DirectoryID IN (SELECT DirectoryID FROM bx_DiskDirectories WHERE [Name] LIKE '%' + @DirectoryName + '%')");
                    query.CreateParameter <string>("@DirectoryName", filter.DirectoryName, SqlDbType.NVarChar, 256);
                }

                if (filter.Filename != null)
                {
                    builder.Append(" AND FileName LIKE '%' + @FileName + '%'");
                    query.CreateParameter <string>("@FileName", filter.Filename, SqlDbType.NVarChar, 256);
                }

                if (filter.Size_1 != null)
                {
                    builder.Append(" AND FileSize >= @FileSize1");
                    long size = filter.Size_1.Value;
                    switch (filter.SizeUnit_1)
                    {
                    case FileSizeUnit.K:
                        size *= 1024;
                        break;

                    case FileSizeUnit.M:
                        size *= 1024 * 1024;
                        break;

                    case FileSizeUnit.G:
                        size *= 1024 * 1024 * 1024;
                        break;
                    }

                    query.CreateParameter <long>("@FileSize1", size, SqlDbType.BigInt);
                }

                if (filter.Size_2 != null)
                {
                    builder.Append(" AND FileSize <= @FileSize2");

                    long size = filter.Size_2.Value;
                    switch (filter.SizeUnit_2)
                    {
                    case FileSizeUnit.K:
                        size *= 1024;
                        break;

                    case FileSizeUnit.M:
                        size *= 1024 * 1024;
                        break;

                    case FileSizeUnit.G:
                        size *= 1024 * 1024 * 1024;
                        break;
                    }
                    query.CreateParameter <long>("@FileSize2", size, SqlDbType.BigInt);
                }

                if (filter.CreateDate_1 != null)
                {
                    builder.Append(" AND CreateDate >= @CreateDate1");
                    query.CreateParameter <DateTime>("@CreateDate1", filter.CreateDate_1.Value, SqlDbType.DateTime);
                }

                if (filter.CreateDate_2 != null)
                {
                    builder.Append(" AND CreateDate <= @CreateDate2");
                    query.CreateParameter <DateTime>("@CreateDate2", filter.CreateDate_2.Value, SqlDbType.DateTime);
                }

                string noSelectRoles = DaoUtil.GetExcludeRoleSQL("[UserID]", exculdeRoles, query);
                if (!string.IsNullOrEmpty(noSelectRoles))
                {
                    builder.Append(" AND ");
                    builder.Append(noSelectRoles);
                }

                if (builder.Length >= 5)
                {
                    builder.Remove(0, 5);
                }

                query.Pager.TableName   = "bx_DiskFiles";
                query.Pager.PageSize    = filter.PageSize;
                query.Pager.PageNumber  = pageIndex;
                query.Pager.Condition   = builder.ToString();
                query.Pager.IsDesc      = filter.IsDesc == null ? true : filter.IsDesc.Value;
                query.Pager.PrimaryKey  = "DiskFileID";
                query.Pager.SortField   = "DiskFileID";
                query.Pager.SelectCount = true;

                if (filter.Order != null)
                {
                    switch (filter.Order.Value)
                    {
                    case FileOrderBy.CreateDate:
                        query.Pager.SortField = "CreateDate";
                        break;

                    case FileOrderBy.Name:
                        query.Pager.SortField = "FileName";
                        break;

                    case FileOrderBy.Size:
                        query.Pager.SortField = "FileSize";
                        break;

                    case FileOrderBy.Type:
                        query.Pager.SortField = "Extension";
                        break;
                    }
                }

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    DiskFileCollection files = new DiskFileCollection(reader);
                    if (reader.NextResult())
                    {
                        if (reader.Read())
                        {
                            files.TotalRecords = reader.Get <int>(0);
                        }
                    }
                    return(files);
                }
            }
        }
Beispiel #5
0
        public override void GetDiskDirectoriesAndDiskFiles(int userID, int directoryID, IEnumerable <int> directoryIds, IEnumerable <int> diskFileIds, out DiskDirectoryCollection directories, out DiskFileCollection diskFiles)
        {
            directories = null;;
            diskFiles   = null;

            bool hasDirectories = ValidateUtil.HasItems(directoryIds);
            bool hasFiles       = ValidateUtil.HasItems(diskFileIds);

            StringBuilder sqlBuilder = new StringBuilder();

            using (SqlQuery query = new SqlQuery())
            {
                if (hasDirectories)
                {
                    sqlBuilder.Append("SELECT * FROM bx_DiskDirectories WHERE DirectoryID IN (@DirectoryIds) ORDER BY Name;");
                    query.CreateInParameter("@DirectoryIds", directoryIds);
                }

                if (hasFiles)
                {
                    sqlBuilder.Append("SELECT * FROM bx_DiskFiles WHERE DiskFileID IN (@DiskFileIds) ORDER BY FileName;");
                    query.CreateInParameter("@DiskFileIds", diskFileIds);
                }

                query.CommandType = CommandType.Text;
                query.CommandText = sqlBuilder.ToString();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    if (hasDirectories)
                    {
                        directories = new DiskDirectoryCollection(reader);
                        //while (reader.Read())
                        //{
                        //    directories.Add(new DiskDirectory(reader));
                        //}
                    }

                    if (hasFiles)
                    {
                        if (hasDirectories)
                        {
                            reader.NextResult();
                        }

                        diskFiles = new DiskFileCollection(reader);
                        //while (reader.Read())
                        //{
                        //    diskFiles.Add(new DiskFile(reader));
                        //}
                    }
                }
            }

            if (directories == null)
            {
                directories = new DiskDirectoryCollection();
            }

            if (diskFiles == null)
            {
                diskFiles = new DiskFileCollection();
            }
        }
Beispiel #6
0
 public void GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files)
 {
     GetDiskFiles(userID, directoryID, out directories, out files, FileOrderBy.None, false, null);
 }
Beispiel #7
0
        /// <summary>
        /// ȡ�ø�Ŀ¼�ļ�����һ��Ŀ¼�������ļ����ļ��С�
        /// </summary>
        /// <param name="userID">��ǰ�û���ID��</param>
        /// <param name="directoryID">���ļ��е�ID��</param>
        /// <param name="directories">������ļ���ʵ��<see cref="DiskDirectory"/>���б��</param>
        /// <param name="files">������ļ�ʵ��<see cref="DiskFile"/>�б��</param>
        /// <param name="totalSize">��ǰ��Ŀ¼���������ļ��Ĵ�С��</param>
        /// <returns>����ɹ�ȡ���򷵻�<c>true</c>,���򷵻�<c>false</c>��</returns>
        public List <IFile> GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files, FileOrderBy orderBy, bool isDesc, ExtensionList fileTypes)
        {
            List <IFile> dirAndFiles;
            int          fileTypeKey          = fileTypes == null || fileTypes.Count == 0?0: fileTypes.ToString("").GetHashCode();
            string       cachekeyOfDirectorys = string.Format(cacheKey_directoryList, userID, directoryID);
            string       cacheKeyOfFiles      = string.Format(cacheKey_fileList, userID, directoryID, fileTypeKey);

            if (!CacheUtil.TryGetValue <DiskFileCollection>(cacheKey_fileList, out files) ||
                CacheUtil.TryGetValue <DiskDirectoryCollection>(cachekeyOfDirectorys, out directories))
            {
                DiskDao.Instance.GetDiskFiles(userID, directoryID, out directories, out files);
                CacheUtil.Set <DiskFileCollection>(cacheKeyOfFiles, files);
                CacheUtil.Set <DiskDirectoryCollection>(cachekeyOfDirectorys, directories);
            }

            /*���´������ܺܲ ԭ����3.0��BO������Ӧ�����ܣ� ��ʱ��Ӧ����������ѭ������*/

            string cacheKeyOfAllFiles = string.Format(cacheKey_directoryList, userID, directoryID, orderBy, isDesc);

            if (!CacheUtil.TryGetValue <List <IFile> >(cacheKeyOfAllFiles, out dirAndFiles))
            {
                dirAndFiles = new List <IFile>(directories.Count + files.Count);


                if (orderBy != FileOrderBy.None)
                {
                    DiskFile temp;
                    int      v;
                    for (int i = 0; i < files.Count - 1; i++)
                    {
                        for (int j = i + 1; j < files.Count; j++)
                        {
                            v = CompareFile(files[i], files[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    temp     = files[i];
                                    files[i] = files[j];
                                    files[j] = temp;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    temp     = files[j];
                                    files[j] = files[i];
                                    files[i] = temp;
                                }
                            }
                        }
                    }

                    DiskDirectory tempDir;

                    for (int i = 0; i < directories.Count - 1; i++)
                    {
                        for (int j = i + 1; j < directories.Count; j++)
                        {
                            v = CompareFile(directories[i], directories[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    tempDir        = directories[i];
                                    directories[i] = directories[j];
                                    directories[j] = tempDir;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    tempDir        = directories[j];
                                    directories[j] = directories[i];
                                    directories[i] = tempDir;
                                }
                            }
                        }
                    }
                }

                if (orderBy == FileOrderBy.Type && isDesc == false)
                {
                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }
                        dirAndFiles.Add(file);
                    }
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }
                }
                else
                {
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }

                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }

                        dirAndFiles.Add(file);
                    }
                }

                CacheUtil.RemoveBySearch(string.Format(cacheKey_allFileListRoot, userID, directoryID));
                CacheUtil.Set <List <IFile> >(cacheKeyOfAllFiles, dirAndFiles);
            }
            return(dirAndFiles);
        }
Beispiel #8
0
 public List <IFile> GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files, FileOrderBy orderBy, bool isDesc)
 {
     return(GetDiskFiles(userID, directoryID, out directories, out files, orderBy, isDesc, null));
 }
Beispiel #9
0
 public void GetDiskDirectoriesAndDiskFiles(int userID, int directoryID, IEnumerable <int> directoryIDs, IEnumerable <int> diskFileIDs, out DiskDirectoryCollection directories, out DiskFileCollection diskFiles)
 {
     DiskDao.Instance.GetDiskDirectoriesAndDiskFiles(
         userID, directoryID, directoryIDs, diskFileIDs, out directories, out diskFiles);
 }
Beispiel #10
0
        public override void GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files)
        {
            files = null;
            directories = null;

            using (SqlQuery query = new SqlQuery())
            {

                query.CommandText = "bx_GetDiskFiles";
                query.CommandType = CommandType.StoredProcedure;

                query.CreateParameter("@UserID", userID, SqlDbType.Int);
                query.CreateParameter("@DirectoryID", directoryID, SqlDbType.Int);

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    directories = new DiskDirectoryCollection(reader);

                    if (reader.NextResult())
                        files = new DiskFileCollection(reader);

                }
            }

            if (files == null)
                files = new DiskFileCollection();

            if (directories == null)
                directories = new DiskDirectoryCollection();
        }
Beispiel #11
0
        public override DiskFileCollection AdminSearchFiles(DiskFileFilter filter, IEnumerable<Guid> exculdeRoles, int pageIndex)
        {
            using (SqlQuery query = new SqlQuery())
            {
                StringBuilder builder = new StringBuilder();

                if (filter.UserID != null)
                {
                    builder.Append(" AND UserID = @UserID");
                    query.CreateParameter<int>("@UserID", filter.UserID.Value, SqlDbType.Int);
                }

                if (filter.Username != null)
                {
                    builder.Append(" AND UserID IN (SELECT UserID FROM bx_Users WHERE Username LIKE '%' + @Username + '%')");
                    query.CreateParameter<string>("@Username", filter.Username, SqlDbType.NVarChar, 50);
                }

                if (filter.DirectoryName != null)
                {
                    builder.Append(" AND DirectoryID IN (SELECT DirectoryID FROM bx_DiskDirectories WHERE [Name] LIKE '%' + @DirectoryName + '%')");
                    query.CreateParameter<string>("@DirectoryName", filter.DirectoryName, SqlDbType.NVarChar, 256);
                }

                if (filter.Filename != null)
                {
                    builder.Append(" AND FileName LIKE '%' + @FileName + '%'");
                    query.CreateParameter<string>("@FileName", filter.Filename, SqlDbType.NVarChar, 256);
                }

                if (filter.Size_1 != null)
                {
                    builder.Append(" AND FileSize >= @FileSize1");
                    long size = filter.Size_1.Value;
                    switch (filter.SizeUnit_1)
                    {
                        case FileSizeUnit.K:
                            size *= 1024;
                            break;
                        case FileSizeUnit.M:
                            size *= 1024 * 1024;
                            break;
                        case FileSizeUnit.G:
                            size *= 1024 * 1024 * 1024;
                            break;
                    }

                    query.CreateParameter<long>("@FileSize1", size, SqlDbType.BigInt);
                }

                if (filter.Size_2 != null)
                {
                    builder.Append(" AND FileSize <= @FileSize2");

                    long size = filter.Size_2.Value;
                    switch (filter.SizeUnit_2)
                    {
                        case FileSizeUnit.K:
                            size *= 1024;
                            break;
                        case FileSizeUnit.M:
                            size *= 1024 * 1024;
                            break;
                        case FileSizeUnit.G:
                            size *= 1024 * 1024 * 1024;
                            break;
                    }
                    query.CreateParameter<long>("@FileSize2", size, SqlDbType.BigInt);
                }

                if (filter.CreateDate_1 != null)
                {
                    builder.Append(" AND CreateDate >= @CreateDate1");
                    query.CreateParameter<DateTime>("@CreateDate1", filter.CreateDate_1.Value, SqlDbType.DateTime);
                }

                if (filter.CreateDate_2 != null)
                {
                    builder.Append(" AND CreateDate <= @CreateDate2");
                    query.CreateParameter<DateTime>("@CreateDate2", filter.CreateDate_2.Value, SqlDbType.DateTime);
                }

                string noSelectRoles = DaoUtil.GetExcludeRoleSQL("[UserID]", exculdeRoles, query);
                if (!string.IsNullOrEmpty(noSelectRoles))
                {
                    builder.Append(" AND ");
                    builder.Append(noSelectRoles);
                }

                if (builder.Length >= 5)
                    builder.Remove(0, 5);

                query.Pager.TableName = "bx_DiskFiles";
                query.Pager.PageSize = filter.PageSize;
                query.Pager.PageNumber = pageIndex;
                query.Pager.Condition = builder.ToString();
                query.Pager.IsDesc = filter.IsDesc == null ? true : filter.IsDesc.Value;
                query.Pager.PrimaryKey = "DiskFileID";
                query.Pager.SortField = "DiskFileID";
                query.Pager.SelectCount = true;

                if (filter.Order != null)
                {
                    switch (filter.Order.Value)
                    {
                        case FileOrderBy.CreateDate:
                            query.Pager.SortField = "CreateDate";
                            break;
                        case FileOrderBy.Name:
                            query.Pager.SortField = "FileName";
                            break;
                        case FileOrderBy.Size:
                            query.Pager.SortField = "FileSize";
                            break;
                        case FileOrderBy.Type:
                            query.Pager.SortField = "Extension";
                            break;
                    }
                }

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    DiskFileCollection files = new DiskFileCollection(reader);
                    if (reader.NextResult())
                        if (reader.Read())
                            files.TotalRecords = reader.Get<int>(0);
                    return files;
                }
            }
        }
Beispiel #12
0
        public override void GetDiskDirectoriesAndDiskFiles(int userID, int directoryID, IEnumerable<int> directoryIds, IEnumerable<int> diskFileIds, out DiskDirectoryCollection directories, out DiskFileCollection diskFiles)
        {
            directories = null; ;
            diskFiles = null;

            bool hasDirectories = ValidateUtil.HasItems(directoryIds);
            bool hasFiles = ValidateUtil.HasItems(diskFileIds);

            StringBuilder sqlBuilder = new StringBuilder();

            using (SqlQuery query = new SqlQuery())
            {
                if (hasDirectories)
                {
                    sqlBuilder.Append("SELECT * FROM bx_DiskDirectories WHERE DirectoryID IN (@DirectoryIds) ORDER BY Name;");
                    query.CreateInParameter("@DirectoryIds", directoryIds);
                }

                if (hasFiles)
                {
                    sqlBuilder.Append("SELECT * FROM bx_DiskFiles WHERE DiskFileID IN (@DiskFileIds) ORDER BY FileName;");
                    query.CreateInParameter("@DiskFileIds", diskFileIds);
                }

                query.CommandType = CommandType.Text;
                query.CommandText = sqlBuilder.ToString();

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    if (hasDirectories)
                    {
                        directories = new DiskDirectoryCollection(reader);
                        //while (reader.Read())
                        //{
                        //    directories.Add(new DiskDirectory(reader));
                        //}
                    }

                    if (hasFiles)
                    {
                        if (hasDirectories)
                            reader.NextResult();

                        diskFiles = new DiskFileCollection(reader);
                        //while (reader.Read())
                        //{
                        //    diskFiles.Add(new DiskFile(reader));
                        //}
                    }
                }
            }

            if (directories == null)
                directories = new DiskDirectoryCollection();

            if (diskFiles == null)
                diskFiles = new DiskFileCollection();
        }
Beispiel #13
0
 public abstract void GetDiskDirectoriesAndDiskFiles(int userID, int directoryID, IEnumerable <int> directoryIds, IEnumerable <int> diskFileIds, out DiskDirectoryCollection directories, out DiskFileCollection diskFiles);
Beispiel #14
0
        //public abstract int GetUserTodayFiles(int userID);

        public abstract void GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files);