ASP实验报告

时间:2024.3.31

ASP.NET体系及编程大作业

网上购书系统

姓名:刘涛

学号:2220111654

专业:网络工程(2)班

 


一、实验目的

1. 熟练掌握ASP.NET服务器控件、ASP.NET内置对象以及ADO.NET数据库访问技术及其应用;

2. 掌握使用ASP.NET开发Web应用程序的基本方法和基本技能。

二、实验内容

1. 实现一个网上书店。管理员将图书信息整理归类发布到网上,用户登录该网站后,首先要注册为会员才能购买图书。该系统的使用者主要分为3类:浏览者、注册用户和管理员。浏览者可以浏览网上书店中的图书信息;注册用户除了可以浏览网上书店中的图书信息外,还可以进行网上购书;管理员可以对网上书店中的图书信息进行管理、对客户订单进行处理等。主要包括以下功能模块:

前台:

(1)用户注册登录;

(2)书籍查询;

(3)书籍订购;

(4)订单查询;

(5)用户信息修改;

(6)书籍评论。

后台:

(1)书籍类别管理;

(2)书籍信息管理;

(3)订单管理;

(4)用户管理;

(5)评论管理。

2. 系统流程

3. 数据库设计

       

Admi表

Comment表

Book表

Orders表

成员表

4.主要模块的实现

主页面

 

后台代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class home : System.Web.UI.Page

{

    public SqlConnection Getconn()

    {

        string constr = ConfigurationManager.AppSettings["connstring"].ToString();

        SqlConnection myconn = new SqlConnection(constr);

        return myconn;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

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

        {

            cart.Visible = false;

        }

        else {

            login.Visible = false;

            signup.Visible = false;

            cart.Visible = true;

            userpage.Visible = true;

            exit.Visible = true;

            Label1.Text="欢?迎®-" + Session["mname"].ToString();

     

        SqlConnection myconn = Getconn();

        myconn.Open();

        string strSQL = "select mid from members where mname='"

        + Session["mname"].ToString() + "'";

        SqlCommand cmd = new SqlCommand(strSQL, myconn);

        SqlDataReader dr = cmd.ExecuteReader();

        dr.Read();

        string mid = dr[0].ToString();

        Session["mid"] = mid;

        dr.Close();

        myconn.Close();

        }

    }

    protected void login_Click(object sender, EventArgs e)

    {

        Response.Redirect("login.aspx");

    }

    protected void signup_Click(object sender, EventArgs e)

    {

        Response.Redirect("regisiter.aspx");

    }

    protected void exit_Click(object sender, EventArgs e)

    {

        Session.Abandon();

        Response.Redirect("home.aspx");

    }

    protected void userpage_Click(object sender, EventArgs e)

    {

        Response.Redirect("userpage.aspx");

    }

    protected void search_Click(object sender, EventArgs e)

    {

        Session.Timeout = 30;

        Session["search"] = sBox.Text.ToString();

        Server.Transfer("search.aspx");

    }

    protected void cart_Click(object sender, EventArgs e)

    {

        Response.Redirect("cart.aspx");

    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

    {

        Response.Redirect("detail.aspx?bid=11");

     

    }

    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)

    {

        Response.Redirect("detail.aspx?bid=12");

    }

    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)

    {

        Response.Redirect("detail.aspx?bid=15");

    }

}

登录

后台代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class login : System.Web.UI.Page

