|
结合ASP.NET与JavaScript开发电子沙盘(2) { if (!IsPostBack) //程序是否是第一次执行 { string strConn=ConfigurationSettings.AppSettings["ConnectionString"]; SqlConnection cn=new SqlConnection(strConn); SqlCommand cm9=new SqlCommand("sp_sketchmap",cn); //提取子单位名称及坐标值 cm9.CommandType=CommandType.StoredProcedure; cm9.Parameters.Add("@unitid",SqlDbType.VarChar,50); //使用者单位编码 cm9.Parameters["@unitid"].Value=Session["unitid"].ToString(); cm9.Parameters.Add("@D1",SqlDbType.VarChar,50); //1号子单位名称 cm9.Parameters["@D1"].Direction=ParameterDirection.Output; cm9.Parameters.Add("@D1A",SqlDbType.Int); //1号子单位横坐标 cm9.Parameters["@D1A"].Direction=ParameterDirection.Output; cm9.Parameters.Add("@D1B",SqlDbType.Int); //1号子单位纵坐标 cm9.Parameters["@D1B"].Direction=ParameterDirection.Output; cm9.Parameters.Add("@D1C",SqlDbType.VarChar,100); //1号子单位基本信息 cm9.Parameters["@D1C"].Direction=ParameterDirection.Output; ……
2、客户端操作
ASP.NET中的Web控件没有坐标属性,因此它们不能在网页中移动。可以采用HTML控件中的Label控件(div),把它当成一个可以移动的层来使用,在这个层上嵌入一个Image控件,两者合并在一起即可作为活动的图标。
编写的JavaScript脚本主要有两类:一类是拖动动作,即图标可以被鼠标拖动到地图上的某一位置;另一类是点击动作,在图标被选中状态下,单击鼠标的右键可以显现图标的基本信息。节选程序如下:
<script language="JavaScript"> // JavaScript脚本 …… function dragIt(evt) // 鼠标拖动动作 { …… if (selectedObj) { shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY)) document.forms(0).TextBox1.value=window.event.clientX – offsetX document.forms(0).TextBox2.value=window.event.clientY – offsetY document.forms(0).TextBox3.value=window.event.srcElement.id } } …… function rightclick(){ //鼠标右键点击动作 if (event.button==2){ linkex.innerHTML=document.forms(0).TextBoxD1C.value linkex.style.posTop=plane1.style.posTop+20 linkex.style.posLeft=plane1.style.posLeft+20 linkex.style.backgroundColor="Pink" linkex.style.visibility="visible" } } </script>
3、坐标值保存
在用户完成图标的配置后,可选择保存设置,这一动作由Web控件Button按钮的Click事件激发。Web服务器将用户ID、图标ID和坐标值赋传送给数据库服务器的存储过程,由存储过程将数据保存到数据库表中。节选程序如下:
private void Button1_Click(object sender, System.EventArgs e)
|