コード例 #1
0
        /// <summary>
        /// 新增新的附件元素
        /// </summary>
        /// <returns>The new attachment.</returns>
        /// <param name="type">Type.</param>
        public Attachment GetNewAttachment(AttachmentTypeEnum type)
        {
            string identifier = DateTime.Now.Ticks.ToString();
            var    rectPoint  = new ImageRectPoint();
            string systemPath = string.Empty;

            if (type == AttachmentTypeEnum.Note)
            {
            }
            else
            {
                systemPath = string.Empty;
                Bitmap saveBitmap = type == AttachmentTypeEnum.Paint ? drawRectLineBitmap : CameraApp.bitmap;
                systemPath       = getSaveImageLocalSystemPath(identifier, type, saveBitmap);
                rectPoint.LeftX  = type == AttachmentTypeEnum.Paint ? drawLineView.GetRectLeftX() : cameraImageView.GetX() + 600;
                rectPoint.TopY   = type == AttachmentTypeEnum.Paint ? drawLineView.GetRectTopY() : drawLineView.GetY() + 250;
                rectPoint.Width  = type == AttachmentTypeEnum.Paint ? drawLineView.Width : 150;
                rectPoint.Height = type == AttachmentTypeEnum.Paint ? drawLineView.Height : 75;
                string filePath = System.IO.Path.Combine(DocumentPath, systemPath);
            }

            Attachment newAttachment = new Attachment();

            newAttachment.Name      = identifier;
            newAttachment.PageIndex = PageNumber;
            newAttachment.Note      = string.Empty;
            newAttachment.Type      = type;
            newAttachment.Path      = systemPath;
            newAttachment.Width     = (int)rectPoint.Width;
            newAttachment.Height    = (int)rectPoint.Height;
            newAttachment.X         = (float)rectPoint.LeftX;
            newAttachment.Y         = (float)rectPoint.TopY;

            return(newAttachment);
        }
コード例 #2
0
        public void CreateNewUIViewHandle(AttachmentTypeEnum type)
        {
            //建立新的附件物件
            Attachment newAttachment = GetNewAttachment(type);

            //根據Attachment物件,建立UIView物件
            CreateUIView(newAttachment);
            //編輯Attachment物件
            EditDocumentAttachments(newAttachment);
            //儲存至Json檔
            SaveJsonData();
        }
コード例 #3
0
        /// <summary>
        /// Converts a AttachmentTypeEnum value to a corresponding string value
        /// </summary>
        /// <param name="enumValue">The AttachmentTypeEnum value to convert</param>
        /// <returns>The representative string value</returns>
        public static string ToValue(AttachmentTypeEnum enumValue)
        {
            switch (enumValue)
            {
            //only valid enum elements can be used
            //this is necessary to avoid errors
            case AttachmentTypeEnum.ENUM_IMAGE_PDF:
                return(StringValues[(int)enumValue]);

            //an invalid enum value was requested
            default:
                return(null);
            }
        }
コード例 #4
0
        private string getSaveImageLocalSystemPath(string IdentifierName, AttachmentTypeEnum savetype, Bitmap image)
        {
            string SAVE_FILE_NAME     = string.Format("{0}.{1}", IdentifierName, savetype == AttachmentTypeEnum.Photo ? "jpg" : "png");
            string SYSTEM_FILE_PATH   = System.IO.Path.Combine(PDF_RECORD_DIR, SAVE_FILE_NAME);
            var    documentsDirectory = System.IO.Path.Combine(DocumentPath, PDF_RECORD_DIR);

            if (!Directory.Exists(documentsDirectory))
            {
                Directory.CreateDirectory(documentsDirectory);
            }

            string saveFilePath = System.IO.Path.Combine(documentsDirectory, SAVE_FILE_NAME);

            saveBitmapFile(saveFilePath, image);
            if (!System.IO.File.Exists(saveFilePath))
            {
                SYSTEM_FILE_PATH = string.Empty;
            }
            return(SYSTEM_FILE_PATH);
        }
