圖片管理系統(tǒng)ppt課件_第1頁(yè)
圖片管理系統(tǒng)ppt課件_第2頁(yè)
圖片管理系統(tǒng)ppt課件_第3頁(yè)
圖片管理系統(tǒng)ppt課件_第4頁(yè)
圖片管理系統(tǒng)ppt課件_第5頁(yè)
已閱讀5頁(yè),還剩84頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、1.創(chuàng)建專(zhuān)輯創(chuàng)建專(zhuān)輯/修改專(zhuān)輯封皮圖片及簡(jiǎn)介修改專(zhuān)輯封皮圖片及簡(jiǎn)介/刪除專(zhuān)輯刪除專(zhuān)輯/ 按名稱(chēng)查詢(xún)專(zhuān)輯按名稱(chēng)查詢(xún)專(zhuān)輯;2.為專(zhuān)輯添加圖片為專(zhuān)輯添加圖片/瀏覽專(zhuān)輯圖片瀏覽專(zhuān)輯圖片/刪除選中圖片刪除選中圖片/ 修改圖片簡(jiǎn)介及所屬專(zhuān)輯名修改圖片簡(jiǎn)介及所屬專(zhuān)輯名;3.分頁(yè)查詢(xún)分頁(yè)查詢(xún)用力圖用力圖創(chuàng)建專(zhuān)輯創(chuàng)建專(zhuān)輯修改專(zhuān)輯修改專(zhuān)輯刪除專(zhuān)輯刪除專(zhuān)輯查詢(xún)專(zhuān)輯查詢(xún)專(zhuān)輯添加圖片添加圖片瀏覽圖片瀏覽圖片刪除圖片刪除圖片修改圖片修改圖片圖片管理系統(tǒng)圖片管理系統(tǒng)創(chuàng)建專(zhuān)輯創(chuàng)建專(zhuān)輯修改專(zhuān)輯修改專(zhuān)輯刪除專(zhuān)輯刪除專(zhuān)輯查詢(xún)專(zhuān)輯查詢(xún)專(zhuān)輯添加圖片添加圖片瀏覽圖片瀏覽圖片刪除圖片刪除圖片修改圖片修改圖片功能結(jié)構(gòu)圖功能結(jié)構(gòu)圖數(shù)據(jù)表設(shè)計(jì)數(shù)

2、據(jù)表設(shè)計(jì)表名表名album(專(zhuān)輯表)(專(zhuān)輯表)列名列名描述描述數(shù)據(jù)類(lèi)型(精度范圍)數(shù)據(jù)類(lèi)型(精度范圍)空空/非空非空約束條件約束條件albumID專(zhuān)輯編號(hào)專(zhuān)輯編號(hào) int非空非空PK(自增)(自增)albumName專(zhuān)輯名稱(chēng)專(zhuān)輯名稱(chēng) varchar(50)非空非空albumTime創(chuàng)建時(shí)間創(chuàng)建時(shí)間 datetime非空非空l(shuí)ogoUrl圖片地址圖片地址 varchar(100)非空非空albumDesc專(zhuān)輯簡(jiǎn)介專(zhuān)輯簡(jiǎn)介 Varchar(100)非空非空表名表名image(圖片表)(圖片表)列名列名描述描述數(shù)據(jù)類(lèi)型(精度范圍)數(shù)據(jù)類(lèi)型(精度范圍) 空空/非空非空約束條件約束條件imageID圖片

