using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; namespace Bowin.Web.Controls.Mvc { public class Uploader { public string Name { get; set; } public string Title { get; set; } public object Value { get; set; } public Dictionary Attributes { get; set; } public FileType FileType { get; set; } public bool? IsEnabled { get; set; } public int? MaxFileSize { get; set; } public string UploadUrl { get; set; } public Uploader() { } public string Render(UrlHelper Url) { TagBuilder tabBuilder = new TagBuilder("fieldset"); tabBuilder.MergeAttribute("name", Name); tabBuilder.MergeAttribute("data-uploader", ""); tabBuilder.MergeAttribute("data-value", (Value ?? "").ToString()); tabBuilder.MergeAttribute("data-type", ((int)FileType).ToString()); tabBuilder.MergeAttribute("data-rooturl", Url.Content("~/")); if (this.MaxFileSize.HasValue) { tabBuilder.MergeAttribute("maxFileSize", this.MaxFileSize.Value.ToString()); } if (!string.IsNullOrEmpty(UploadUrl)) { tabBuilder.MergeAttribute("data-uploadurl", Url.Content(UploadUrl)); } tabBuilder.MergeAttributes(Attributes); StringBuilder sb = new StringBuilder(); sb.AppendLine(""); sb.AppendFormat("\r\n", Name, Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/add.png")); sb.AppendLine(" " + (Title ?? "附件上传") + " "); sb.AppendLine("
"); sb.AppendLine(""); sb.AppendLine("
"); tabBuilder.InnerHtml = sb.ToString(); return tabBuilder.ToString(TagRenderMode.Normal); } public static Uploader CreateControl(uploaderOption uOption, IDictionary attributes = null, FileType fileType = FileType.ALL) { Uploader uploader = new Uploader(); uploader.Name = uOption.Name; uploader.Title = uOption.Title; uploader.Value = uOption.MainTableID == null ? Guid.Empty.ToString() : uOption.MainTableID; uploader.FileType = fileType == FileType.ALL ? uOption.FileType : fileType; uploader.IsEnabled = uOption.IsEnabled; uploader.MaxFileSize = uOption.MaxFileSize; uploader.UploadUrl = uOption.UploadUrl; return uploader; } } }