Ejemplo n.º 1
0
        public ActionResult DownloadFolder(int id)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var tb = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                          where t.Id == id && t.tbSysUser.Id == Code.Common.UserId
                          select t).FirstOrDefault();

                if (tb != null)
                {
                    List <int> ids = new List <int>();
                    ids.Add(tb.Id);
                    List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(ids);

                    string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                    string strTempPath     = strTempPathName + "/";
                    string zipFileName     = strTempPathName + ".zip";

                    foreach (var folder in folderDescendants)
                    {
                        if (!Directory.Exists(strTempPath + folder.FolderPath))
                        {
                            Directory.CreateDirectory(strTempPath + folder.FolderPath);
                        }
                    }

                    List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(ids);
                    string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                    foreach (var diskFile in diskFileDescendants)
                    {
                        FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                        file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                    }

                    Code.ZipHelper.CreateZip(zipFileName, strTempPath + tb.DiskFolderName + "/");

                    Code.FileHelper.DeleteDirectory(strTempPath);

                    return(File(zipFileName, Code.Common.DownloadType, tb.DiskFolderName + ".zip"));
                }

                return(RedirectToAction("List"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Report()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.DiskFolder.Report();

                if (vm.ParentId == 0)
                {
                    var tb = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                              where t.DiskFolderName == "学校共享文件夹" &&
                              t.tbDiskType.DiskType == Code.EnumHelper.DiskType.Public
                              select t).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.ParentId = tb.Id;
                    }
                }

                var expr = from t in db.Table <Disk.Entity.tbDiskFolder>()
                           where t.tbDiskType.DiskType == Code.EnumHelper.DiskType.Public &&
                           t.DiskPermit != Code.EnumHelper.DiskPermit.Private &&
                           t.tbDiskFolderParent.Id == vm.ParentId
                           select new Dto.DiskFolder.Report
                {
                    Id             = t.Id,
                    DiskFolderName = t.DiskFolderName,
                    DiskPermit     = t.DiskPermit
                };
                if (!String.IsNullOrWhiteSpace(vm.SearchText))
                {
                    expr = expr.Where(t => t.DiskFolderName.Contains(vm.SearchText));
                }

                vm.FolderList        = expr.ToList();
                vm.DiskPowerUserList = DiskPowerController.SelectReportUserList(vm.ParentId);
                vm.DiskFileUserList  = DiskFileController.SelectReportUserList(vm.ParentId);

                return(View(vm));
            }
        }
