第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/7/10 15:43:27 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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

网站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实验报告 - 图文 的文档
黑龙江大学ASPnet实验报告 - 图文.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c72y0j3uagl6ehs64cpel_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top