3、編號(hào)圖片編號(hào)int非空非空PK(自增)(自增)imageName圖片名稱(chēng)圖片名稱(chēng)varchar(50)非空非空imageUrl圖片地址圖片地址varchar(50)非空非空imageTime添加時(shí)間添加時(shí)間datetime非空非空imageDesc圖片簡(jiǎn)介圖片簡(jiǎn)介varchar(100)非空非空albumID所屬專(zhuān)輯編號(hào)所屬專(zhuān)輯編號(hào)int非空非空數(shù)據(jù)表設(shè)計(jì)數(shù)據(jù)表設(shè)計(jì)模塊類(lèi)別功能創(chuàng)建專(zhuān)輯創(chuàng)建專(zhuān)輯創(chuàng)建專(zhuān)輯名稱(chēng),添加封面圖片、添加專(zhuān)輯簡(jiǎn)介創(chuàng)建專(zhuān)輯名稱(chēng),添加封面圖片、添加專(zhuān)輯簡(jiǎn)介修改專(zhuān)輯修改專(zhuān)輯修改專(zhuān)輯封面圖片和簡(jiǎn)介信息修改專(zhuān)輯封面圖片和簡(jiǎn)介信息刪除專(zhuān)輯刪除專(zhuān)輯刪除專(zhuān)輯信息包括專(zhuān)輯中圖片信息刪除專(zhuān)輯信

4、息包括專(zhuān)輯中圖片信息查詢(xún)專(zhuān)輯查詢(xún)專(zhuān)輯按專(zhuān)輯名稱(chēng)查詢(xún)或分頁(yè)查詢(xún)按專(zhuān)輯名稱(chēng)查詢(xún)或分頁(yè)查詢(xún),瀏覽專(zhuān)輯編號(hào)、專(zhuān)瀏覽專(zhuān)輯編號(hào)、專(zhuān)輯名稱(chēng)、專(zhuān)輯封面圖片、專(zhuān)輯簡(jiǎn)介等信息輯名稱(chēng)、專(zhuān)輯封面圖片、專(zhuān)輯簡(jiǎn)介等信息添加圖片添加圖片上傳圖片及圖片簡(jiǎn)介上傳圖片及圖片簡(jiǎn)介查詢(xún)圖片查詢(xún)圖片顯示圖片的名稱(chēng)、地址、上傳時(shí)間、簡(jiǎn)介、顯示圖片的名稱(chēng)、地址、上傳時(shí)間、簡(jiǎn)介、所屬專(zhuān)輯名以及圖片本身所屬專(zhuān)輯名以及圖片本身修改圖片修改圖片修改圖片的簡(jiǎn)介信息及所屬的專(zhuān)輯修改圖片的簡(jiǎn)介信息及所屬的專(zhuān)輯刪除圖片刪除圖片刪除圖片相關(guān)信息刪除圖片相關(guān)信息系統(tǒng)模塊劃分系統(tǒng)模塊劃分1、文件新建網(wǎng)站,在站點(diǎn)下新 建App_Code和 App_Data 文件

5、夾;2、將數(shù)據(jù)庫(kù)文件及數(shù)據(jù)庫(kù)日志文 件,存放在App_Data中;3、右擊App_Code,添加新 項(xiàng),添加類(lèi)文件SqlHelper.cs 和DB.cs;4、右擊站點(diǎn)添加配置文件 web.config5、添加兩個(gè)文件夾image和 logo分別存放圖片利用利用SqlDataSource生成數(shù)據(jù)庫(kù)連接字符串生成數(shù)據(jù)庫(kù)連接字符串 將SqlDataSource生成的數(shù)據(jù)庫(kù)連接字符串復(fù)制到web.config中,然后就可以刪除該SqlDataSource,如下所示: 為了代碼重用,為了體現(xiàn)分層思想,我們將數(shù)據(jù)庫(kù)連接代碼寫(xiě)在SqlHelper.cs公共類(lèi)中,將數(shù)據(jù)庫(kù)操作代碼寫(xiě)在DB.cs公共類(lèi)中。Sql

6、Helper.cs中:1、右擊站點(diǎn)添加引用.NETSystem.Configuration2、代碼中添加using System.Data; using System.Data.SqlClient;SqlHelper.cs代碼如下:代碼如下:public class SqlHelper private static readonly string ConnectionString = ConfigurationManager.ConnectionStringsConnectionString.ConnectionString; SqlConnection conn = new SqlConne

