Exemple #1
0
    public bool GetUserFileList(string uid,int pageSize,int pageIndex,out string result)
    {
        var flag=false;
        result = string.Empty;

        if (string.IsNullOrEmpty(uid))
        {
            result="用户ID不能为空";
            return flag;
        }

        if (pageSize == 0)
        {
            pageSize = 10;
        }
        if (pageIndex == 0)
        {
            pageIndex = 1;
        }

        BllPdfFileInfoMangr bpfm = new BllPdfFileInfoMangr();
        List<UserPdfFileInfo> list=new List<UserPdfFileInfo>();
        StringBuilder sb = new StringBuilder();
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        ResultDataMangr reData = new ResultDataMangr();
        var strJoin = "&&";
        long pageCount=0;

        if (bpfm.GetPdfFileByUserID(uid, pageSize, pageIndex, out list, out pageCount, out result))
        {
            if (list != null || list.Count == 0)
            {
                result = "该用户还未上传任何文件!";
                return flag; ;
            }
            foreach (var file in list)
            {
                reData.result = true;
                reData.fileID = file.pdfFileID;
                reData.title = file.pdfFileName;
                reData.time = file.createTime.ToString();
                reData.author = file.pdfFileAuthor;

                sb.Append(serializer.Serialize(reData));
                sb.Append(strJoin);
            }
            sb.Append(pageCount);
        }

        return flag;
    }
Exemple #2
0
 private string pdf2String(ResultDataMangr reData)
 {
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     return serializer.Serialize(reData);
 }
Exemple #3
0
 /// <summary>
 /// 输出
 /// </summary>
 /// <param name="reData"></param>
 private void OutPut(ResultDataMangr reData)
 {
     JavaScriptSerializer serializer=new JavaScriptSerializer();
     string result = serializer.Serialize(reData);
     Response.ContentType = "text/html";
     Response.Write(result);
     Response.End();
 }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var uID = string.Empty;
        var extName = string.Empty;
        var pdfPath = Config.ReadSetting("SourcePath", "");
        var fileName = string.Empty;

        if (Request["uid"] == null && Request["uid"] == "")
        {
            ResultDataMangr reData = new ResultDataMangr() { result = false, errCode = "用户名为空!" };
            OutPut(reData);
        }
        uID = Request["uid"].ToString();
        var fileData = Request.Files["FileData"];
        ApplicationLog.WriteInfo("uid="+uID);
        if (fileData != null)
        {
            extName = fileData.FileName.Substring(fileData.FileName.LastIndexOf(".")).ToLower();
            var fileType = Config.ReadSetting("SourceFileter", "");

            if (!fileType.ToString().Contains(extName))
            {
                ResultDataMangr reData = new ResultDataMangr() { result = false, errCode = "文件类型错误,不支持该类型文件上传!" };
                OutPut(reData);
            }
            pdfPath =Server.MapPath("../pdfFile/source/") + uID;
            ApplicationLog.WriteInfo("pdfPath:"+pdfPath);
            if (!Directory.Exists(pdfPath))
            {
                Directory.CreateDirectory(pdfPath);
            }
            //DirectoryInfo dirInfo = new DirectoryInfo(pdfPath);
            //dirInfo.CreateSubdirectory(uID);
            fileName = fileData.FileName.Substring(0,fileData.FileName.LastIndexOf("."))+"-"+ DateTime.Now.Ticks.ToString();
            var filePath=pdfPath + "\\" + fileName + extName;
            fileData.SaveAs(filePath);//保存图片

            //往数据添加文件数据
            var msg=string.Empty;
            UserPdfFileInfo pdf = new UserPdfFileInfo();
            BllPdfFileInfoMangr bpfm = new BllPdfFileInfoMangr();

            pdf.pdfFileID = Guid.NewGuid().ToString();
            pdf.pdfFileAuthor = uID;
            pdf.pdfUserName = uID;
            pdf.pdfFileName = fileName;
            pdf.createTime = DateTime.Now.ToString("yyyy-MM-dd");
            pdf.pdfPath = filePath;

            if (!bpfm.AddPdfFileInfo(pdf, out msg))
            {
                msg = "往数据库写数据失败!";
                ApplicationLog.WriteError(msg);
            }

            ResultDataMangr resultData=new ResultDataMangr(){result=true,title=fileName,author=uID,time=pdf.createTime};
            var strData=pdf2String(resultData);
            ApplicationLog.WriteInfo("上传成功,Info"+strData);
            var strHtml = "<script type=\"text/javascript\">window.parent.Bing.templateData='"+strData+"'</script>";
            Context.Response.Write(strHtml);
            Context.Response.End();
        }
    }
