试题十(谭一娟)

mobdescriptiveSoftware and s/w Development

Oct 28, 2013 (4 years and 15 days ago)

175 views


1


效果截图

查询页面:


新增页面:

验证:










新增到查询页面(分页):


新增到查询页面(分页):






2


代码块:

display.aspx

<%
@

Page

Language
="C#"

AutoEventWireup
="true"

CodeFile
="display.aspx.cs"

Inherits
="_Default"

%>

<!
DOCTYPE

HTML

PUBLIC

"
-
//W3C//DTD HTML 4.01 Transitional//EN"

"http://www
.w3c.org/TR/1999/REC
-
html401
-
19991224/loose.dtd">

<
HTML
><
HEAD
><
TITLE
>
413
网上书城
|
管理员
</
TITLE
>

<
META

http
-
equiv
=Content
-
Type

content
="text/html; charset=gb2312">

<
SCRIPT

language
?
javascript
?>


function init(){


alert("");


}



</
SCRIPT
>

<
LINK

href
="display.files/22.css"

type
=text/css

rel
=stylesheet>

<
META

content
="MSHTML 6.00.2900.2523"

name
=GENERATOR></
HEAD
>

<
BODY
>

<
form

id
="form1"

runat
="server">

<
DIV

id
=container>

<
DIV

id
=banner><
IMG

src
="display.files/p01.jpg"></
DIV
>

<
DIV

id
=globallink>

<
U
L
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/enter.jsp#">
首页
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/login.jsp#">
用户注册
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/hot_books.jsp#">
图书促销
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
在线阅读
</
A
>

</
LI
>


<
LI
><
A

hre
f
="http://localhost:8080/bookstore1/vip.jsp#">
会员中心
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/about_me.jsp#">
联系我们
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
支付方式
</
A
>


</
LI
></
UL
><
BR
></
DIV
>

<
DIV

id
=left>

<
DIV

id
=lo
gin>
网上书店欢迎你
&nbsp;&nbsp;
<
A


href
="http://localhost:8080/bookstore1/booklist.jsp">
[
退出
]
</
A
>


<
UL
>


<
LI
>
图书信息管理


<
UL
>


<
LI
><
A

href
="display.aspx">
查看图书
</
A
>



<
LI
><
A

href
="addbook.aspx">
增加图书
</
A
>

</
LI
></
UL
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/F
indAllBook#">
订单管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
客户管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
查看留言
</
A
>


</
LI
></
UL
></
DIV
>

<
DIV

id
=category>

<
H4
><
SPAN
>
种类
</
SPAN
></
H4
>

<
UL
>


<
LI
><
A

href
="http://lo
calhost:8080/bookstore1/FindAllBook#">
计算机
/
网络
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
人文科社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
培训教材
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
经济
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
文化
/
文学
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
百科全书
</
A
>



<
LI
><
A

href
="http://localhost:8
080/bookstore1/FindAllBook#">
艺术
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
小说
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
期刊杂志
</
A
>

</
LI
></
UL
>

<
H4
><
SPAN
>
品牌出版社
</
SPAN
></
H4
>

<
UL
>


<
LI
><
A

href
="http://localhost:80
80/bookstore1/FindAllBook#">
人民教育出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
现代出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
新世纪出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
中国少儿出版

</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
二十一世纪出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
清华大学出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
泰博文化出版社
</
A
>



<
LI
><
A

href
="http://l
ocalhost:8080/bookstore1/FindAllBook#">
科学普及出版社
</
A
>


</
LI
></
UL
>

<
H4
><
SPAN
>
本周热销榜
</
SPAN
></
H4
>

<
UL
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
南渡北归
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
气场
</
A
>



<
LI
><
A

href
="htt
p://localhost:8080/bookstore1/FindAllBook#">
读心术
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
java web
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
网络安全
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAll
Book#">
曾国藩家书
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/FindAllBook#">
XML
</
A
>


</
LI
></
UL
></
DIV
></
DIV
>

<
DIV

id
=main>

<
DIV

id
=latest><
BR
><
BR
><
BR
><
BR
>

<
H3

align
=center><
FONT

color
=#ff0000>
图书信息列表
</
FONT
></
H3
><
FONT

size
=2>
共有页,这是第页。
<!
--
如果是第一页,则不显示超链接
--
>

第一页

上一页


<!
--
如果不是第一页,则显示超链接
--
><!
--
如果是最后一页,则不显示超链接
--
>

下一页

最后一


