- 热门文章:
- · 个性化查询(具有分类模糊查询、换页等功能)
- · .net中即时消息发送的实现……
- · 用vb.net做的校友录……(附所有源代码)
- · web.config一个中文解释
- · Application事件的执行顺序
- · asp.net中当服务器出错时显示指定的错误页面,同时把错误信息写入系统日志文件的探讨
- · 完整的网站间共享数据的WebService(Love.NET原创)
- · HOW TO: Create an Assembly with a Strong Name
- · 图象显示和翻转控件(用户自定义控件)--我也来凑凑热闹--(转)
- · web组件的通信---浅谈事件
- · Using DropDownList control in DataGrid
- · KW大师精品文章赏析
上一篇:改写我前面的即时消息的发送,包含同时给多人发送信息! >>
利用.net来发送即时消息:)
数据库设计: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=1"
Dim comm As SqlCommand = New SqlCommand(mysql, conn)
comm.Parameters.Add(New SqlParameter("@myid", SqlDbType.Int, 4))
comm.Parameters("@myid").Value = Session("stu_id")
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
If dr.Read Then
Response.Write("<script language=JavaScript>window.open(@#info.aspx@#,@#@#,@#height=330,width=560,status=no,location=no,toolbar=no,directories=no,menubar=no@#)</script>")
End If
dr.Close()
comm.Cancel()
下面的代码是用来发送即时消息的页面,其中里面分了两个部分,一个是用来回复的,一个是用来专门发送的,两个的页面稍有区别,仔细看一下就会明白的:)
下面是所有的代码: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
页面部分:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="info.aspx.vb" Inherits="_99re1.info"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body background="image/bg.gif" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:image id="Image3" style="Z-INDEX: 111; LEFT: 141px; POSITION: absolute; TOP: 312px" runat="server" Width="221px" Height="98px" ImageUrl="image/99re1-1.gif"></asp:image>
<asp:textbox id="TextBox1" style="Z-INDEX: 101; LEFT: 73px; POSITION: absolute; TOP: 123px" runat="server" BorderColor="Navy" BorderWidth="1px"></asp:textbox>
<asp:label id="Label1" style="Z-INDEX: 102; LEFT: 26px; POSITION: absolute; TOP: 127px" runat="server" Width="42px" Height="18px" Font-Size="X-Small" ForeColor="Navy" Font-Bold="True">发往:</asp:label>
<asp:label id="Label2" style="Z-INDEX: 103; LEFT: 26px; POSITION: absolute; TOP: 156px" runat="server" Font-Size="X-Small" ForeColor="Navy" Font-Bold="True">内容:</asp:label>
<asp:textbox id="TextBox2" style="Z-INDEX: 104; LEFT: 73px; POSITION: absolute; TOP: 154px" runat="server" TextMode="MultiLine" Width="449px" Height="74px" BorderColor="Navy" BorderWidth="1px" MaxLength="200"></asp:textbox>
<asp:button id="Button1" style="Z-INDEX: 105; LEFT: 357px; POSITION: absolute; TOP: 252px" runat="server" Width="50px" Height="20px" Text="发送" BorderColor="Navy" BorderWidth="1px" BackColor="#FFE0C0"></asp:button>
<asp:button id="Button2" style="Z-INDEX: 106; LEFT: 176px; POSITION: absolute; TOP: 253px" runat="server" Width="87px" Height="20px" Text="继续发送…" BorderColor="Navy" BorderWidth="1px" BackColor="#FFE0C0"></asp:button>
<asp:label id="Label3" style="Z-INDEX: 107; LEFT: 75px; POSITION: absolute; TOP: 10px" runat="server" Width="135px" Height="6px" Font-Size="Small">Label</asp:label>
<asp:label id="Label4" style="Z-INDEX: 108; LEFT: 300px; POSITION: absolute; TOP: 9px" runat="server" Width="219px" Height="13px" Font-Size="Small">Label</asp:label>
<asp:label id="Label5" style="Z-INDEX: 109; LEFT: 73px; POSITION: absolute; TOP: 40px" runat="server" Width="447px" Height="71px" Font-Size="X-Small" BorderColor="SlateGray" BorderWidth="1px">Label</asp:label>
<asp:label id="Label6" style="Z-INDEX: 110; LEFT: 26px; POSITION: absolute; TOP: 12px" runat="server" Font-Size="X-Small" ForeColor="Red" Font-Bold="True">来自:</asp:label>
<asp:TextBox id="TextBox3" style="Z-INDEX: 112; LEFT: 247px; POSITION: absolute; TOP: 122px" runat="server" Visible="False"></asp:TextBox>
<asp:Label id="Label8" style="Z-INDEX: 113; LEFT: 116px; POSITION: absolute; TOP: 55px" runat="server" Height="33px" Width="327px" Font-Bold="True" ForeColor="Navy" Font-Size="Large" Font-Names="方正姚体" Font-Underline="True">直接写入内容点击发送即可!</asp:Label>
<asp:Label id="Label7" style="Z-INDEX: 114; LEFT: 225px; POSITION: absolute; TOP: 12px" runat="server" Height="15px" Width="71px" Font-Bold="True" ForeColor="Red" Font-Size="X-Small">发信日期:</asp:Label>
<asp:Label id="Label9" style="Z-INDEX: 115; LEFT: 25px; POSITION: absolute; TOP: 41px" runat="server" Font-Bold="True" ForeColor="Red" Font-Size="X-Small">内容:</asp:Label>
</FONT>
</form>
</body>
</HTML>
以上代码在bata2环境下调试成功.
特别感谢:cheery_ke提供思路!
朋友一生一起走,多一个朋友就多一分收获!
下一篇:个性化查询(具有分类模糊查询、换页等功能) >>
相关文章:
- · 实现一个客户端的DataSet-----index.htm
- · 实现一个客户端的DataSet-----ClientDataSetDataProvider.asmx.cs(1)
- · 实现一个客户端的DataSet-----ClientDataSetDataProvider.asmx.cs(2)
- · 实现一个客户端的DataSet-----ClientDataSet.htc
- · 安装framework以后出现不能显示aspx页面,提示用户名和密码不匹配问题的解决(chicken修改补充)
- · IIS5 HTTP500内部错误解决办法(转自eNet)------(一)
- · IIS5 HTTP500内部错误解决办法(转自eNet)------(二)
- · IIS5 HTTP500内部错误解决办法(转自eNet)-------(三)
- · page_Load和page_Init的区别
- · 关于如何添加一个自增的列【原创】
- · 获得存储过程返回值的方法(return的值)
- · 关于返回前面的页面。如何两者兼得,自问自答
- · 在ASP.NET中的变量数值管理------看了这个我基本上对原来的REQUEST.FORM的方法传递变量绝望了
- · XML技术上传文件-转贴
- · 在datagrid中的HyperLinkColumn上达到谈出一个窗口的效果
- · 再datagrid中使用droplist。。。。重要的是其中的几个用法
- · 一个用C#做的HTTP SERVER(从WINFORM搬来的)
- · ViewState 到底是什么?
- · 允许用户一次上传多个文件
- · 用C# 实现Web文件的上传
- · ASP.NET Caching
- · ASP.NET Caching(2)
- · ASP.NET ViewState 初探 (3) 转自msdn
- · ASP.NET ViewState 初探 (2) 转自msdn
- · ASP.NET ViewState 初探 (1) 转自msdn
- · ASP.NET Framework深度历险(3)
- · ASP.NET下根据QueryString决定使用哪块javascript的两种方法 :)
- · ASP.NET Framework深度历险(2)
- · 图片上传的功能简介及web.config设置(自动生成所略图)
- · 图片上传的数据库部分(自动生成所略图)
- · 图片上传的WebForm(自动生成所略图)
- · 图片上传的Codebehind(自动生成所略图)
- · ASP.NET中的事务处理和异常处理
- · ASP.NET中异常处理使用(详细)
- · ASP.NET Framework深度历险(1)
- · 我写的上传(upload)文件的codebehind代码(1gdt)
- · 我写的上传(upload)文件的codebehind代码
- · 先装.net后装IIS的问题
