动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 即时消息的发送,包含同时给多人发送信息

作者来源: 
阅读 1173 人次 , 2006-3-29 4:34:00 


以前的的发送消息按钮事件改写如下:
  '/////////////////////转到发送即时消息页面
private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
dim i, j as integer
j = 0
dim tostu_id as string = ""
for i = 0 to mycheck.items.count - 1
if mycheck.items(i).selected then
'////////////////////////限制发送条数
j = j + 1
if j < 6 then
'/////////////////////参数构造
tostu_id = tostu_id & checkboxlist1.items(i).text & "@"
else
label2.visible = true
label2.text = "一次最多能给五个用户发送信息!"
return
'response.write("<script language=javascript>window.open('info.aspx?tostu_id=' & checkboxlist1.items(i).text,'','height=330,width=560,status=no,location=no,toolbar=no,directories=no,menubar=no')</script>")
end if
end if
next i
response.redirect("info.aspx?tostu_id=" & tostu_id)
end sub



  这里发送信息的页面由于修改的比较多,所以把全部代码全都抓来了,呵呵:)
  codebebind部分:
  imports system.data
  imports system.data.sqlclient
  public class info
inherits system.web.ui.page
protected withevents label1 as system.web.ui.webcontrols.label
protected withevents label2 as system.web.ui.webcontrols.label
protected withevents textbox2 as system.web.ui.webcontrols.textbox
protected withevents button1 as system.web.ui.webcontrols.button
protected withevents button2 as system.web.ui.webcontrols.button
protected withevents label3 as system.web.ui.webcontrols.label
protected withevents label4 as system.web.ui.webcontrols.label
protected withevents label5 as system.web.ui.webcontrols.label
protected withevents label6 as system.web.ui.webcontrols.label
protected withevents textbox3 as system.web.ui.webcontrols.textbox
protected withevents image3 as system.web.ui.webcontrols.image
protected withevents label8 as system.web.ui.webcontrols.label
protected withevents label7 as system.web.ui.webcontrols.label
protected withevents label9 as system.web.ui.webcontrols.label
protected withevents label10 as system.web.ui.webcontrols.label
protected withevents button3 as system.web.ui.webcontrols.button
protected withevents label11 as system.web.ui.webcontrols.label
protected withevents textbox1 as system.web.ui.webcontrols.textbox

  #region " web form designer generated code "

'this call is required by the web form designer.
<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

end sub

private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init
'codegen: this method call is required by the web form designer
'do not modify it using the code editor.
initializecomponent()
end sub

  #end region
dim conn as sqlconnection = new sqlconnection("server=lixinri;uid=sa;pwd=;database=99re1")
public sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
if not ispostback then
dim tostu_id as string = request.querystring("tostu_id")
dim splitname() as string
  '///////////这里用了split函数将传过来的参数取出
splitname = split(tostu_id, "@")
if tostu_id = "" then
'//////////////////当回复留言时
dim sql as string = "select a.*,b.nick from info a,pwd b where a.fromstu_id=b.stu_id and a.tostu_id='" & session("stu_id") & "' and a.term=1"
dim comm as sqlcommand = new sqlcommand(sql, conn)
dim dr as sqldatareader
conn.open()
dr = comm.executereader
while dr.read
label3.text = dr.item("nick")
label4.text = dr.item("tim")
label5.text = "   " & dr.item("content")
textbox1.text = dr.item("nick")
textbox3.text = dr.item("fromstu_id")
textbox1.enabled = false
label8.visible = false
label11.visible = false
end while
dr.close()
comm.cancel()
'//////////////////////更新留言使留言属性为已阅读过
dim sql_1 as string = "update info set term=0 where tostu_id='" & session("stu_id") & "' and term=1 and tim='" & label4.text & "'"
comm = new sqlcommand(sql_1, conn)
comm.executenonquery()
else
'////////////////////当发送留言时
'/////////////////读取参数
dim i as integer
for i = 0 to ubound(splitname) - 1
dim mysql as string = "select nick from pwd where stu_id='" & splitname(i) & "'"
dim comm as sqlcommand = new sqlcommand(mysql, conn)
dim dr as sqldatareader
if i = 0 then
conn.open()
dr = comm.executereader
if dr.read then
textbox1.text = trim(dr.item("nick")) & ";"
end if
control()
dr.close()
else
dr = comm.executereader
if dr.read then
textbox1.text = textbox1.text & trim(dr.item("nick")) & ";"
end if
control()
dr.close()
end if
next i
end if
end if
end sub
'/////////////////control事件,没有什么实际意义,使代码简单罢了。
sub control()
textbox1.enabled = false : label3.text = "" : label4.text = "" : label5.visible = false
label8.visible = true : label6.visible = false : label7.visible = false : label9.visible = false
button3.visible = false : label11.visible = true
label11.text = "<a href=board.aspx><<<返回学友录</a>"
end sub

