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

简介:

以前的的发送消息按钮事件改写如下:

 


'/////////////////////转到发送即时消息页面
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
Dimi,jAsInteger
j=0
Dimtostu_idAsString=""
Fori=0Tomycheck.Items.Count-1
Ifmycheck.Items(i).SelectedThen
'////////////////////////限制发送条数
j=j+1
Ifj<6Then


'/////////////////////参数构造
tostu_id=tostu_id&CheckBoxList1.Items(i).Text&"@"
Else
Label2.Visible=True
Label2.Text="一次最多能给五个用户发送信息!"
Return
'Response.Write("<scriptlanguage=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>")
EndIf
EndIf
Nexti
Response.Redirect("info.aspx?tostu_id="&tostu_id)
EndSub

这里发送信息的页面由于修改的比较多,所以把全部代码全都抓来了

codebebind部分:


ImportsSystem.Data
ImportsSystem.Data.SqlClient
PublicClassinfo
InheritsSystem.Web.UI.Page
ProtectedWithEventsLabel1AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel2AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox2AsSystem.Web.UI.WebControls.TextBox
ProtectedWithEventsButton1AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsButton2AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsLabel3AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel4AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel5AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel6AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox3AsSystem.Web.UI.WebControls.TextBox
ProtectedWithEventsImage3AsSystem.Web.UI.WebControls.Image
ProtectedWithEventsLabel8AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel7AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel9AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsLabel10AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsButton3AsSystem.Web.UI.WebControls.Button
ProtectedWithEventsLabel11AsSystem.Web.UI.WebControls.Label
ProtectedWithEventsTextBox1AsSystem.Web.UI.WebControls.TextBox

#Region"WebFormDesignerGeneratedCode"

'ThiscallisrequiredbytheWebFormDesigner.
<System.Diagnostics.DebuggerStepThrough()>PrivateSubInitializeComponent()

EndSub

