栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

vs2015 dynamicweb11-1 .NET PET SHOP宠物商店完整项目代码

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vs2015 dynamicweb11-1 .NET PET SHOP宠物商店完整项目代码

此练习为一个完整的项目代码,含有用户注册、用户登录、宠物商品列表、购物车、结算、个人信息更新等功能。

在项目根目录,先创建App_Themes文件夹,其内建立一个文件夹PetShop1,内含一个css主题样式文件。

stylesheet1.css

*, html, body {
    margin:0;
    padding:0;
}

body {
    background-color:#e3e5dc;
    margin:0;
    background-image:url("../../Comm_Images/bg-body.gif");
    background-repeat:repeat-x;
}

a:visited {
    color:#333333;
    text-decoration:none;
}

a:hover {
    color:#1639a9;
    text-decoration:underline;
}

a:link {
    color:#333333;
    text-decoration:none;
}

.label {
    font-family:Arial,Helvetica,sans-serif;
    font-size:13px;
    color:#333333;
    margin-left:20px;
    margin-bottom:10px;
    text-align:left;
}



.homeBody {
    background-color:#ffffff;
    margin:0;
    background-image:url("../../Comm_Images/home-bg-body.gif");
    background-repeat:repeat-x;
}

.divHome {
    width:800px;
    margin:0 auto;
    height:100px;
}

#logoH {
    float:left;
    width:380px;
    height:40px;
    border:1px solid #cccccc;
    margin-top:20px;
    text-align:center;
    font-size:30px;
    line-height:40px;
    color:#333333;
    font-style:oblique;
    border-radius:15px;
    background-color:#e3e5dc;
}

.homeBgSearch {
    width:306px;
    height:35px;
    float:right;
    margin-top:33px;
}

.homeL {
    width:100%;
    height:60px;
    background-color:#e3e5dc;
}

.homeSearchBox {
    font-size:16px;
    line-height:18px;
    color:#404040;
    background-color:#ffffff;
    border-width:1px;
    border-style:solid;
    border-top-color:#e9eed8;
    border-right-color:#c6c3b3;
    border-bottom-color:#abaf94;
    border-left-color:#c6c3b3;
    height:20px;
    margin-top:7px;
    width:160px;
    float:left;
}

.paddingSearchicon {
    width:20px;
    height:20px;
    margin-top:6px;
    margin-left:10px;
    float:left;
    border:1px solid #eeeeee;
}

.homeLink {
    font-family:Arial,Helvetica,sans-serif;
    font-size:15px;
    font-weight:bold;
    color:lightblue;
    width:80px;
    float:left;
    display:inline-block;
    height:20px;
    line-height:15px;
    margin-top:10px;
    margin-left:15px;
}


.divContent {
    width:800px;
    margin:0 auto;
    height:400px;

}

.divContent .leftH {
    float:left;
          
}

#seahorse {
    width:112px;
    float:left;
}

#mainContent {
    position:relative;
    width:450px;
    top:-26px;
    float:left;
}

.welcome {
    font-family:Arial,Helvetica,sans-serif;
    font-size:15px;
    font-weight:bold;
    color:#ffffff;
    padding-left:20px;
    background-color:#abaf94;
    line-height:26px;
}

.bgControl {
    background-color:#e3e5dc;
}

.intro {
    font-family:Arial,Helvetica,sans-serif;
    font-size:15px;
    font-weight:bold;
    color:#555555;
    padding-top:20px;
    line-height:18px;
    padding-left:20px;
    display:inline-block;
    width:300px;
}



.navigationLabel {
    color:#9a839;
    font-size:15px;
    font-weight:bold;
    line-height:22px;
    font-family:Arial,Helvetica,sans-serif;
    padding-left:20px;
}

.ctMenu {
    padding-left:40px;
    height:270px;
}

.navigationLinks {
    font-family: 宋体,新宋体;
    font-size:16px;
    color:#333333;
    line-height:22px;
    font-weight:bold;
    vertical-align:middle;
    width:300px;
    height:22px;
    border-bottom:1px dotted #555555;
    margin-top:10px;
    margin-bottom: -10px;
}



.footerHome {
    font-family:Arial,Helvetica,sans-serif;
    font-size:14px;
    text-transform:uppercase;
    color:#ffffff;
    background-color:#122e87;
    padding-left:16px;
    line-height:22px;
}

.fishPosition {

}

.fishPosition img {
    position:relative;
    left: 497px;
    top: -331px;
    width:241px;
    height:250px;
    float:left;
}





.divMaster {
    width:800px;
    heigt: 100px;
    margin:0 auto;
}

.divLogoM {
    float:left;
    width:380px;
    height:70px;
    border:1px solid #cccccc;
    margin-top:15px;
    margin-bottom:5px;
    text-align:center;
    font-size:30px;
    font-weight:bold;
    line-height:70px;
    color:#333333;
    font-style:oblique;
    border-radius:15px;
    background-color:#e3e5dc;
}