Ejemplo n.º 3
0
        public ActionResult DownloadChecked(string ids)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                List <int> fileIds   = new List <int>();
                List <int> folderIds = new List <int>();
                string[]   arrIds    = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (arrIds.Length == 1)
                {
                    string[] arrId = arrIds[0].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                    if (arrId[1] == "Folder")
                    {
                        int folderId = arrId[0].ConvertToInt();
                        var tb       = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                        where t.Id == folderId
                                        select t).FirstOrDefault();

                        if (tb != null)
                        {
                            folderIds.Add(folderId);
                            List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);

                            string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                            string strTempPath     = strTempPathName + "/";
                            string zipFileName     = strTempPathName + ".zip";

                            foreach (var folder in folderDescendants)
                            {
                                if (!Directory.Exists(strTempPath + folder.FolderPath))
                                {
                                    Directory.CreateDirectory(strTempPath + folder.FolderPath);
                                }
                            }

                            List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(folderIds);
                            string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                            foreach (var diskFile in diskFileDescendants)
                            {
                                FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                                file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                            }

                            Code.ZipHelper.CreateZip(zipFileName, strTempPath + tb.DiskFolderName + "/");

                            Code.FileHelper.DeleteDirectory(strTempPath);

                            return(File(zipFileName, Code.Common.DownloadType, tb.DiskFolderName + ".zip"));
                        }
                    }
                    else
                    {
                        int fileId = arrId[0].ConvertToInt();
                        if (fileId != 0)
                        {
                            var tb = (from p in db.Table <Disk.Entity.tbDiskFile>()
                                      where p.Id == fileId
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                string filePath = Server.MapPath("~/Files/Disk/") + tb.FileName;

                                return(File(filePath, Code.Common.DownloadType, tb.FileTitle));
                            }
                        }
                    }
                }
                else
                {
                    foreach (string strIds in arrIds)
                    {
                        string[] arrId = strIds.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

                        if (arrId[1] == "Folder")
                        {
                            folderIds.Add(arrId[0].ConvertToInt());
                        }
                        else
                        {
                            fileIds.Add(arrId[0].ConvertToInt());
                        }
                    }

                    List <Dto.DiskFolder.Info> folderDescendants = DiskFolderController.SelectDescendants(folderIds);
                    string strTempPathName = Path.GetTempPath() + Guid.NewGuid().ToString();
                    string strTempPath     = strTempPathName + "/";
                    string zipFileName     = strTempPathName + ".zip";

                    if (!Directory.Exists(strTempPath))
                    {
                        Directory.CreateDirectory(strTempPath);
                    }

                    foreach (var folder in folderDescendants)
                    {
                        if (!Directory.Exists(strTempPath + folder.FolderPath))
                        {
                            Directory.CreateDirectory(strTempPath + folder.FolderPath);
                        }
                    }

                    List <Dto.DiskFile.Info> diskFileDescendants = DiskFileController.SelectDescendantsByFolder(folderIds);
                    foreach (var fileId in fileIds)
                    {
                        var tb = (from t in db.Table <Disk.Entity.tbDiskFile>()
                                  where t.Id == fileId
                                  select new Dto.DiskFile.Info
                        {
                            Id = t.Id,
                            FileTitle = t.FileTitle,
                            FileName = t.FileName,
                            FolderId = t.tbDiskFolder == null ? 0 : t.tbDiskFolder.Id
                        }).FirstOrDefault();
                        if (tb != null)
                        {
                            diskFileDescendants.Add(tb);
                        }
                    }

                    string strFilesDiskPath = Server.MapPath("~/Files/Disk/");
                    foreach (var diskFile in diskFileDescendants)
                    {
                        FileInfo file = new FileInfo(strFilesDiskPath + diskFile.FileName);
                        file.CopyTo(strTempPath + diskFile.FolderPath + diskFile.FileTitle);
                    }

                    Code.ZipHelper.CreateZip(zipFileName, strTempPath + "/");

                    Code.FileHelper.DeleteDirectory(strTempPath);

                    return(File(zipFileName, Code.Common.DownloadType, DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip"));
                }

                return(Content("<script>alert('文件不存在');</script>"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult List()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.DiskFile.List();

                var tbDiskType = DiskTypeController.SelectInfo(vm.DiskTypeId);

                #region 文件夹路径
                if (vm.UserId == 0)
                {
                    vm.FolderPath = DiskFolderController.SelectFolderPath(vm.FolderId);
                }
                else
                {
                    if (tbDiskType != null && tbDiskType.DiskType == Code.EnumHelper.DiskType.Public)
                    {
                        var tbSysUser    = db.Set <Sys.Entity.tbSysUser>().Find(vm.UserId);
                        var tbDiskFolder = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                            where t.DiskFolderName == "教师共享文件夹"
                                            select t).FirstOrDefault();
                        vm.FolderPath = DiskFolderController.SelectFolderPath(tbDiskFolder.Id);
                        vm.FolderPath.Add(new Dto.DiskFolder.Info
                        {
                            DiskFolderName = tbSysUser.UserName,
                            DiskTypeId     = vm.DiskTypeId,
                            UserId         = tbSysUser.Id,
                            ParentId       = 0
                        });
                    }

                    if (vm.FolderId != 0)
                    {
                        vm.FolderPath = vm.FolderPath.Union(DiskFolderController.SelectFolderPath(vm.FolderId, vm.DiskTypeId, vm.UserId)).ToList();
                    }
                }
                #endregion

                #region 文件夹
                if (vm.FolderId == 0)
                {
                    if (vm.DiskTypeId == 0)
                    {
                        // /Disk/DiskFile/List
                        vm.DiskFileList = DiskFolderController.SelectPublicRootFolder();
                        vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText, 0, Code.Common.UserId)).ToList();
                    }

                    if (vm.UserId != 0)
                    {
                        vm.DiskFileList = DiskFolderController.SelectByDiskPermitPublic(vm.UserId, vm.DiskTypeId);
                        vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByDiskPermitAuthorize(vm.UserId, vm.DiskTypeId)).ToList();
                    }
                }
                else
                {
                    if (tbDiskType != null && tbDiskType.DiskType == Code.EnumHelper.DiskType.Public)
                    {
                        // 管理员查看全部
                        if (Code.Common.UserType == Code.EnumHelper.SysUserType.Administrator)
                        {
                            vm.DiskFileList = DiskFolderController.SelectPublicFolderByParentId(vm.FolderId);
                        }
                        else
                        {
                            // 学校共享文件夹-共有
                            vm.DiskFileList = DiskFolderController.SelectPublicFolderByParentId(vm.FolderId, Code.EnumHelper.DiskPermit.Public);

                            // 学校共享文件夹-授权
                            var tbDiskFolderAuthorize = DiskFolderController.SelectPublicFolderAuthorizeByParentId(vm.FolderId, Code.EnumHelper.DiskPermit.Public);
                            foreach (Dto.DiskFile.List diskFile in tbDiskFolderAuthorize)
                            {
                                if (!vm.DiskFileList.Any(t => t.FileTitle.Equals(diskFile.FileTitle)))
                                {
                                    vm.DiskFileList.Add(diskFile);
                                }
                            }
                        }

                        var folder = (from t in db.Table <Disk.Entity.tbDiskFolder>()
                                      where t.Id == vm.FolderId
                                      select t).FirstOrDefault();
                        if (folder != null)
                        {
                            if (folder.DiskFolderName.Equals("教师共享文件夹"))
                            {
                                vm.DiskFileList = vm.DiskFileList.Union(DiskFolderController.SelectByPublic(Code.EnumHelper.DiskType.Private, vm.DiskTypeId)).ToList();

                                foreach (Dto.DiskFile.List diskFile in DiskFolderController.SelectByAuthorize(Code.EnumHelper.DiskType.Private, vm.DiskTypeId))
                                {
                                    if (!vm.DiskFileList.Any(t => t.FileTitle.Equals(diskFile.FileTitle)))
                                    {
                                        vm.DiskFileList.Add(diskFile);
                                    }
                                }
                            }
                            else if (!folder.DiskFolderName.Equals("公开文件夹") && !(folder.DiskFolderName.Equals("学校共享文件夹")))
                            {
                                vm.DiskFileList = DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText, vm.DiskTypeId, vm.UserId);
                            }
                        }
                    }
                    else
                    {
                        vm.DiskFileList = DiskFolderController.SelectByParentId(vm.FolderId, vm.SearchText);
                    }
                }
                #endregion

                #region 文件
                var tbDiskFile = from t in db.Table <Disk.Entity.tbDiskFile>()
                                 select t;
                if (vm.FolderId != 0)
                {
                    tbDiskFile = tbDiskFile.Where(t => t.tbDiskFolder.Id == vm.FolderId);
                }
                else
                {
                    tbDiskFile = tbDiskFile.Where(t => t.tbDiskFolder == null);

                    //if (vm.UserId != 0)
                    //{
                    //    tbDiskFile = tbDiskFile.Where(t => t.tbSysUser.Id == vm.UserId);
                    //}
                    //else
                    //{
                    tbDiskFile = tbDiskFile.Where(t => t.tbSysUser.Id == Code.Common.UserId);
                    //}
                }
                if (!String.IsNullOrWhiteSpace(vm.SearchText))
                {
                    tbDiskFile = tbDiskFile.Where(t => t.FileTitle.Contains(vm.SearchText));
                }

                int diskTypeId = DiskTypeController.SelectByEnumDiskType(Code.EnumHelper.DiskType.Private).Id;

                var tb = (from t in tbDiskFile
                          orderby t.Id descending
                          select new Dto.DiskFile.List
                {
                    Id = t.Id,
                    DiskTypeId = t.tbDiskFolder == null ? diskTypeId : t.tbDiskFolder.tbDiskType.Id,
                    FileType = "File",
                    FileTitle = t.FileTitle,
                    FileLength = t.FileLength,
                    InputDate = t.InputDate,
                    UserId = t.tbSysUser.Id,
                    UserName = t.tbSysUser.UserName
                }).ToList();

                vm.DiskFileList = vm.DiskFileList.Union(tb).ToList();
                #endregion

                #region 文件夹文件权限

                // 管理权限
                vm.AdminFolderIds = DiskFolderController.SelectOwnFolderIdsByUserId(Code.Common.UserId);
                if (Code.Common.UserType == Code.EnumHelper.SysUserType.Administrator)
                {
                    vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Public, Code.Common.UserId)).ToList();
                }
                vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Private, Code.Common.UserId)).ToList();
                vm.AdminFolderIds = vm.AdminFolderIds.Union(DiskPowerController.SelectAdminFolderIds(Code.Common.UserId)).ToList();

                // 查看权限
                vm.ViewFolderIds = DiskFolderController.SelectOwnFolderIdsByUserId(Code.Common.UserId);
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Public, Code.Common.UserId)).ToList();
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskFolderController.SelectDiskPermitPublicFolderIdsByUserId(Code.EnumHelper.DiskType.Private, Code.Common.UserId)).ToList();
                vm.ViewFolderIds = vm.ViewFolderIds.Union(DiskPowerController.SelectViewFolderIds(Code.Common.UserId)).ToList();

                #endregion

                #region 文件权限
                vm.AdminFileIds = DiskFileController.SelectDescendantsByFolder(vm.AdminFolderIds).Select(t => t.Id).ToList();
                vm.ViewFileIds  = DiskFileController.SelectDescendantsByFolder(vm.ViewFolderIds).Select(t => t.Id).ToList();

                var MyRootFileIds = (from t in db.Table <Disk.Entity.tbDiskFile>()
                                     where t.tbDiskFolder == null &&
                                     t.tbSysUser.Id == Code.Common.UserId
                                     select t.Id).ToList();
                vm.AdminFileIds = vm.AdminFileIds.Union(MyRootFileIds).ToList();
                vm.ViewFileIds  = vm.ViewFileIds.Union(MyRootFileIds).ToList();

                #endregion

                return(View(vm));
            }
        }