正在阅读:.net中即时消息发送的实现…….net中即时消息发送的实现……

2004-02-14 09:34 出处:PConline 作者:icefox/ASPCool.com 责任编辑:zwg
下面的代码是用来发送即时消息的页面,其中里面分了两个部分,一个是用来回复的,一个是用来专门发送的,两个的页面稍有区别,仔细看一下就会明白的:) 下面是所有的代码:codebehind部分 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") 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 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 mysql As String = "select nick from pwd where stu_id='" & tostu_id & "'" Dim comm As SqlCommand = New SqlCommand(mysql, conn) Dim dr As SqlDataReader conn.Open() dr = comm.ExecuteReader While dr.Read TextBox1.Text = dr.item("nick") End While TextBox1.Enabled = False Label3.Text = "" Label4.Text = "" Label5.Visible = False Label8.Visible = True Label6.Visible = False Label7.Visible = False Label9.Visible = False dr.close() End If End If 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") If tostu_id = "" Then '/////////////////////////当回复留言时 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 = "" Else '/////////////////////////当发送留言时 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 = tostu_id 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 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 End Class
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品