Ejemplo n.º 1
0
        public ActionResult Print()
        {
            bool isPrint     = false;
            bool canDownload = false;
            //string userName = string.Empty;
            string fileFullPath = string.Empty;

            int    modifyVerionId = -1;
            string fileId         = Request.QueryString["fileId"];
            string userHandle     = Request.QueryString["userHandle"];

            if (!int.TryParse(Request.QueryString["modifyVerionId"], out modifyVerionId))
            {
                return(View("ArgumentsError"));

                throw new Exception("参数错误");
            }
            if (string.IsNullOrEmpty(fileId) || string.IsNullOrEmpty(userHandle))
            {
                return(View("ArgumentsError"));

                throw new Exception("参数错误");
            }
            OpenModeType type = OpenModeType.docReadOnly; //默认为word文档

            LibHandle libHandle = LibHandleCache.Default.GetCurrentHandle(userHandle) as LibHandle;

            if (libHandle == null)
            {
                return(View("ArgumentsError"));

                throw new Exception("参数错误");
            }
            string personName = libHandle.PersonName;

            #region 获取权限
            List <DMFuncPermissionEnum> permissionList = DMPermissionControl.Default.GetPermissionOf(userHandle, fileId);

            if (permissionList.Contains(DMFuncPermissionEnum.Print))
            {
                isPrint = true;
            }

            if (permissionList.Contains(DMFuncPermissionEnum.Download))
            {
                canDownload = true;
            }
            #endregion

            #region 获取文件路径
            DirLinkAddress dirLink = new DirLinkAddress(fileId);
            fileFullPath = dirLink.GetDocFullPath(modifyVerionId);
            #endregion

            #region 根据扩展名,确定打开方式
            string extName = dirLink.DocType;
            if (extName == ".doc" || extName == ".docx")
            {
                type = OpenModeType.docReadOnly;
            }
            else if (extName == ".pptx" || extName == ".ppt")
            {
                type = OpenModeType.pptReadOnly;
            }
            else if (extName == ".xlsx" || extName == ".xls")
            {
                type = OpenModeType.xlsReadOnly;
            }
            else if (extName == ".txt")
            {
                if (isPrint)
                {
                    StreamReader sr      = new StreamReader(fileFullPath, FileEncoding.GetType(fileFullPath));
                    string       content = string.Empty;
                    string       temp    = string.Empty;
                    while ((temp = sr.ReadLine()) != null)
                    {
                        content += temp;
                        content += "\n";
                    }

                    sr.Close();
                    if (isPrint)
                    {
                        ViewData["content"]  = content;
                        ViewData["canPrint"] = true;
                        return(View("ReadTxt"));
                    }
                }
            }
            else if (extName == ".pdf")
            {
                if (isPrint)
                {
                    ViewData["fileId"]      = fileId;
                    ViewData["filename"]    = dirLink.DocName;
                    ViewData["canPrint"]    = true;
                    ViewData["canDownload"] = canDownload;
                    return(View("Viewer"));
                }
            }
            else
            {
                return(View("NoSupportError"));

                throw new Exception("不能打印该文件类型");
            }
            #endregion

            //是否可以打印
            if (isPrint)
            {
                ViewData["docName"]      = fileFullPath;
                ViewData["OpenModeType"] = type;
                ViewData["userName"]     = personName;
                ViewData["canDownload"]  = canDownload;
                return(View());
            }
            else
            {
                return(View("PermissionError"));

                throw new Exception("无打印权限");
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit()
        {
            bool   isAllow        = false;
            string fileFullPath   = string.Empty;
            string fileId         = Request.QueryString["fileId"];
            string userHandle     = Request.QueryString["userHandle"];
            string dirId          = Request.QueryString["dirId"];
            string dirType        = Request.QueryString["dirType"];
            string isChrome       = Request.QueryString["isChrome"];
            int    modifyVerionId = -1;

            //if (!int.TryParse(Request.Form["modifyVerionId"], out modifyVerionId))
            //{
            //    throw new Exception("参数错误");
            //}
            if (string.IsNullOrEmpty(fileId) || string.IsNullOrEmpty(userHandle) || string.IsNullOrEmpty(dirId) || string.IsNullOrEmpty(dirType) || string.IsNullOrEmpty(isChrome))
            {
                return(View("ArgumentsError"));

                throw new Exception("参数错误");
            }

            OpenModeType type = OpenModeType.docNormalEdit; //默认为word文档

            #region 用户判断
            LibHandle libHandle = LibHandleCache.Default.GetCurrentHandle(userHandle) as LibHandle;
            if (libHandle == null)
            {
                return(View("ArgumentsError"));

                throw new Exception("参数错误");
            }
            string personName = libHandle.PersonName;
            #endregion

            #region 权限判断
            List <DMFuncPermissionEnum> permissionList = DMPermissionControl.Default.GetPermissionOf(userHandle, fileId);
            if (permissionList.Contains(DMFuncPermissionEnum.Edit))
            {
                isAllow = true;
            }
            #endregion

            #region 获取文件路径
            DirLinkAddress dirLink = new DirLinkAddress(fileId);
            fileFullPath = dirLink.GetDocFullPath(modifyVerionId);
            #endregion

            #region 判断是否锁定文档,未锁定可以编辑
            #endregion

            #region 根据扩展名,确定打开方式
            string extName = dirLink.DocType;
            if (extName == ".doc" || extName == ".docx")
            {
                type = OpenModeType.docNormalEdit;
            }
            else if (extName == ".pptx" || extName == ".ppt")
            {
                type = OpenModeType.pptNormalEdit;
            }
            else if (extName == ".xlsx" || extName == ".xls")
            {
                type = OpenModeType.xlsNormalEdit;
            }
            else if (extName == ".txt")
            {
                ViewBag.Contents    = System.IO.File.ReadAllText(fileFullPath, FileEncoding.GetType(fileFullPath));
                ViewBag.FileId      = fileId;
                ViewBag.UserHandle  = userHandle;
                ViewBag.NewFileName = Guid.NewGuid().ToString() + extName;
                ViewBag.DirId       = dirId;
                ViewBag.DirType     = dirType;
                return(View("EditTxt"));
            }
            else
            {
                return(View("NoSupportError"));

                throw new Exception("无法打开该文件");
            }
            #endregion

            if (isAllow)
            {
                ViewBag.FileFullPath = fileFullPath;
                ViewBag.UserName     = personName;
                ViewBag.FileId       = fileId;
                ViewBag.DirId        = dirId;
                ViewBag.DirType      = dirType;

                ViewBag.OpenModeType = type;
                ViewBag.UserHandle   = userHandle;
                ViewBag.NewFileName  = Guid.NewGuid().ToString() + extName;
                ViewBag.IsChrome     = isChrome;
                return(View());
            }
            else
            {
                return(View("PermissionError"));

                throw new Exception("无编辑权限");
            }
        }