7、ction(ConnectionString); public SqlCommand GetCommand(string sqlStr, params SqlParameter cmdparms) SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sqlStr; cmd.CommandType = CommandType.Text; if (cmdparms != null) foreach (SqlParameter p in cmdparms) cmd.Parameters.Add(p);

8、 return cmd; public SqlHelper() conn.Open();DB.cs代碼首先引用using System.Data.SqlClient;)public class DBpublic DB()/ TODO: 在此處添加構(gòu)造函數(shù)邏輯/ /在首頁(yè)上顯示所有專(zhuān)輯信息 public DataTable GetAll() SqlHelper helper = new SqlHelper(); string strsql = select * from album; SqlCommand cmd = new SqlCommand(); cmd = helper.GetComma

9、nd(strsql,null); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; /在首頁(yè)上按名稱(chēng)查詢(xún)專(zhuān)輯信息 public DataTable GetByID(int id) SqlHelper helper = new SqlHelper(); string strsql = select * from album where albumID=albumID; SqlParameter parm = new SqlParameter

10、 new SqlParameter(albumID,id) ; SqlCommand cmd = new SqlCommand(); cmd = helper.GetCommand(strsql, parm); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; /為首頁(yè)的專(zhuān)輯名稱(chēng)下拉菜單綁定名稱(chēng) public DataTable GetAlbumName() SqlHelper helper = new SqlHelper(); stri

11、ng strsql = select albumID,albumName from album; SqlCommand cmd = new SqlCommand(); cmd = helper.GetCommand(strsql, null); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; 當(dāng)SqlHelper.cs和DB.cs兩個(gè)公共類(lèi)寫(xiě)好后,右擊站點(diǎn),生成網(wǎng)站,檢查是否生成成功。如果生成成功,做如下操作: 利用GridView顯示

12、專(zhuān)輯信息,用上述方法新建數(shù)據(jù)源對(duì)象,與上述方法中不同的是,選擇的DB方法不同。留意:GridView的屬性設(shè)置:AllowPaging=True,AutoGenerateColumns=False,DataKeyNames=albumID,PageSize=2. 利用GridView顯示專(zhuān)輯信息,用上述方法新建數(shù)據(jù)源對(duì)象,與上述方法中不同的是,選擇的DB方法不同。給給GridView編輯列,如下所示:編輯列,如下所示:BoundField:專(zhuān)輯編號(hào)、專(zhuān)輯名稱(chēng)、專(zhuān)輯創(chuàng)建時(shí)間專(zhuān)輯編號(hào)、專(zhuān)輯名稱(chēng)、專(zhuān)輯創(chuàng)建時(shí)間TemplateField:專(zhuān)輯封面專(zhuān)輯封面HyperLinkField:為專(zhuān)輯添加圖片、瀏

13、覽專(zhuān)輯圖片、修改專(zhuān)輯為專(zhuān)輯添加圖片、瀏覽專(zhuān)輯圖片、修改專(zhuān)輯CommandField:刪除刪除Height:100pxwidth:100px注意檢查注意檢查GridView的屬性設(shè)置:的屬性設(shè)置:AllowPaging=“True”AutoGenerateColumns=“False”DataKeyNames=“albumID”P(pán)ageSize=“2”增加查詢(xún)按鈕增加查詢(xún)按鈕Button新建ObjectDataSource,配置數(shù)據(jù)源,選擇DB中的GetByID雙擊查詢(xún)按鈕buttton1,進(jìn)入Default.aspx.cs代碼中編輯: protected void Button1_Click(

14、object sender, EventArgs e) GridView1.DataSourceID = ObjectDataSource3.ID; GridView1.DataBind(); 對(duì)于創(chuàng)建專(zhuān)輯按鈕按下后,應(yīng)該打開(kāi)新的窗體AddAlbum.aspx,實(shí)現(xiàn)專(zhuān)輯名稱(chēng),專(zhuān)輯封面圖片和專(zhuān)輯簡(jiǎn)介信息的添加.如下圖:在在DB.cs中繼續(xù)添加功能塊中繼續(xù)添加功能塊,實(shí)現(xiàn)添加專(zhuān)輯信息的功能實(shí)現(xiàn)添加專(zhuān)輯信息的功能public void AddAlbum(string albumName, DateTime albumTime, string logoUrl, string albumDesc) Sq

