黑龙江大学ASPnet实验报告 - 图文

2026/1/17 14:27:11

没有购物车等信息,因此该页面在用户登录后与未登陆时显示效果不一样,但整体布局相差不大。如下是网页的整体布局:

网站Logo图片 返回链接 网站Logo图片 商品导航文字 网站导航 购物车 一共八个商品的图片展示 提交清除按钮 加入购物车按

4、 编码及流程图

(1)用户登录时首先应该验证用户是否已经存在,其次还要验证用户密码是否正确,具体的流程图如下所示:

用户登录的关键代码如下所示,所在的文件为Default2.aspx.cs:

protected void Page_Load(object sender, EventArgs e) {

if (Session[\] != null) {

Label1.Text = \欢迎您:\ + (String)Session[\]; }

else if (Session[\] == null && TextBox1.Text.Length == 0) {

HttpCookie hcusername = Request.Cookies[\]; HttpCookie hcuserpassword = Request.Cookies[\]; if (hcusername != null)

TextBox1.Text = Server.HtmlEncode(hcusername.Value); if (hcuserpassword != null)

TextBox2.Text = Server.HtmlEncode(hcuserpassword.Value); CheckBox1.Checked = true; } }

private bool check() {

String name = TextBox1.Text; String password = TextBox2.Text; bool ret = false;

if ((name != null && name.Length > 0) && (password != null && password.Length > 0)) {

OleDbConnection conn = new OleDbConnection(\Source=\ + Server.MapPath(\));

OleDbCommand cmd = new OleDbCommand(\* from user1 where name='\ + name + \, conn);

//打开数据库连接 conn.Open();

//建立DataReader对象

OleDbDataReader dr = cmd.ExecuteReader(); if (dr.Read()) {

String psw = (String)dr[\]; if (psw == password) {

Session[\] = name; ret = true; } else {

RequiredFieldValidator2.ErrorMessage = \密码错误!\;

RequiredFieldValidator2.IsValid = false; RequiredFieldValidator2.Visible = true; } } else {

RequiredFieldValidator1.ErrorMessage = \不存在的用户!\; RequiredFieldValidator1.IsValid = false; RequiredFieldValidator1.Visible = true; }

conn.Close(); }

return ret; }

(2)用户注册时对用户所输入的信息获取后插入数据库中即可。用户注册时对数据库的操作、点击提交按钮后执行的函数代码如下所示,所在的文件为register.aspx.cs:

protected void Button2_Click(object sender, EventArgs e) {

if (CustomValidator1.IsValid == false) { CustomValidator1.Visible = true; return; }

OleDbConnection conn = new OleDbConnection(@\Source=\ + Server.MapPath(\)); //建立Command对象 string strSql;

strSql = \values('\ + TextBox1.Text + \ + TextBox2.Text + \ + TextBox4.Text + \ + TextBox5.Text + \ + TextBox6.Text + \ + TextBox7.Text + \; OleDbCommand cmd = new OleDbCommand(strSql, conn); conn.Open();

cmd.ExecuteNonQuery(); conn.Close();

Session[\] = TextBox1.Text; Response.Redirect(\);

}

(3)用户的文章展示,首先要获取用户所输入的内容,然后追加到Label的末尾即可。流程图如下所示:

开始String s = TextBox1.Text;s=s.Replace(\否i==-1?是ltext=slText+=sLabel1.Text = ltextTextBox1.Text = \i++结束 以及用户评论功能实现的代码如下所示:

static String ltext=\; static int i=1;

protected void Page_Load(object sender, EventArgs e) {

if (i != 1) {

Label1.Text = ltext + \; } }

protected void Button2_Click(object sender, EventArgs e)

{

String s = TextBox1.Text; s=s.Replace(\, \); if (i == 1) {

ltext = \style=\\\border-bottom-color:Green; border-bottom-width:1px;\\\#993300;\\\楼:
\ + s + \; } else {

ltext += \border-bottom-color:Green; border-bottom-width:1px;\\\#993300;\\\ + i + \楼:
\ + s + \; }

Label1.Text = ltext+\;


黑龙江大学ASPnet实验报告 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: 黑龙江大学ASPnet实验报告 - 图文 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219