.signIn {
    background-color:#e9eed8;
    width:400px;
    height:40px;
    margin-top:15px;
    float:right;
}

.textboxSearch {
    font-size:16px;
    line-height:24px;
    color:#000000;
    background-color:#ffffff;
    border-width:1px;
    border-style:solid;
    border-top-color:#e9eed8;
    border-right-color:#c6c3b3;
    border-bottom-color:#abaf94;
    border-left-color:#c6c3b3;
    height:24px;
    margin-left:15px;
    float:left;
    margin-top:8px;
    margin-bottom:8px;
    width:180px;
}

#btnSearch {
    float:left;
    width:20px;
    height:20px;
    margin-top:10px;
    margin-bottom:10px;
    margin-left:10px;
}

.link {
    font-family: 宋体;
    font-size:15px;
    color:#333333;
    margin-top:8px;
    margin-bottom:8px;
    margin-left:15px;
    line-height:24px;
    width:60px;
    float:left;
}

#btnLgnStatus {
    float:left;
    line-height:24px;
    margin-top:8px;
    margin-bottom:8px;
    margin-left:15px;
    width:80px;
    font-family: 宋体,Arial;
    font-weight:bold;
}

.disableLink {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.65em;
    text-transform:uppercase;
    color:#999999;
    text-indent:10px;
}

.checkOut {
    background-color:#abaf94;
    width:400px;
    height:30px;
    float:right;
}

.checkOut img {
    width:20px;
    height:20px;
    margin-left:15px;
    margin-top:5px;
    margin-bottom:5px;
    margin-right:2px;
    border:none;
    float:left;    
}

.checkOutLink {
    font-family: 宋体,Arial;
    font-size:15px;
    color:#333333;
    margin-right:20px;
    line-height:20px;
    margin-top:6px;
    margin-bottom:4px;
    float:left;
}


.divTitle {
    width:800px;
    height:52px;
    margin:0 auto;
    clear:both;
    border-bottom:2px solid #eeeeee;
}

.breadrumb {
    font-family: 宋体,Arial;
    font-size:14px;
    color:#333333;
    font-weight:bold;
    height:25px;
    line-height:25px;
    text-align:right;
    margin-right:30px;

}


.pageHeader {
    font-family: 宋体,Arial;
    font-size:14px;
    font-weight:bold;
    color:#ffffff;
    background-color:#0a1b50;
    text-indent:16px;
    height:20px;
    line-height:20px;
    width:620px;
    margin-left:180px;
}

.divCenter {
    width:800px;
    margin:0 auto;
    min-height:400px;
}

.leftMenu {
    float:left;
    width:180px;
    height:auto;
}

.menuLinks {
    font-family: 宋体,Arial;
    font-size:15px;
    color:#333333;
    font-weight:bold;
    width:150px;
    height:35px;
    padding-left:20px;
    border-bottom:1px dotted #999999;
}


.mainContent {
    float:right;
    background-color:white;
    width:620px;
}

.footer {
    font-family:Arial,Helvetica,sans-serif;
    font-size:13px;
    text-transform:uppercase;
    color:#ffffff;
    background-color:#abaf94;
    padding-left:18px;
    line-height:18px;
}



.dottedLine {
    background-image:url("../../Comm_Images/dotten-line.gif");
    background-repeat:repeat-x;
    background-position:bottom;
    height:8px;
}

.mainNavigation {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.7em;
    text-transform:uppercase;
    padding-left:2px;
    color:#333333;
    font-weight:bold;
    line-height:20px;
    padding-right:5px;
    display:block;
    height:100%;
}





.signinPosition {
    width:400px;
    height:200px;
    margin:0 auto;
    
}


.signinHeader {
    font-family:Arial,Helvetica,sans-serif;
    font-size:16px;
    font-weight:bold;
    text-align:left;
    white-space:nowrap;
    color:#333333;
    padding-top:5px;
    padding-bottom:5px;
    line-height:30px;
}

.signinLabel {
    font-family:Arial,Helvetica,sans-serif;
    font-weight:normal;
    color:#333333;
    font-size:15px;
    margin-top:5px;
}

.signinTextbox {
    font-size:15px;
    color:#000000;
    text-indent:3px;
    background-color:#eae9e4;
    border-width:1px;
    border-style:solid;
    border-top-color:#c6c3b3;
    border-right-color:#7c7d6a;
    border-bottom-color:#000000;
    border-left-color:#7c7d6a;
    height:20px;
    line-height:20px;
    margin-right:2px;
    margin-left:30px;
    margin-top:5px;
}

.ErrorLabel {
    font-family:Arial,Helvetica,sans-serif;
    font-weight:bold;
    color:#cc3300;
    font-size:15px;
    margin-bottom:30px;
    margin-left:100px;
}