Exemple #5
0
    public string GenerateImages(string fileId, string uid, string index, bool firstOr, string type)
    {
        if (string.IsNullOrEmpty(fileId))
        {
            return ResultData2String(new ResultDataMangr()
            {
                result = false,
                errCode = "文件名不能为空!"
            });
        }

        if (string.IsNullOrEmpty(uid))
        {
            return ResultData2String(new ResultDataMangr()
            {
                result = false,
                errCode = "用户名不能为空!"
            });
        }

        // 页码列表
        List<string> pageIndex = new List<string>();
        if (!string.IsNullOrEmpty(index))
        {
            pageIndex = index.Split(',').ToList<string>();
        }

        string pdfFilePath = Context.Server.MapPath("~/pdffile/source/" + uid + "/" + fileId + ".pdf");

        if (!System.IO.File.Exists(pdfFilePath))
        {
            return ResultData2String(new ResultDataMangr()
            {
                result = false,
                errCode = "PDF文件不存在!"
            });
        }

        string msg = string.Empty;

        // 获取 fileName
        string pdfFileName = string.Empty;
        var pdfInfo = new WebOS.PdfReader.BLL.BllPdfFileInfoMangr().GetPdfInfoByID(fileId);
        if (pdfInfo != null)
        {
            pdfFileName = pdfInfo.pdfFileName;
        }

        if (type == "simple")
        {
            if (pageIndex.Count > 0)
            {
                string thumbnailsUrl = Config.ReadSetting("ThumbnailsUrl", "");
                string thumbnailsDirPath = Context.Server.MapPath("~/pdffile/thumbnails/" + uid + "/");
                if (!System.IO.Directory.Exists(thumbnailsDirPath))
                    System.IO.Directory.CreateDirectory(thumbnailsDirPath);

                string thumbnailsFilePath = string.Empty;
                string thumbnailsUrlTemp = string.Empty;
                int pageCount = 0;
                Dictionary<int, string> dicPath = new Dictionary<int, string>();

                foreach (var p in pageIndex)
                {
                    thumbnailsFilePath = thumbnailsDirPath + fileId + "_" + p + ".jpeg"; // thumb 磁盘路径
                    thumbnailsUrlTemp = thumbnailsUrl + uid + "/" + fileId + "_" + p + ".jpeg"; // thumb url
                    if (!System.IO.File.Exists(thumbnailsFilePath))
                    {
                        if (ImageTools.ConvertPDF2Thumbnails(
                            pdfFilePath,
                            thumbnailsFilePath,
                            fileId,
                            int.Parse(p),
                            int.Parse(p),
                            System.Drawing.Imaging.ImageFormat.Jpeg,
                            ImageTools.Definition.Two,
                            out pageCount))
                        {
                            msg = "图片已生成!";
                        }
                    }
                    else
                    {
                        pageCount = ImageTools.GetPDF2ImageCount(pdfFilePath);
                    }
                    dicPath.Add(Convert.ToInt32(p), thumbnailsUrlTemp);
                }

                System.Text.StringBuilder sb = DictionaryToStr(dicPath);
                sb.Remove(sb.Length - 2, 2);
                ResultDataMangr outData = null;
                if (firstOr == true)
                {
                    outData = new ResultDataMangr()
                    {
                        result = true,
                        index = index,
                        title = pdfFileName,
                        allNumber = pageCount.ToString(),
                        author = uid,
                        pageContent = sb.ToString()
                    };
                }
                else
                {
                    outData = new ResultDataMangr() { result = true, index = index, pageContent = sb.ToString() };
                }
                return ResultData2String(outData);
            }
        }
        else if (type == "rich")
        {
            if (pageIndex.Count > 0)
            {
                var thumbnailsName = string.Empty;
                byte[] list = null;
                var pageCount = 0;
                Dictionary<int, byte[]> dicPath = new Dictionary<int, byte[]>();

                if (!File.Exists(pdfFilePath))
                {
                    return ResultData2String(new ResultDataMangr() { result = false, errCode = "该PDF文件不存在!" });
                }

                foreach (var p in pageIndex)
                {
                    if (ImageTools.ConvertPDF2Image(
                        pdfFilePath,
                        Convert.ToInt32(p),
                        Convert.ToInt32(p),
                        ImageFormat.Jpeg,
                        ImageTools.Definition.Two,
                        out list,
                        out pageCount))//生成图片
                    {
                        dicPath.Add(Convert.ToInt32(p), list);
                    }
                    else
                    {
                        msg = "生成图片错误!";
                        ApplicationLog.WriteError(msg);
                    }
                }

                StringBuilder sb = DictionaryToStr(dicPath);
                sb.Remove(sb.Length - 2, 2);//移除末尾的"&&"
                ResultDataMangr outData = null;
                if (firstOr == true)
                {
                    outData = new ResultDataMangr()
                    {
                        result = true,
                        index = index,
                        allNumber = pageCount.ToString(),
                        title = pdfFileName,
                        fileID=fileId,
                        author = uid,
                        pageContent = sb.ToString()
                    };
                }
                else
                {
                    outData = new ResultDataMangr() { result = true, index = index, pageContent = sb.ToString() };
                }

                ApplicationLog.WriteInfo(sb.ToString());

                return ResultData2String(outData);
            }
        }

        return ResultData2String(new ResultDataMangr()
            {
                result = false,
                errCode = "未知错误!"
            });
    }