コード例 #5
0
        /// <summary>
        /// 新增新的附件元素
        /// </summary>
        /// <returns>The new attachment.</returns>
        /// <param name="type">Type.</param>
        public Attachment GetNewAttachment(AttachmentTypeEnum type)
        {
            string identifier = DateTime.Now.Ticks.ToString();
            UIView uiview     = new UIView();
            string systemPath = string.Empty;

            if (type == AttachmentTypeEnum.Note)
            {
                uiview.Frame = new CGRect(scrollView.Center.X, scrollView.Center.Y, 100, 100);
            }
            else
            {
                if (type == AttachmentTypeEnum.Paint)
                {
                    uiview.Frame = new CGRect(path.BoundingBox.Location, path.BoundingBox.Size);
                }
                else
                {
                    uiview.Frame = new CGRect(scrollView.Center.X, scrollView.Center.Y, 225, 225);
                }

                UIImage saveUImage = type == AttachmentTypeEnum.Paint ? GetCropImage(DrawImageView.Image, path.BoundingBox) : photo;
                systemPath = getSaveImageLocalSystemPath(identifier, type, saveUImage);
            }

            Attachment newAttachment = new Attachment();

            newAttachment.Name      = identifier;
            newAttachment.PageIndex = PageNumber;
            newAttachment.Note      = string.Empty;
            newAttachment.Type      = type;
            newAttachment.Path      = systemPath;
            newAttachment.Width     = uiview.Frame.Width;
            newAttachment.Height    = uiview.Frame.Height;
            newAttachment.X         = uiview.Frame.Location.X;
            newAttachment.Y         = uiview.Frame.Location.Y;

            return(newAttachment);
        }
コード例 #6
0
        private string getSaveImageLocalSystemPath(string IdentifierName, AttachmentTypeEnum savetype, UIImage uiimage)
        {
            string SAVE_FILE_NAME     = string.Format("{0}.{1}", IdentifierName, savetype == AttachmentTypeEnum.Photo ? "jpg" : "png");
            string SYSTEM_FILE_PATH   = Path.Combine(PDF_RECORD_DIR, SAVE_FILE_NAME);
            var    documentsDirectory = Path.Combine(DocumentPath, PDF_RECORD_DIR);

            if (!Directory.Exists(documentsDirectory))
            {
                Directory.CreateDirectory(documentsDirectory);
            }

            #region save to Local Photo

            /*
             * ALAssetsLibrary library = new ALAssetsLibrary();
             * library.WriteImageToSavedPhotosAlbum(photo.CGImage, meta, (assetUrl, error) =>
             * {
             *      Debug.WriteLine(assetUrl);
             * });
             */
            #endregion

            string saveFilePath = Path.Combine(documentsDirectory, SAVE_FILE_NAME);

            using (NSData imageData = savetype == AttachmentTypeEnum.Paint ? uiimage.AsPNG() : uiimage.AsJPEG())
            {
                NSError err = null;
                imageData.Save(
                    saveFilePath,
                    NSDataWritingOptions.Atomic,
                    out err
                    );
            }
            if (!File.Exists(saveFilePath))
            {
                SYSTEM_FILE_PATH = string.Empty;
            }
            return(SYSTEM_FILE_PATH);
        }
コード例 #7
0
        /// <summary>
        /// Adding attachment to DB
        /// </summary>
        /// <param name="type">Attachment type</param>
        /// <param name="applicationId">Main application id</param>
        /// <param name="attachments">List of new attachment that will be saved to db</param>
        /// <param name="attachmentBlock">Block that contains all attachment list</param>
        public void AddAttachments(AttachmentTypeEnum type, int applicationId, List<Attachment> attachments, AttachmentBlock attachmentBlock)
        {
            var dbModel = this.databaseHelper.Get<ApplicationForm>(o => o.ApplicationFormId == applicationId);

            dbModel.Attachments.AddRange(attachments.Select(s => s.ToDbModel(applicationId)));

            if (attachmentBlock != null && attachmentBlock.Attachments != null)
            {
                foreach (var attachment in attachmentBlock.Attachments)
                {
                    var att = dbModel.Attachments.FirstOrDefault(f => f.ServerFileName == attachment.ServerFileName);

                    if (att != null)
                    {
                        att.Description = attachment.Description;
                        att.DocumentName = attachment.DocumentName;
                    }
                }
            }

            this.databaseHelper.Update(dbModel);
        }
