数据库设计
info表
id fromstu_id tostu_id content term
其中id是主键fromstu_id是发送信息的用户的学号tostu_id是接受信息的用户的学号content是消息的内容term是判断是否为新消息
下面的代码加在校友录中的if not ispostback中
/////////////////////判断是否有新留言将自动弹出页面这里还要将页面的刷新时间设置一下以便可以循环的读取信息
Dim mysql As String = select * from info where tostu_id=@myid and term=
Dim comm As SqlCommand = New SqlCommand(mysql conn)
commParametersAdd(New SqlParameter(@myid SqlDbTypeInt ))
commParameters(@myid)Value = Session(stu_id)
Dim dr As SqlDataReader
connOpen()
dr = commExecuteReader
If drRead Then
ResponseWrite( )
End If
drClose()
commCancel()
下面的代码是用来发送即时消息的页面其中里面分了两个部分一个是用来回复的一个是用来专门发送的两个的页面稍有区别仔细看一下就会明白的
下面是所有的代码codebehind部分
Public Sub Page_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
If Not IsPostBack Then
Dim tostu_id As String = RequestQueryString(tostu_id)
If tostu_id = Then
//////////////////当回复留言时
Dim sql As String = select a*bnick from info apwd b where afromstu_id=bstu_id and atostu_id= & Session(stu_id) & and aterm=
Dim comm As SqlCommand = New SqlCommand(sql conn)
Dim dr As SqlDataReader
connOpen()
dr = commExecuteReader
While drRead
LabelText = drItem(nick)
LabelText = drItem(tim)
LabelText = drItem(content)
TextBoxText = drItem(nick)
TextBoxText = drItem(fromstu_id)
TextBoxEnabled = False
LabelVisible = False
End While
drClose()
commCancel()
//////////////////////更新留言使留言属性为已阅读过
Dim sql_ As String = update info set term= where tostu_id= & Session(stu_id) & and term= and tim= & LabelText &
comm = New SqlCommand(sql_ conn)
commExecuteNonQuery()
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
connOpen()
dr = commExecuteReader
While drRead
TextBoxText = em(nick)
End While
TextBoxEnabled = False
LabelText =
LabelText =
LabelVisible = False
LabelVisible = True
LabelVisible = False
LabelVisible = False
LabelVisible = False
drclose()
End If
End If
End Sub
/////////////////书写提交消息事件
Public Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
Dim tostu_id As String = RequestQueryString(tostu_id)
If tostu_id = Then
/////////////////////////当回复留言时
connOpen()
Dim sql As String = insert into info(fromstu_idtostu_idcontenttermtim) values(@fromstu_id@tostu_id@content@term@tim)
Dim comm As SqlCommand = New SqlCommand(sql conn)
commParametersAdd(New SqlParameter(@fromstu_id SqlDbTypeInt ))
commParameters(@fromstu_id)Value = Session(stu_id)
commParametersAdd(New SqlParameter(@tostu_id SqlDbTypeInt ))
commParameters(@tostu_id)Value = TextBoxText
commParametersAdd(New SqlParameter(@content SqlDbTypeVarChar ))
commParameters(@content)Value = TextBoxText
commParametersAdd(New SqlParameter(@term SqlDbTypeInt ))
commParameters(@term)Value =
commParametersAdd(New SqlParameter(@tim SqlDbTypeChar ))
commParameters(@tim)Value = DateNow
commExecuteNonQuery()
TextBoxText =
Else
/////////////////////////当发送留言时
connOpen()
Dim sql As String = insert into info(fromstu_idtostu_idcontenttermtim) values(@fromstu_id@tostu_id@content@term@tim)
Dim comm As SqlCommand = New SqlCommand(sql conn)
commParametersAdd(New SqlParameter(@fromstu_id SqlDbTypeInt ))
commParameters(@fromstu_id)Value = Session(stu_id)
commParametersAdd(New SqlParameter(@tostu_id SqlDbTypeInt ))
commParameters(@tostu_id)Value = tostu_id
commParametersAdd(New SqlParameter(@content SqlDbTypeVarChar ))
commParameters(@content)Value = TextBoxText
commParametersAdd(New SqlParameter(@term SqlDbTypeInt ))
commParameters(@term)Value =
commParametersAdd(New SqlParameter(@tim SqlDbTypeChar ))
commParameters(@tim)Value = DateNow
commExecuteNonQuery()
TextBoxText =
End If
ResponseWrite( )
End Sub
////////////////////返回继续发送
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
ResponseRedirect(boamanaspx)
End Sub
End Class