.signinButton {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    background-color:#fb9d00;
    font-size:15px;
    color:#ffffff;
    font-weight:bold;
    cursor:pointer;
    border: 1px solid;
    border-bottom-color:#f07c00;
    border-top-color:#ffcc00;
    border-right-color:#f07c00;
    border-left-color:#ffcc00;
    padding-left:5px;
    padding-right:5px;
    margin-left:150px;
    margin-top:10px;
}

.linkNewUser {
    font-family:Arial,Helvetica,sans-serif;
    font-size:14px;
    color:#33333;
    text-indent:3px;
}

.signInContent {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.8em;
    background-color:#ffffff;
    white-space:nowrap;
    color:#333333;
    padding-top:10px;
    padding-bottom:10px;
}

.welcomeName {
    font-size:0.7em;
    font-weight:bold;
    white-space:nowrap;
    text-indent:37px;
    color:#555555;
    font-family:Arial,Helvetica,sans-serif;
}


.signinNewUser {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.8em;
    text-transform:uppercase;
    color:#333333;
}


.profilePostition {
    position:relative;
    width:360px;
    top:0;
    left:0;
    margin:0 auto;
    vertical-align:top;
}

.info {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.8em;
    color:#333333;
    margin-bottom:15px;
    text-align:left;
}


.divLeft {
    float:left;
    width:145px;
    height:145px;
    border:2px solid #555555;
    margin-left:10px;
    text-align:center;
    margin-top:10px;
    margin-bottom:10px;
}

.divLeft img {
    width:138px;
    height:138px;
    border:2px solid #cccccc;
    padding:2px;
}

.divRight {
    float:left;
    width:120px;
    height:145px;
    margin-left:8px;
    margin-top:10px;
    margin-bottom:10px;
}

.productName {
    font-family:Arial,Helvetica,sans-serif;
    font-size:16px;
    font-weight:bold;
    color:#333333;
    margin-top:3px;
    padding-left:2px;
    padding-bottom:8px;
}

.productDescription {
    font-family:Arial,Helvetica,sans-serif;
    font-size:12px;
    font-weight:normal;
    color:#333333;
    padding-left:2px;
    padding-bottom:8px;
}

.itemText {
    font-family:Arial,Helvetical,sans-serif;
    font-size:13px;
    font-weight:normal;
    line-height:30px;
    width:100%;
    height:30px;
}

.itemText #imgCart {
    width:20px;
    height:20px;
    border-width:0;
    float:left;
    margin-left:20px;
    margin-top:6px;
}

.linkCart {
    font-family:Arial,Helvetical,sans-serif;
    font-size:14px;
    font-weight:bold;
    cursor:pointer;
    line-height:28px;
    margin-top:3px;
    margin-left:4px;
    float:left;
}



.itemText #imgWishList {
    width:20px;
    height:20px;
    border-width:0;
    float:left;
    margin-left:20px;
    margin-top:6px;
}

.linkWishlist {
    font-family:Arial,Helvetical,sans-serif;
    font-size:14px;
    font-weight:bold;
    cursor:pointer;
    line-height:28px;
    margin-top:3px;
    margin-left:4px;
    float:left;
}




.cartPosition {
    position:relative;
    width:400px;
    top:0;
    left:0;
    margin:0 auto;
    vertical-align:top;
    padding-top:50px;
    padding-bottom:33px;
}

.linkCheckOut {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.65em;
    text-transform:uppercase;
    color:#333333;
    text-indent:7px;
}

.cartHeader {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.9em;
    text-align:center;
    white-space:nowrap;
    color:#333333;
    width:387px;
    padding-bottom:16px;
}

.labelLists {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    font-size:0.7em;
    font-weight:bold;
    color:#747c6d;
    vertical-align:bottom;
    background-image:url("../../Comm_Images/bg-labelLists.gif");
    text-align:left;
    line-height:21px;
    padding-left:5px;
    text-indent:2px;
    padding-right:5px;
    padding-top:8px;
    padding-bottom:1px;
    border-bottom-color:#ffffff;
    border-bottom-style:solid;
}

.listItem {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    font-size:0.7em;
    color:#3333333;
    text-decoration:none;
    line-height:15px;
    padding-left:5px;
    padding-right:5px;
    padding-bottom:2px;
    padding-top:2px;
    white-space:nowrap;
    text-align:left;
    background-color:#e8eadd;

}


.dottedLineCentered {
    background-image:url("../../Comm_Images/dotten-line.gif");
    background-repeat:repeat-x;
    background-position:center;
    height:8px;
    width:400px;
}

.total {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.7em;
    font-weight:bold;
    color:#000000;
    padding-top:10px;
    padding-right:30px;
    line-height:1.5em;
    text-align:right;
}


.otherCon {
    width:400px;
    text-align:right;
    margin-top:20px;
}


.checkoutContent {
    font-family:Arial,Helvetica,sans-serif;
    background-color:#ffffff;
    white-space:nowrap;
    color:#333333;
    width:270px;
    padding-left:150px;
    padding-top:20px;
    padding-bottom:33px;
}

.checkoutHeaders {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.9em;
    font-weight:bold;
    color:#333333;
    text-transform:capitalize;
    white-space:nowrap;
    height:30px;
    padding-top:3px;
    padding-bottom:5px;
}

.checkoutButtonBg {
    text-align:right;
    width:336px;
}

.continue {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    font-size:0.7em;
    color:#000000;
    text-decoration:none;
    font-weight:bold;
    background-image:url("../../Comm_Images/button-continue.gif");
    background-repeat:no-repeat;
    background-position:right 7px;
    padding-right:22px;
    padding-top:9px;
    margin-right:7px;
    cursor:pointer;
    line-height:40px;
}

.submit {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    background-color:#fb9d00;
    font-size:0.7em;
    color:#ffffff;
    text-decoration:none;
    font-weight:bold;
    cursor:pointer;
    line-height:30px;
    border:1px solid;
    border-bottom-color:#f07c00;
    border-top-color:#ffcc00;
    border-right-color:#f07c00;
    border-left-color:#ffcc00;
    padding-right:10px;
    padding-left:10px;
    padding-top:1px;
    padding-bottom:1px;
}

.checkOutLabel {
    font-family:Arial,Helvetica,sans-serif;
    font-size:0.7em;
    color:#333333;
    margin-left:3px;
    margin-bottom:10px;
    text-align:left;
}

.back {
    font-family:Tahoma,Arial,Helvetica,sans-serif;
    font-size:0.7em;
    color:#000000;
    text-decoration:none;
    font-weight:bold;
    background-image:url("../../Comm_Images/button-back.gif");
    background-repeat:no-repeat;
    background-position:left 7px;
    padding-left:22px;
    padding-top:9px;
    margin-left:7px;
    cursor:pointer;
    line-height:40px;
}

.checkoutTextbox {
    font-size:1em;
    color:#000000;
    text-indent:3px;
    background-color:#eae9e4;
    border-width:1px;
    border-style:solid;
    border-top-color:#c6c3b3;
    border-right-color:#7c7d6a;
    border-bottom-color:#000000;
    border-left-color:#7c7d6a;
    height:16px;
    margin-top:1px;
}

.checkoutDropdown {
    font-size:1em;
    color:#000000;
    text-indent:3px;
    background-color:#eae9e4;
    border-width:1px;
    border-style:solid;
    border-top-color:#c6c3b3;
    border-right-color:#7c7d6a;
    border-bottom-color:#000000;
    height:20px;
    margin-top:2px;
}






创建数据库

sql

CREATE DATABASE netPetShop;

use netPetShop;

--用户表
CREATE TABLE account(
	user_name nvarchar(256) not null,
	user_pwd nvarchar(16)  not null,
	cname nvarchar(80) null,
	country nvarchar(80) null,
	province nvarchar(80) null,
	city nvarchar(80) null,
	address nvarchar(80) null,
	zip_code nvarchar(80) null,
	phone nvarchar(80) null,
	email nvarchar(80) null,
	primary key(user_name)
);


--宠物分类表
CREATE TABLE category(
	category_id nvarchar(50) not null,
	name nvarchar(80) not null,
	descn nvarchar(255) null,
	primary key(category_id)
);


--宠物表
CREATE TABLE product(
	product_id nvarchar(50) not null,
	category_id nvarchar(50) not null,
	name nvarchar(80) not null,
	descn nvarchar(255) not null,
	pro_image nvarchar(80) not null,
	list_price decimal(18,2) not null,
	primary key(product_id)
);


--购物车
CREATE TABLE cart(
	user_name nvarchar(256) not null,
	product_id nvarchar(50) not null,
	name nvarchar(80) not null,
	list_price decimal(18,2) not null,
	category_id nvarchar(50) not null,
	quantity int not null,
	primary key(user_name,product_id)
);

--订单表
CREATE TABLE orders(
	order_id int not null identity(1,1),
	user_name nvarchar(256) not null,
	order_date datetime not null,
	primary key(order_id)
);



--订单明细表
CREATE TABLE orderlineitem(
	item_id int not null identity(1,1),
	order_id int not null,
	product_id nvarchar(50) not null,
	quantity int not null,
	list_price decimal(18,2) not null,
	primary key(item_id)
);

insert into category values('BACKYARD','大型动物','大型动物');
insert into category values('BIRDS','鸟类','鸟类');
insert into category values('BUGS','昆虫','昆虫');
insert into category values('FISH','鱼类','鱼类');

insert into product values('BD-01','BIRDS','塘鹅','动静皆宜','~/Prod_Images/Birds/icon-pelican.gif',86);
insert into product values('BD-02','BIRDS','企鹅','形态可掬','~/Prod_Images/Birds/icon-penguin.gif',130);
insert into product values('BD-03','BIRDS','翼龙','亿年前的空中霸主','~/Prod_Images/Birds/icon-pteranodon.gif',2100);
insert into product values('BD-04','BIRDS','猫头鹰','日夜守候','~/Prod_Images/Birds/icon-owl.gif',40);
insert into product values('BD-05','BIRDS','鸭子','口齿不清但歌声美妙','~/Prod_Images/Birds/icon-duck.gif',32);
insert into product values('BG-01','BUGS','蚂蚁','搬运工','~/Prod_Images/Bugs/icon-ant.gif',2);
insert into product values('BG-02','BUGS','蝴蝶','越大越美','~/Prod_Images/Bugs/icon-butterfly.gif',8);
insert into product values('BG-03','BUGS','蜘蛛','冷酷美','~/Prod_Images/Bugs/icon-spider.gif',5);
insert into product values('BG-04','BUGS','蜗牛','你的柔软伙伴','~/Prod_Images/Bugs/icon-slug.gif',7);
insert into product values('BG-05','BUGS','青蛙','想灭蚊吗','~/Prod_Images/Bugs/icon-frog.gif',12);
insert into product values('BG-06','BUGS','蜻蜓','精致的宠物','~/Prod_Images/Bugs/icon-dragonfly.gif',3);
insert into product values('BY-01','BACKYARD','绵羊','软绵绵的拥抱','~/Prod_Images/Backyard/icon-sheep.gif',120);
insert into product values('BY-02','BACKYARD','猫','多情而敏感','~/Prod_Images/Backyard/icon-cat.gif',80);
insert into product values('BY-03','BACKYARD','浣熊','胃口不错','~/Prod_Images/Backyard/icon-raccoon.gif',240);
insert into product values('BY-04','BACKYARD','鹅','曲项向天歌','~/Prod_Images/Backyard/icon-goose.gif',45);
insert into product values('BY-05','BACKYARD','巨蟹','冰箱里出现','~/Prod_Images/Backyard/icon-crad.gif',28);
insert into product values('BY-06','BACKYARD','臭鼬','味道比较浓厚','~/Prod_Images/Backyard/icon-skunk.gif',98);
insert into product values('BY-07','BACKYARD','斑马','摩登的美女','~/Prod_Images/Backyard/icon-zebra.gif',820);
insert into product values('FI-01','FISH','丑鱼','海底总动员','~/Prod_Images/Fish/icon-meno.gif',20);
insert into product values('FI-02','FISH','河豚','温度越高,身体越大','~/Prod_Images/Fish/icon-ballonfish.gif',18);
insert into product values('FI-03','FISH','盲鱼','视觉退化','~/Prod_Images/Fish/icon-blindfish.gif',34);
insert into product values('FI-04','FISH','海蟹','喂食时会跳舞','~/Prod_Images/Fish/icon-cradfish.gif',16);
insert into product values('FI-05','FISH','章鱼','给你按摩','~/Prod_Images/Fish/icon-eucalyptus.gif',27);
insert into product values('FI-07','FISH','鲨鱼','小心咬你','~/Prod_Images/Fish/icon-nosyfish.gif',360);
insert into product values('FI-08','FISH','巨齿鱼','素食动物','~/Prod_Images/Fish/icon-toothferry.gif',280);



创建首页

default1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default1.aspx.cs" Inherits="dynamicweb11_1.Default1" %>






    欢迎来到.NET宠物商店



    
.NET PET SHOP 欢迎来到动物世界 从我们精选的宠物中挑选你的最爱吧 宠物分类: ' Text='<%# Eval("name") %>'>

" SelectCommand="SELECT [category_id], [name] FROM [category]"> Powered by .NET 4.6

default1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class Default1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            if (!String.IsNullOrEmpty(txtSearch.Text))
            { 
                Response.Redirect("~/Search.aspx?keywords=" + txtSearch.Text);
            }
            
        }

        protected void btnLgnStatus_Click(object sender, EventArgs e)
        {
            Response.Redirect("SignIn1.aspx");
        }
    }
}

创建母版页

masterpage1.master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage1.master.cs" Inherits="dynamicweb11_1.MasterPage1" %>






    .NET宠物商店



        
.NET PET SHOP 我的资料 购物车   ' Text='<%# Eval("name") %>'>
" SelectCommand="SELECT [category_id], [name] FROM [category]"> powered by .net 4.6

masterpage1.master.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class MasterPage1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ltlHeader.Text = Page.Header.Title;
            Page.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            if (Session["UserName"] != null)
            {
                ltlName.Text = "欢迎," + Session["UserName"].ToString();
                btnLgnStatus.Text = "退出";
            }
            else
            {
                btnLgnStatus.Text = "登录";
            }
        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            if (!String.IsNullOrEmpty(txtSearch.Text))
            {
                Response.Redirect("~/Search.aspx?keywords=" + txtSearch.Text);
            }
        }

        protected void btnLgnStatus_Click(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/SignIn1.aspx");
            }
            else
            {
                Session["UserName"] = null;
                Response.Redirect("~/SignIn1.aspx");
            }
        }
    }
}

创建内容页

