网络U盘课程设计说明书_第1页
网络U盘课程设计说明书_第2页
网络U盘课程设计说明书_第3页
网络U盘课程设计说明书_第4页
网络U盘课程设计说明书_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 课程设计设计说明书 电子信息工程09-1班 王旭涛科信学院课程设计说明书(2011/2012学年第一学期)课程名称 : 软件程序设计 题 目 : 网络U盘 专业班级 : 电子信息工程09-1 学生姓名 : 学 号: 指导教师 : 设计周数 : 2周 设计成绩 : 2012年1月6日目 录1. 绪论11.1 课程设计的意义及目的21.2 课程设计的主要任务21.3 课程设计的技术要求22设计正文32.1 网络U盘设计分析32.1.1 需求分析32.1.2 系统总体框图32.2 数据库设计32.2.1 数据库所列表32.3 程序设计42.3.1 程序分析42.3.2 程序流程图42.3.3 主要

2、代码52.4 系统测试153设计总结164参考资料171 绪论1.1 课程设计的意义及目的 软件程序设计是一个重要的实践性教学环节,是通信专业的技术基础课。通过这一训练可以巩固学生所学C#和数据库的理论知识,有助于学生培养正确的设计思想,逐步树立正确的设计思想,培养分析和解决实际问题的能力。对后续专业课程的学习、毕业设计以及今后从事程序设计工作奠定扎实的基础具有重要的意义。 其目的主要包括:(1)通过本次课程设计,熟悉网络U盘的设计过程;(2)掌握C#和数据库相结合设计软件的方法;(3)掌握登录、文件上传、下载、删除、重命名等常用功能的编写方法;(4)掌握数据绑定、排序、分页的实现方法;(5)

3、掌握其主要思想,能够举一反三,设计其他软件程序。1.2 课程设计的主要任务(1)根据技术要求和现有开发环境,分析题目;(2)设计软件方案。包括:模式的选择(B/S或C/S)、数据库的选择、软件功能结构、各功能模块的详细描述、关键程序流程图、数据库中表的结构设计等;(3)调试、修改并完善程序(4)生成安装程序,编写软件使用说明书(图文结合进行描述);(5)修改并完善设计;(6)撰写课程设计报告。1.3 课程设计的技术要求(1)个人用户登录,新用户注册,密码修改;(2)个人上传文件,并可对文件进行管理;(3)个人可下载自己的文件;(4)文件按时间先后顺序排序显示,并支持分页显示功能。2 设计正文2

4、.1 网络U盘设计分析2.1.1 需求分析根据网络U盘的技术要求和现有开发环境,作如下具体需求分析:本设计可以在基于Web模式下实现用户对文件的基本管理,包括上传、下载、重命名和删除等基本操作;可注册一些新用户进行个人文件的管理;用户可自行修改自身密码;在文件列表中文件需按时间先后顺序排序显示,并支持分页显示功能。2.1.2 系统总体框图网络U盘系统pan系统新用户注册系统普通用户系统新用户注册模块新用户登录模块用户操作模块文件管理模块帮助用户登录模块修改密码模块用户上传文件模块重命名文件模块删除文件模块下载文件模块帮助图2-1 网络U盘系统设计结构图2.2 数据库设计2.2 数据库所列表文件

5、信息表(Directory):表2-1 文件列表(Directory)列名数据类型长度是否为主键是否为空注释DirIDint是否文件序号Namevarchar20否否文件名称Containint否否文件大小CreateDatedatetime否否创建时间Urlvarchar255否否文件路径Typevarchar200否否文件类型用户信息表(Users):表2-2 用户信息表(Users)列名数据类型长度是否为主键是否为空注释UserNamevarchar20是否用户登录帐号UserPasswordvarchar20否否用户登录密码2.3程序设计2.3.1 程序分析通过分析任务,程序中封装一个

6、类供各部分相应窗体后台代码调用,类名为:王旭涛.cs。其中包括的方法为:获取单个文件的信息-GetSingleFile添加文件信息到数据库-AddFile修改数据库中的文件名-EditFile删除数据库中的文件信息-DeleteFile对应设计中的用户登录页面、新用户注册页面、查看文件页面、修改密码页面、上传文件页面和管理页面,设计的后台代码及名称包括登录代码Login.aspx.cs,注册代码UserAdd.aspx.cs,文件列表代码List.aspx.cs,修改密码的代码ModifyPwd.aspx.cs,上传代码UpLoad.aspx.cs,下载代码Down.aspx.cs,重命名代码

