




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
項(xiàng)目八綜合實(shí)例【拓展實(shí)驗(yàn)】實(shí)驗(yàn)1實(shí)現(xiàn)增加書(shū)目信息功能1.實(shí)驗(yàn)?zāi)康氖炀毦幊碳记伞U莆談?dòng)態(tài)更新數(shù)據(jù)的方法。2.實(shí)驗(yàn)要求(1)環(huán)境準(zhǔn)備:電腦中裝有IIS,安裝有數(shù)據(jù)庫(kù)SQLServer2012。(2)知識(shí)準(zhǔn)備:掌握更新書(shū)店數(shù)據(jù)庫(kù)的關(guān)鍵技術(shù)。3.實(shí)驗(yàn)?zāi)繕?biāo)實(shí)現(xiàn)管理員控制下的書(shū)目信息增加功能。4.問(wèn)題分析需要注意的是,由于叮當(dāng)書(shū)店網(wǎng)站的庫(kù)房管理屬于網(wǎng)站后臺(tái)運(yùn)營(yíng)數(shù)據(jù)的管理,不是任何人都可以訪問(wèn)的,只有具有相應(yīng)權(quán)限的后臺(tái)管理員才能夠進(jìn)入到庫(kù)房管理的界面。所以首先要進(jìn)行管理員登錄,只有登錄成功后,才能進(jìn)行增加書(shū)目信息、修改書(shū)目信息和刪除書(shū)目信息。5.解決辦法建立管理員登錄頁(yè)面adminlogin.aspx,通過(guò)Session傳遞管理員的用戶名和密碼,代碼如下:if(Adminusername.Text!=""){Session["Adminusername"]=Adminusername.Text;}6.實(shí)驗(yàn)步驟添加書(shū)目信息的頁(yè)面文件為addbooks.aspx。(1)界面的實(shí)現(xiàn)。創(chuàng)建一個(gè)書(shū)目信息輸入的ASP.NET頁(yè)面addbooks.aspx,并在其中創(chuàng)建8個(gè)文本框和1個(gè)Button按鈕控件。詳細(xì)代碼如下:<tablewidth=760align="center"border=0><tr><tdvalign="top"align="center"><asp:DataGridid="myGrid"runat="server"Width="700"BackColor="#ccccff"BorderColor="black"ShowFooter="false"CellPadding=3CellSpacing="0"Font-Name="Verdana"Font-Size="8pt"HeaderStyle-BackColor="#aaaadd"AutoGenerateColumns="false"MaintainState="false"><Columns><asp:BoundColumnHeaderText="書(shū)目編號(hào)"DataField="smbh"ReadOnly="True"/><asp:BoundColumnHeaderText="書(shū)目類(lèi)別"DataField="smlb"/><asp:BoundColumnHeaderText="書(shū)名"DataField="sm"/><asp:BoundColumnHeaderText="單價(jià)"DataField="dj"/><asp:BoundColumnHeaderText="作者"DataField="zz"/><asp:BoundColumnHeaderText="出版單位"DataField="cbdw"/><asp:BoundColumnHeaderText="出版時(shí)間"DataField="cbsj"/><asp:BoundColumnHeaderText="簡(jiǎn)單介紹"DataField="jdjs"/><asp:BoundColumnHeaderText="圖片路徑"DataField="tplj"/></Columns></asp:DataGrid></td></tr><tr><tdheight=20></td></tr><TR><tdvalign="top"><tablestyle="font:8ptverdana"align="center"><tr><tdcolspan="2"bgcolor="#aaaadd"style="font:10ptverdana">添加新書(shū)目信息:</td></tr><tr><tdnowrap>書(shū)目類(lèi)別:</td><td><asp:TextBoxid="smlb"runat="server"/></td></tr><tr><tdnowrap>書(shū)名:</td><td><asp:TextBoxid="sm"runat="server"/></td></tr><tr><tdnowrap>單價(jià):</td><td><asp:TextBoxid="dj"runat="server"/></td></tr><tr><tdnowrap>作者:</td><td><asp:TextBoxid="zz"runat="server"/></td></tr><tr><tdnowrap>出版單位:</td><td><asp:TextBoxid="cbdw"runat="server"/></td></tr><tr><tdnowrap>出版時(shí)間:</td><td><asp:TextBoxid="cbsj"runat="server"/></td></tr><tr><tdnowrap>簡(jiǎn)單介紹:</td><td><asp:TextBoxid="jdjs"runat="server"/></td></tr><tr><tdnowrap>圖片路徑:</td><td><asp:TextBoxid="tplj"runat="server"/></td></tr><tr><tdcolspan="2"style="padding-top:15"align="center"><asp:Buttontext="添加"OnClick="Add_Click"runat="server"/></td></tr><tr><tdcolspan="2"style="padding-top:15"align="center"><spanid="Message"MaintainState="false"style="font:arial11pt;"runat="server"/></td></tr></table></td></tr></table>(2)功能實(shí)現(xiàn)。在增加書(shū)目信息界面中,填寫(xiě)相應(yīng)的書(shū)目信息后,單擊“添加”按鈕后,將啟動(dòng)Add_Click事件處理輸入的客戶信息,從而在books表中增加了一個(gè)新的書(shū)目信息。源代碼如下:protectedvoidPage_Load(ObjectSrc,EventArgsE){if(!IsPostBack)BindGrid();}//處理添加事件publicvoidAdd_Click(Objectsender,EventArgsE){stringmyCnn=ConfigurationSettings.AppSettings["ConnectionString"];SqlConnectionConn=newSqlConnection(myCnn);//構(gòu)造SQL語(yǔ)句//創(chuàng)建Command對(duì)象SqlCommandComm=newSqlCommand(strSQL,Conn);//添加并設(shè)置參數(shù)的值Comm.Parameters.Add(newSqlParameter("@smlb",SqlDbType.Char));Comm.Parameters["@smlb"].Value=smlb.Text;Comm.Parameters.Add(newSqlParameter("@sm",SqlDbType.Char));Comm.Parameters["@sm"].Value=sm.Text;Comm.Parameters.Add(newSqlParameter("@dj",SqlDbType.Char));Comm.Parameters["@dj"].Value=dj.Text;Comm.Parameters.Add(newSqlParameter("@zz",SqlDbType.Char));Comm.Parameters["@zz"].Value=zz.Text;Comm.Parameters.Add(newSqlParameter("@cbdw",SqlDbType.Char));Comm.Parameters["@cbdw"].Value=cbdw.Text;Comm.Parameters.Add(newSqlParameter("@cbsj",SqlDbType.Char));Comm.Parameters["@cbsj"].Value=cbsj.Text;Comm.Parameters.Add(newSqlParameter("@jdjs",SqlDbType.Char));Comm.Parameters["@jdjs"].Value=jdjs.Text;Comm.Parameters.Add(newSqlParameter("@tplj",SqlDbType.Char));Comm.Parameters["@tplj"].Value=tplj.Text;Comm.Connection.Open();try{Comm.ExecuteNonQuery();Message.InnerHtml="<b>添加成功</b>";}catch(SqlException){Message.InnerHtml="添加失敗";Message.Style["color"]="red";}Comm.Connection.Close();BindGrid();smlb.Text="";sm.Text="";dj.Text="";zz.Text="";cbdw.Text="";cbsj.Text="";jdjs.Text="";tplj.Text="";}//BindGrid()執(zhí)行數(shù)據(jù)綁定publicvoidBindGrid(){stringmyCnn=ConfigurationSettings.AppSettings["ConnectionString"];SqlConnectionConn=newSqlConnection(myCnn);DataSetds=newDataSet();da.Fill(ds);myGrid.DataSource=ds;myGrid.DataBind();}實(shí)驗(yàn)2實(shí)現(xiàn)修改書(shū)目信息功能1.實(shí)驗(yàn)?zāi)康氖炀毦幊碳记?。掌握?shū)目信息修改的方法。2.實(shí)驗(yàn)要求(1)環(huán)境準(zhǔn)備:電腦中裝有IIS,安裝有數(shù)據(jù)庫(kù)SQLServer2012。(2)知識(shí)準(zhǔn)備:掌握更新書(shū)店數(shù)據(jù)庫(kù)的關(guān)鍵技術(shù)。3.實(shí)驗(yàn)?zāi)繕?biāo)實(shí)現(xiàn)管理員控制下的書(shū)目信息管理功能。修改書(shū)目信息頁(yè)面如圖8-19和圖8-20所示。4.問(wèn)題分析需要注意的是,由于叮當(dāng)書(shū)店網(wǎng)站的庫(kù)房管理屬于網(wǎng)站后臺(tái)運(yùn)營(yíng)數(shù)據(jù)的管理,不是任何人都可以訪問(wèn)的,只有具有相應(yīng)權(quán)限的后臺(tái)管理員才能夠進(jìn)入到庫(kù)房管理的界面。所以首先要進(jìn)行管理員登錄,只有登錄成功后,才能進(jìn)行增加書(shū)目信息、修改書(shū)目信息和刪除書(shū)目信息。5.解決辦法建立管理員登錄頁(yè)面adminlogin.aspx,通過(guò)Session傳遞管理員的用戶名和密碼,代碼如下:if(Adminusername.Text!=""){Session["Adminusername"]=Adminusername.Text;}6.實(shí)驗(yàn)步驟修改書(shū)目信息的頁(yè)面文件為editbooks.aspx。(1)界面的實(shí)現(xiàn)。創(chuàng)建一個(gè)書(shū)目信息修改的ASP.NET頁(yè)面editbooks.aspx,并在其中創(chuàng)建1個(gè)DataGrid控件。詳細(xì)代碼如下:<TABLEcellSpacing=0cellPadding=0width="600"align=centerborder=0><TBODY><TR><TDalign=middleheight=40><BR><BR><FONTcolor=#000000size=4><B>修改書(shū)目信息</B></FONT></TD></TR><TR><TDvAlign=topalign=centerheight=150><formrunat="server"><asp:DataGridid="myGrid"runat="server"Width="600"BackColor="#ffffff"BorderColor="black"ShowFooter="false"CellPadding=2CellSpacing="0"Font-Name="Verdana"Font-Size="8pt"HeaderStyle-BackColor="#aaaadd"OnEditCommand="myGrid_Edit"OnCancelCommand="myGrid_Cancel"OnUpdateCommand="myGrid_Update"DataKeyField="smbh"AutoGenerateColumns="false"MaintainState="false"><Columns><asp:EditCommandColumnEditText="編輯"CancelText="取消"UpdateText="更新"ItemStyle-Wrap="false"/><asp:BoundColumnHeaderText="書(shū)目編號(hào)"DataField="smbh"ReadOnly="True"/><asp:BoundColumnHeaderText="書(shū)目類(lèi)別"DataField="smlb"/><asp:BoundColumnHeaderText="書(shū)名"DataField="sm"/><asp:BoundColumnHeaderText="單價(jià)"DataField="dj"/><asp:BoundColumnHeaderText="作者"DataField="zz"/><asp:BoundColumnHeaderText="出版單位"DataField="cbdw"/><asp:BoundColumnHeaderText="出版時(shí)間"DataField="cbsj"/><asp:BoundColumnHeaderText="簡(jiǎn)單介紹"DataField="jdjs"/><asp:BoundColumnHeaderText="圖片路徑"DataField="tplj"/></Columns></asp:DataGrid></td></TR><TR><tdalign="center"><fontsize=5color="red"><spanid="Message"MaintainState="false"runat="server"/></font></td></TR></form></TD></TR></TBODY></TABLE>(2)功能實(shí)現(xiàn)。當(dāng)用戶單擊“編輯”鏈接時(shí),調(diào)用myGrid_Edit事件中的代碼,詳細(xì)代碼如下:voidPage_Load(ObjectSender,EventArgsE){if(!IsPostBack)BindGrid();}voidmyGrid_Edit(Objectsender,DataGridCommandEventArgsE){myGrid.EditItemIndex=(int)E.Item.ItemIndex;BindGrid();}voidmyGrid_Cancel(Objectsender,DataGridCommandEventArgsE){myGrid.EditItemIndex=-1;BindGrid();}voidmyGrid_Update(Objectsender,DataGridCommandEventArgsE){stringmyCnn=ConfigurationSettings.AppSettings["ConnectionString"];SqlConnectionConn=newSqlConnection(myCnn);SqlCommandcm=newSqlCommand(CnStr,Conn);cm.Parameters.Add(newSqlParameter("@smlb",SqlDbType.Char));cm.Parameters["@smlb"].Value=((TextBox)E.Item.Cells[2].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@sm",SqlDbType.Char));cm.Parameters["@sm"].Value=((TextBox)E.Item.Cells[3].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@dj",SqlDbType.Char));cm.Parameters["@dj"].Value=((TextBox)E.Item.Cells[4].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@zz",SqlDbType.Char));cm.Parameters["@zz"].Value=((TextBox)E.Item.Cells[5].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@cbdw",SqlDbType.Char));cm.Parameters["@cbdw"].Value=((TextBox)E.Item.Cells[6].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@cbsj",SqlDbType.Char));cm.Parameters["@cbsj"].Value=((TextBox)E.Item.Cells[7].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@jdjs",SqlDbType.Char));cm.Parameters["@jdjs"].Value=((TextBox)E.Item.Cells[8].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@tplj",SqlDbType.Char));cm.Parameters["@tplj"].Value=((TextBox)E.Item.Cells[9].Controls[0]).Text;cm.Parameters.Add(newSqlParameter("@SNO",SqlDbType.Char));cm.Parameters["@SNO"].Value=myGrid.DataKeys[(int)E.Item.ItemIndex];cm.Connection.Open();try{cm.ExecuteNonQuery();Message.InnerHtml="<b>信息修改成功!</b>";}catch(SqlException){Message.InnerHtml="抱歉,信息修改失敗!";Message.Style["color"]="red";}cm.Connection.Close();BindGrid();}publicvoidBindGrid(){stringmyCnn=ConfigurationSettings.AppSettings["ConnectionString"];SqlConnectionConn=newSqlConnection(myCnn);//構(gòu)造SQL語(yǔ)句SqlDataAdapterda=newSqlDataAdapter(strSQL,Conn);DataSetds=newDataSet();da.Fill(ds);myGrid.DataSource=ds;myGrid.DataBind();}實(shí)驗(yàn)3實(shí)現(xiàn)書(shū)目訂購(gòu)界面功能1.實(shí)驗(yàn)?zāi)康模?)熟練SQL語(yǔ)言的使用。(2)熟練商務(wù)流程。(3)提高編程能力。2.實(shí)驗(yàn)要求(1)環(huán)境準(zhǔn)備:電腦中裝有IIS,安裝有數(shù)據(jù)庫(kù)SQLServer2012。(2)知識(shí)準(zhǔn)備:了解電子商務(wù)數(shù)據(jù)處理流程,具有后臺(tái)規(guī)劃單據(jù)流向的能力。3.實(shí)驗(yàn)?zāi)繕?biāo)實(shí)現(xiàn)書(shū)目訂購(gòu)界面,如圖8-25所示。4.問(wèn)題分析對(duì)數(shù)據(jù)庫(kù)的操作出錯(cuò)。由于本節(jié)對(duì)數(shù)據(jù)庫(kù)的幾張表都有操作,而且會(huì)比較頻繁,所以出錯(cuò)難以避免。與前面的實(shí)驗(yàn)練習(xí)一樣,現(xiàn)在出現(xiàn)的問(wèn)題主要是由于對(duì)數(shù)據(jù)庫(kù)中表間關(guān)系不太清楚,會(huì)對(duì)數(shù)據(jù)庫(kù)的操作出錯(cuò),或者代碼有誤,比如中英文狀態(tài)的單引號(hào)或雙引號(hào)引起出錯(cuò)。也有可能是代碼中丟失操作符號(hào)或字母,或者寫(xiě)錯(cuò)字段名等低級(jí)錯(cuò)誤。5.解決辦法為避免程序出錯(cuò),需要按格式規(guī)范書(shū)寫(xiě)代碼。一旦程序運(yùn)行出錯(cuò),認(rèn)真閱讀出錯(cuò)信息,能很快找出問(wèn)題所在。另外,為了避免對(duì)數(shù)據(jù)庫(kù)的操作出現(xiàn)問(wèn)題,一般情況下,數(shù)據(jù)庫(kù)連接對(duì)象使用完畢后,應(yīng)及時(shí)關(guān)閉。使用如下語(yǔ)句:Conn.Close();6.實(shí)驗(yàn)步驟書(shū)目訂購(gòu)界面的頁(yè)面文件為orderlist.aspx。(1)界面的實(shí)現(xiàn)。創(chuàng)建一個(gè)書(shū)目訂購(gòu)界面的ASP.NET頁(yè)面orderlist.aspx,并在其中創(chuàng)建1個(gè)DataList控件。詳細(xì)代碼如下:<TABLEcellSpacing=0cellPadding=0width="100%"border=0><TBODY><TR><TDheight=5align="center">共有<asp:Labelid="lblRecordCount"ForeColor="red"runat="server"/>條記錄</TD></TR></TBODY></TABLE><asp:DataListalign="center"id="DataList1"runat="server"RepeatColumns="3"cellpadding="10"cellspacing="10"RepeatDirection="Horizontal"EnableViewState="false"><ItemTemplate><TABLEcellSpacing=0cellPadding=0width="100%"bgColor=#ffffffborder=0><TBODY><tr><tdalign="center"><IMGsrc="<%#DataBinder.Eval(Container.DataItem,"tplj")%>"height="150"width="100"></td></tr><tr><tdalign="center">書(shū)名:<%#DataBinder.Eval(Container.DataItem,"sm")%></td></tr><tr><tdalign="center">單價(jià):<%#DataBinder.Eval(Container.DataItem,"dj")%></td></tr><tr><tdalign="center"></a></td></tr></TBODY></TABLE></a> </ItemTemplate></asp:DataList><TABLEcellSpacing=0cellPadding=0width="100%"bgColor=#ffffffborder=0><TBODY><tr><tdalign="right"><asp:LinkButtonid="lbnPrevPage"Text="上一頁(yè)"CommandArgument="prev"OnClick="PageButton_Click"runat="server"/></td><td> </td><tdalign="left"><asp:LinkButtonid="lbnNextPage"Text="下一頁(yè)"CommandArgument="next"OnClick="PageButton_Click"runat="server"/></td></tr></TABLE>(2)功能實(shí)現(xiàn)。在書(shū)目訂購(gòu)界面中,能夠利用DataList控件顯示書(shū)目的圖片,并且實(shí)現(xiàn)分頁(yè)的功能。代碼如下:intPageSize,RecordCount,PageCount,CurrentPage;publicvoidPage_Load(ObjectSender,EventArgsE){//設(shè)定PageSizePageSize=6;//第一次請(qǐng)求執(zhí)行if(!Page.IsPostBack){ListBind();CurrentPage=0;ViewState["PageIndex"]=0;//計(jì)算總共有多少記錄RecordCount=CalculateRecord();lblRecordCount.Text=RecordCount.ToString();//計(jì)算總共有多少頁(yè)P(yáng)ageCount=RecordCount/PageSize+1;lblPageCount.Text=PageCount.ToString();ViewState["PageCount"]=PageCount;}}//計(jì)算總共有多少條記錄publicintCalculateRecord(){intintCount;stringConn=ConfigurationSettings.AppSettings["ConnectionString"];SqlConnectionMyConn;MyConn=newSqlConnection(Conn);MyConn.Open();stringstrCount="selectcount(*)ascolsfrombooks";SqlCommandMyComm=newSqlCommand(strCount,MyConn);SqlDataReaderdr=MyComm.ExecuteReader();if(dr.Read()){intCoun
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 母嬰用品專(zhuān)業(yè)代購(gòu)服務(wù)合作協(xié)議
- 遺產(chǎn)糾紛調(diào)節(jié)協(xié)議書(shū)
- 裝修公司結(jié)算協(xié)議書(shū)
- 銀行承兌抽屜協(xié)議書(shū)
- 酒店經(jīng)營(yíng)合伙協(xié)議書(shū)
- 首飾工廠訂購(gòu)協(xié)議書(shū)
- 鄉(xiāng)村黨建宣傳欄協(xié)議書(shū)
- 餐廳設(shè)備租售協(xié)議書(shū)
- 跳舞團(tuán)隊(duì)免責(zé)協(xié)議書(shū)
- 解除勞務(wù)協(xié)議協(xié)議書(shū)
- 轉(zhuǎn)讓店鋪輪胎協(xié)議書(shū)
- 2025年遼寧省盤(pán)錦市中考數(shù)學(xué)二模試卷
- 完整版新修訂《厲行節(jié)約反對(duì)浪費(fèi)條例》(課件)
- 貴州國(guó)企招聘2025貴州省水利投資(集團(tuán))有限責(zé)任公司招聘84人筆試參考題庫(kù)附帶答案詳解
- 【8生 會(huì)考】2022-2024年安徽省初中(八年級(jí))中考初二會(huì)考生物試卷(3年真題)
- 2025年網(wǎng)絡(luò)與信息安全專(zhuān)業(yè)考試試卷及答案
- 2024年河北承德辰飛供電服務(wù)有限公司招聘真題
- 滬教版八年級(jí)化學(xué)(下冊(cè))期末試卷及答案
- DL-T-1878-2018燃煤電廠儲(chǔ)煤場(chǎng)盤(pán)點(diǎn)導(dǎo)則
- 小小科學(xué)家《物理》模擬試卷A(附答案)
- 體能科學(xué)訓(xùn)練方法智慧樹(shù)知到期末考試答案2024年
評(píng)論
0/150
提交評(píng)論