<!
--
如果不是最后一页,则显示超链接
--
>
</
FONT
>

跳转到
<
INPUT

name
=pageNo>

<
INPUT

type
=submit

value
=
跳转
>




<
asp
:
GridView

ID
="gvwDisplay"

runat
="server"

AllowPaging
="True"

AutoGenerateColumns
="False"



DataKeyNames
="Book_number"

DataSourceID
="sdsDisplay"

Width
="482px"

PageSize
="3"

BorderWidth
="0px">


<
Columns
>


<
asp
:
BoundField

DataField
="Book_name"

HeaderText
="
书名
"

SortExpression
="Book_name">


<
ItemStyle

HorizontalAlign
="
Center"

/>


<
HeaderStyle

HorizontalAlign
="Center"

/>


</
asp
:
BoundField
>


<
asp
:
BoundField

DataField
="Book_number"

HeaderText
="
书号
"

ReadOnly
="True"

SortExpression
="Book_number"

>


<
ItemStyle

HorizontalAlign
=
"Center"

/>


<
HeaderStyle

HorizontalAlign
="Center"

/>


</
asp
:
BoundField
>


<
asp
:
BoundField

DataField
="Author"

HeaderText
="
作者
"

SortExpression
="Author"

>


<
ItemStyle

HorizontalAlign
="Center"

/>



<
HeaderStyle

HorizontalAlign
="Center"

/>


</
asp
:
BoundField
>


<
asp
:
BoundField

DataField
="Publisher"

HeaderText
="
出版社
"

SortExpression
="Publisher"

>


<
ItemStyle

HorizontalAlign
="Center"

/>


<
HeaderStyle

Ho
rizontalAlign
="Center"

/>


</
asp
:
BoundField
>


<
asp
:
BoundField

DataField
="Price"

HeaderText
="
定价
"

SortExpression
="Price"

>


<
ItemStyle

HorizontalAlign
="Center"

/>


<
HeaderStyle

HorizontalAlign
="Center"

/>



</
asp
:
BoundField
>


<
asp
:
TemplateField

HeaderText
="
修改

删除
">


<
ItemStyle

HorizontalAlign
="Center"

/>


<
HeaderStyle

HorizontalAlign
="Center"

/>


<
ItemTemplate
>


<
asp
:
Button

I
D
="btnModify"

runat
="server"

Text
="
修改
"

/>


&nbsp;&nbsp;


<
asp
:
Button

ID
="btnDelete"

runat
="server"

Text
="
删除
"

/>


</
ItemTemplate
>


</
asp
:
TemplateField
>


</
Columns
>


</
asp
:
GridView
>



<
asp
:
SqlDataSource

ID
="sdsDisplay"

runat
="server"

ConnectionString
="
<%
$ ConnectionStrings:BookStoreDBConnectionString
%>
"


SelectCommand
="SELECT [Book_number], [Book_name], [Author], [Publisher], [Price] FROM
[T_book]">


</
asp
:
SqlDataSource
>



&nbsp;
<
br

/>


&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;


&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;&nbsp;


<
br

/>

</
DIV
></
DIV
></
DIV
>

</
form
>

</
BODY
>

</
html
>



addbook.aspx

<%
@

Page

Language
="C#"

AutoEventWireup
=
"true"

CodeFile
="addbook.aspx.cs"

Inherits
="addbook"

%>


<!
DOCTYPE

HTML

PUBLIC

"
-
//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3c.org/TR/1999/REC
-
html401
-
19991224/loose.dtd">

<
HTML
><
HEAD
><
TITLE
>
413
网上书城
|
管理员
|
添加新图书
</
TITLE
>

<
META

http
-
equiv
=Content
-
Type

content
="text/html; charset=gb2312">

<
SCRIPT

language
=javascript>

function

isValidate(form1)

{


Book_name=form1.Book_name.value;


Book_number=form1.Book_number.value;


Author=form1.Author.value;


Publisher=form1.Publisher.value;


Price=form1.Price.value
;




if
(Book_name==
""
)


{



alert(
"
图书名称不能为空!
"
);



form1.Book_name.focus();


return

false
;


}


if
(Book_number==
""
)


{



alert(
"
图书编号不能为空!
"
);



form1.Book_number.focus();


return

false
;


}


if
(Author==
""
)


{



alert(
"
作者信息不能为空!
"
);



form1.Author.focus();


return

false
;


}


if
(Publisher==
""
)


{



alert(
"
出版社信息不能为空!
"
);



form1.Publisher.focus();


return

false
;


}

if
(Price==
""
)


{



alert(
"
单价信息不能为空!
"
);



form1.Price.focus();


return

false
;


}


function

isNull(str)


{



if
(str.length==0)



return

true
;



else



return

false
;


}



}