7、EditFile.aspx.cs,删除文件代码GuanLi.aspx.cs。开始初始化程序进入相应登录页面输入登录账号和密码判断数据库里帐号与密码是否相符?进入各自相应界面输出登录失败信息结束2.3.2 程序流程图图2-2 用户登录流程图开始初始化程序新用户注册页面进入各自相应界面输出注册失败信息结束进入登录页面注册成功?意接受图2-3 新注册用户登录流程图2.3.1 主要代码(1)封装类王旭涛.cs:public class 王旭涛 public SqlDataReader GetSingleFile(int nFileID) SqlConnection myConnection = new

8、 SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); string cmdText = "SELECT * "+ "FROM Directory WHERE Directory.DirID='"+ nFileID.ToString() + "'" SqlCommand myCommand = new SqlCommand(cmdText, myConnection);

9、 SqlDataReader dr = null; myConnection.Open(); dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);/返回DataReader return dr; public int AddFile(string sName, int nContain, string sUrl, string sType) /创建链接 SqlConnection myConnection = new SqlConnection( ConfigurationManager.ConnectionStrings

10、"SQLCONNECTIONSTRING".ConnectionString); /定义SQL语句,添加 string cmdText = "INSERT INTO Directory Name,Contain,Url,Type,CreateDate)VALUES("+ "'" + sName + "'," + "'" + nContain.ToString() + "'," + "'" + sUrl + "

11、;'," + "'" + sType + "'," + "GetDate()"+ ")" /创建Command SqlCommand myCommand = new SqlCommand(cmdText, myConnection); /定义返回值 int nResult = -1; try myConnection.Open(); /执行SQL语句 nResult = myCommand.ExecuteNonQuery(); finally /关闭链接 myConnection.

12、Close(); /返回nResult return nResult; public int EditFile(int nFileID, string sName, string sUrl) SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); string cmdText = "UPDATE Directory SET Name ="+ "'

13、;" + sName + "'"+ ", Url ="+ "'" + sUrl + "'"+ " WHERE DirID='" + nFileID.ToString() + "'" /创建Command SqlCommand myCommand = new SqlCommand(cmdText, myConnection); /定义返回值 int nResult = -1; try /打开链接 myConnection.Ope

14、n(); /执行SQL语句 nResult = myCommand.ExecuteNonQuery(); finally /关闭链接 myConnection.Close(); return nResult; public int DeleteFile(int nFileID) SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); string cmdText = "d

15、elete Directory where DirID ="+ "'" + nFileID.ToString() + "'" SqlCommand myCommand = new SqlCommand(cmdText, myConnection); int nResult = -1; try myConnection.Open(); /执行SQL语句 nResult = myCommand.ExecuteNonQuery(); finally /关闭链接 myConnection.Close(); /返回nResult retu

16、rn nResult; (2)用户登录代码Login.aspx.cs:protected void Button1_Click(object sender, EventArgs e) /打开连接 SqlConnection myConnection = new SqlConnection( ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); myConnection.Open(); /定义查询语句 string sql = "select * from Use

17、rs where UserName='" + txtUserName.Text.Trim() + "'and UserPassword='" + txtUserPassword.Text.Trim() + "'" SqlCommand myCommand = new SqlCommand(sql, myConnection); SqlDataReader dr = myCommand .ExecuteReader (); if (dr.Read() /登录成功 保存用户名到下一页 Session"use

18、rname" = txtUserName.Text.Trim(); Response.Redirect("/Default.aspx"); else Response.Write("<script>alert('" + "用户名或密码错误!" + "');</script>"); dr.Close(); myConnection.Close(); (3)新用户注册代码UserAdd.aspx.cs:protected void Button1_Click (obje

19、ct sender, EventArgs e) if (TextBox1.Text.Trim().Length != 0) if (TextBox2.Text.Trim().Length != 0) if (TextBox2.Text.Trim() = TextBox3.Text.Trim() /创建连接 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); myConnecti