Exemple #6
0
 private string ResultData2String(ResultDataMangr resultData)
 {
     return new JavaScriptSerializer().Serialize(resultData);
 }
Exemple #7
0
    public string FileList(string uid, int pageSize, int pageIndex)
    {
        ResultDataMangr result = new ResultDataMangr();
        if (string.IsNullOrEmpty(uid))
        {
            return resultData2String(new ResultDataMangr()
            {
                result = false,
                errCode = "用户ID不能为空!"
            });
        }

        if (pageSize <= 0)
        {
            pageSize = 10;
        }
        if (pageIndex <= 0)
        {
            pageIndex = 1;
        }

        List<UserPdfFileInfo> list = new List<UserPdfFileInfo>();
        long pageCount = 0;
        var msg = string.Empty;
        List<ResultDataMangr> items = new List<ResultDataMangr>();

        if (new BllPdfFileInfoMangr().GetPdfFileByUserID(uid, pageSize, pageIndex, out list, out pageCount, out msg))
        {
            if (list == null || list.Count == 0)
            {
                return resultData2String(new ResultWrapper()
                {
                    ErrorCode = "该用户还未上传任何文件!",
                    IsError = true,
                    Item = null,
                    PageCount = 0
                });
            }

            foreach (var file in list)
            {
                ResultDataMangr reData = new ResultDataMangr();
                reData.result = true;
                reData.fileID = file.pdfFileID;
                reData.title = file.pdfFileName;
                reData.time = file.createTime.ToLocalTime().ToString();
                reData.author = file.pdfFileAuthor;
                items.Add(reData);
            }
        }
        else
        {
            return resultData2String(new ResultWrapper()
            {
                ErrorCode = "获取该用户数据出错!",
                IsError = true,
                Item = null,
                PageCount = 0
            });
        }

        return resultData2String(new ResultWrapper()
        {
            ErrorCode = string.Empty,
            IsError = false,
            Item = items,
            PageCount = Convert.ToInt32(pageCount)
        });
    }