15、lHelper helper = new SqlHelper(); string strsql = insert into album (albumName,albumTime,logoUrl,albumDesc) values(name,time,logourl,desc); SqlParameter parm = new SqlParameter new SqlParameter(name,albumName), new SqlParameter(time,albumTime), new SqlParameter(logourl,logoUrl), new SqlParameter(des

16、c,albumDesc) ; SqlCommand cmd = helper.GetCommand(strsql, parm); cmd.ExecuteNonQuery(); 雙擊提交按鈕雙擊提交按鈕,將專(zhuān)輯信息添加到將專(zhuān)輯信息添加到album數(shù)據(jù)表中數(shù)據(jù)表中. protected void Button1_Click(object sender, EventArgs e) DB db = new DB(); string albumName = TextBox1.Text; DateTime albumTime = DateTime.Now; string logourl = image/

17、+ FileUpload1.FileName; string exname = FileUpload1.FileName.Split(.)1; string albumDesc = TextBox2.Text; if (exname.ToLower() = jpg | exname.ToLower() = gif | exname.ToLower() = png) FileUpload1.SaveAs(Server.MapPath(logourl); db.AddAlbum(albumName, albumTime, logourl, albumDesc); Response.Write(al

18、ert(創(chuàng)建專(zhuān)輯成功); location.href=default.aspx;); 為專(zhuān)輯添加圖片功能的實(shí)現(xiàn)為專(zhuān)輯添加圖片功能的實(shí)現(xiàn):右擊站點(diǎn)添加新頁(yè)面右擊站點(diǎn)添加新頁(yè)面addimage.aspx,給給image數(shù)據(jù)表添加信息數(shù)據(jù)表添加信息再次給再次給GridView編輯列,如下所示:編輯列,如下所示:查看查看HyperLinkField列列:為專(zhuān)輯添加圖片為專(zhuān)輯添加圖片DataNavigateUrlFields: albumID綁定到超鏈接的綁定到超鏈接的NavigateUrl屬性字段屬性字段;DataNavigateUrlFormatString: addimage.aspx?id=0對(duì)

19、綁定到超鏈接的對(duì)綁定到超鏈接的NavigateUrl屬性的值應(yīng)用的格式設(shè)置屬性的值應(yīng)用的格式設(shè)置.給給image數(shù)據(jù)表添加信息數(shù)據(jù)表添加信息:表名表名image(圖片表)(圖片表)列名列名描述描述數(shù)據(jù)類(lèi)型(精度范圍)數(shù)據(jù)類(lèi)型(精度范圍)空空/非空非空約束條件約束條件imageID圖片編號(hào)圖片編號(hào)int非空非空PK(自增)(自增)imageName圖片名稱(chēng)圖片名稱(chēng)varchar(50)非空非空imageUrl圖片地址圖片地址varchar(50)非空非空imageTime添加時(shí)間添加時(shí)間datetime非空非空imageDesc圖片簡(jiǎn)介圖片簡(jiǎn)介varchar(100)非空非空albumID所屬專(zhuān)

20、輯編號(hào)所屬專(zhuān)輯編號(hào)int非空非空/打開(kāi)打開(kāi)DB.cs,添加方法添加方法,實(shí)現(xiàn)給專(zhuān)輯添加照片功能實(shí)現(xiàn)給專(zhuān)輯添加照片功能:public void addimage(int albumID,string imageName,string imageUrl,DateTime imageTime,string imageDesc) SqlHelper helper = new SqlHelper(); string addimage = insert into image (albumID,imageName,imageUrl,imageTime,imageDesc) Values(albumID,im

21、ageName,imageUrl, imageTime,imageDesc); SqlParameter parm = new SqlParameter new SqlParameter(albumID,albumID), new SqlParameter(imageName,imageName), new SqlParameter(imageUrl,imageUrl), new SqlParameter(imageTime,imageTime), new SqlParameter(imageDesc,imageDesc) ; SqlCommand cmd = helper.GetComman

22、d(addimage, parm); cmd.ExecuteNonQuery(); /點(diǎn)擊點(diǎn)擊addimage.aspx的的 “提交按鈕時(shí)提交按鈕時(shí):protected void Button1_Click(object sender, EventArgs e) DB db = new DB(); int albumID =Convert.ToInt32(DropDownList1.SelectedValue); DateTime imageTime = DateTime.Now; string imageUrl = image/ + FileUpload1.FileName; string

23、imageType = FileUpload1.FileName.Split(.)1; string imageName = FileUpload1.FileName.Split(.)0; string imageDesc = TextBox1.Text.ToString(); if (imageType.ToLower() = jpg | imageType.ToLower() = gif | imageType.ToLower() = png) FileUpload1.SaveAs(Server.MapPath(imageUrl); db.addimage(albumID,imageNam

24、e,imageUrl,imageTime,imageDesc);Response.Write(alert(添加成功!添加成功!); location.href=default.aspx;); 瀏覽專(zhuān)輯圖片功能的實(shí)現(xiàn)瀏覽專(zhuān)輯圖片功能的實(shí)現(xiàn):右擊站點(diǎn)添加新頁(yè)面右擊站點(diǎn)添加新頁(yè)面ViewImage.aspx 首先對(duì)首先對(duì)default.aspx的的GridView進(jìn)行編輯列操作,使得進(jìn)行編輯列操作,使得 “瀏覽專(zhuān)輯圖片按鈕具有超鏈接功能瀏覽專(zhuān)輯圖片按鈕具有超鏈接功能,可鏈到可鏈到ViewImage.aspx如下所示如下所示:/在在DB.cs中編寫(xiě)方法中編寫(xiě)方法,實(shí)現(xiàn)瀏覽某個(gè)專(zhuān)輯中的所有照片實(shí)現(xiàn)瀏覽某

25、個(gè)專(zhuān)輯中的所有照片首先引用命名空間首先引用命名空間:using System.Text;和和using System.Collections; public DataTable showImage(int albumID) SqlHelper helper = new SqlHelper(); StringBuilder strsql_show = new StringBuilder(); strsql_show.Append(select imageID,alb.albumID,alb.albumName, imageName,imageUrl,imageTime,imageDesc); s

26、trsql_show.Append( from image as img,album as alb where img.albumID=alb.albumID and img.albumID=id); SqlParameter parm = new SqlParameter new SqlParameter(id,albumID) ; SqlCommand cmd = helper.GetCommand(strsql_show.ToString(), parm); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.Ex

27、ecuteReader() dt.Load(rdr); return dt; 有空格 設(shè)計(jì)ViewImage.asp頁(yè)面對(duì)對(duì)GridView進(jìn)行編輯列操作進(jìn)行編輯列操作:CommandField:選擇選擇 showselectButton:true;BoundField:HeaderText:圖片編號(hào)圖片編號(hào)DataField:imageIDHeaderText:圖片地址圖片地址DataField:imageUrl HeaderText:圖片名稱(chēng)圖片名稱(chēng)DataField:imageNameHeaderText:所屬專(zhuān)輯名所屬專(zhuān)輯名DataField:albumNameHeaderText:圖

28、片上傳時(shí)間圖片上傳時(shí)間DataField:imageTime,HeaderText:圖片簡(jiǎn)介圖片簡(jiǎn)介DataField:imageDescHyperLinkField:Text:修改圖片所屬專(zhuān)輯修改圖片所屬專(zhuān)輯TemplateField 編輯模板:TemplateField,其中HeaderTemplate和ItemTemplate設(shè)計(jì)如下:注意將GridView的屬性設(shè)置如下:AllowPaging:True, AutoGenergateColumns:False,PageSize:2,DataKeyNames:imageID/在在DB.cs中編寫(xiě)方法中編寫(xiě)方法,實(shí)現(xiàn)在實(shí)現(xiàn)在DetailsV

29、iew中顯示某張照片的詳細(xì)信息中顯示某張照片的詳細(xì)信息注意是否引用命名空間注意是否引用命名空間:using System.Text;和和using System.Collections; public DataTable showMoreImage(int id) SqlHelper helper = new SqlHelper(); StringBuilder strsql_show = new StringBuilder(); strsql_show.Append(select imageID,alb.albumID,alb.albumName, imageName,imageUrl,im

30、ageTime,imageDesc); strsql_show.Append( from image as img,album as alb where img.albumID=alb.albumID and img.imageID=id); SqlParameter parm = new SqlParameter new SqlParameter(id,id) ; SqlCommand cmd = helper.GetCommand(strsql_show.ToString(), parm); DataTable dt = new DataTable(); using (SqlDataRea

31、der rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; 空格設(shè)計(jì)ViewImage.aspx增加Button和DetailsView控件給DetailsView控件編輯字段-添加模板給DetailsView控件編輯模板,如下所示:Label1Text:Eval(“imageName”)Label2Text:Eval(“albumName”)Image1imageUrl:Eval(“imageUrl”)Label3Text:Eval(“imageTime”)Label4Text:Eval(“imageDesc”)并將DetailsView的A

32、utoGenerateRows屬性設(shè)為False修改專(zhuān)輯功能的實(shí)現(xiàn)修改專(zhuān)輯功能的實(shí)現(xiàn) 為站點(diǎn)添加新頁(yè)面為站點(diǎn)添加新頁(yè)面updateAlbum.aspx,然后在然后在Default.aspx中單擊中單擊 “修改專(zhuān)輯導(dǎo)航到修改專(zhuān)輯導(dǎo)航到updateAlbum.aspx頁(yè)面頁(yè)面 在在DB.cs中編寫(xiě)中編寫(xiě)updateAlbum方法實(shí)現(xiàn)修改專(zhuān)輯信息的功能方法實(shí)現(xiàn)修改專(zhuān)輯信息的功能 public void updateAlbum(int id, string albumDesc, string albumName, DateTime albumTime, string logourl) SqlHelpe

33、r helper = new SqlHelper(); string strsql = update album set albumName=albumName,albumTime=albumTime, albumDesc=albumDesc,logoUrl=logourl where albumID=albumID; SqlParameter parm = new SqlParameter new SqlParameter(albumID,id), new SqlParameter(albumDesc,albumDesc), new SqlParameter(albumName,albumN

34、ame), new SqlParameter(logourl,logourl), new SqlParameter(albumTime,albumTime) ; SqlCommand cmd = helper.GetCommand(strsql, parm); cmd.ExecuteNonQuery(); Textbox:TextMode:SingleLineImageFileuploadTextbox:TextMode:MultiLinebutton 因?yàn)檫M(jìn)行修改時(shí),要先把舊的數(shù)據(jù)顯示在控件中,在此基礎(chǔ)上修改再提交,所以要先按照從Default.aspx傳過(guò)來(lái)的albumID查找出該專(zhuān)輯的所

35、有信息,然后再修改提交。我們?cè)贒B.cs中寫(xiě)入新的方法select_albumMore,代碼如下:public DataTable select_albumMore(int id) SqlHelper helper = new SqlHelper(); string strsql = select albumName,logoUrl,albumDesc from album where albumID=albumID; SqlParameter parm = new SqlParameter new SqlParameter(albumID,id) ; SqlCommand cmd = hel

36、per.GetCommand(strsql, parm); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; 當(dāng)點(diǎn)擊default.aspx的修改專(zhuān)輯時(shí),會(huì)打開(kāi)updateAlbum.aspx頁(yè)面,并觸發(fā)該頁(yè)面的Page_Load事件,代碼如下所示: protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) DB db = new DB(); int alb

