ASPNET课程实验报告_第1页
ASPNET课程实验报告_第2页
ASPNET课程实验报告_第3页
ASPNET课程实验报告_第4页
ASPNET课程实验报告_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGEPAGE1《ASP.NET程序设计》课程实验报告实验课题:专业:计算机应用班级:指导教师:完成人: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('请输入留言主题和内容!');</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('发表成功!');</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="当前在线人数为"+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>您已经投过票了!</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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论