资源描述
软件工程课程设计实验报告
摘要:
本系统实现网络相册的的基本功能,包括用户创建影集,修改影集名称,用户的注册和登录,用户图片的上传,数据库图片的播放;管理员管理图片和用户。系统利用.Net平台技术进行开发,实现相册的的动态管理,使得对信息的管理更加及时、高效,提高了效率。同时还对系统的开发原理、功能特点和设计方案进行了介绍。
一、课程设计的目的与要求
通过软件开发的实践训练,进一步掌握软件工程的方法和技术,提高软件开发的实际能力,培养工程设计能力和综合分析、解决问题的能力。
具体如下:
1.学习和实践在分析和设计计算机应用系统所需要的知识,包括面向对象的系统分析与设计,编码和测试方面的知识;
2.熟悉自动化的软件开发工具Rational Rose 2003,并将其运用于软件开发的全过程;
3.进一步加强和提高软件工程文档的编写能力;
4.培养协作能力和团队精神。
二、设计正文
1.概述
1.1课题题目:个人电子相册的设计与实现
1.2系统的主要目标:
研究Flash、Flex、Silverlight等富客户端(Rich Client)编程技术,了解B/S编程技术
发展的未来趋势,掌握一种开发平台,编写出具有更高交互性和网络体验的Web应用程序。
1.3系统的开发环境及运行环境:
操作系统:Windows 7旗舰版
建模工具:Rational Rose 2003
数据库系统:Access 2007
开发工具:Visual Studio 2010
Web服务器:IIS+ASP.NET 2.0平台
2.1可行性分析
2.1.1系统总体目标
电子相册是互联网络的产物,现在电子相册系统已经层出不穷,而本系统是一个区别于现在国内外已经开发出来的电子相册网站系统,它是一个单用户空间而非网站,主要是一个为用户提供的个人相片展示、存放的个人相册空间。
这个电子相册的定位是一群朋友共享照片、交流讨论的开放式的个人空间。本系统可以供自己展示、存放照片,可以让拥有正确口令的浏览者浏览该用户的照片以及发表留言,同时拥有正确口令的浏览者也享有用户所有的权利(上传、删除相片等),它在某种程度上是开放式的、自由式的。因此这是一个相对来说安全、私密、开放的和朋友分享、交流的私人电子相册空间。
2.1.2技术可行性分析
1
这个电子相册是一种基于B/S架构的管理系统,它采用目前最有发展前景的c#语言编写,用到了当今先进的技术如Html,CSS+DIV,JavaScript,Mysql等关键技术来实现该系统。开发本系统的Visual Studio 2010编程软件、是可以直接在网络上免费下来得来的,其中的Wamp集成环境在Windows平台下集成了Apache、MySQL、PHP服务,无需再另外下载PHP环境和MySQL数据库。这些应用软件是现在常用的网页开发工具,都能够很方便的掌握,并且也学了有关网页开发的课程,实现该电子相册空间的技术能够比较好的实现,所以对于本系统在技术上是可以达到的。
2.2需求分析
2.2.1总体需求
该设计系统要具有实用性,功能完善,界面良好。设计该系统的流程如图3所示。
流程设计:程序设计:
图2.1程序设计流程图
2.2.2功能需求
本系统应该具有登录验证、修改密码、创建相册、浏览相片、上传相片、删除相册或相片、等功能,详见图4。
图2.2电子相册系统功能结构图
2
3.系统总体设计
3.1设计问题域子系统
相册系统是实现用户上传照片、用户交流图片以的一个平台,整个电子相册系统有前台和后台两部分,共分为4个模块:用户上传,管理模块,注册登录模块和阅览模块,分别用于完成各自的功能。
(1)各模块功能
表2-1学生选课系统功能模块表
3.2设计数据管理子系统
(1)数据库表
表3-2数据库表
(3)数据库表结构
①相册tb_type的详细数据字段:
②相片tb_photo的详细数据字段:
表3-4 Teacher教师用户表
3
③用户表admin的详细数据字段:
3.3设计人机交互子系统
(1)用户分类
本系统的用户可分为三类:②管理员用户;②普通用户;(2)用户描述
①管理员用户的描述:
管理员用户在整个选课系统中起到管理和维护的作用,对普通的信息进行管理和维护。②普通用户的描述:普通用户负责试用系统的各项
4.1用户注册流程图
4
4.2用户上传图片流程图
4.3用户创建相册流程图
图4-1系统用户登录流程图5
图4-3用户创建相册流程图
4.系统实现
本系统采用了三层架构来实现,即分为用户界面层(UI)、业务逻辑层(BLL)和数据访问层(DAL),用户界面层是展示给用户的界面,方便用户与系统进行交互;业务逻辑层是对系统业务实体的封装,完成系统业务功能;数据访问层直接与数据库打交道,为业务逻辑层提供底层的数据库操作。
5.1主要是与数据库连接,提供数据库操作功能,代码如下:
public static OleDbConnection createNewCon()//创建并打开一个链接
{
string conStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="
+System.AppDomain.CurrentDomain.BaseDirectory+@"\App_Data\photo.mdb";
OleDbConnection con=new OleDbConnection(conStr);
con.Open();
return con;
}
}
5.2所有系统角色用户的基类,完成用户登录验证功能,代码如下:
private void LoginCheck()
{
string UserID=txtuser.Text.Trim().ToString();
string pwd=txtpassword.Text.Trim().ToString();
OleDbConnection con=Db.createNewCon();
//con.Open();
string Sql="Select user,pwd from admin where user='"+UserID+"'and pwd='"+pwd+"'";OleDbCommand cmd=new OleDbCommand(Sql.ToString(),con);
//开a始??验¨?证?è
OleDbDataReader read=cmd.ExecuteReader();
if(read.Read())
6
{
Response.Redirect("Index.aspx");
}
else
{
Response.Write("<script>alert('帐¨?号?或¨°密¨?码?错?¨?误¨?!')</script>");}
con.Close();
}
//登录
protected void btnOK_Click(object sender,EventArgs e)
{
LoginCheck();
}
protected void btnSi_Click(object sender,EventArgs e)
{
Response.Redirect("resign.aspx");
}
5.3系统注册页面,代码及运行效果如下:
private void Add()
{
string UserID=txtuser.Text.Trim().ToString();
string pwd=txtpassword.Text.Trim().ToString();
OleDbConnection con=Db.createNewCon();
string Sql="insert into admin([user],[pwd])"+
"values(@user,@pwd)";
OleDbCommand cmd=new OleDbCommand(Sql.ToString(),con);
cmd.Parameters.AddWithValue("@user",UserID);
cmd.Parameters.AddWithValue("@pwd",pwd);
int redult=cmd.ExecuteNonQuery();
if(redult>0)
Response.Redirect("Login.aspx");
}
protected void btnqd_Click(object sender,EventArgs e)
{
Add();
}
}
7
5.4上传读取图片信息代码如下:
public int add(string typename){
OleDbConnection con=Db.createNewCon();
string sql="insert into tb_type(typeName)"+
"values(@typeName)";
OleDbCommand cmd=new OleDbCommand(sql);
cmd.Connection=con;
cmd.Parameters.AddWithValue("@typeName",typename);
int count=cmd.ExecuteNonQuery();
return count;
}
//新?增?图??片?
public int addpic(string Title,int type,string imgPath,string Content,string Creater,string creatTime)
{
OleDbConnection con=Db.createNewCon();
string sql="insert into tb_photo(Title,type,imgPath,Content,Creater,creatTime)"+"values(@Title,@type,@imgPath,@Content,@Creater,@creatTime)";
OleDbCommand cmd=new OleDbCommand(sql);
cmd.Connection=con;
cmd.Parameters.AddWithValue("@Title",Title);
cmd.Parameters.AddWithValue("@type",type);
cmd.Parameters.AddWithValue("@imgPath",imgPath);
cmd.Parameters.AddWithValue("@Content",Content);
cmd.Parameters.AddWithValue("@Creater",Creater);
cmd.Parameters.AddWithValue("@creatTime"
,creatTime);
8
int count=cmd.ExecuteNonQuery();
return count;
}
//读¨?取¨?图??片?信?息?é
public DataSet getAllPic(){
OleDbConnection con=Db.createNewCon();
OleDbDataAdapter dad=new OleDbDataAdapter();
dad.SelectCommand=new OleDbCommand("select*from[tb_photo]order by[id]DESC",con);DataSet ds=new DataSet();
dad.Fill(ds,"tb_photo");
con.Close();
return ds;
}
public DataSet getAllPicToN()
{
OleDbConnection con=Db.createNewCon();
OleDbDataAdapter dad=new OleDbDataAdapter();
dad.SelectCommand=new OleDbCommand("select top 10*from[tb_photo]order by[id]DESC",con);DataSet ds=new DataSet();
dad.Fill(ds,"tb_photo");
con.Close();
return ds;
}
public DataSet getAllPicType()
{
OleDbConnection con=Db.createNewCon();
OleDbDataAdapter dad=new OleDbDataAdapter();
dad.SelectCommand=new OleDbCommand("select*from[tb_type]order by[id]asc",con);DataSet ds=new DataSet();
dad.Fill(ds,"tb_type");
con.Close();
return ds;
}
public DataSet getAllPicTypeById(int id)
{
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand("select*from[tb_type]where id=@id order by[id]asc",con);cmd.Parameters.AddWithValue("@id",id);
OleDbDataAdapter dad=new OleDbDataAdapter(cmd);
DataSet ds=new DataSet();
dad.Fill(ds,"tb_type");
con.Close();
return ds;
}
9
public DataSet getAllPicTypeByType(int typeId)
{
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand("select*from[tb_photo]where type=@typeId order by[id]asc",con);
cmd.Parameters.AddWithValue("@typeId",typeId);
OleDbDataAdapter dad=new OleDbDataAdapter(cmd);
DataSet ds=new DataSet();
dad.Fill(ds,"tb_photo");
con.Close();
return ds;
}
public int GetMaxId(){
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand("select max(Id)from[tb_photo]",con);
int count=(int)cmd.ExecuteScalar();
con.Close();
return count;
}
public int GetMinId()
{
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand("select min(Id)from[tb_photo]",con);
int count=(int)cmd.ExecuteScalar();
con.Close();
return count;
}
public DataSet getAllPicById(int id)
{
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand("select*from[tb_photo]where id=@id order by[id]asc",con);
cmd.Parameters.AddWithValue("@id",id);
OleDbDataAdapter dad=new OleDbDataAdapter(cmd);
DataSet ds=new DataSet();
dad.Fill(ds,"tb_photo");
con.Close();
return ds;
}
10
public int getAllPicCount(){
OleDbConnection con=Db.createNewCon();
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=con;
cmd.CommandText="select count(*)from tb_photo";
int count=(int)cmd.ExecuteScalar();
return count;
}
}
5.5用户创建相册界面代码及运行效果如下:
protected void Page_Load(object sender,EventArgs e)
{
if(!Page.IsPostBack){
DataTable dt=new photo().getAllPicType().Tables[0];
this.GridView1.DataSource=dt;
this.GridView1.DataBind();
}
}
protected void btnadd_Click(object sender,EventArgs e)
{
string typename=this.TextBox1.Text.ToString();
int count=new photo().add(typename);
if(count>0)
{
Page.RegisterStartupScript(null,"<script>alert('添?¨?加¨?成¨?功|!');</script>");}
else{
Page.RegisterStartupScript(null,"<script>alert('添?¨?加¨?失???败?¨?!');</script>");}
}
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor,this.style.backgroundColor='red'");
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
}
11
}
5.6用户图片代码及运行效果如下:
public void databinds(){
DataTable dt=new photo().getAllPicType().Tables[0];
this.dropdownlists.DataSource=dt;
this.dropdownlists.DataTextField="typeName";
this.dropdownlists.DataValueField="id";
this.dropdownlists.DataBind();
}
protected void btnadd_Click(object sender,EventArgs e)
{
//string id=new Random().Next(1,1000).ToString();
//将?附?件t传??送¨?到??服¤t务?器??上??
string path=FileUpload1.PostedFile.FileName.ToString();//获?取¨?上??传??图??片?路?¤径?string ext=path.Substring(path.LastIndexOf(".")+1);//获?取¨?图??片?扩¤?展1名?
if(ext.ToLower()=="jpg"||ext.ToLower()=="bmp"||ext.ToLower()=="gif"||ext.ToLower()=="png"||ext.ToLower()=="tif"||ext.ToLower()=="jpeg")
{
string phototitle=this.txttitle.Text.ToString();
string photocontent=this.txtcontent.Text.ToString();
string wPath="../upload/"+path;
string sPath=Server.MapPath("../upload/"+path);//设?¨¨置?图??片?保??ê存??到??服¤t务?器??上??路?¤径?
string suoPath=Server.MapPath("../suo/")+path;
//path="..\\Photo\\"+PhotoID+"."+ext;//保??ê存??到
??
12
数?y据Y库a中D路?¤径?
FileUpload1.PostedFile.SaveAs(sPath);//保??ê存??到??服¤t务?器??string urlPath=wPath;
string photoUser="admin";
string time=DateTime.Now.ToString();
int type=Convert.ToInt32(this.dropdownlists.SelectedValue.ToString());
int count=new photo().addpic(phototitle,type,path,photocontent,photoUser,time);if(count>0)
{
PictureSlightly.MakeImage(sPath,suoPath,100,100,"hw");
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,"<script>alert('添?¨?加¨?成¨?功|!');</script>");
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,"<script>alert('添?¨?加¨?失???败?¨?!');</script>");
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,"<script>alert('只?能¨?上??传??图??片?!');</script>");
}
}
}
13
5.7用户查看代码及运行效果如下:
protected void ImageButton1_Click(object sender,ImageClickEventArgs e)
{
id=Request.QueryString["id"];
if(id!=null)
{
int newId=int.Parse(id)-1;
if(newId>=new photo().GetMinId())
{
this.Repeater1.DataSource=new photo().getAllPicById(newId).Tables[0];
this.Repeater1.DataBind();
Response.Redirect("show.aspx?id="+newId);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,"<script>alert('再¨?无T数?y据Y可¨?查¨?!');</script>");
return;
}
}
}
//下?一°?张?图??片?
5.系统测试
在系统测试中,我们首先对各个子模块进行单元测试,即把每一个模块作为一个单独的实体来测
14
试,保证每个模块作为一个单元能正确运行。然后在完成所有模块后,我们将各子模块集成起来,再对它进行系统测试,找出系统设计或编码上的错误,以及验证系统是否实现了指定的功能。最后找几个其他的同学再对系统进行黑盒子测试,验证系统是否满足用户的功能需求。
在测试的过程,特别是在集成测试之后,发现了许多问题及功能缺陷,最后经过修改调试后都解决了。
三、课程设计总结或结论
1.通过这次软件工程课程设计的实践训练,进一步掌握软件工程的方法和技术,提高软件开发的实
际能力,培养工程设计能力和综合分析、解决问题的能力。
1.1
1.2
1.3
1.4学习和实践了分析和设计软件系统的各种知识,包括面向对象的系统分析与设计,编码和测试方面的知识。掌握了自动化的软件开发工具Rational Rose 2003,并将其运用于软件开发的全过程。加深掌握了.Net平台的三层架构模式设计。进一步加强和提高软件工程文档的编写能力。
2.本系统基本实现了关键的功能模块,在功能上基本满足了用户的需求,但是由于时间较紧,有些
模块以及整个系统还有许多不完善的地方,如界面不太美观,操作性不太友好等。
展开阅读全文