📄 imagegallery.cs
字号:
namespace FreeTextBoxControls
{
using FreeTextBoxControls.Support;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.HtmlControls;
[ToolboxData("<{0}:ImageGallery runat=\"server\"></{0}:ImageGallery>")]
public class ImageGallery : Control, IPostBackDataHandler, IPostBackEventHandler
{
public ImageGallery()
{
this.request = null;
this.browserInfo = null;
this.response = null;
this.context = null;
this.MaxThumbnailWidth = 100;
this.MaxThumbnailHeight = 80;
this.returnMessage = "";
this.inputFile = null;
this._currentDirectories = null;
this._currentImages = null;
this.context = HttpContext.Current;
this.request = this.context.Request;
this.response = this.context.Response;
this.browserInfo = new BrowserInfo();
}
protected override void CreateChildControls()
{
this.inputFile = new HtmlInputFile();
this.inputFile.ID = "command_UploadFile";
base.CreateChildControls();
}
private string CreateResourceString(string filename, ResourceType resourceType)
{
switch (resourceType)
{
case ResourceType.JavaScript:
if (this.JavaScriptLocation == ResourceLocation.InternalResource)
{
return ClientScriptWrapper.GetWebResourceUrl(this, "FreeTextBoxControls.Resources.JavaScript." + filename, this.AssemblyResourceHandlerPath);
}
return base.ResolveUrl(this.SupportFolder + filename);
case ResourceType.Utility:
if (this.UtilityImagesLocation == ResourceLocation.InternalResource)
{
return ClientScriptWrapper.GetWebResourceUrl(this, "FreeTextBoxControls.Resources.Images.Utility." + filename + ".gif", this.AssemblyResourceHandlerPath);
}
return base.ResolveUrl(this.SupportFolder + "Utility/" + filename + ".gif");
}
return string.Empty;
}
public virtual ArrayList GetImages()
{
if (this.CurrentImagesFolder == "")
{
return null;
}
string text1 = "FTB-Images-" + this.CurrentImagesFolder;
if ((this.context.Cache[text1] == null) || (this._currentImages != null))
{
ArrayList list1 = new ArrayList();
string text2 = this.request.ApplicationPath;
if (!text2.EndsWith("/"))
{
text2 = text2 + "/";
}
text2 = base.ResolveUrl(this.CurrentImagesFolder) + "/";
while (text2.IndexOf("//") > -1)
{
text2 = text2.Replace("//", "/");
}
DirectoryInfo info1 = new DirectoryInfo(this.context.Server.MapPath(this.CurrentImagesFolder));
FileInfo[] infoArray1 = null;
if (this._currentImages != null)
{
infoArray1 = this._currentImages;
}
else
{
try
{
infoArray1 = info1.GetFiles("*");
}
catch
{
}
}
if (infoArray1 != null)
{
foreach (FileInfo info2 in infoArray1)
{
bool flag1 = false;
foreach (string text3 in this.AcceptedFileTypes)
{
if (info2.Extension.ToLower() == ("." + text3.ToLower()))
{
flag1 = true;
break;
}
}
if (flag1)
{
FreeTextBoxControls.ImageInfo info3 = new FreeTextBoxControls.ImageInfo();
info3.Filename = info2.Name;
info3.PhysicalPath = info2.FullName;
info3.AbsoluteWebPath = (text2 + info2.Name).Replace(@"\", "/");
info3.Size = info2.Length;
try
{
Image image1 = Image.FromFile(info3.PhysicalPath);
info3.Width = image1.Width;
info3.Height = image1.Height;
image1.Dispose();
}
catch (Exception)
{
goto Label_0429;
}
info3.ThumbnailAbsoluteWebPath = info3.AbsoluteWebPath;
if (info3.Width > info3.Height)
{
if (info3.Width > this.MaxThumbnailWidth)
{
info3.ThumbnailWidth = this.MaxThumbnailWidth;
info3.ThumbnailHeight = Convert.ToInt32((int) ((info3.Height * this.MaxThumbnailWidth) / info3.Width));
}
else
{
info3.ThumbnailWidth = info3.Width;
info3.ThumbnailHeight = info3.Height;
}
}
else if (info3.Height > this.MaxThumbnailHeight)
{
info3.ThumbnailHeight = this.MaxThumbnailHeight;
info3.ThumbnailWidth = Convert.ToInt32((int) ((info3.Width * this.MaxThumbnailHeight) / info3.Height));
}
else
{
info3.ThumbnailWidth = info3.Width;
info3.ThumbnailHeight = info3.Height;
}
if (info3.ThumbnailHeight < this.MaxThumbnailHeight)
{
info3.ThumbnailVSpace = Convert.ToInt32((int) ((this.MaxThumbnailHeight / 2) - (info3.ThumbnailHeight / 2)));
}
if (info3.Size > 0x100000)
{
info3.SizeString = string.Format("{0:###.##} MB", (info3.Size / ((long) 0x400)) / ((long) 0x400));
}
else if (info3.Size > 0x400)
{
info3.SizeString = string.Format("{0:###.##} KB", info3.Size / ((long) 0x400));
}
else
{
info3.SizeString = string.Format("{0} bytes", info3.Size);
}
list1.Add(info3);
Label_0429:;
}
}
}
this.context.Cache.Insert(text1, list1, new CacheDependency(this.context.Server.MapPath(this.CurrentImagesFolder)), DateTime.MaxValue, TimeSpan.Zero);
}
return (ArrayList) this.context.Cache[text1];
}
public bool LoadPostData(string postDataKey, NameValueCollection values)
{
return false;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
if (!this.Page.IsPostBack)
{
string text1 = this.request.QueryString["rif"] + "";
if (text1 != "")
{
this.RootImagesFolder = text1;
}
string text2 = this.request.QueryString["cif"] + "";
if (text2 != "")
{
this.CurrentImagesFolder = text2;
}
string text3 = this.request.QueryString["ftb"] + "";
if (text3 != "")
{
this.TargetFreeTextBox = text3;
}
}
base.OnLoad(e);
}
protected override void OnPreRender(EventArgs e)
{
if (!this.Page.IsClientScriptBlockRegistered("FTB-Utility"))
{
this.Page.RegisterClientScriptBlock("FTB-Utility", "<script type=\"text/javascript\" src=\"" + this.CreateResourceString("FTB-Utility.js", ResourceType.JavaScript) + "\"></script>");
}
if (!this.Page.IsClientScriptBlockRegistered("FTB-ImageGallery"))
{
this.Page.RegisterClientScriptBlock("FTB-ImageGallery", "<script type=\"text/javascript\" src=\"" + this.CreateResourceString("FTB-ImageGallery.js", ResourceType.JavaScript) + "\"></script>");
}
this.Page.RegisterStartupScript("FTB-StartUp-Resize", "<script type=\"text/javascript\">\r\n\t\t\t\t\tFTB_AddEvents(window,new Array(\"load\",\"resize\"),FTB_ResizeGalleryArea);\r\n\t\t\t\t</script>");
this.Page.RegisterRequiresPostBack(this);
this.Page.GetPostBackEventReference(this);
}
public virtual void RaisePostBackEvent(string eventArgument)
{
Exception exception1;
this.EnsureChildControls();
DirectoryInfo info1 = new DirectoryInfo(this.context.Server.MapPath(this.CurrentImagesFolder));
string[] textArray1 = eventArgument.Split(new char[] { ':' });
switch (textArray1[0])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -