ASPNET課程實驗報告_第1頁
ASPNET課程實驗報告_第2頁
ASPNET課程實驗報告_第3頁
ASPNET課程實驗報告_第4頁
ASPNET課程實驗報告_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

PAGEPAGE1《ASP.NET程序設(shè)計》課程實驗報告實驗課題:專業(yè):計算機應(yīng)用班級:指導(dǎo)教師:完成人:2011年5月29

5.3留言板publicpartialclassliuyan:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){if(Session["userID"]!=null){if(TextBox1.Text==""||TextBox2.Text==""){Page.RegisterStartupScript("","<script>alert('請輸入留言主題和內(nèi)容!');</script>");}else{try{stringconnstr=ConfigurationManager.ConnectionStrings["WShopConnectionString"].ConnectionString;SqlConnectionconn=newSqlConnection(connstr);conn.Open();SqlCommandcmd=newSqlCommand("Proc_InsertMessageInfo",conn);cmd.CommandType=CommandType.StoredProcedure;SqlParameterpara1=newSqlParameter("@userID",SqlDbType.Int);para1.Value=Session["userID"].ToString();cmd.Parameters.Add(para1);SqlParameterpara2=newSqlParameter("@Heading",TextBox1.Text);cmd.Parameters.Add(para2);SqlParameterpara3=newSqlParameter("@Content",SqlDbType.NVarChar);para3.Value=TextBox2.Text;cmd.Parameters.Add(para3);SqlParameterpara4=newSqlParameter("@Time",SqlDbType.DateTime);para4.Value=DateTime.Now.ToShortDateString();cmd.Parameters.Add(para4);SqlParameterpara5=newSqlParameter("@flag",DbType.Int32);para5.Direction=ParameterDirection.Output;cmd.Parameters.Add(para5);cmd.ExecuteNonQuery();Page.RegisterStartupScript("","<script>alert('發(fā)表成功!');</script>");conn.Close();}catch{}}}else{Response.Redirect("denglu.aspx");}Response.Redirect("liuyan.aspx");}}5.4商品查詢protectedvoidButton1_Click(objectsender,EventArgse){SqlDataSource2.SelectParameters.Clear();stringstr=SqlDataSource2.SelectCommand+"whereWaretype.typeID=@typeID";Parameterpara1=newParameter("typeID",DbType.Int16);para1.DefaultValue=DropDownList1.SelectedItem.Value;SqlDataSource2.SelectParameters.Add(para1);if(TextBox1.Text!=""){str+="andWare.Warenamelike'%'+@Warename+'%'";SqlDataSource2.SelectParameters.Add("Warename",TextBox1.Text);}GridView1.DataSourceID=null;SqlDataSource2.SelectCommand=str;GridView1.DataSourceID="SqlDataSource2";}5.5在線聊天protectedvoidPage_Load(objectsender,EventArgse)

{

if(Session["uName"]!=null)

{

lblOnlineNum.Text="當(dāng)前在線人數(shù)為"+Application["count"].ToString()+"人";

txtChatRoom.Text=Application["chat"].ToString();

lblName.Text=Session["uName"].ToString();

}

else

{

Response.Redirect("denglu.aspx");

}

}

protectedvoidbtnSend_Click(objectsender,EventArgse)

{

stringtab="";

stringnewline="\r";

stringnewMessage=lblName.Text+";"+tab+txtChat.Text+newline+Application["chat"];

if(newMessage.Length>500)

newMessage=newMessage.Substring(0,499);

Application.Lock();

Application["chat"]=newMessage;

Application.UnLock();

txtChat.Text="";

txtChatRoom.Text=Application["chat"].ToString();

}

5.6在線投票publicpartialclasstoupiao:System.Web.UI.Page{ArrayListcn=newArrayList();protectedvoidPage_Load(objectsender,EventArgse){//validatorlogin.Validator();if(Request.Cookies["vote"]!=null){lblState.Text="<b>您已經(jīng)投過票了!</b>";}else{lblState.Text="<b>您可以投票!</b>";}getVote();}protectedvoidgetVote(){stringfilePath=Server.MapPath("vote.txt");try{StreamReadersr=File.OpenText(filePath);stringstr=sr.ReadLine();string[]strvote=str.Split(',');foreach(stringssinstrvote)cn.Add(int.Parse(ss));sr.Close();}catch(Exceptionee){Response.Write("<script>alert('"+ee.Message+"')</script>");}}protectedvoidputVote(){stringfilePath=Server.MapPath("vote.txt");try{StreamWritersw=newStreamWriter(filePath,false);//false表示不是追加的stringstr=cn[0].ToString();for(inti=1;i<cn.Count;i++){str+=","+cn[i].ToString();}sw.WriteLine(str);sw.Close();}catch(Exceptionee){Response.Write("<script>alert('"+ee.Message+"')</script>");}}protectedvoidbtnVote_Click(objectsender,EventArgse){if(rbtlVote.SelectedIndex!=-1){if(Request.Cookies["vote"]==null){inti=rbtlVote.SelectedIndex;cn[i]=int.Parse(cn[i].ToString())+1;putVote();Response.Cookies["vote"].Value="vt";Response.Cookies["vote"].Expires=DateTime.Now.AddDays(14);Response.Write("<script>alert('投票成功!')</script>");}else{Response.Write("<script>alert('您

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論