Example #1
0
        /// <summary>
        /// 修改书本图片使用次数
        /// </summary>
        /// <param name="pdata"></param>
        /// <param name="bookid"></param>
        /// <param name="isReduce"></param>
        /// <returns></returns>
        public static BaseResponse ChangeImageUsedNum(XElement pdata, int bookid, bool isReduce, ref List <int> imageids)
        {
            BaseResponse br = new BaseResponse();

            br.IsSuccess = false;
            try
            {
                int         baseNum = isReduce ? -1 : 1;
                PageDataObj pageObj = (PageDataObj)SerializeXmlHelper.DeserializeFromXml(pdata, typeof(PageDataObj));
                if (pageObj.image != null)
                {
                    foreach (PageImage img in pageObj.image)
                    {
                        Inpinke_Book_Image model = InpinkeDataContext.Instance.Inpinke_Book_Images.Get(e => e.BookID == bookid && e.ImageID == img.imageid);
                        if (model != null)
                        {
                            model.UsedNum += baseNum;
                            if (model.UsedNum < 0)
                            {
                                model.UsedNum = 0;
                            }
                            if (isReduce && model.UsedNum == 0)
                            {
                                imageids.Add(model.ImageID);
                            }
                            else if (!isReduce && model.UsedNum == 1)
                            {
                                imageids.Add(model.ImageID);
                            }
                            model.SaveWhenSubmit(InpinkeDataContext.Instance);
                        }
                    }
                    InpinkeDataContext.Instance.Submit();
                }
                br.IsSuccess = true;
                return(br);
            }
            catch (Exception ex)
            {
                br.IsSuccess = false;
                br.Message   = "修改书本图片使用次数失败,请稍后再试";
                Logger.Error(string.Format("ChangeImageUsedNum BookID:{0},Error:{1}", bookid, ex.ToString()));
                return(br);
            }
        }
Example #2
0
        /// <summary>
        /// 生成书本pdf
        /// </summary>
        /// <param name="bookid"></param>
        /// <returns></returns>
        public static bool CreateBookPDF(int bookid)
        {
            Inpinke_Book model   = DBBookBLL.GetBookByID(bookid);
            string       pdfname = FilterSpecial(model.BookName);

            pdfname = OutPath + pdfname + "-" + model.ID + "-intime.pdf";
            PDFProcessBLL pdfProcess = new PDFProcessBLL(PageWidth + 2 * TrimLineLength, PageHeight + 2 * TrimLineLength, pdfname);

            try
            {
                IList <Inpinke_Book_Page> pages = DBBookBLL.GetBookPage(bookid);
                pdfProcess.PaintScale = PaintScale;
                if (pages != null)
                {
                    pages = pages.OrderBy(e => e.PageNum).ToList();


                    pdfProcess.doc.Open();
                    float boneWidth = backboneWidth * model.PageCount;
                    pdfProcess.FlodPageWidth    = flodPageWidth;
                    pdfProcess.BackBoneWidth    = boneWidth;
                    pdfProcess.SinglePageWidth  = PageWidth;
                    pdfProcess.SinglePageHeight = PageHeight;
                    for (int i = 0; i <= model.PageCount; i++)
                    {
                        Inpinke_Book_Page p = pages.Where(e => e.PageNum == i).SingleOrDefault();
                        if (p == null)
                        {
                            pdfProcess.PageWidth  = PageWidth + 2 * TrimLineLength;
                            pdfProcess.PageHeight = PageHeight + 2 * TrimLineLength;
                            pdfProcess.doc.SetPageSize(new iTextSharp.text.Rectangle(pdfProcess.PageWidth, pdfProcess.PageHeight));
                            pdfProcess.doc.NewPage();
                            pdfProcess.PaintTirmLine();
                        }
                        else
                        {
                            float pWidth = PageWidth;
                            if (p.IsSkip)
                            {
                                pWidth = PageWidth * 2;
                                if (i != 0)
                                {
                                    i++;
                                }
                            }
                            else if (i != 1 && i != model.PageCount)
                            {
                                pWidth = PageWidth * 2;
                            }
                            if (i == 0)
                            {
                                //封面和封底和折页书脊总宽度
                                pWidth = PageWidth * 2 + flodPageWidth * 2 + boneWidth;
                            }

                            pdfProcess.PageWidth  = pWidth + 2 * TrimLineLength;
                            pdfProcess.PageHeight = PageHeight + 2 * TrimLineLength;
                            pdfProcess.doc.SetPageSize(new iTextSharp.text.Rectangle(pdfProcess.PageWidth, pdfProcess.PageHeight));
                            pdfProcess.doc.NewPage();
                            pdfProcess.PaintTirmLine();
                            PageDataObj pageObj = (PageDataObj)SerializeXmlHelper.DeserializeFromXml(p.PageData, typeof(PageDataObj));
                            pdfProcess.PaintPage(pageObj, 0);
                            if (!p.IsSkip && i != 1 && i != model.PageCount)
                            {
                                p = pages.Where(e => e.PageNum == i + 1).SingleOrDefault();
                                if (p != null)
                                {
                                    pageObj = (PageDataObj)SerializeXmlHelper.DeserializeFromXml(p.PageData, typeof(PageDataObj));
                                    pdfProcess.PaintPage(pageObj, PageWidth);
                                    i++;
                                }
                            }
                        }
                    }
                    pdfProcess.doc.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                pdfProcess.doc.Close();
                Logger.Error(string.Format("CreateBookPDF BookID:{0},Error:{1}", bookid, ex.ToString()));
                return(false);
            }
        }