Example #1
0
        private void HandleDocumentToImg(string filePath, string fullFileName, string imgType, ProgressNotice noticeCallback, int rowIndex)
        {
            Document pdfDocument = new Document(filePath);
            var      pageCount   = pdfDocument.Pages.Count;
            var      realPercent = 0.0;

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                realPercent += (double)100 / pageCount;
                using (FileStream imageStream = new FileStream(fullFileName + "\\" + pageIndex + imgType,
                                                               FileMode.Create))
                {
                    Resolution resolution = new Resolution(300);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                    jpegDevice.Process(pdfDocument.Pages[pageIndex], imageStream);
                    imageStream.Close();
                }
                if (pageIndex == pdfDocument.Pages.Count)
                {
                    realPercent = 100;
                }
                var noticeResult = new NoticeResult
                {
                    Success   = true,
                    rowIndex  = rowIndex,
                    pageIndex = pageIndex,
                    per       = (int)realPercent
                };
                this.Invoke(noticeCallback, noticeResult);
            }
        }
Example #2
0
        /// <summary>
        /// 开始转换
        /// </summary>
        public void StartConvert(object p)
        {
            var savePath   = _mainForm.LbllblSavePath.Text;
            var parameters = p as List <object>;

            _convertingtablerowIndex = Convert.ToInt32(parameters[0]);
            var             noticeAction          = parameters[1];
            var             convertCompleteAction = parameters[2];
            ConvertComplete completedCalback      = convertCompleteAction as ConvertComplete;
            ProgressNotice  noticeCallback        = noticeAction as ProgressNotice;
            var             imgType = parameters[3].ToString();

            foreach (Row row in this.tableFiles.TableModel.Rows)
            {
                var filePath     = row.Cells[FilePathColIndex].Text;
                var fileName     = row.Cells[FileNameColIndex].Text;
                var fullFileName = Path.Combine(savePath, fileName.Contains(".") ?
                                                fileName.Remove(fileName.LastIndexOf(".")) : fileName);
                if (!Directory.Exists(fullFileName))
                {
                    Directory.CreateDirectory(fullFileName);
                }

                try
                {
                    row.Tag = ConvertState.Converting;
                    HandleDocumentToImg(filePath, fullFileName, imgType, noticeCallback, _convertingtablerowIndex);
                }
                catch (Exception ex)
                {
                    row.Tag = ConvertState.NotConvert;
                    if (ex is InvalidPasswordException)
                    {
                        var noticeResult = new NoticeResult
                        {
                            Success = false,
                            ErrMsg  = $"文件\n{fileName}\n是加密文件,请先解密!"
                        };
                        this.Invoke(noticeCallback, noticeResult);
                    }
                    else
                    {
                        throw;
                    }
                }
                //标志为转换完成
                if ((ConvertState)row.Tag == ConvertState.Converting)
                {
                    row.Tag = ConvertState.Converted;
                }
                _convertingtablerowIndex++;
            }
            this.Invoke(completedCalback);
            convertThread = null;
        }
Example #3
0
 public void ProgressAction(NoticeResult result)
 {
     if (result.Success)
     {
         try
         {
             this.tableFiles.TableModel.Rows[result.rowIndex].Cells[ProgressColIndex].Data = result.per;
         }
         catch (Exception)
         {
             convertThread.Abort();
         }
     }
     else
     {
         YMessageBox.ShowMsgBox(150, result.ErrMsg);
     }
 }
Example #4
0
        public JsonResult GetLastNotice()
        {
            NoticeResult res = new NoticeResult();
            Notice       n   = NoticeLogic.GetLastNotice();

            if (n != null)
            {
                res.State           = State.Success;
                res.Title           = n.Title;
                res.Content         = n.Content;
                res.CreatedUserName = n.CreateUserName;
                res.Created         = n.Created.Value.ToString("yyyy-MM-dd");
            }
            else
            {
                res.State = State.Falid;
            }
            return(Json(res));
        }
Example #5
0
 public Projection(NoticeResult notice)
 {
     PublicationDate = notice.PublicationDate;
     EditionNumber   = notice.EditionNumber;
 }