コード例 #8
0
        public async Task <string> ExportCV(long userId, AttachmentTypeEnum typeOffile, bool isHiddenYear)
        {
            var userInfor = await _myProfileAppService.GetUserGeneralInfo(userId);

            var fileName = $"CV_{userInfor.Surname}{userInfor.Name}_{userId}";
            var path     = SetLinkForSaveFile(fileName);
            var doc      = DocX.Create(path);

            doc.SetDefaultFont(new Xceed.Document.NET.Font("Times new roman"));
            CreateHeaderAndFooter(doc);

            Formatting formatting = new Formatting();

            formatting.Bold = true;
            formatting.Size = 14;

            doc.InsertParagraph("Professional Resume", false, formatting).SpacingBefore(5).Alignment = Alignment.right;
            doc.InsertParagraph($"Last updated: {DateTime.Now.ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-US"))}").FontSize(12).SpacingBefore(5).Alignment = Alignment.right;

            CreateContactDetails(doc, userInfor);
            doc.InsertParagraph().SpacingAfter(20);
            await CreateEducationBackground(doc, userId, isHiddenYear);

            doc.InsertParagraph().SpacingAfter(20);
            await CreateTechnicalExpertises(doc, userId);

            doc.InsertParagraph().SpacingAfter(20);
            await CreatePersonalAtributes(doc, userId);

            doc.InsertParagraph().SpacingAfter(20);
            await CreateWorkingExperiences(doc, userId);

            doc.Save();

            var fileDownloadName = GetFileDownLoadType(path, fileName, typeOffile);

            return(fileDownloadName);
        }
コード例 #9
0
        public string GetFileDownLoadType(string path, string fileName, AttachmentTypeEnum typeOffile)
        {
            string fileDownloadName;
            var    folder            = RootConstant.Documents;
            var    filePath          = Path.Combine(_hostingEnvironment.WebRootPath, folder);
            var    ServerRootAddress = RootConstant.ServerRootAddress;

            filePath = Path.GetFullPath(filePath);
            var filePDF = Path.Combine(filePath, fileName + ".pdf");
            RichEditDocumentServer server = new RichEditDocumentServer();

            server.LoadDocument(path);
            server.ExportToPdf(filePDF);
            if (typeOffile == AttachmentTypeEnum.DOCX)
            {
                fileDownloadName = $"{ServerRootAddress}{folder}{fileName}.docx";
            }
            else
            {
                fileDownloadName = $"{ServerRootAddress}{folder}{fileName}.pdf";
            }
            return(fileDownloadName);
        }
コード例 #10
0
        public static SortAttachmentObject AddAttachment(int sortMainId, string fileName, string description, AttachmentTypeEnum attachmentType, int?size)
        {
            var sao = new SortAttachmentObject()
            {
                SortMainId         = sortMainId,
                FileName           = fileName,
                Note               = description,
                AttachmentTypeEnum = attachmentType,
                IsDeleted          = false,
                Size               = CalcSize(size)
            };

            sao.Save();

            return(sao);
        }
コード例 #11
0
 public AttachmentTypeEf(AttachmentTypeEnum @enum)
 {
     Id   = (int)@enum;
     Name = @enum.GetDescription();
 }
コード例 #12
0
 public virtual ActionResult UploadFile(AttachmentTypeEnum attachmentType, int applicationId, AttachmentBlock model)
 {
     return FileSaver.UploadFile(
         this,
         MVC.OLE.ActionNames.DeleteFile,
         MVC.OLE.ActionNames.DownloadFile,
         attachmentType,
         businessLogic,
         applicationId,
         model);
 }