signin1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SignIn1.aspx.cs" Inherits="dynamicweb11_1.SignIn1" MasterPageFile="~/MasterPage1.Master" %>


    
        用户登录
        
用户名:
密码:


注册新用户

signin1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class SignIn1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["UserName"] != null)
                {
                    txtName.Text = Request.Cookies["UserName"].Value;
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string conString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPetShop"].ToString();
            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString);
            con.Open();
            string sql = "select * from account where user_name=@uName and user_pwd=@uPwd";
            System.Data.SqlClient.SqlCommand cmd  = new System.Data.SqlClient.SqlCommand(sql,con);
            cmd.Parameters.AddWithValue("@uName",txtName.Text);
            cmd.Parameters.AddWithValue("@uPwd",txtPassword.Text);
            System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader();
            if(reader.HasRows)
            {
                if (chkRememberMe.Checked == true)
                {
                    Response.Cookies["UserName"].Value = txtName.Text;
                    //Response.Cookies["UserName"].Expires = DateTime.Now.AddDays("7");
                    Response.Cookies["UserName"].Expires = DateTime.Now.AddMinutes(2);
                }
                Session["UserName"] = txtName.Text;
                if(Request.QueryString["from"] == null)
                {
                    Response.Redirect("~/Products1.aspx?categoryId=BACKYARD");
                }
                else
                {
                    Response.Redirect(Request.QueryString["from"]);
                }
            }
            else
            {
                lblError.Text = "用户名或密码错误";
            }

            reader.Close();
            con.Close();
        }
    }
}

newuser1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewUser1.aspx.cs" Inherits="dynamicweb11_1.NewUser1" MasterPageFile="~/MasterPage1.Master" %>


    
        
            
               注册新用户
            
            
用户名:
密码:
确认密码:


感谢你的注册。

用户创建成功,现在你可以:

继续选购

购物车

变更你的资料

newuser1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class NewUser1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string conString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPetShop"].ToString();
            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString);
            con.Open();

            string sqlSelect = "select * from account where user_name=@uName";
            System.Data.SqlClient.SqlCommand cmdSelect = new System.Data.SqlClient.SqlCommand(sqlSelect, con);
            cmdSelect.Parameters.AddWithValue("@uName",txtName.Text);
            System.Data.SqlClient.SqlDataReader reader = cmdSelect.ExecuteReader();

            if (reader.HasRows)
            {
                lblError.Text = "此用户已存在";
                reader.Close();
            }
            else
            {
                reader.Close();
                string sqlInsert = "insert into account(user_name,user_pwd) values(@uName,@uPwd)";
                System.Data.SqlClient.SqlCommand cmdInsert = new System.Data.SqlClient.SqlCommand(sqlInsert, con);
                cmdInsert.Parameters.AddWithValue("@uName",txtName.Text);
                cmdInsert.Parameters.AddWithValue("@uPwd",txtPassword.Text);
                cmdInsert.ExecuteNonQuery();
                plRegister.Visible = false;
                plSuccess.Visible = true;
            }

            con.Close();
        }
    }
}

checkout1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CheckOut1.aspx.cs" Inherits="dynamicweb11_1.CheckOut1" MasterPageFile="~/MasterPage1.Master" %>


    
        
        
            
                订购商品
            
            
            " SelectCommand="SELECT * FROM [cart] WHERe user_name=@uName" OnSelecting="sdsCart_Selecting">
                
                    
                
            
            
                
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
                
                
                
                
                
                
                
                
                
                
            
            
            
                
            
            
            " SelectCommand="SELECT * FROM [account] WHERe user_name=@uName" OnSelecting="sdsAccount_Selecting" UpdateCommand="UPDATE [account] SET [cname] = @cname, [country] = @country, [province] = @province, [city] = @city, [address] = @address, [zip_code] = @zip_code, [phone] = @phone, [email] = @email WHERe [user_name] = @user_name">
                
                    
                
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
            
            
                
                
姓名:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
 
国家:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
省:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
城市:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
邮编:
' CssClass="checkoutTextbox" MaxLength="80" Width="80px">
地址:
' CssClass="checkoutTextbox" MaxLength="80" Width="330px">
电话:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
电子邮箱:
' CssClass="checkoutTextbox" MaxLength="80" Width="330px">
感谢你的订购!

订单商品将开始通过快递配送,请保持联系方式畅通。

如对订单有任何疑问,请随时联系我们的客户服务400123456

.NET宠物商店

