购物网站设计-Web实验报告(共7页).doc
精选优质文档-倾情为你奉上J I A N G S U U N I V E R S I T Y 班 级:学生姓名:学 号:完成时间:2014年11月18日购物网站设计报告专心-专注-专业购物网站设计报告一:设计要求1. 购物车包含注册页面、登录页面、购物页面、购物车四个页面。2. 在购物页面中,将页面信息与数据库绑定,直接将数据库中的内容显示到网页上。另外,对“名称”设计超链接,点击进入商品的详细信息介绍页面。3. 网站美观大方2 实现效果1. 登录页面2. 注册页面3. 购物页面4. 购物车3 主要代码1. 登录页面与数据库连接 protected void Button2_Click(object sender, EventArgs e) string connstr = "Data Source=XIAOZHENZHEN-PC;Initial Catalog=login;Integrated Security=True" StringBuilder sb = new StringBuilder(); sb.Append("select count ("); sb.Append("'"); sb.Append(TextBox1.Text); sb.Append("') from userinfo where password="); sb.Append(TextBox2.Text); using (SqlConnection conn = new SqlConnection(connstr) SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sb.ToString(); conn.Open(); int num = (int)cmd.ExecuteScalar(); if (num > 0) Response.Redirect("shop.aspx"); else Response.Write("账号密码错误"); 2. 注册页面与数据库连接 protected void Button1_Click(object sender, EventArgs e) string connstr = "Data Source=XIAOZHENZHEN-PC;Initial Catalog=login;Integrated Security=True" StringBuilder sb = new StringBuilder(); sb.Append("insert into userinfo(username,password,shenfen,name,sex,birthday,telephone)values("); sb.Append("'");sb.Append(TextBox1.Text);sb.Append("'"); sb.Append(","); sb.Append("'");sb.Append(TextBox2.Text);sb.Append("'");sb.Append(","); . Response.Write(sb.ToString(); using (SqlConnection conn = new SqlConnection(connstr) conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sb.ToString(); int num =(int) cmd.ExecuteNonQuery(); int count =(int)cmd.ExecuteNonQuery(); if (count > 0) Response.Redirect("Default.aspx"); else Response.Redirect("fault.aspx"); conn.Close(); 3. 购物车页面 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="162px" Width="644px" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" style="text-align: center" onselectedindexchanged="GridView1_SelectedIndexChanged"> <AlternatingRowStyle BackColor="PaleGoldenrod" /> <Columns><asp:BoundField DataField="序列" HeaderText="序列" SortExpression="序列" /><asp:HyperLinkField DataNavigateUrlFields="序列" DataNavigateUrlFormatString="detail.aspx?id=0" DataTextField="名称" HeaderText="名称" /><asp:BoundField DataField="介绍 HeaderText="介绍 SortExpression="介绍”/><asp:ImageField DataAlternateTextField="图片" DataImageUrlField="图片" HeaderText="图片"> </asp:ImageField><asp:BoundField DataField="价格" HeaderText="价格" SortExpression="价格" /><asp:CommandField ShowDeleteButton="True" /><asp:TemplateField HeaderText="购o买ò" ShowHeader="False"> <ItemTemplate><asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="" Text="加入购物车" CommandArgument='<%# Eval("序列 ")%>' OnClick="LinkButton1_Click" ></asp:LinkButton></ItemTemplate></asp:TemplateField></Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:loginConnectionString %>" SelectCommand="SELECT * FROM shopping"></asp:SqlDataSource>4. 详细信息 <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"> <EditItemTemplate> 序列: <asp:TextBox ID="序列TextBox" runat="server" Text='<%# Bind("序列") %>' /> <br /> 名称:<asp:TextBox ID="名称TextBox" runat="server" Text='<%# Bind("名称") %>' /> <br /> 介绍:<asp:TextBox ID="介绍TextBox" runat="server" Text='<%# Bind("介绍”) %>' /> <br /> 价格:<asp:TextBox ID="价格TextBox" runat="server" Text='<%# Bind("价格") %>' /> <br /><asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="更新" /> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消" /></EditItemTemplate> <InsertItemTemplate> 序列:<asp:TextBox ID="序ò列TextBox" runat="server" Text='<%# Bind("序列") %>' /> <br /> 名称:<asp:TextBox ID="名?称?TextBox" runat="server" Text='<%# Bind("名称") %>' /> <br /> 介绍<asp:TextBox ID="介绍TextBox" runat="server" Text='<%# Bind("介绍”) %>' /> <br /> 价格:<asp:TextBox ID="价格TextBox" runat="server" Text='<%# Bind("价格") %>' /> <br /><asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="插入" /> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消" /></InsertItemTemplate><ItemTemplate> 序列:<asp:Label ID="序ò列Label" runat="server" Text='<%# Bind("序列") %>' /><br /> 名称:<asp:Label ID="名称Label" runat="server" Text='<%# Bind("名称") %>' /><br /> 介绍<asp:Label ID="介绍Label" runat="server" Text='<%# Bind("介绍) %>' /><br /> 价格:<asp:Label ID="价格Label" runat="server" Text='<%# Bind("价格") %>' /><br /></ItemTemplate></asp:FormView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:loginConnectionString %>" SelectCommand="SELECT * FROM detail WHERE (序列 = 序列2)"> <SelectParameters><asp:QueryStringParameter Name="序列2" QueryStringField="id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>5. 购物车页面public partial class shopcar : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) if (Convert.ToInt32(Request.QueryString"序ò列") = 1) Session"list1" = "<tr><td>水?杯?<td>" Session"check1" = "¥辍?0.0<td>" Session"count1" = Convert.ToInt32(Session"count1") + 1; int r = Convert.ToInt32(Session"account"); string strArray = new stringSession.Count; Session.CopyTo(strArray, 0); Response.Write("<table border=1px align=center>"); Response.Write("<caption align=left >购物车</caption>"); Response.Write("<tr><td>名称<td>单价<td>数量"); foreach (string str in strArray) Response.Write(Sessionstr); Response.Write("</table>");4、 实验小结:5、 收获和提高方向:通过这次网页设计,让我对网页基本布局和设计方法有了深刻的了解,了解了网页中的各种属性以及css+div这种设计方法的优势,让我能够通过更加快捷,方便,准确的方法来建立以及修改网页。在日后的学习和实验中,我要着重学习在网页中应用一些程序和数据库,以及网页的后台程序,我认为这才是能够体现出一个网站强大功能的地方,而网页只是一个网站的脸面,要真正买足用户的需求,不光只能看,还要有更加丰富的功能支持。 谢谢老师这学期的悉心指导,我会在今后的学习中更加认真努力!