</
SCRIPT
>

<
LINK

href
="addbook.files/25.css"

type
=text/css

rel
=stylesheet>

<
META

content
="MSHTML 6.00.2900.2523"

name
=GENERATOR></
HEAD
>

<
BODY
>

<
form

id
="form1"

runat
="server">

<
DIV

id
=container>

<
DIV

id
=banner><
IMG

src
="addbook.files/p01.jpg"></
DIV
>

<
D
IV

id
=globallink>

<
UL
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/enter.jsp#">
首页
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/login.jsp#">
用户注册
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/hot_books.jsp#">
图书促销
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
在线阅读
</
A
>

</
LI
>


<
LI
><
A

hre
f
="http://localhost:8080/bookstore1/vip.jsp#">
会员中心
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/about_me.jsp#">
联系我们
</
A
>

</
LI
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
支付方式
</
A
>


</
LI
></
UL
><
BR
></
DIV
>

<
DIV

id
=left>

<
DIV

id
=lo
gin>
网上书店欢迎你
<
A


href
="http://localhost:8080/bookstore1/booklist.jsp">
[
退出
]
</
A
>


<
UL
>


<
LI
>
图书信息管理


<
UL
>


<
LI
><
A

href
="display.aspx">
查看图书
</
A
>



<
LI
><
A

href
="addbook.aspx">
增加图书
</
A
>

</
LI
></
UL
>


<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#"
>
订单管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
客户管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
查看留言
</
A
>


</
LI
></
UL
></
DIV
>

<
DIV

id
=category>

<
H4
><
SPAN
>
种类
</
SPAN
></
H4
>

<
UL
>


<
LI
><
A

href
="http://localhost:8080
/bookstore1/addbook.jsp#">
计算机
/
网络
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
人文科社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
培训教材
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
经济
</
A
>



<
L
I
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
管理
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
文化
/
文学
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
百科全书
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstor
e1/addbook.jsp#">
艺术
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
小说
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
期刊杂志
</
A
>

</
LI
></
UL
>

<
H4
><
SPAN
>
品牌出版社
</
SPAN
></
H4
>

<
UL
>


<
LI
><
A

href
="http://localhost:8080/bookstore
1/addbook.jsp#">
人民教育出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
现代出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
新世纪出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
中国少儿出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
清华大学出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
泰博文化出版社
</
A
>



<
LI
><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#">
科学普及出版社
</
A
>


</
LI
></
UL
></
DIV
></
DIV
>

<
DIV

id
=main>

<
DIV

id
=latest><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#"><
IMG


src
="addbook.files/p06.jpg"></
A
></
DIV
>


<
DIV

id
=latt>

<
H2

align
=center>
添加图书信息
</
H2
>

<
TABLE

align
=center>


<
TBODY
>


<
TR
>


<
TH
><
FONT

size
=4>
书名:
</
FONT
></
TH
>


<
TD

style
="width
: 247px"><
FONT

color
=red

size
=5>


<
asp
:
TextBox

ID
="txtBookName"

runat
="server"></
asp
:
TextBox
><
span

style
="color:Red">
*
<
asp
:
RequiredFieldValidator


ID
="valrBookName"

runat
="server"

ControlToValidate
="txtPrice"

ErrorMessage
="
必填
"></
asp
:
Requi
redFieldValidator
></
span
></
FONT
></
TD
></
TR
>


<
TR
>


<
TH
><
FONT

size
=4>
书号:
</
FONT
></
TH
>


<
TD

style
="width: 247px"><
FONT

color
=red

size
=5>


<
asp
:
TextBox

ID
="txtBookNumber"

runat
="server"></
asp
:
TextBox
><
span

style
="color:Red">
*
<
asp
:
RequiredFieldVali
dator


ID
="valrBookNumber"

runat
="server"

ControlToValidate
="txtBookNumber"

ErrorMessage
="
必填
"></
asp
:
RequiredFieldValidator
></
span
></
FONT
></
TD
></
TR
>


<
TR
>


<
TH
><
FONT

size
=4>
作者:
</
FONT
></
TH
>


<
TD

style
="width: 247px"><
FONT

color
=red

size
=5>


