信息系统集成实用技术.doc_第1页
信息系统集成实用技术.doc_第2页
信息系统集成实用技术.doc_第3页
信息系统集成实用技术.doc_第4页
信息系统集成实用技术.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

信息系统集成实用技术实验报告实验报告实验目的:熟悉Visual Studio 2008与SQL Server2005的使用,了解如何使用Visual Studio 2008与SQL Server2005实现网页的登陆、注册、上传、下载、超链接功能。实验内容: 在SQL Server2005中新建一个数据库,然后用Visual Studio 2008新建网站并连接数据库,最终实现网页的登陆、注册、上传、下载、超链接功能。实验步骤:1、在SQL Server2005中新建一个数据库,然后新建2个表,一个是登陆和注册用户的信息表,另一个是上传和下载文件的信息表。用户的信息表:文件的信息表:2、数据库建好后打开Visual Studio 2008新建网站,然后连接数据库,添加LINQ to SQL类并把数据库的2个信息表拖进去。3、登陆在WEB窗体设计登陆界面。设计好登陆界面后就可以编写代码。“登陆”按钮的代码为:protected void Button1_Click(object sender, EventArgs e) DataClassesDataContext db = new DataClassesDataContext(); db.SubmitChanges(); var resquest = from p in db.aa where p.用户名 = TextBox1.Text where p.密码 = TextBox2.Text select new p.用户名, p.密码 ; if (resquest.Count() 0) Response.Redirect(/主页.aspx); else Response.Write(alert(登陆失败,密码错误或用户名不存在); “注册”按钮的代码为:protected void Button2_Click(object sender, EventArgs e) Response.Redirect(/注册.aspx); 4、注册新建一个WEB窗体,设计注册界面。代码为:public partial class 注册 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e) DataClassesDataContext dr = new DataClassesDataContext(); var cs = new aa 用户名 = TextBox1.Text.ToString().Trim(), 密码 = TextBox2.Text.ToString().Trim(), 性别 = TextBox3.Text.ToString().Trim() ; dr.aa.InsertOnSubmit(cs); dr.SubmitChanges(); Response.Redirect(/登陆.aspx); 5、上传和超链接新建2个WEB窗体,一个是上传和显示文件名的页面(命名为“主页”),另一个是打开超链接时的新页面(命名为“newspage”)。新建一个名为“Files”的文件夹,用来保存上传的文件。“主页”页面:“主页”页面的代码为:public partial class 主页 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) DataClassesDataContext dd = new DataClassesDataContext(); var linqstr = from a in dd.bb select new a.FileAllName, a.FileName ; GridView1.DataSource = linqstr; GridView1.DataBind(); protected void Button1_Click(object sender, EventArgs e) /判断是否选择了文件 if (FileUpload1.HasFile) string strFileSize; /获得文件名 string fileName = FileUpload1.FileName; /计算文件有多少K double fileSize = Math.Round(FileUpload1.PostedFile.ContentLength / 1024.00, 2); /如果文件大于1024K if (fileSize 1024) /将文件大小转化为M,传入strFileSoze变量中 strFileSize = Math.Round(fileSize / 1024.00, 2).ToString() + M; else strFileSize = fileSize.ToString() + K; /获取文件在服务器中存放的位置 string filePath = Server.MapPath(/Files/); /设置时间刻度 string fileTimeName = DateTime.Now.Ticks.ToString(); /以时间刻度定义文件名 string fileAllName = fileTimeName + fileName; try /将文件保存到服务器的指定位置 FileUpload1.PostedFile.SaveAs(filePath + fileAllName); DataClassesDataContext db = new DataClassesDataContext(); /将文件信息存储到数据库 var insertFile = new bb /以时间刻度作为文件编号 FileID = fileTimeName, FileName = fileName, FileAllName = fileAllName, FileSize = strFileSize, FilePath = filePath, FileUpTime = DateTime.Now.ToLocalTime() ; db.bb.InsertOnSubmit(insertFile); db.SubmitChanges(); Response.Write(alert(上传成功!); catch (Exception ex) Response.Write(ex.Message.ToString(); protected void Button2_Click(object sender, EventArgs e) Response.Redirect(/下载.aspx); Newspage页面的代码为:public partial class newspage : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) string filename = Request.ParamsFileAllName; System.Diagnostics.Process.Start(E:/kkk/22/Files/ + filename); 6、下载新建一个WEB窗体,然后设计下载界面。新建一个名为“Images”的文件夹,用来存放下载按钮的图片。然后编写代码:public partial class 下载 : System.Web.UI.Page DataClassesDataContext db = new DataClassesDataContext(); protected void Page_Load(object sender, EventArgs e) var resultQuery = from c in db.bb select c; GridView1.DataSource = resultQuery; GridView1.DataBind(); protected void ImageDownButton_Click(object sender, ImageClickEventArgs e) /获取ImageDownButton下载按钮对象 ImageButton imageButton = (ImageButton)sender; /获取imageDownButton图标按钮控件的父控件的父控件 GridViewRow gvr = (GridViewRow)imageButton.Parent.Parent; /获取文件Id编号值 string fileId = GridView1.DataKeysgvr.RowIndex.Value.ToString(); /按照指定的文件编号查询数据库中的文件信息 var resultQuery = from c in db.bb where c.FileID = fileId select c; foreach (bb strFile in resultQuery) /获取文件在服务器中存储的名称 string fileAllName = strFile.FileAllName; /获取文件在服务器存放的路径 string filePath = strFile.FilePath; string fileAllPath = filePath + fileAllName; /判断文件是否存在 if (File.Exists(fileAllPath) /清空输出流 Response.Clear(); /设置字符集 Response.Charset = GB2312; /启动缓存 Response.Buffer = true; /关闭ViewState this.EnableViewState = false; /将HTTP头添加到输出流 Response.AppendHeader(Content-Disposition, attachment;filename= + HttpUtility.UrlEncode(fileAllName); Response.ContentType = application/unknown; /将指定的文件直接写入HTTP响应输出流 Response.WriteFile(fileAllPath); /向客户端发送当前所有缓冲的输出 Response.Flush(); /关闭到客户端的套接字连接 Response.Close(); /停止执行 Response.End(); else Response.Write(alert(文件不存在); protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) if (e.Row.RowType = DataControlRowType.DataRow) /访问ItemTemplate模板上的Label控件 Label lbl = (Label)e.Row.Cells0.FindControl(l

温馨提示

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

最新文档

评论

0/150

提交评论