protected void cmdUpload_Command(Object sender, CommandEventArgs e) { if (null != e.CommandArgument) { AttachmentCategory category = (AttachmentCategory)Enum.Parse(typeof(AttachmentCategory), e.CommandArgument.ToString()); ShowUploadDlg(-1, category, "Upload Supporting Attachment", "You can upload a supporting attachment for each description."); } }
protected void btnUpload_Click(object sender, EventArgs e) { FileUpload fileUpload = modalDialog.FindControl("txtFileUpload") as FileUpload; Label lblAttachmentCategory = modalDialog.FindControl("lblAttachmentCategory") as Label; Label lblUploadInstructions = modalDialog.FindControl("lblUploadInstructions") as Label; Label lblAttachmentName = modalDialog.FindControl("lblAttachmentName") as Label; Label lblAttachmentId = modalDialog.FindControl("lblAttachmentId") as Label; AttachmentCategory category = (AttachmentCategory)Enum.Parse(typeof(AttachmentCategory), lblAttachmentCategory.Text); this.Validate("Upload"); if (this.IsValid && null != fileUpload && fileUpload.HasFile && FileUtils.IsValidFile(fileUpload.FileName)) { int id = Convert.ToInt32(lblAttachmentId.Text); Attachment attachment = null; if (id > 0) { attachment = PortfolioService.GetAttachment(id); } if (id <= 0 || null == attachment) { attachment = new Attachment(); Portfolio portfolio = GetPortfolio(); if (category == AttachmentCategory.Image || category == AttachmentCategory.Document || category == AttachmentCategory.Media) { attachment.Type = AttachmentType.Portfolio; attachment.ObjectRowId = portfolio.Id; } else { attachment.Type = AttachmentType.Portfolio; attachment.ObjectRowId = GetPortfolio().Id; } attachment.Category = category; } attachment.Description = lblAttachmentName.Text; attachment.Name = fileUpload.FileName; using (BinaryReader reader = new BinaryReader(fileUpload.FileContent)) { byte[] buf = reader.ReadBytes((int)fileUpload.FileContent.Length); reader.Close(); fileUpload.FileContent.Close(); if (FileUtils.IsImageFile(attachment.Name)) { attachment.Data = buf;// ImageUtils.NormalizeImage(buf); } else { attachment.Data = buf; } } PortfolioService.SaveAttachment(attachment); modalDialog.HideModal(); LoadPortfolio(); } }
protected virtual void ValidateFiles(AttachmentCategory cat, IEnumerable <IFileInfo> lst) { if (cat == null) { throw new ArgumentException("MSG_unknown_category"); } foreach (var d in lst) { if (!cat.ValidateFile(d, out ValidationResult res)) { throw new ArgumentException(res.ErrorMessage); } } }
private void ShowUploadDlg(int id, AttachmentCategory category, string title, string instructions) { Label lblAttachmentCategory = modalDialog.FindControl("lblAttachmentCategory") as Label; Label lblUploadInstructions = modalDialog.FindControl("lblUploadInstructions") as Label; Label lblAttachmentName = modalDialog.FindControl("lblAttachmentName") as Label; Label lblAttachmentId = modalDialog.FindControl("lblAttachmentId") as Label; Label lblFormats = modalDialog.FindControl("lblFormats") as Label; Label lblTitle = modalDialog.FindControl("lblTitle") as Label; lblFormats.Text = FileUtils.SupportedFileFormats(); lblAttachmentCategory.Text = Enum.GetName(typeof(AttachmentCategory), category); lblUploadInstructions.Text = instructions; lblAttachmentName.Text = category.ToDescription(); lblTitle.Text = title; lblAttachmentId.Text = id.ToString(); modalDialog.ShowModal(); }
private void LoadData() { //public virtual int Id { get; set; } //public virtual string { get; set; } //public virtual string Description { get; set; } //public virtual int { get; set; } string where = " where 1=1 "; if (ddlCategory.SelectedValue != "-1") { AttachmentCategory category = (AttachmentCategory)Enum.Parse(typeof(AttachmentCategory), ddlCategory.SelectedValue.ToString()); where += " and a.Category = " + (int)category; } if (ddlType.SelectedValue != "-1") { AttachmentType type = (AttachmentType)Enum.Parse(typeof(AttachmentType), ddlType.SelectedValue.ToString()); where += " and a.Type = " + (int)type; } if (!String.IsNullOrEmpty(txtDescription.Text)) { where += " and (a.Description like '%" + txtDescription.Text + "%')"; } if (!String.IsNullOrEmpty(txtName.Text)) { where += " and (a.Name like '%" + txtName.Text + "%')"; } if (!String.IsNullOrEmpty(txtObjectRow.Text)) { where += " and (a.ObjectRowId = " + txtObjectRow.Text + ")"; } // string orderby = (SortDirection == SortDirection.Ascending) ? " order by " + SortColumn + " ASC " : " order by " + SortColumn + " DESC "; IList <Attachment> list = PortfolioService.GetAttachments(where); gvAttachments.DataSource = list; gvAttachments.DataBind(); }