且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-08-14 16:16:24

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

 


'/////////////////////转到发送即时消息页面
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