1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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<string, object> 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("<legend>");
- sb.AppendFormat("<input type=\"image\" name=\"uploader_btn_add\" src=\'{1}' onclick=\"uploader_showFileDialog('{0}');return false;\" " + (IsEnabled == false ? "disabled=\"disabled\"" : "") + " />\r\n", Name, Url.Content("~/Scripts/Bowin.Control.Core/Plugins/uploadifyFile/add.png"));
- sb.AppendLine(" " + (Title ?? "附件上传") + " </legend>");
- sb.AppendLine("<div style=\"position: relative; vertical-align: bottom;\">");
- sb.AppendLine("<ul name=\"uploader_ul\" class=\"uploader_ul\">");
- sb.AppendLine("</ul>");
- sb.AppendLine("</div>");
- tabBuilder.InnerHtml = sb.ToString();
- return tabBuilder.ToString(TagRenderMode.Normal);
- }
- public static Uploader CreateControl(uploaderOption uOption, IDictionary<string, object> 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;
- }
- }
- }
|