using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoManage;
namespace PhotoControl
{
[DefaultProperty("PhotoID")]
[ToolboxData("<{0}:PhotoImage runat=server></{0}:PhotoImage>")]
public class PhotoImage : WebControl
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
private string _PhotoID;
private string _NavigateUrl;
private Targer _Target;
private string _SqlConn;
private string _ToolTip;
private string _NOPhotoUrl;
/// <summary>
/// 資料庫連結字元串
/// </summary>
[Description("資料庫連結字元串"), Category("Appearance")]
public string SqlConn
{
get
{
return _SqlConn;
}
set
_SqlConn = value;
}
/// 要顯示的照片ID
[Description("要顯示的照片ID"), Category("Appearance")]
public string PhotoID
return _PhotoID;
_PhotoID = value;
/// 連結位址
[Description("連結位址"), Category("Appearance")]
public string NavigateUrl
return ((_NavigateUrl == null) ? String.Empty : _NavigateUrl);
_NavigateUrl = value;
/// 連結打開方式
[Description("連結打開方式"), Category("Appearance")]
//[DefaultValue("_blank")]
public Targer Target
return _Target;
_Target = value;
/// 将滑鼠移到控件上時顯示的工具提示。
[Description("将滑鼠移到控件上時顯示的工具提示。"), Category("Appearance")]
public string ToolTip
return ((_ToolTip == null) ? String.Empty : _ToolTip);
_ToolTip = value;
/// 無照片時使用的替換圖檔
[Description("無照片時使用的替換圖檔"), Category("Appearance")]
public string NOPhotoUrl
return ((_NOPhotoUrl == null) ? String.Empty : _NOPhotoUrl);
_NOPhotoUrl = value;
protected override void RenderContents(HtmlTextWriter output)
string outStr = "";
if (this.PhotoID != null && this.PhotoID != "" && this.SqlConn != null && this.SqlConn != "")
PhotoDetail pDetail = new PhotoManage.PhotoDB(this.SqlConn).getPhotoDetail(this.PhotoID);
if (pDetail != null)
{
string tar = "";
switch (this.Target)
{
case Targer._blank: tar = "_blank"; break;
case Targer._parent: tar = "_parent"; break;
case Targer._search: tar = "_search"; break;
case Targer._self: tar = "_self"; break;
case Targer._top: tar = "_top"; break;
}
if (this.NavigateUrl == null || this.NavigateUrl == string.Empty)
this.NavigateUrl = pDetail.PhotoPath;
if (this.Height.IsEmpty != true && this.Width.IsEmpty != true)
outStr = "<a href=\"" + this.NavigateUrl + "\" target=\"" + tar + "\"><img border=\"0\" height=\"" + this.Height + "\" width=\"" + this.Width + "\" src=\"" + pDetail.SmallPhotoPath + "\" Alt=\"" + this.ToolTip + "\"/></a>";
else if (this.Height.IsEmpty == true && this.Width.IsEmpty == false)
outStr = "<a href=\"" + this.NavigateUrl + "\" target=\"" + tar + "\"><img border=\"0\" width=\"" + this.Width + "\" src=\"" + pDetail.SmallPhotoPath + "\" Alt=\"" + this.ToolTip + "\"/></a>";
else if (this.Height.IsEmpty == false && this.Width.IsEmpty == true)
outStr = "<a href=\"" + this.NavigateUrl + "\" target=\"" + tar + "\"><img border=\"0\" height=\"" + this.Height + "\" src=\"" + pDetail.SmallPhotoPath + "\" Alt=\"" + this.ToolTip + "\"/></a>";
else
outStr = "<a href=\"" + this.NavigateUrl + "\" target=\"" + tar + "\"><img border=\"0\" src=\"" + pDetail.SmallPhotoPath + "\" Alt=\"" + this.ToolTip + "\"/></a>";
output.Write(outStr);
return;
}
else
outStr = "<img border=\"0\" src=\"" + this.NOPhotoUrl + "\" alt=\"暫無照片\"";
else
outStr = "<img border=\"0\" alt=\"未提供屬性SqlConn或者屬性PhotoID\"";
output.Write(outStr);
return;
}
public enum Targer
_blank = 0,
_parent,
_search,
_self,
_top
}