checkout1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace dynamicweb11_1
{
    public partial class CheckOut1 : System.Web.UI.Page
    {
        private decimal total;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                Response.Redirect("~/SignIn.aspx?from=CheckOut1.aspx");
            }
        }

        protected void sdsCart_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.Parameters[0].Value = Session["UserName"].ToString();
        }

        protected void gvCart_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                System.Data.DataRowView row1 = e.Row.DataItem as System.Data.DataRowView;
                total += Convert.ToInt32(row1.Row["quantity"]) * Convert.ToDecimal(row1.Row["list_price"]);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                ltlTotal.Text = "总价:" + total.ToString("C");
            }
            else
            {
                ltlTotal.Text = "";
            }
        }

        protected void sdsAccount_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.Parameters[0].Value = Session["UserName"].ToString();
        }

        protected void fvAccount_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
        {
            lblMessage.Text = "你的资料已更新
"; } protected void FinishButton_Click(object sender, EventArgs e) { string cnString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPetShop"].ToString(); System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(cnString); con.Open(); string sqlOrder = "insert into orders values(@user_name,@order_date)"; sqlOrder += " ; SELECT @@identity AS 'id'"; System.Data.SqlClient.SqlCommand cmdOrder = new System.Data.SqlClient.SqlCommand(sqlOrder, con); cmdOrder.Parameters.AddWithValue("@user_name", Session["UserName"]); cmdOrder.Parameters.AddWithValue("@order_date",DateTime.Now.ToShortDateString()); string order_id = cmdOrder.ExecuteScalar().ToString(); string sqlCart = "select * from cart where user_name=@uName"; System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(sqlCart, con); adapter.SelectCommand.Parameters.AddWithValue("@uName",Session["UserName"]); System.Data.DataSet dsCart = new System.Data.DataSet(); adapter.Fill(dsCart); for (int i = 0; i < dsCart.Tables[0].Rows.Count; i++) { string sqlOrderDetails = "insert into orderlineitem values(@order_id,@product_id,@quantity,@list_price)"; System.Data.SqlClient.SqlCommand cmdDetails = new System.Data.SqlClient.SqlCommand(sqlOrderDetails, con); cmdDetails.Parameters.AddWithValue("@order_id", order_id); cmdDetails.Parameters.AddWithValue("@product_id",dsCart.Tables[0].Rows[i]["product_id"]); cmdDetails.Parameters.AddWithValue("@quantity",dsCart.Tables[0].Rows[i]["quantity"]); cmdDetails.Parameters.AddWithValue("@list_price",dsCart.Tables[0].Rows[i]["list_price"]); cmdDetails.ExecuteNonQuery(); } string sqlDelete = "delete from cart where user_name=@user_name"; System.Data.SqlClient.SqlCommand cmdDelete = new System.Data.SqlClient.SqlCommand(sqlDelete, con); cmdDelete.Parameters.AddWithValue("@user_name",Session["UserName"]); cmdDelete.ExecuteNonQuery(); con.Close(); panForm.Visible = false; panFinish.Visible = true; } } }

products1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Products1.aspx.cs" Inherits="dynamicweb11_1.Products1" MasterPageFile="~/MasterPage1.Master" %>


    
        
            
                
                    ' src='<%# Eval("pro_image") %>' runat="server"/>
                
                
                    
                        <%# Eval("name") %>
                    
                    
                        <%# Eval("descn ") %>
                    
                    
                        价格:<%# Eval("list_price ","{0:c}") %>
                    
                    
                        
                        ' CssClass="linkCart" Text="添加购物车">
                    
                
            
        
        " SelectCommand="SELECT * FROM [product] WHERe ([category_id] = @category_id)">
            
                
            
        
    

products1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class Products1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["name"] != null)
            { 
                //Page.Master.Page.Title = Request.QueryString["name"].ToString(); //正确的写法
                Page.Title = Request.QueryString["name"].ToString();
            }

        }
    }
}

search.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="dynamicweb11_1.Search" MasterPageFile="~/MasterPage1.Master" %>

    

很抱歉,这个功能暂未开发,你可以试着自己完善。

shoppingcart1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCart1.aspx.cs" Inherits="dynamicweb11_1.ShoppingCart1" MasterPageFile="~/MasterPage1.Master" %>


    
        
            购物车中的商品
        
        
        " OnSelecting="sdsCart_Selecting" SelectCommand="SELECT * FROM [cart] WHERe user_name=@uName" DeleteCommand="DELETE FROM [cart] WHERe [user_name] = @user_name AND [product_id] = @product_id" InsertCommand="INSERT INTO [cart] ([user_name], [product_id], [name], [list_price], [category_id], [quantity]) VALUES (@user_name, @product_id, @name, @list_price, @category_id, @quantity)" UpdateCommand="UPDATE [cart] SET [quantity] = @quantity WHERe [user_name] = @user_name AND [product_id] = @product_id">
            
                
            
            
                
                
            
            
                
                
                
                
                
                
            
            
                
                
                
            
        
        
            
            
                
                
                
                
                
                
                
                    
                        ' AutoPostBack="True" OnTextChanged="txtQuantity_TextChanged">
                        
                    
                    
                
                
                
                
                
                
                
                
            
            
            
            
            
            
            
            
            
            
            
        
        
        
             
        
        
            
        
        
        
            继续选购

