西安航空技术高等专科学校计算机工程系
5.3普通用户对管理员进行留言或查看管理员回复的留言
普通用户可以给管理员留言,也可以查看管理员给的回复具体代码如下: 给管理员留言的代码如下:
protected void btnMessage_Click(object sender, EventArgs e) {
if (txtName.Text.Trim() == \ || txtTitle.Text.Trim() == \ || txtContent.Text.Trim()==\) {
Response .Write (\网友昵称、留言标题、留言内容不能为空!')\); }
MessageManage mm = new MessageManage(); mm.MassageNickName = txtName.Text.Trim(); mm.MessageContent = txtContent.Text.Trim(); mm.MessageTitle = txtTitle.Text.Trim();
mm.MessageHomePage = txtHomePage.Text.Trim(); mm.MessageDate = DateTime.Now; mm.MessageReply = null; mm.AddMessage(); txtName.Text =\; txtContent.Text = \; txtTitle.Text = \; txtHomePage.Text = \; MessageBind();
}
运行界面如下:
16
西安航空技术高等专科学校计算机工程系
5.4管理员登录界面
从数据库中提取管理员的账号和密码,如果数据库中存在该用户的信息且账号和密码都输入正确则进入后台管理界面并将账号和密码存入session中,否则不能进入后台管理,具体代码如下: 登录后台管理的代码如下:
protected void btnLogin_Click(object sender, EventArgs e) {
if (txtLoginID.Text.Trim() == \) {
Response.Write(\用户名不能为空!')\);
return; }
if(txtLoginPWD.Text.Trim()==\) {
Response.Write(\密码不能为空!')\);
return; }
string sqlString = string.Format(\where adminId='{0}' and adminPWD='{1}'\, txtLoginID.Text, txtLoginPWD.Text);
DBOperate DBOp=new DBOperate();
if (DBOp.Scalar(sqlString)>0) {
Session[\] = txtLoginID.Text.Trim(); Session[\] = txtLoginPWD.Text.Trim(); Response.Redirect(\); } else {
Response.Write(\用户名或密码错误!')\);
return; } }
运行界面如下:
17
西安航空技术高等专科学校计算机工程系
5.5后台文章管理界面
管理员可以更新文章的类容,如果该文章没有评论则可以删除文章,有评论则提示不能删除该文章请先删除该文章的评论,具体代码如下: 编辑文章的代码如下:
protected void btnEditArticle_Click(object sender, EventArgs e) {
ArticleManage am = new ArticleManage();
am.ArticleAuthor = txtarticleAuthor.Text.Trim(); am.ArticleBrief = txtarticleBrief.Text.Trim(); am.ArticleTitle = txtarticleTitle.Text.Trim(); am.ArticleContent = txtarticleContent.Text.Trim(); am.ArticleDate = DateTime.Now;
am.ClassId =Convert.ToInt32( drpclassName.SelectedValue); string
value=Server.UrlDecode(Request.QueryString[\]); am.UpdateArticle(value);
Response.Redirect(\); }
删除文章的代码如下:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {
ArticleManage am = new ArticleManage(); string keyValue =
GridView1.DataKeys[e.RowIndex].Value.ToString(); int deleteResult;
string IsDeleteResult = null;
IsDeleteResult = am.IsDelete(keyValue);
18
西安航空技术高等专科学校计算机工程系
if (IsDeleteResult == null) {
deleteResult = am.DeleteArticle(keyValue); if (deleteResult > 0) {
string myMessage = \:删除成功!\;
Response.Write(\alert('\ + myMessage + \); } else {
string myMessage = \删除失败,在试一次,如果出现相同的情况,请向开发者报告情况\;
Response.Write(\alert('\ + myMessage + \);
}
} else {
string myMessage = \删除失败原因是:\ + IsDeleteResult; Response.Write(\ + myMessage + \); }
Bind(); }
运行界面如下:
19
西安航空技术高等专科学校计算机工程系
5.6后台添加文章
向数据库中插入添加文章的信息,具体代码如下:
protected void btnAddArticle_Click(object sender, EventArgs e) {
if (txtarticleAuthor.Text.Trim().ToString() == \ || txtarticleTitle.Text.Trim().ToString() == \ || txtarticleBrief.Text.Trim().ToString() == \ || txtarticleContent.Text.Trim().ToString() == \) {
Response.Write(\文章作者、文章标题、文章摘要、文章类容均不能为空!')\); } else {
ArticleManage am = new ArticleManage(); am.ArticleAuthor =
txtarticleAuthor.Text.Trim().ToString(); am.ArticleTitle =
txtarticleTitle.Text.Trim().ToString(); am.ArticleBrief =
txtarticleBrief.Text.Trim().ToString(); am.ArticleContent =
txtarticleContent.Text.Trim().ToString();
am.ArticleDate = DateTime.Now; am.ArticleRQ = 0; am.ArticleReply = 0; am.ClassId =
Convert.ToInt32(drpclassName.SelectedValue.ToString()); int i = 0;
i=am.AddArticle(); if (i > 0) {
Response.Redirect(\); } else {
Response.Write(\添加文章失败!')\); } } }
运行界面如下:
20