37、umID = Convert.ToInt32(Request.QueryStringid); TextBox1.Text = db.select_albumMore(albumID).Rows00.ToString(); TextBox2.Text = db.select_albumMore(albumID).Rows02.ToString(); Image1.ImageUrl = db.select_albumMore(albumID).Rows01.ToString(); 在在updateAlbum.aspx中點(diǎn)擊中點(diǎn)擊 ”提交修改提交修改“按鈕時(shí),觸發(fā)以下方法:按鈕時(shí),觸發(fā)以下方法:pr

38、otected void Button1_Click(object sender, EventArgs e) DB db = new DB(); int albumID = Convert.ToInt32(Request.QueryStringid); string albumDesc = TextBox2.Text.ToString(); string albumName = TextBox1.Text.ToString(); DateTime albumTime = DateTime.Now; string logourl = image/ + FileUpload1.FileName;

39、string exname = FileUpload1.FileName.Split(.)1; if (exname.ToLower() = jpg | exname.ToLower() = png | exname.ToLower() = gif) FileUpload1.SaveAs(Server.MapPath(logourl); db.updateAlbum(albumID, albumDesc, albumName, albumTime, logourl); Response.Write(alert(修改成功修改成功); location.href=default.aspx?;);

40、在在default.aspx中點(diǎn)擊中點(diǎn)擊 “刪除按鈕時(shí),刪除專(zhuān)輯的方法在刪除按鈕時(shí),刪除專(zhuān)輯的方法在DB中:中: public void deleteAlbum(int albumID) SqlHelper helper = new SqlHelper(); string strsql = delete from image where image.albumID=albumID; delete from album where albumID=albumID; SqlParameter parm = new SqlParameter new SqlParameter(id,albumID)

41、; SqlCommand cmd = helper.GetCommand(strsql, parm); cmd.ExecuteNonQuery(); 在objectdatasource2中的DELETE方法中選擇DB中的deleteAlbum方法。 刪除專(zhuān)輯功能的實(shí)現(xiàn),在default.aspx中編輯列時(shí),將刪除按鈕啟動(dòng)留意:如果通過(guò)查詢(xún)按鈕查出某個(gè)專(zhuān)輯后,再點(diǎn)刪除按鈕,不留意:如果通過(guò)查詢(xún)按鈕查出某個(gè)專(zhuān)輯后,再點(diǎn)刪除按鈕,不能實(shí)現(xiàn)刪除,因?yàn)椴樵?xún)功能是通過(guò)能實(shí)現(xiàn)刪除,因?yàn)椴樵?xún)功能是通過(guò)ObjectDataSource3實(shí)現(xiàn)的,實(shí)現(xiàn)的,而它不支持而它不支持CommandField的刪除鈕,除非再