shoppingcart1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class ShoppingCart1 : System.Web.UI.Page
    {
        //
        private decimal total;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
            {
                if (Request.QueryString["categoryId"] == null) return;
                string qsValue = "~/Products1.aspx?categoryId=" + Request.QueryString["categoryId"].ToString();
                Response.Redirect("~/SignIn1.aspx?from=" + qsValue);
            }

            if (!IsPostBack)
            { 
                if(!string.IsNullOrEmpty(Request.QueryString["productId"]))
                {
                    string cnString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPetShop"].ToString();
                    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(cnString);
                    con.Open();

                    string sqlUpdate = "update cart set quantity=quantity + 1 where user_name=@uName and product_id=@proId";
                    System.Data.SqlClient.SqlCommand cmdUpdate = new System.Data.SqlClient.SqlCommand(sqlUpdate,con);
                    cmdUpdate.Parameters.AddWithValue("@uName",Session["UserName"]);
                    cmdUpdate.Parameters.AddWithValue("@proId",Request.QueryString["productId"]);
                    int numUpdate = cmdUpdate.ExecuteNonQuery();

                    if(numUpdate <= 0)
                    {
                        string sqlInsert  = "insert into cart values(@uName,@proId,@name,@price,@categoryId,1)";
                        System.Data.SqlClient.SqlCommand cmdInsert  = new System.Data.SqlClient.SqlCommand(sqlInsert,con);
                        cmdInsert.Parameters.AddWithValue("@uName",Session["UserName"]);
                        cmdInsert.Parameters.AddWithValue("@proId",Request.QueryString["productId"]);
                        cmdInsert.Parameters.AddWithValue("@name",Request.QueryString["name"]);
                        cmdInsert.Parameters.AddWithValue("@price",Request.QueryString["price"]);
                        cmdInsert.Parameters.AddWithValue("@categoryId",Request.QueryString["categoryId"]);
                        cmdInsert.ExecuteNonQuery();
                    }
                    con.Close();
                }
            }
        }

        protected void sdsCart_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            if (Session["UserName"] == null)
            { 
                Response.Redirect("~/SignIn1.aspx");
            }
                
            e.Command.Parameters[0].Value = Session["UserName"].ToString();
        }

        protected void gvCart_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                System.Data.DataRowView row1 = e.Row.DataItem as System.Data.DataRowView;
                total += Convert.ToInt32(row1.Row["quantity"]) * Convert.ToDecimal(row1.Row["list_price"]);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                ltlTotal.Text = "总价:" + total.ToString("C");
            }
            else
            {
                ltlTotal.Text = "";
            }
        }

        protected void txtQuantity_TextChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < gvCart.Rows.Count; i++)
            {
                gvCart.UpdateRow(i, false);
            }
        }

        protected void lbtnBack_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["categoryId"] != null)
            {
                Response.Redirect("~/products1.aspx?categoryId=" + Request.QueryString["categoryId"]);
            }
            else
            {
                Response.Redirect("~/products1.aspx?categoryId=BACKYARD");
            }
        }

        protected void lbtnCheckout_Click(object sender, EventArgs e)
        {
            if (gvCart.Rows.Count <= 0)
            {
                Response.Write("");
                return;
            }
            else
            {
                Response.Redirect("~/CheckOut1.aspx");
            }
        }
    }
}

userprofile1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserProfile1.aspx.cs" Inherits="dynamicweb11_1.UserProfile1" MasterPageFile="~/MasterPage1.Master" %>


    
        
            个人信息
        
        
            用户名:
        
        
        
            
                
姓名:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
 
国家:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
省:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
城市:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
邮编:
' CssClass="checkoutTextbox" MaxLength="80" Width="80px">
地址:
' CssClass="checkoutTextbox" MaxLength="80" Width="330px">
电话:
' CssClass="checkoutTextbox" MaxLength="80" Width="155px">
电子邮箱:
' CssClass="checkoutTextbox" MaxLength="80" Width="330px">
" SelectCommand="SELECT * FROM [account] WHERe ([user_name] = @user_name)" UpdateCommand="UPDATE [account] SET [cname] = @cname, [country] = @country, [province] = @province, [city] = @city, [address] = @address, [zip_code] = @zip_code, [phone] = @phone, [email] = @email WHERe [user_name] = @user_name" OnSelecting="sdsAccount_Selecting">

userprofile1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dynamicweb11_1
{
    public partial class UserProfile1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                lblName.Text = Session["UserName"].ToString();
                
            }
            else
            {
                Response.Redirect("~/SignIn1.aspx?from=~/UserProfile1.aspx");
            }
        }

        protected void sdsAccount_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            if (Session["UserName"] != null)
            {
                e.Command.Parameters[0].Value = Session["UserName"].ToString();
            }
            else
            {
                return;
            }
            
        }

        protected void fvAccount_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
        {
            lblMessage.Text = "你的资料已完成更新
"; } } }

web.config






    
        
    
    
      
      
      
    


项目中所用图片

 

 

以上是全部代码及部分图片,因为图片太多,完整的项目代码,我会上传至博客资源中。

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/954636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号