华北科技学院网络编程B大作业.docx

上传人:b****7 文档编号:10607695 上传时间:2023-02-21 格式:DOCX 页数:14 大小:88.05KB
下载 相关 举报
华北科技学院网络编程B大作业.docx_第1页
第1页 / 共14页
华北科技学院网络编程B大作业.docx_第2页
第2页 / 共14页
华北科技学院网络编程B大作业.docx_第3页
第3页 / 共14页
华北科技学院网络编程B大作业.docx_第4页
第4页 / 共14页
华北科技学院网络编程B大作业.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

华北科技学院网络编程B大作业.docx

《华北科技学院网络编程B大作业.docx》由会员分享,可在线阅读,更多相关《华北科技学院网络编程B大作业.docx(14页珍藏版)》请在冰豆网上搜索。

华北科技学院网络编程B大作业.docx

华北科技学院网络编程B大作业

华北科技学院计算机系综合性实验

实验报告

 

课程名称网络编程B

实验学期2011至2012学年第2学期

学生所在系部计算机系

年级专业班级

学生姓名学号

任课教师

实验成绩

 

计算机系制

实验报告须知

1、学生上交实验报告时,必须为打印稿(A4纸)。

页面空间不够,可以顺延。

2、学生应该填写的内容包括:

封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。

3、教师应该填写的内容包括:

实验成绩、教师评价等。

4、教师根据本课程的《综合性实验指导单》中实验内容的要求,评定学生的综合性实验成绩;要求在该课程期末考试前将实验报告交给任课教师。

综合性实验中,所涉及的程序,文档等在交实验报告前,拷贝给任课教师。

任课教师统一刻录成光盘,与该课程的期末考试成绩一同上交到系里存档。

5、未尽事宜,请参考该课程的实验大纲和教学大纲。

《网络编程B》课程综合性实验报告

开课实验室:

四机房2012年5月14日

实验题目

聊天室的设计

一、实验目的

1、掌握ASP.NET内部控件的应用。

2、掌握ASP.NET内部对象的应用。

3、Application对象的深入应用。

4、掌握数据库的建立、连接与数据的存取。

5、掌握动态网站开发的基本流程。

二、设备与环境

硬件:

多媒体计算机

软件:

Windows系列操作系统(含IIS5.0以上版本)、.Net运行环境及编译环境、Access2000、SQLServer2000

三、实验内容及要求

1.实验要求

1、简单文字聊天室的需求分析。

2、系统的功能模块设计。

要求画出功能模块框图。

3、数据库的设计,要求数据库结构设计合理。

4、系统的详细设计。

要求可以统计在线人数、实现私聊等功能。

5、应用到的关键技术的详细说明。

可附相关的关键程序代码。

6、系统页面设计要求清晰、实用、美观。

2.实验内容

1)需求分析:

简易聊天室开发一般不能实现网页的动态刷新和数据的更新。

本聊天室的设计通过定时刷新解决了这一问题,使聊天室中的在线用户列表和即时聊天信息得到动态更新。

2)主要功能:

发送、接受聊天信息、删除聊天记录、清楚在线用户等功能。

3)登陆界面:

 

4)聊天室资源管理器窗口:

5)系统文件说明:

文件名

说明

Default.aspx.cs

用户登录类

Main.aspx.cs

主界面类

SendMessage.aspx.cs

消息发送类

Session.aspx.cs

消息会话类

ShowMessage.aspx.cs

消息显示类

Users.aspx.cs

用户登录判断类

AspChat.sln

聊天记录保存文件

6)聊天室界面布局:

用户登录类Default.aspx.cs:

用户登录类,用于用户登录限制及判断,以及对用户信息的处理。

Default.aspx.cs类的具体代码如下:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

usingSystem.Collections;

publicpartialclass_Default:

System.Web.UI.Page

{

///

///登陆事件

///

///

///

protectedvoidbtnLogin_Click(objectsender,EventArgse)

{

//如果用户名的长度小于四,则提示用户名太短

if(this.txtUserName.Text.Trim().Length<3)

{

lblTs.Visible=true;//提示用户名太短的Lbl控件显示

}

else

{

stringUserIp=Request.UserHostAddress.ToString(); //获取客户端IP地址

Session["User"]=this.txtUserName.Text.Trim();//把用户名存入Session

stringUserInfo=this.txtUserName.Text.Trim()+"--"+UserIp;//定义变量把用户名和用户Ip地址拼接起来,在用户列表页面使用

ArrayListUserList;//定义一个集合

if(Application["UserList"]==null)//如果Application中的UserList如空,也就是初始化的时候

{

UserList=newArrayList();//定义一个ArrayList集合接收Application的值

UserList.Add(UserInfo);//将用户信息添入集合

Application["UserList"]=UserList;//重新给Application赋值

Response.Redirect("Main.aspx");//将页面重定向,跳转至聊天主页面

}

else

{

UserList=(ArrayList)Application["UserList"];//如果不为空的话,直接将Application中的UserList赋值给UserList

UserList.Add(UserInfo);//向有原始值的UserList集合里面添加用户信息

Application["UserList"]=UserList;//将原始数据覆盖

Response.Redirect("Main.aspx");//将页面重定向,跳转至聊天主页面

}

}

}

}

 