コード例 #13
0
        /// <summary>
        /// File saving logic to save files to DB and file system
        /// </summary>
        /// <param name="controller">Controller that contains data about uploaded files</param>
        /// <param name="deleteActionUrl">Url that will be used in file deletion</param>
        /// <param name="downloadActionUrl">Url that will be used in file downloading</param>
        /// <param name="attachmentType">Type of attachment block</param>
        /// <param name="attachmentLogic">Logic to have posibility save file information to DB</param>
        /// <param name="applicationId">Main application Id</param>
        /// <param name="attachmentBlock">Attachment block that contains data about all block files</param>
        public static ActionResult UploadFile(BaseController controller, string deleteActionUrl, string downloadActionUrl, AttachmentTypeEnum attachmentType, IAttachmentLogic attachmentLogic, int applicationId, AttachmentBlock attachmentBlock)
        {
            // here we can send in some extra info to be included with the delete url
            var statuses = new List<ViewDataUploadFileResult>();
            for (var i = 0; i < controller.Request.Files.Count; i++)
            {
                var st = StoreFile(new FileSaveModel()
                {
                    File = controller.Request.Files[i],
                    // note how we are adding an additional value to be posted with delete request

                    // and giving it the same value posted with upload
                    DeleteUrl = controller.Url.Action(deleteActionUrl, new { attachmentType }),
                    StorageDirectory = controller.Server.MapPath("~/Content/uploads"),
                    UrlPrefix = ResolveServerUrl(VirtualPathUtility.ToAbsolute("~/Content/uploads"), false), // this is used to generate the relative url of the file

                    // overriding defaults
                    FileName = controller.Request.Files[i].FileName, // default is filename suffixed with filetimestamp
                    ThrowExceptions = true // default is false, if false exception message is set in error property
                });

                statuses.Add(st);
            }

            // statuses contains all the uploaded files details (if error occurs then check error property is not null or empty)
            // todo: add additional code to generate thumbnail for videos, associate files with entities etc

            // adding thumbnail url for jquery file upload javascript plugin
            statuses.ForEach(x => x.ThumbnailUrl = x.Url + string.Empty); // uses ImageResizer httpmodule to resize images from this url

            // setting custom download url instead of direct url to file which is default
            statuses.ForEach(x => x.Url = controller.Url.Action(downloadActionUrl, new { fileUrl = x.Url, mimetype = x.FileType }));

            var viewresult = controller.JsonPublic(new { files = statuses });
            // for IE8 which does not accept application/json
            if (controller.Request.Headers["Accept"] != null && !controller.Request.Headers["Accept"].Contains("application/json"))
            {
                viewresult.ContentType = "text/plain";
            }

            var attachments = new List<Attachment>();
            List<Attachment> newAttachments = null;

            if (attachmentBlock != null && attachmentBlock.Attachments != null)
            {
                newAttachments =
                    attachmentBlock.Attachments.Where(a => string.IsNullOrEmpty(a.ServerFileName)).ToList();
            }

            foreach (var viewDataUploadFileResult in statuses)
            {
                var idx = statuses.IndexOf(viewDataUploadFileResult);

                if (newAttachments != null && newAttachments.Count != 0)
                {
                    viewDataUploadFileResult.Description = newAttachments[idx].Description;
                    viewDataUploadFileResult.DocumentName = newAttachments[idx].DocumentName;
                    newAttachments[idx].ServerFileName = viewDataUploadFileResult.SavedFileName;
                }

                attachments.Add(new Attachment()
                {
                    FileName = viewDataUploadFileResult.Name,
                    ServerFileName = viewDataUploadFileResult.SavedFileName,
                    AttachmentType = attachmentType
                });
            }

            attachmentLogic.AddAttachments(attachmentType, applicationId, attachments, attachmentBlock);

            return viewresult;
        }