閱讀833 返回首頁    go 技術社區[雲棲]


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

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

 


'/////////////////////轉到發送即時消息頁麵
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_border-right:#cccccc 1px dotted;table-layout:fixed;border-top:#cccccc 1px dotted;border-left:#cccccc 1px dotted;border-bottom:#cccccc 1px dotted;" border="0">


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_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_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

最後更新:2017-04-02 00:06:33

  上一篇:go ASP.NET中水晶報表的使用
  下一篇:go 校內網API的.net版本XiaoNei.Net 1.0(非官方)