PrivateSubPage_Init(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Init
'CODEGEN:ThismethodcallisrequiredbytheWebFormDesigner
'Donotmodifyitusingthecodeeditor.
InitializeComponent()
EndSub

#EndRegion
DimconnAsSqlConnection=NewSqlConnection("server=lixinri;uid=sa;pwd=;database=99re1")
PublicSubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
IfNotIsPostBackThen
Dimtostu_idAsString=Request.QueryString("tostu_id")
Dimsplitname()AsString
'///////////这里用了Split函数将传过来的参数取出
splitname=Split(tostu_id,"@")
Iftostu_id=""Then
'//////////////////当回复留言时
DimsqlAsString="selecta.*,b.nickfrominfoa,pwdbwherea.fromstu_id=b.stu_idanda.tostu_id='"&Session("stu_id")&"'anda.term=1"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
DimdrAsSqlDataReader
conn.Open()
dr=comm.ExecuteReader
Whiledr.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
EndWhile
dr.Close()
comm.Cancel()
'//////////////////////更新留言使留言属性为已阅读过
Dimsql_1AsString="updateinfosetterm=0wheretostu_id='"&Session("stu_id")&"'andterm=1andtim='"&Label4.Text&"'"
comm=NewSqlCommand(sql_1,conn)
comm.ExecuteNonQuery()
Else
'////////////////////当发送留言时
'/////////////////读取参数
DimiAsInteger
Fori=0ToUBound(splitname)-1
DimmysqlAsString="selectnickfrompwdwherestu_id='"&splitname(i)&"'"
DimcommAsSqlCommand=NewSqlCommand(mysql,conn)
DimdrAsSqlDataReader
Ifi=0Then
conn.Open()
dr=comm.ExecuteReader
Ifdr.ReadThen
TextBox1.Text=Trim(dr.item("nick"))&";"
EndIf
control()
dr.close()
Else
dr=comm.ExecuteReader
Ifdr.ReadThen
TextBox1.Text=TextBox1.Text&Trim(dr.item("nick"))&";"
EndIf
control()
dr.close()
EndIf
Nexti
EndIf
EndIf
EndSub
'/////////////////control事件,没有什么实际意义,使代码简单罢了。
Subcontrol()
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="<ahref=board.aspx><<<返回学友录</a>"
EndSub

'/////////////////书写提交消息事件
PublicSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Dimtostu_idAsString=Request.QueryString("tostu_id")
Dimsplitname()AsString
splitname=Split(tostu_id,"@")
Iftostu_id=""Then
'/////////////////////////当回复留言时
IfTextBox2.Text=""OrTextBox2.Text=""Then
Label10.Visible=True
Label10.Text="消息不能为空!"
Return
Else
Label10.Visible=False
conn.Open()
DimsqlAsString="insertintoinfo(fromstu_id,tostu_id,content,term,tim)values(@fromstu_id,@tostu_id,@content,@term,@tim)"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
comm.Parameters.Add(NewSqlParameter("@fromstu_id",SqlDbType.Int,4))
comm.Parameters("@fromstu_id").Value=Session("stu_id")

comm.Parameters.Add(NewSqlParameter("@tostu_id",SqlDbType.Int,4))
comm.Parameters("@tostu_id").Value=TextBox3.Text

comm.Parameters.Add(NewSqlParameter("@content",SqlDbType.VarChar,200))
comm.Parameters("@content").Value=TextBox2.Text

comm.Parameters.Add(NewSqlParameter("@term",SqlDbType.Int,4))
comm.Parameters("@term").Value="1"

comm.Parameters.Add(NewSqlParameter("@tim",SqlDbType.Char,20))
comm.Parameters("@tim").Value=Date.Now
comm.ExecuteNonQuery()
'TextBox2.Text=""
EndIf
Else
'/////////////////////////当发送留言时
IfTextBox2.Text=""OrTextBox2.Text=""Then
Label10.Visible=True
Label10.Text="消息不能为空!"
Return
Else
'////////////////插入i条数据
DimiAsInteger
Fori=0ToUBound(splitname)-1
Label10.Visible=False
Ifi=0Then
conn.Open()
Else
EndIf
DimsqlAsString="insertintoinfo(fromstu_id,tostu_id,content,term,tim)values(@fromstu_id,@tostu_id,@content,@term,@tim)"
DimcommAsSqlCommand=NewSqlCommand(sql,conn)
comm.Parameters.Add(NewSqlParameter("@fromstu_id",SqlDbType.Int,4))
comm.Parameters("@fromstu_id").Value=Session("stu_id")

comm.Parameters.Add(NewSqlParameter("@tostu_id",SqlDbType.Int,4))
comm.Parameters("@tostu_id").Value=splitname(i)

comm.Parameters.Add(NewSqlParameter("@content",SqlDbType.VarChar,200))
comm.Parameters("@content").Value=TextBox2.Text

comm.Parameters.Add(NewSqlParameter("@term",SqlDbType.Int,4))
comm.Parameters("@term").Value="1"

comm.Parameters.Add(NewSqlParameter("@tim",SqlDbType.Char,20))
comm.Parameters("@tim").Value=Date.Now
comm.ExecuteNonQuery()
'TextBox2.Text=""
Nexti
EndIf
EndIf
Response.Write("<scriptlanguage=javascript>alert('发送成功!')</script>")
EndSub

'////////////////////返回继续发送
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
Response.Redirect("boaman.aspx")
EndSub

PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
Response.Write("<scriptlanguage=javascript>window.close()</script>")
EndSub
EndClass

目录
相关文章
|
监控 前端开发 安全
SpringCloud Gateway鉴权和跨域解决方案
SpringCloud Gateway鉴权和跨域解决方案
1571 0
|
监控 Ubuntu Unix
Linux |Nethogs 监控网络使用情况
Linux |Nethogs 监控网络使用情况
Linux |Nethogs 监控网络使用情况
|
8月前
|
运维 监控 调度
普通人如何用PCDN来赚钱
私有内容分发网络(PCDN)利用分散的终端设备和带宽资源,构建去中心化的内容分发系统。普通人可通过搭建PCDN,利用闲置设备实现低成本、高灵活性的赚钱机会。主要步骤包括硬件准备、选择稳定软件平台、设计网络架构、内容管理和运维监控。盈利模式涵盖提供PCDN服务、广告合作、流量变现及增值服务。通过优化网络配置和设备选择,可最大化收益。尽管存在法律风险和收益波动,但合理搭建和维护能带来可观回报。
13000 0
|
机器学习/深度学习 人工智能 监控
AI安防监控
AI安防监控运用人工智能技术分析视频监控,实现对象识别、追踪和预警,广泛应用在安防、交通和工业等领域。它提升了监控的实时性和准确性,降低了人力成本,但面临误判、隐私泄露和高成本等问题。随着市场需求增长,全球安防监控行业将迎来持续发展,需在提升技术的同时保障个人隐私。
587 0
|
JavaScript 前端开发
每天一道面试题——JavaScript的this指向【一】
每天一道面试题——JavaScript的this指向【一】
115 0
深度解析:短信号码都有那些?他们之间有什么区别?
您的手机上常见的短信号码都有哪些呢,他们直接有什么区别呢,本文将带您一起学习了解哦。
深度解析:短信号码都有那些?他们之间有什么区别?
|
存储 Java fastjson
打造一个高可用多租户的企业级Maven私有仓库服务
本文讨论了构建高可用多租户企业级Maven私有仓库服务的必要性,指出传统Nexus和Artifactory开源版缺乏高可用性,商业版虽支持但成本高、扩展性有限。理想的解决方案应包含无状态节点、使用云存储(如阿里云OSS)和集群化的数据库与Elasticsearch。
370 0
打造一个高可用多租户的企业级Maven私有仓库服务
|
存储 资源调度 前端开发
javascript面试题--持续更新 3
javascript面试题--持续更新
199 0
|
存储 C++ 索引
彻底理解 HashMap 及 LinkedHashMap,面试官请随便问!(2)
彻底理解 HashMap 及 LinkedHashMap,面试官请随便问!
127 0
彻底理解 HashMap 及 LinkedHashMap,面试官请随便问!(2)