商务网站代码.doc

上传人:cn****1 文档编号:562042800 上传时间:2023-12-12 格式:DOC 页数:6 大小:48KB
返回 下载 相关 举报
商务网站代码.doc_第1页
第1页 / 共6页
商务网站代码.doc_第2页
第2页 / 共6页
商务网站代码.doc_第3页
第3页 / 共6页
商务网站代码.doc_第4页
第4页 / 共6页
商务网站代码.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《商务网站代码.doc》由会员分享,可在线阅读,更多相关《商务网站代码.doc(6页珍藏版)》请在金锄头文库上搜索。

1、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

2、.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得到查询结果外存对象

3、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

4、(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 *

5、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 = ne

6、w 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) /存在该会员 /此

7、处添加代码:将会员名和会员编号赋值给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;

8、); 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.Co

9、mmandName = 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)

10、/* *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_Bu

11、yInfo 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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号