{

    public SqlConnection Getconn()

    {

        string constr = ConfigurationManager.AppSettings["connstring"].ToString();

        SqlConnection myconn = new SqlConnection(constr);

        return myconn;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void tz_Click(object sender, EventArgs e)

    {

        Response.Redirect("regisiter.aspx");

    }

    protected void LoginButton_Click(object sender, EventArgs e)

    {

        SqlConnection myconn = Getconn();

        myconn.Open();

        string strSQL = "select count(*) as xcount from members where mname='"

        + mname.Text+"'"

        +" and mpwd='"+mpwd.Text.Trim() +"'";

        SqlCommand cmd = new SqlCommand(strSQL,myconn);

        SqlDataReader dr = cmd.ExecuteReader();

        dr.Read();

        string Count = dr["xCount"].ToString();

        dr.Close();

        myconn.Close();

       

        if (Count != "0")

        {

            myconn.Open();

            string strSQL1 = "select * from members where mname='"

            + mname.Text + "'"

            + " and mpwd='" + mpwd.Text.Trim() + "'";

            SqlCommand cmd1 = new SqlCommand(strSQL1, myconn);

            SqlDataReader dr1 = cmd1.ExecuteReader();

            dr1.Read();

            string mid = dr1["mid"].ToString();

            dr1.Close();

            myconn.Close();

            Session.Timeout = 60;

            Session["mid"] = mid;

            Session["mname"] = mname.Text.ToString();

            Server.Transfer("home.aspx");

        }

        else {

            Response.Write("<script language='javascript'>alert('用户名密码错误');</script>");

            mname.Text = "";

            mpwd.Text = "";

        }

    }

          protected void search_Click(object sender, EventArgs e)

    {

        Session.Timeout = 30;

        Session["search"] = sBox.Text.ToString();

        Server.Transfer("search.aspx");

    }

    }

注册

后台代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class regisiter : System.Web.UI.Page

{   public SqlConnection Getconn(){

    string constr = ConfigurationManager.AppSettings["connstring"].ToString();

    SqlConnection myconn= new SqlConnection(constr);

    return myconn;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void search_Click(object sender, EventArgs e)

    {

        Session.Timeout = 30;

        Session["search"] = sBox.Text.ToString();

        Server.Transfer("search.aspx");

    }

    protected void sign_Click(object sender, EventArgs e)

    {

        SqlConnection myconn = Getconn();

        myconn.Open();

       string  strSQL="insert into members (mname,mpwd,email,mobile) values('";

        strSQL+= mname.Text.ToString() + "','";

        strSQL+= mpwd.Text.ToString()+"','";

        strSQL+= email.Text.ToString()+"',' ";

        strSQL+= mobile.Text.ToString()+" ')";

      

        SqlCommand cmd = new SqlCommand(strSQL, myconn);

        if (cmd.ExecuteNonQuery() > 0)

        {

            Session.Timeout = 60;

            Session["mname"] = mname.Text.ToString();

            Response.Write("<script>alert('添加成功')</script>");

            mname.Text = "";

            mpwd.Text = "";

            mpwdconfirm.Text = "";

            email.Text = "";

            mobile.Text = "";

            Server.Transfer("home.aspx");

        }

        else {

            Response.Write("添加失败");

        }

       

        myconn.Close();

       

    }

    protected void tz_Click(object sender, EventArgs e)

    {

        Response.Redirect("login.aspx");

    }

}

购物车

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class cart : System.Web.UI.Page

{

    public SqlConnection Getconn()

    {

        string constr = ConfigurationManager.AppSettings["connstring"].ToString();

        SqlConnection myconn = new SqlConnection(constr);

        return myconn;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Session["mname"] == null) {

            Response.Redirect("login.aspx") ;

        }

        else

        {

            exit.Visible = true;

            Label1.Text = "欢迎" + Session["mname"].ToString();

        }

    

            SqlConnection myconn = Getconn();

            myconn.Open();

            string mid = Session["mid"].ToString();

            string strSQL = "select bprice from cart where mid='" + mid + "'";

            SqlCommand cmd = new SqlCommand(strSQL, myconn);

            SqlDataReader dr = cmd.ExecuteReader();

            float aaa = 0;

            while (dr.Read())

            {

                string bprice = dr["bprice"].ToString();

                aaa += float.Parse(bprice);

            }

            myconn.Close();

            L2.Text = "您选购图书的总价为:" + aaa.ToString() + "<br/>";

       

    }

    protected void search_Click(object sender, EventArgs e)

    {

        Session.Timeout = 30;

        Session["search"] = sBox.Text.ToString();

        Server.Transfer("search.aspx");

    }

    protected void cart1_Click(object sender, EventArgs e)

    {

        Response.Redirect("cart.aspx");

    }

    protected void home_Click(object sender, EventArgs e)

    {

        Response.Redirect("home.aspx");

    }

    protected void exit_Click(object sender, EventArgs e)

    {

        Session.Abandon();

        Response.Redirect("home.aspx");

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        Response.Redirect("order.aspx");

    }

}

管理员

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

public partial class admin : System.Web.UI.Page

{

    public SqlConnection Getconn()

    {

        string constr = ConfigurationManager.AppSettings["connstring"].ToString();

        SqlConnection myconn = new SqlConnection(constr);

        return myconn;

    }

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void LoginButton_Click(object sender, EventArgs e)

    {

        SqlConnection myconn = Getconn();

        myconn.Open();

        string strSQL = "select count(*) as xcount from admin where aname='"

        + aname.Text + "'"

        + " and apwd='" + apwd.Text.Trim() + "'";

        SqlCommand cmd = new SqlCommand(strSQL, myconn);

        SqlDataReader dr = cmd.ExecuteReader();

        dr.Read();

        string Count = dr["xCount"].ToString();

        dr.Close();

        myconn.Close();

        if (Count != "0")

        {

            myconn.Open();

            string strSQL1 = "select * from admin where aname='"

            + aname.Text + "'"

            + " and apwd='" + apwd.Text.Trim() + "'";

            SqlCommand cmd1 = new SqlCommand(strSQL1, myconn);

            SqlDataReader dr1 = cmd1.ExecuteReader();

            dr1.Read();

            string aid = dr1["aid"].ToString();

            dr1.Close();

            myconn.Close();

            Session.Timeout = 60;

            Session["aid"] = aid;

            Session["aname"] = aname.Text.ToString();

            Server.Transfer("bookmanage.aspx");

        }

        else

        {

            Response.Write("<script language='javascript'>alert('用户名或密码错误');</script>");

            aname.Text = "";

            apwd.Text = "";

        }

    }

}

书籍管理

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class admin_admincomment : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

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

        {

            Response.Redirect("admin.aspx");

        }

        else

        {

            exit.Visible = true;

            Label1.Text = "欢迎管理员" + Session["aname"].ToString();

        }

    }

    protected void exit_Click(object sender, EventArgs e)

    {

        Session.Abandon();

        Response.Redirect("admin.aspx");

    }

}

  另外还有用户管理,订单管理,和评论管理等。