主界面类Main.aspx.cs:

如果用户未登陆,直接进入本页面,将自动将页面转发至首页。

实现代码如下:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

publicpartialclassMain:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

//如果用户未登陆,直接进入本页面,将自动将页面转发至首页

if(Session["User"]==null)

{

Response.Redirect("Default.aspx");

}

}

}

消息发送类SendMessage.aspx.cs:

包括所有的聊天信息和聊天用户,用于处理聊天记录以及用户信息的综合类。

实现代码如下:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

publicpartialclassSendMessage:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

//如果用户未登陆,直接进入本页面,将自动将页面转发至首页

if(Session["User"]==null)

{

Response.Redirect("Default.aspx");

}

}

///

///发送消息

///

///

///

protectedvoidbtnSend_Click1(objectsender,EventArgse)

{

ArrayListMessageList=newArrayList();//定义ArrayList集合

stringSendUser=Session["User"].ToString();//定义变量接收保存再Session里面的用户名

stringSendMessage=this.txtMessage.Text;//定义变量接收文本框里面的值

stringSendTime=DateTime.Now.ToString();//获取当前时间

stringMessage=SendUser+"于"+SendTime+"说:

"+SendMessage+"

";//拼接聊天信息格式如:

xluo于2009-9-1204:

27:

21说:

大家好啊!

if(Application["MessageList"]==null)//如果为空

{

MessageList.Add(Message);//将集合初始化

Application["MessageList"]=MessageList;//重新覆盖

}

else

{

MessageList=(ArrayList)Application["MessageList"];//如果不为空的话,将原始数据赋值给集合

MessageList.Add(Message);//将新数据和原始数据合并添入集合

Application["MessageList"]=MessageList;//覆盖原始数据

}

}

///

///删除聊天信息

///

///

///

protectedvoidbtnDeleteMessage_Click(objectsender,EventArgse)

{

Application.Remove("MessageList");//将MessageList从Application里面删除

}

///

///清除在线用户

///

///

///

protectedvoidbtnDeleteUsers_Click(objectsender,EventArgse)

{

Application.Remove("UserList");//将UserList从Application里面删除

Response.Redirect("Default.aspx");//返回首页

}

}

消息会话类Session.aspx.cs类:

用于保存用户聊天信息。

Session.aspx.cs具体代码:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

publicpartialclassSession:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

}

protectedvoidButton1_Click(objectsender,EventArgse)

{

stringaaa=TextBox1.Text;

Session["neirong"]=aaa;

Response.Write(Session["neirong"].ToString());

}

}

消息显示类ShowMessage.aspx.cs类:

聊天实时显示类。

ShowMessage.aspx.cs具体代码:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

publicpartialclassShowMessage:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

//如果用户未登陆,直接进入本页面,将自动将页面转发至首页

if(Session["User"]==null)

{

Response.Redirect("Default.aspx");

}

}

}

用户登录判断类Users.aspx.cs类:

如果用户未登陆,直接进入本页面,将自动将页面转发至首页。

Users.aspx.cs具体代码:

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Collections;

usingSystem.Web;

usingSystem.Web.Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

publicpartialclassUsers:

System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

//如果用户未登陆,直接进入本页面,将自动将页面转发至首页

if(Session["User"]==null)

{

Response.Redirect("Default.aspx");

}

}

}

四、实验结果及分析

 

用户登录界面

聊天室主界面

通过本次.NET聊天室的设计,实现了聊天室的基本功能,主要包括了消息的发送,接受,聊天内容的实时更新、在线用户的动态,用户登录后可以进行聊天记录的清空,以及用户的在线清楚,聊天是没有实现用户私聊等功能,还有许多要改进之处!

 

教师评价

评定项目

A

B

C

D

评定项目

A

B

C

D

算法正确

界面美观,布局合理

程序结构合理

操作熟练

语法、语义正确

解析完整

实验结果正确

文字流畅

报告规范

题解正确

其他:

 

评价教师签名:

年月日

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1