using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConn;
string strSQL;
SqlConnection sqlConn; //定义
RectangleHotSpot rhs = new RectangleHotSpot();
PolygonHotSpot phs = new PolygonHotSpot();
CircleHotSpot chs = new CircleHotSpot();
HotSpot hs;
protected void Page_Load(object sender, EventArgs e)
{
strConn = System.Configuration.ConfigurationManager.AppSettings["MapConnectionString"];//链接
sqlConn = new SqlConnection(strConn);
int intMapID = 1;
if (Request["mapid"] != null)
{
intMapID = int.Parse(Request["mapid"].ToString());
}
strSQL = "SELECT * FROM tMap WHERE MMapID=@PMapID";
SqlCommand sqlComm = new SqlCommand(strSQL, sqlConn);
sqlComm.Parameters.Add(new SqlParameter("@PMapID", SqlDbType.Int));//获取传过来的值再动态绑定要显示的图片
sqlComm.Parameters["@PMapID"].Value = intMapID;
sqlComm.Connection.Open();
SqlDataReader sqlDR = sqlComm.ExecuteReader();
if (sqlDR.Read())
{
imap1.ImageUrl = sqlDR["MMapSRC"].ToString();
sqlComm.Connection.Close();
this.SubMap(intMapID);
}
}
protected void SubMap(int intMapID1) //动态绑定热点
{
strSQL = "SELECT * FROM tArea WHERE MMapID=@PMapID";
SqlCommand sqlComm = new SqlCommand(strSQL, sqlConn);
sqlComm.Parameters.Add(new SqlParameter("@PMapID", SqlDbType.Int));
sqlComm.Parameters["@PMapID"].Value = intMapID1;
sqlComm.Connection.Open();
SqlDataReader sqlDR = sqlComm.ExecuteReader();
while (sqlDR.Read())
{
int intLinkType =int.Parse(sqlDR["MLinkType"].ToString()); //通过LinkType获取链接到的页面
string strLink="";
if (intLinkType == 0)
{
strLink = "Default.aspx?mapid=" + sqlDR["MLinkMapID"];
}
else if (intLinkType == 1)
{
strLink = "Company.aspx?BID=" + int.Parse(sqlDR["MLinkBigGroup"].ToString()) + "&SID=" + int.Parse(sqlDR["MLinkSmallGroup"].ToString());
}
string strShape = sqlDR["MShape"].ToString();
if (strShape == "poly")
{
phs.NavigateUrl = strLink;
phs.Coordinates = sqlDR["MCoords"].ToString();
hs = phs;
imap1.HotSpots.Add(hs);
}
else if (strShape == "rect")
{
rhs.NavigateUrl = strLink;
string strCoor = sqlDR["MCoords"].ToString();
string[] strCoorArr = strCoor.Split(',');
rhs.Top = int.Parse(strCoorArr[0]);
rhs.Left = int.Parse(strCoorArr[1]);
rhs.Right = int.Parse(strCoorArr[2]);
rhs.Bottom = int.Parse(strCoorArr[3]);
hs = rhs;
imap1.HotSpots.Add(hs);
}
else if (strShape == "Circle")
{
chs.NavigateUrl = strLink;
string strCoor = sqlDR["MCoords"].ToString();
string[] strCoorArr = strCoor.Split(',');
chs.Radius = int.Parse(strCoorArr[0]);
chs.X = int.Parse(strCoorArr[1]);
chs.Y = int.Parse(strCoorArr[2]);
hs = chs;
imap1.HotSpots.Add(hs);
}
}
sqlComm.Connection.Close();
}
}