天天看點

改寫即時消息的發送 包含同時給多人發送資訊

以前的的發送消息按鈕事件改寫如下:

'/////////////////////轉到發送即時消息頁面

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

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()

privatesubpage_init(byvalsenderassystem.object,byvaleassystem.eventargs)handlesmybase.init

'codegen:thismethodcallisrequiredbythewebformdesigner

'donotmodifyitusingthecodeeditor.

initializecomponent()

#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()

'////////////////////當發送留言時

'/////////////////讀取參數

dimiasinteger

fori=0toubound(splitname)-1

dimmysqlasstring="selectnickfrompwdwherestu_id='"&splitname(i)&"'"

dimcommassqlcommand=newsqlcommand(mysql,conn)

ifi=0then

ifdr.readthen

textbox1.text=trim(dr.item("nick"))&";"

control()

textbox1.text=textbox1.text&trim(dr.item("nick"))&";"

'/////////////////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>"

'/////////////////書寫送出消息事件

publicsubbutton1_click(byvalsenderassystem.object,byvaleassystem.eventargs)handlesbutton1.click

'/////////////////////////當回複留言時

iftextbox2.text=""ortextbox2.text=""then

label10.visible=true

label10.text="消息不能為空!"

label10.visible=false

dimsqlasstring="insertintoinfo(fromstu_id,tostu_id,content,term,tim)values(@fromstu_id,@tostu_id,@content,@term,@tim)"

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

'textbox2.text=""

'/////////////////////////當發送留言時

'////////////////插入i條資料

comm.parameters("@tostu_id").value=splitname(i)

response.write("<scriptlanguage=javascript>alert('發送成功!')</script>")

'////////////////////傳回繼續發送

privatesubbutton2_click(byvalsenderassystem.object,byvaleassystem.eventargs)handlesbutton2.click

response.redirect("boaman.aspx")

response.write("<scriptlanguage=javascript>window.close()</script>")

endclass