三.实验体会

1.通过一学期的学习,掌握了许多ASP的编程方法。

2.刚开始看到大作业时完全不知道该怎么做,后来经过看书和看课件慢慢有了思路,但是在构建数据库的时候出了一些问题,问了几个同学以后得到了解决。

3.在连接数据库的时候总是出错,后来把SQLserver换成了2008版本的就好了。至于这是为什么到现在还不知道。

4.再后来编写代码的时候总是出小问题,例如在用GridView的时候数源的配置有问题,再用DetailsView的时候数据库里面的表没有设置主键,就不成功。诸如此类的小问题简直是层出不穷。

5.老师检查的时候说界面太简单,由于不会做界面设计所以找了同学帮忙。

更多相关推荐:
ae实验报告

实验报告三实验名称跟踪与稳定实验地点13栋602实验时间第10周实验人员姓名蒋义专业教育技术学年级09实验目的1熟练掌握AfterEffectscs4跟踪面板的使用2熟练掌握AfterEffectscs4轴心点...

AE实例实验报告

江西科技师范学院实验报告课程院系班级学号姓名报告规格一实验目的四实验方法及步骤二实验原理五实验记录及数据处理三实验仪器六误差分析及问题讨论目录1制作技巧和后期特效软件使用2风格设计3声音素材和图像素材处理4电视...

AE实验报告

实验报告二实验名称三维场景构建实验地点13栋602实验时间第4周实验人员姓名专业教育技术学年级09实验目的1熟练掌握AfterEffectscs4三维属性摄像动画2熟练掌握AfterEffectscs4表达式应...

AE实验报告

实验报告实验二实验名称专业班级级班姓名学号成绩审阅教师一实验目的1了解AfterEffects层的基本概念2熟练掌握AfterEffects层的基本操作二实验仪器设备1硬件环境学生用微机2软件环境windows...

AE实验报告格式

实验报告课程名称数字影视合成与非线性编辑实验项目名称矢量绘图学生姓名魏梅香学号20xx0861209专业08计算机科学与技术数字媒体技术实验日期20xx年3月10日注实验日期P75标志20xx310水墨画效果2...

AE提高性实验报告

提高型实验报告实验课题KobeBryant设计型应用型实验类型综合型实验课程非线性编辑专业名称教育技术学实验班级教育技术学1101实验者周洁实验时间20xx12教育科学与技术学院一实验目的1熟悉3D层的操作2掌...

AE实习实验报告

20xx20xx学年度第一学期学生实习实验报告

安徽工业大学数据结构实验报告

安徽工业大学计算机学院数据结构实验报告姓名学号班级教师内容线性表基本操作的实现栈的基本操作串的模式匹配二叉树操作图的创建与遍历20xx525实验一线性表基本操作的实现一实验目的1掌握使用TurboC20上机调试...

电子科技大学 TCPIP实验三 FTP中的TCP传输服务 实验报告

电子科技大学实验报告学号学生姓名课程名称任课老师张科实验项目名称FTP中的TCP传输服务实验3FTP中的TCP传输服务实验内容实验拓扑中VMware虚拟机PC2和Server分别位于由提供集线器功能的虚拟网卡V...

AD及DA实验报告

微机原理及接口技术之AD及DA实验一实验目的1了解AD芯片ADC0809和DA芯片DAC0832的电气性能外围电路的应用性搭建及有关要点和注意事项与CPU的接口和控制方式相关接口参数的确定等2了解数据采集系统中...

撕纸实验报告

实验二实验器材A4纸实验目的将A4纸剪出一个正方形1将一条边三等分2折一个正三角形3找一条边的黄金分割点4找一条长为3的线段1将一条边三等分实验步骤1剪出正方形AEFD折出其对角线为AF与DE如下图所示2取AD...

AE提高性实验报告

提高型实验报告实验课题房地产宣传片设计型应用型实验类型综合型实验课程非线性编辑专业名称教育技术学实验班级教育技术学实验者实验时间20xx教育科学与技术学院一实验目的1熟悉3D层的操作2掌握虚拟摄像机的使用3结合...

ae实验报告(20篇)