42、編寫(xiě)相應(yīng)的刪除的刪除鈕,除非再編寫(xiě)相應(yīng)的刪除方法。方法。修改圖片所屬專(zhuān)輯和簡(jiǎn)介修改圖片所屬專(zhuān)輯和簡(jiǎn)介 給站點(diǎn)添加新頁(yè)面update.aspx,用于修改圖片所屬的專(zhuān)輯名和修改圖片簡(jiǎn)介。 在DB.cs中編寫(xiě)需要的方法,因?yàn)樾薷南纫@示舊的專(zhuān)輯名和專(zhuān)輯簡(jiǎn)介信息,所以要有一個(gè)按imageID查找所屬albumID和imageDesc的方法select_Desc(),代碼如下所示: public DataTable select_Desc(int imageID) SqlHelper helper = new SqlHelper(); string strsql = select imageDesc f

43、rom image where imageID=imageID; SqlParameter parm = new SqlParameter new SqlParameter(imageID,imageID) ; SqlCommand cmd = helper.GetCommand(strsql, parm); DataTable dt = new DataTable(); using (SqlDataReader rdr = cmd.ExecuteReader() dt.Load(rdr); return dt; 在DB.cs中編寫(xiě)需要的方法,因?yàn)辄c(diǎn)擊提交修改按鈕后,實(shí)現(xiàn)修改,所以要有一個(gè)修改