20、on.Open(); /验证用户名是否存在 SqlCommand cmd=new SqlCommand ("select * from Users where UserName = '"+ TextBox1.Text.Trim() + "'",myConnection ); SqlDataReader dr = cmd.ExecuteReader(); bool i = dr.Read(); dr.Close(); if (i = true | j = true) Response.Write("<script>al

21、ert('" + "注册失败!用户名已存在!" + "');</script>"); dr.Close(); myConnection.Close(); else /打开连接 SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); /定义语句 string sql = "insert into Users(

22、UserName,UserPassword)values('" + TextBox1.Text.Trim() + "','" + TextBox2.Text + "')" myConn.Open(); SqlCommand myCommand3 = new SqlCommand(sql, myConn); int x = myCommand3.ExecuteNonQuery(); /执行添加信息到数据库操作 if (x = 1) Session"username" = TextBox1.Tex

23、t.Trim(); Response.Write("<script>alert('注册成功!请牢记您的用户名和密码!');location.href='Default.aspx'</script>"); else Response.Write("<script>alert('" + "注册失败!" + "');</script>"); myConn.Close(); else Response.Write("&

24、lt;script>alert('" + "两次输入的密码不一致!" + "');</script>"); else Response.Write("<script>alert('" + "新密码不能为空!" + "');</script>"); else Response.Write("<script>alert('" + "用户名不能为空!" + &

25、quot;');</script>"); (4)文件列表代码List.aspx.cs:protected void Page_Load(object sender, EventArgs e) if (!Page.IsPostBack) /显示目录列表的信息 BindDirectoryData(); /自定义函数,绑定数据库 private void BindDirectoryData() SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings&quo

26、t;SQLCONNECTIONSTRING".ConnectionString); SqlDataAdapter da = new SqlDataAdapter("select * from directory order by CreateDate desc", myConnection); DataSet ds = new DataSet(); da.Fill(ds, "o"); DiskView.DataSource = ds.Tables0; DiskView.DataBind(); /分页 protected void DiskVie

27、w_PageIndexChanging(object sender, GridViewPageEventArgs e) DiskView.PageIndex = e.NewPageIndex; BindDirectoryData(); ;/对GridView进行再次绑定 protected void Turn_Click(object sender, EventArgs e) if (int.Parse(TextBox)DiskView.BottomPagerRow.FindControl("txtGoPage").Text) > 0) DiskView.PageIn

28、dex = int.Parse(TextBox)DiskView.BottomPagerRow.FindControl("txtGoPage").Text) - 1; else DiskView.PageIndex = 0; BindDirectoryData();/对GridView进行再次绑定 (5)修改用户密码的代码ModifyPwd.aspx.cs:protected void Button1_Click(object sender, EventArgs e) if (TextBox1.Text.Trim().Length != 0) if (TextBox3.Te

29、xt.Trim().Length != 0) if (TextBox3.Text.Trim() = TextBox4.Text.Trim() /打开连接 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings"SQLCONNECTIONSTRING".ConnectionString); myConnection.Open(); SqlCommand cmd = new SqlCommand("select * from Users where Us

30、erName = '" + TextBox1.Text.Trim() + "' and UserPassword = '" + TextBox2.Text.Trim() + "'", myConnection); SqlDataReader dr = cmd.ExecuteReader(); bool i = dr.Read(); dr.Close(); if (i = true) SqlCommand cmd1 = new SqlCommand("update Users set UserPasswo

31、rd ='" + TextBox3.Text.Trim() + "'where UserName = '" + TextBox1.Text.Trim() + "'", myConnection); int j = cmd1.ExecuteNonQuery(); if (j = 1) Response.Write("<script>alert('" + "修改用户密码成功!请牢记新密码!" + "');</script>&qu

32、ot;); else Response.Write("<script>alert('" + "修改用户密码失败!" + "');</script>"); myConnection.Close(); else Response.Write("<script>alert('" + "用户名错误或用户名和旧密码不一致" + "');</script>"); else Response.Write(&qu

33、ot;<script>alert('" + "两次输入的密码不一致!" + "');</script>"); else Response.Write("<script>alert('" + "密码不能为空!" + "');</script>"); else Response.Write("<script>alert('" + "用户名不能为空!"

34、+ "');</script>"); (6)上传文件代码UpLoad.aspx.cs:protected void Button1_Click1(object sender, EventArgs e) Boolean fileOK = false; /指定文件上传路径 string path = Server.MapPath("WebDisk/"); if (FileUpload1.HasFile) string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileN

35、ame).ToLower(); string allowedExtensions = ".gif", ".png", ".jpeg", ".jpg", ".exe", ".txt", ".rar", ".dll" ; for (int i = 0; i < allowedExtensions.Length; i+) if (fileExtension = allowedExtensionsi) fileOK = true; if

36、(fileOK) /调用IDisk 王旭涛 disk = new 王旭涛(); try /保存文件到指定位置 FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName); Session"FileName" = FileUpload1.FileName; /把文件信息保存到数据库 disk.AddFile(FileUpload1.FileName, FileUpload1.PostedFile.ContentLength, "WebDisk/" + FileUpload1.FileName, Fi

37、leUpload1.PostedFile.ContentType); Label1.Visible = true; Label1.Text = "上传成功!" catch Label1.Text = "上传出现问题!" else Label1.Text = ;"上传文件类型错误!" (7)下载代码Down.aspx.cs:public partial class Down : System.Web.UI.Page int nFileID = -1; protected void Page_Load(object sender, Eve

38、ntArgs e) /获取参数DirID的值 if (Request.Params"DirID" != null) if (Int32.TryParse(Request.Params"DirID".ToString(), out nFileID) = false) return; string FileUrl = "" /调用王旭涛来获取单个文件的信息 王旭涛 disk = new 王旭涛(); SqlDataReader dr = disk.GetSingleFile(nFileID); if (dr.Read() FileUrl

39、= dr"Url".ToString(); dr.Close(); /获取文件存放位置的相对路径 string path = Server.MapPath(""); string strPath = (path + "/" + FileUrl); /下载文件到指定位置 FileInfo FInfo = new FileInfo(strPath); if (FInfo.Exists) Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.

40、ContentType = "application/octet-stream" Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FInfo.FullName, System.Text.Encoding.UTF8); Response.AppendHeader("Content-length", FInfo.Length.ToString(); Response.WriteFile(FI

41、nfo.FullName); Response.Flush(); else Response.Write("<script>alert('下载失败!')</script>"); (8)重命名代码EditFile.aspx.cs:public partial class EditFile : System.Web.UI.Page int nFileID = -1; protected void Page_Load(object sender, EventArgs e) /获取参数DirID的值 if (Request.Params&qu

42、ot;DirID" != null) if (Int32.TryParse(Request.Params"DirID".ToString(), out nFileID) = false) return; if (!Page.IsPostBack) /显示目录的名称 if (nFileID > -1) BindFileData(nFileID); /自定义函数BindFileData,在TextBox1显示原文件名 private void BindFileData(int nDirID) string sFileName = "" 王旭涛

43、 disk = new 王旭涛(); SqlDataReader dr = disk.GetSingleFile(nFileID); if (dr.Read() /获取文件的名称(包含后缀) sFileName = dr"Name".ToString(); dr.Close(); /查找最后一个“.” int dotIndex = sFileName.LastIndexOf("."); if (dotIndex > -1) /获取文件的名称(不包含后缀)并显示 TextBox1.Text = sFileName.Substring(0, dotIn

44、dex); protected void Button1_Click(object sender, EventArgs e) try string sFileName = "" /定义对象 王旭涛 disk = new 王旭涛(); /执行数据库操作 修改文件名 SqlDataReader dr = disk.GetSingleFile(nFileID); if (dr.Read() /获取文件的名称(包含后缀) sFileName = dr"Url".ToString(); string path = Server.MapPath("&quo

45、t;);/设置相对路径 string strPath = (path + "/" + sFileName); /获得完整路径 string fileExtension = System.IO.Path.GetExtension(strPath).ToLower(); System.IO.FileInfo FInfo = new System.IO.FileInfo(strPath);/创建对文件操作的实例 FInfo.MoveTo(path + "/" + "WebDisk/" + TextBox1.Text.Trim() + fil

46、eExtension); string NewUrl = "WebDisk/" + TextBox1.Text.Trim() + fileExtension; /新的文件的Url disk.EditFile(nFileID, TextBox1.Text.Trim() + fileExtension, NewUrl); Response.Write("<script>alert('" + "修改成功" + "');</script>"); catch Response.Write("<script>alert('" + "修改失败!" + "');</script>"); (9)删除文件

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论