资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) /页面加载的时候给dlstGoods绑定数据源 string sql = select top 16 * from dbo.tb_Goods order by AddDate desc; SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettingsconnstr); SqlDataAdapter sda = new SqlDataAdapter(sql, conn);/sda得到查询结果外存对象 DataSet ds = new DataSet();/内存对象 sda.Fill(ds);/ds dlstGoods.DataSource = ds.Tables0.DefaultView; dlstGoods.DataBind();/dlstGoods绑定数据源 if (SessionMemberName != null) /会员没有退出登陆 divLogin.Visible = false; divShow.Visible = true; protected void Button2_Click(object sender, EventArgs e) /Response.Redirect(register.aspx); /在当前页打开 Response.Write(window.open(HTMLPage.aspx););/在新窗口中打开 Response.Write(document.location=document.location;);/执行后当前页面字体会变大,解决办法是加入当前这句代码 protected void btLogin_Click(object sender, EventArgs e) /登陆 /*程序思路: * 1 获得输入的会员名和密码 * 2 生成select语句,定义变量sql来接受 * 3 建立conn、sda、ds,执行查询语句sql * 4 根据ds中是否有记录判定输入的信息是否正确,如果正确则显示登陆后的信息;否则提示用户重新登陆 */ /此处添加代码 string membername = txtMemberName.Text.Trim();/Trim() 去掉字符串前后的无效空格 string pwd = txtPWD.Text; string sql1 = select *from tb_Member where MemberName=0and MemberPwd=1; string sql2 = string.Format(sql1, membername, pwd); SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettingsconnstr); /string sql = select * from tb_Member where MemberName + Int32.Parse(Request.QueryStringnewsid.ToString(); SqlDataAdapter sda = new SqlDataAdapter(sql2, conn); DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables0.Rows.Count = 1) /存在该会员 /此处添加代码:将会员名和会员编号赋值给SessionMemberName, SessionMemberID /显示登陆后信息,隐藏登陆前输入的用户名和密码 divLogin.Visible = false; divShow.Visible = true; SessionMemberName = ds.Tables0.Rows01.ToString(); SessionMemberID = ds.Tables0.Rows00.ToString(); else Response.Write(alert(错误的用户名或者密码!);document.location=document.location;); protected void linkbtUpdate_Click(object sender, EventArgs e) protected void linkbtExit_Click(object sender, EventArgs e) Session.Clear(); Session.Abandon();/丢弃session Response.Redirect(Default.aspx);/网页定向到首页 protected void dlstGoods_ItemCommand(object source, DataListCommandEventArgs e) if (e.CommandName = detail) /获得当前商品编号 Int32 id = Int32.Parse(dlstGoods.DataKeyse.Item.ItemIndex.ToString(); /在新窗口中弹出商品详细信息页面 Response.Write(window.open(goodsdetail.aspx?goodsid= + id + );document.location=document.location;); else if (e.CommandName = buy) /当前用户是否登陆? 只有登陆用户才可以购物 if (SessionMemberID != null) /* *1 获得当前商品的编号、会员编号、数量(默认为1)、订购日期写入数据库中的tb_BuyInfo中。* 2: 调用静态方法 BuyCar .AddShopCart() ,保存新订购的商品记录。*3提示:恭喜您,添加成功! */ int goodsid = Int32.Parse(dlstGoods.DataKeyse.Item.ItemIndex.ToString(); float price = BuyCar.GetPriceByGoodsID(Int32.Parse(dlstGoods.DataKeyse.Item.ItemIndex.ToString(); /添加商品到表tb_BuyInfo BuyCar.AddShopCart(goodsid, price, Int32.Parse(SessionMemberID.ToString(), 1); /提示添加成功 Response.Write(alert(恭喜您,添加成功!);document.location=document.location;); else /没有登陆。提示:请先登录,谢谢合作! Response.Write(alert(请先登录,谢谢合作!);document.location=document.location;); protected void GridView2_SelectedIndexChanged(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e) string goodsname = txtGoodsName.Text.Trim(); if (goodsname = ) return; Page.RegisterStartupScript(js2, script l
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号