44、圖片所屬專(zhuān)輯和圖片簡(jiǎn)介的方法,代碼如下所示: public void update(int albumID,string imageDesc,int imageID) SqlHelper helper = new SqlHelper(); string strsql=update image set albumID=albumID, imageDesc=imageDesc where imageID=imageID; SqlParameter parm = new SqlParameter new SqlParameter(albumID,albumID), new SqlParameter(

45、imageDesc,imageDesc), new SqlParameter(imageID,imageID), ; SqlCommand cmd = helper.GetCommand(strsql,parm); cmd.ExecuteNonQuery(); 點(diǎn)擊 按鈕,導(dǎo)航到update.aspx頁(yè)面時(shí)觸發(fā)該頁(yè)的page_load事件,代碼如下: protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) DB db = new DB(); int imageID = Convert.ToInt32(Reque

46、st.QueryStringimageID); TextBox1.Text = db.select_Desc(imageID).Rows00.ToString(); 當(dāng)點(diǎn)擊update.aspx的 時(shí),觸發(fā)下面的事件:protected void Button1_Click(object sender, EventArgs e) DB db = new DB(); int albumID = Convert.ToInt32(DropDownList1.SelectedValue); string imageDesc = TextBox1.Text.ToString(); int imageID

47、 = Convert.ToInt32(Request.QueryStringimageID); db.update(albumID,imageDesc,imageID); Response.Write(alert(修改成功); location.href=default.aspx?;); 通過(guò)通過(guò)ViewImage.aspx頁(yè)面的頁(yè)面的“全選框,實(shí)現(xiàn)全部選擇功全選框,實(shí)現(xiàn)全部選擇功能,并且可以任意多選或單選,翻頁(yè)可以保存選擇狀態(tài)。能,并且可以任意多選或單選,翻頁(yè)可以保存選擇狀態(tài)。當(dāng)顯示圖片信息的GridView1翻頁(yè)時(shí),觸發(fā)以下事件,代碼如下:protected void GridView1_

48、PageIndexChanging(object sender, GridViewPageEventArgs e) RememberOldValues(); /調(diào)用RememberOldValues()方法, 保存選中狀 態(tài)到session中 GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); RePopulateValue(); /調(diào)用RePopulateValue()方法,將session中保存的 狀態(tài)表現(xiàn)在CheckBox中 e.Cancel = true; /退出事件,如果沒(méi)有此動(dòng)作,GridView將會(huì)再次 Data

49、Bind(),將覆蓋CheckBox的選中狀態(tài) /保存選中狀態(tài)到session中 private void RememberOldValues() ArrayList al = null; /聲名集合 / 創(chuàng)建一個(gè)Session并檢查是否為空,這個(gè)Session用來(lái)保存集合 /這里是判斷是否是第一次進(jìn)行分頁(yè) if (Sessionchecked_items != null) /將Session對(duì)象保存到集合中 al = (ArrayList)Sessionchecked_items; else al = new ArrayList(); /聲明一個(gè)變量用來(lái)保存相應(yīng)數(shù)據(jù)從而判斷操作的是哪個(gè)check控件 int index =

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論