Пример #1
0
 private void PDFViewer_Disposed(object sender, EventArgs e)
 {
     if (pdfDoc != null)
     {
         pdfDoc.Dispose();
     }
 }
Пример #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (_pdfDoc != null)
     {
         _pdfDoc.Dispose();
         _pdfDoc = null;
     }
 }
Пример #3
0
        public SigmaResultType AddDrawingImage(string sourcePath, string targetPath)
        {
            SigmaResultType result = new SigmaResultType();
            TransactionScope scope = null;

            TypeUserInfo userinfo = AuthMgr.GetUserInfo();

            //PDFLibNet.PDFWrapper pdfDoc;

            PDFLibNet.PDFWrapper pdfDoc = new PDFLibNet.PDFWrapper();

            ////       target directory 는 쿠키 값 확인하여 추가 경로를 생성해야 된다.
            ////       추가 경로 --> [company]/[project id]/[document type]/[document name(id)]/[document revision]
            //string targetChildPath = "Company\\" + "Project\\" + "Drawing\\";

            string targetChildPath = userinfo.CompanyName + "\\" + userinfo.CurrentProjectId + "\\" + "Drawing\\";

            targetPath = targetPath + targetChildPath;

            // Source Path에서 읽고 확인 후 정상이면 Target Path로 이동
            string[] filePaths = Directory.GetFiles(sourcePath);

            // Get connection string
            string connStr = ConnStrHelper.getDbConnString();

            // * [1] Image file upload - multiple files
            foreach (string path in filePaths)
            {

                string convertfilepath = string.Empty;
                string Importedfilename = Path.GetFileNameWithoutExtension(path);
                FileInfo fileinfo = new FileInfo(path);
                long fileSize = fileinfo.Length; // byte
                string fileExtention = Path.GetExtension(path);
                string fileType = "FILE_TYPE_DRAWING";
                string CreateBy = userinfo.SigmaUserId;

                int fileStroeId;
                int fileId;

                string fileCategory = "FILE_CATEGORY_DRAWING";

                if (fileExtention == ".pdf" || fileExtention == ".PDF")
                {
                    // pdf --> jpg 로 변경해서 등록
                    pdfDoc.LoadPDF(path);
                    //pdfDoc.RenderPage();
                    convertfilepath = targetPath + Importedfilename + ".jpg";
                    //pdfDoc.ExportJpg(@"c:\temp\page_pdf%d.jpg", 1, 1, 150, 90);
                    //*** waitpoc  --> 동기화, 비동기화 --> 기다릴 거냐?
                    pdfDoc.ExportJpg(convertfilepath, 1, 1, 150, 90, 1);

                    //** Dispose 시점을 늦춰 본다.. 아래 foreach end 시점  -- Object X  foreach 밖으로 사용 후에 처리 할 것
                    //pdfDoc.Dispose()

                }
                else if (fileExtention == ".xls" || fileExtention == ".xlsx")
                    continue;

                //---------------------------------------------------------------------------

                SqlParameter[] fileStoreParm = new SqlParameter[] {
                    new SqlParameter("@FileStoreID", SqlDbType.Int, 10), // sp에서 output 설정했을 경우
                    new SqlParameter("@Title", Importedfilename),
                    new SqlParameter("@Description", Importedfilename),
                    new SqlParameter("@Category", fileCategory),
                    new SqlParameter("@TypeCode", fileType),
                    new SqlParameter("@CreatedBy", CreateBy),
                    new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                };

                fileStoreParm[0].Direction = ParameterDirection.Output;
                fileStoreParm[6].Direction = ParameterDirection.ReturnValue;

                // 하나의 TransctionScope으로..
                using (scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddFileStoreDrawing", fileStoreParm);

                    fileStroeId = (int)fileStoreParm[0].Value;
                    int AffectedRow = (int)fileStoreParm[6].Value;

                    string targetFilePath = targetChildPath + Importedfilename + ".jpg";

                    // Compose parameters
                    SqlParameter[] uploadfileParm = new SqlParameter[] {
                        new SqlParameter("@UploadedFileInfoId", SqlDbType.Int, 10), // sp에서 output 설정했을 경우
                        new SqlParameter("@FileStoreID", fileStroeId),
                        new SqlParameter("@Name", Importedfilename),
                        new SqlParameter("@Size", fileSize),
                        //new SqlParameter("@Path", path),
                        new SqlParameter("@Path", targetFilePath),
                        new SqlParameter("@FileExtension", fileExtention),
                        new SqlParameter("@Revision", "None"),
                        new SqlParameter("@FileType", fileType),
                        new SqlParameter("@CreatedBy", CreateBy),
                        new SqlParameter("RETURN_VALUE",SqlDbType.Int) // sp에서 return 값을 설정했을경우 사용
                    };

                    uploadfileParm[0].Direction = ParameterDirection.Output;
                    uploadfileParm[9].Direction = ParameterDirection.ReturnValue;

                    result.AffectedRow = SqlHelper.ExecuteNonQuery(connStr, CommandType.StoredProcedure, "usp_AddUploadedFileInfoDrawing", uploadfileParm);

                    fileId = (int)uploadfileParm[0].Value;
                    int uploadAffectedRow = (int)uploadfileParm[9].Value;

                    scope.Complete();
                }

            }

            pdfDoc.Dispose();
            pdfDoc = null;

            // * [2] To Copy all the files (in source directory -> to target directory)

            //MemoryStream destination = new MemoryStream();

            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            if (System.IO.Directory.Exists(sourcePath))
            {
                string[] sourcefilePaths = Directory.GetFiles(sourcePath);
                foreach (string sourceFile in sourcefilePaths)
                {
                    string sourcefilename = Path.GetFileNameWithoutExtension(sourceFile);
                    string fileExtention = Path.GetExtension(sourceFile);
                    //string sourceFile = System.IO.Path.Combine(sourcePath, sourcefilename);

                    string destFile = System.IO.Path.Combine(targetPath, sourcefilename + fileExtention);
                    try
                    {

                        // *** converted jpg File
                        string strSavePath = targetPath + sourcefilename + ".jpg";

                        // Thumbnail 비율 적용 - 원본 이미지의  가로:세율 비율 확인 - 축소 길이 - 가로 고정 - 200)
                        System.IO.Stream imgstream = File.Open(strSavePath, FileMode.Open);
                        System.Drawing.Image sourceImage = System.Drawing.Image.FromStream(imgstream);

                        float orgheight = sourceImage.PhysicalDimension.Height;
                        float orgwidth = sourceImage.PhysicalDimension.Width;
                        int newwidth = 200;

                        float newheight = orgheight / orgwidth * newwidth;

                        System.Drawing.Image thumbnailImage = sourceImage.GetThumbnailImage(newwidth, (int)newheight, null, IntPtr.Zero);
                        thumbnailImage.Save(targetPath + sourcefilename + ".thumbnail" + ".jpg");

                        imgstream.Dispose();

                        //  pdf file copy to DocumentFolderRoot
                        System.IO.File.Copy(sourceFile, destFile, true);

                    }
                    catch (System.IO.IOException copye)
                    {
                        //Console.WriteLine(copye.Message);
                        result.ErrorMessage = copye.Message + " copy error";
                        result.IsSuccessful = false;
                        return result;
                    }
                }
            }
            else
            {
                //Console.WriteLine("Source path does not exist!");
                result.ErrorMessage = "Source path : " + sourcePath + " does not exist!";
                result.IsSuccessful = false;
                return result;
            }

            // * [3] Delete source files - optional
            try
            {
                string[] sourcefilePaths = Directory.GetFiles(sourcePath);
                foreach (string sourceFile in sourcefilePaths)
                {
                    System.IO.File.Delete(sourceFile);
                }
            }
            catch (System.IO.IOException dele)
            {
                //Console.WriteLine(dele.Message);
                result.ErrorMessage = dele.Message + " delete error";
                result.IsSuccessful = false;
                return result;
            }

            result.IsSuccessful = true;
            return result;
        }
Пример #4
0
 private void PreviewForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     pdfDoc.Dispose();
 }