<
asp
:
TextBox

ID
="txtAuthor"

runat
="server"></
asp
:
TextBox
><
span

style
="color:Red">
*
<
asp
:
RequiredFieldValidator


ID
="valrAuthor"

runat
="server"

ControlToValidate
="txtAuthor"

ErrorMessage
="
必填
"></
asp
:
RequiredFieldValidator
></
span
></
FONT
></
TD
></
TR
>


<
TR
>


<
TH
><
FONT

size
=4>
出版社:
</
FONT
></
TH
>


<
TD

style
="width: 247px"><
FONT

color
=red

size
=5>


<
asp
:
TextBox

ID
="txtPublisher"

runat
="server"></
asp
:
TextBox
><
span

style
="color:Red">
*
<
asp
:
RequiredFieldValidator


ID
="valrPublisher"

runat
="server"

ControlToValidate
="txtPublisher"

ErrorMessage
="
必填
"></
asp
:
RequiredFieldValidator
></
span
></
FONT
></
TD
></
TR
>


<
TR
>


<
TH
><
FONT

size
=4>
定价:
</
FONT
></
TH
>


<
TD

style
="width: 247px"><
FONT

color
=red

size
=5>


<
asp
:
TextBox

ID
="txtPrice"

run
at
="server"></
asp
:
TextBox
><
span

style
="color:Red">
*
<
asp
:
RequiredFieldValidator


ID
="valrPrice"

runat
="server"

ControlToValidate
="txtPrice"

ErrorMessage
="
必填
"></
asp
:
RequiredFieldValidator
></
span
></
FONT
></
TD
></
TR
>


<
TR
>


<
TD
>


<
H4

align
=ce
nter>


&nbsp;
<
asp
:
Button

ID
="btnReset"

runat
="server"

Text
="
重置
"

/></
H4
></
TD
>


<
TD

style
="width: 247px">


<
H4


align
=center>


&nbsp;
<
asp
:
Button

ID
="btnAddBook"

runat
="server"

Text
="
添加
"

OnClick
="btnAddBook_Click"

/></
H4
></
TD
></
TR
></
TBODY
></
TABLE
></
DIV
>

<
DIV

id
=DIV1><
A

href
="http://localhost:8080/bookstore1/addbook.jsp#"><
IMG


height
=228

src
="addbook.files/p105.jpg"

width
=518></
A
></
DIV
></
DIV
>

<
DIV

id
=bottom>

<
P
><
A


href
="http://localhost:8080/bookstore1/E

mail:lvzb212@demo.com">
http:/
/localhost:8080/bookstore1/E

mail:lvzb212@demo.com
</
A
></
P
></
DIV
></
DIV
></
form
></
BODY
></
HTML
>




addbook.aspx
.cs

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

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

addbook

: System.Web.UI.
Page

{


protected

void

Page_Load(
object

sender,
EventArgs

e)


{



}



//
新增操作


protected

void

btnAddBook_Click(
object

sender,
EventArgs

e)


{


string

bookName= txtBookName.Text;


string

bookNumber = txtBookNumber.Text;


string

author=txtAuthor.Text;


string

price=txtPrice.Te
xt;


string

publisher=txtPublisher.Text;



SqlConnection

conn =
null
;


try


{


//
创建连接对象


conn =
new

SqlConnection
(
"server=.;database=BookStoreDB;uid=sa;pwd=123456"
);


conn.Open();



st
ring

sql =
"insert into T_book
values(@bookName,@bookNumber,@author,@price,@publisher)"
;



SqlParameter
[] paras ={


new

SqlParameter
(
"@bookName"
,bookName),


new

SqlParameter
(
"@bookNumber"
,bookNumber),


new

SqlParameter
(
"@author"
,author),


new

SqlParameter
(
"@price"
,price),


new

SqlParameter
(
"@publisher"
,publisher)


};



//
创建
SqlCommand
对象


SqlCommand

cmd =
new

SqlCommand
(sql,conn);



//

sql
语句中的参数赋值


cmd.Parameters.AddRange(paras);



int

updateRows = cmd.ExecuteNonQuery();


if

(updateRows>0)


{


Response.Redirect(
"display.aspx"
);


}


else


{



Response.Write(
"<script type='text/javascript'>alert('
新增失败
');</script>"
);


}


}
catch
(
Exception

ex){


Response.Write(
"
出错:
"
+ex.Message);


}


finally


{


if

(conn!=
null
)


{



conn.Close();


}


}


}

}