'/////////////////书写提交消息事件
public sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
dim tostu_id as string = request.querystring("tostu_id")
dim splitname() as string
splitname = split(tostu_id, "@")
if tostu_id = "" then
'/////////////////////////当回复留言时
if textbox2.text = "" or textbox2.text = " " then
label10.visible = true
label10.text = "消息不能为空!"
return
else
label10.visible = false
conn.open()
dim sql as string = "insert into info(fromstu_id,tostu_id,content,term,tim) values(@fromstu_id,@tostu_id,@content,@term,@tim)"
dim comm as sqlcommand = new sqlcommand(sql, conn)
comm.parameters.add(new sqlparameter("@fromstu_id", sqldbtype.int, 4))
comm.parameters("@fromstu_id").value = session("stu_id")

comm.parameters.add(new sqlparameter("@tostu_id", sqldbtype.int, 4))
comm.parameters("@tostu_id").value = textbox3.text

comm.parameters.add(new sqlparameter("@content", sqldbtype.varchar, 200))
comm.parameters("@content").value = textbox2.text

comm.parameters.add(new sqlparameter("@term", sqldbtype.int, 4))
comm.parameters("@term").value = "1"

comm.parameters.add(new sqlparameter("@tim", sqldbtype.char, 20))
comm.parameters("@tim").value = date.now
comm.executenonquery()
'textbox2.text = ""
end if
else
'/////////////////////////当发送留言时
if textbox2.text = "" or textbox2.text = " " then
label10.visible = true
label10.text = "消息不能为空!"
return
else
'////////////////插入i条数据
dim i as integer
for i = 0 to ubound(splitname) - 1
label10.visible = false
if i = 0 then
conn.open()
else
end if
dim sql as string = "insert into info(fromstu_id,tostu_id,content,term,tim) values(@fromstu_id,@tostu_id,@content,@term,@tim)"
dim comm as sqlcommand = new sqlcommand(sql, conn)
comm.parameters.add(new sqlparameter("@fromstu_id", sqldbtype.int, 4))
comm.parameters("@fromstu_id").value = session("stu_id")

comm.parameters.add(new sqlparameter("@tostu_id", sqldbtype.int, 4))
comm.parameters("@tostu_id").value = splitname(i)

comm.parameters.add(new sqlparameter("@content", sqldbtype.varchar, 200))
comm.parameters("@content").value = textbox2.text

comm.parameters.add(new sqlparameter("@term", sqldbtype.int, 4))
comm.parameters("@term").value = "1"

comm.parameters.add(new sqlparameter("@tim", sqldbtype.char, 20))
comm.parameters("@tim").value = date.now
comm.executenonquery()
'textbox2.text = ""
next i
end if
end if
response.write("<script language=javascript>alert('发送成功!')</script>")
end sub

'////////////////////返回继续发送
private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
response.redirect("boaman.aspx")
end sub

private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
response.write("<script language=javascript>window.close()</script>")
end sub
  end class


  感谢laodeng了:)

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:asp.NET特写
· 下一篇:.net中即时消息发送的实现
· SOAP Version 1.2中文手冊(3)
· ASP.NET验证控件祥解
· 利用.NET框架简化发布和解决DLL Hell问题(1)
· ASP.NET中Cookie编程的基础知识(4)
· C#正则表达式应用范例


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077