📄 default.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
namespace dayi
{
/// <summary>
/// _default 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtUserPwd;
protected System.Web.UI.WebControls.CheckBox isMaster;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.Label lblMsg;
protected System.Web.UI.WebControls.Label lblAffiche;
protected System.Web.UI.WebControls.Label lblboardList;
protected System.Web.UI.WebControls.TextBox txtSearchWord;
protected System.Web.UI.WebControls.DropDownList listLimite;
protected System.Web.UI.WebControls.ImageButton btnSearch;
protected System.Web.UI.WebControls.Label lblHotSearchWord;
dayi.controlDatabase cd=new controlDatabase();
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
try
{
//显示各栏目热贴
int hotRecordCount=Convert.ToInt32(cd.getSystemPara("hotRecordCount").ToString().Trim());
this.Label1.Text=cd.showHotList("folder.gif","file.gif","showBoard.aspx","showQuestion.aspx",hotRecordCount);
if(this.Label1.Text.Trim()=="")
{
this.Label1.Text="没有任何记录";
if(cd.ErrorString!="")
{
//如果出错,则显示出错信息
this.Label1.Text=cd.getLastError();
}
}
//系统公告
this.lblAffiche.Text="";
string sql="select * from [affiche] order by id desc";
DataTable dt=cd.getDataTable(sql);
foreach(DataRow row in dt.Rows)
{
this.lblAffiche.Text+="<img src=images/l_y.gif><a href=# onClick=showAffiche('showAffiche.aspx?id="+row["id"].ToString()+"')>"+row["subject"].ToString().Trim()+"["+row["addTime"].ToString().Trim()+"]</a><br>";
}
//填充范围列表
dt=cd.getDataTable("select * from [board] where rootID=0");
this.listLimite.Items.Clear();//先清空列表
this.listLimite.Items.Add(new ListItem("所有文章","0"));
foreach(DataRow row in dt.Rows)
{
this.listLimite.Items.Add(new ListItem(row["boardName"].ToString().Trim(),row["boardID"].ToString()));
}
//显示快速通道
this.lblboardList.Text=cd.getMainBoardList(0);
if(this.lblboardList.Text.Trim()=="")
{
this.lblboardList.Text="没有任何栏目";
}
//显示最热搜索词
this.lblHotSearchWord.Text=cd.hotSearchWord(5);
}
catch(Exception ee)
{
Response.Write(ee.ToString());
//Response.Redirect("err.aspx?err="+ee.Message);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
//登录系统
if(Session["userName"].ToString()=="")
{
string userName=this.txtUserName.Text.Trim().Replace("'","");
string userPwd=this.txtUserPwd.Text.Trim().Replace("'","");
userPwd=FormsAuthentication.HashPasswordForStoringInConfigFile(userPwd,"sha1");//加密
string userType=(this.isMaster.Checked)?"master":"user";
string sql="select * from [user] where userName='"+userName+"' and userPwd='"+userPwd+"' and locked='0'";
if(userType=="master")
{
sql="select * from [master] where masterName='"+userName+"' and masterPwd='"+userPwd+"' and locked='0' and agreed='1'";
}
try
{
if(cd.catchRecord(sql))
{
Session["userName"]=userName;
Session["userType"]="user";
//得到管理员管理栏目的ID
if(userType=="master")
{
DataTable dt=cd.getDataTable("select * from [board] where [boardMaster]='"+userName+"' and rootID=0");
if(dt.Rows.Count>0)
{
Session["userType"]=userType+dt.Rows[0]["boardID"].ToString().Trim();
}
Response.Redirect("masterCenter.htm");
}
else
{
Response.Redirect("userCenter.htm");
}
}
else
{
this.lblMsg.Text="<b>可能出现以下错误:</b><br>1、用户名或密码错误;<br>2、未通过管理员验证;<br>3、此帐户已被锁定。<br>具体请联系管理员";
}
}
catch(Exception)
{
//Response.Redirect("err.aspx?err="+ee.Message);
}
}
else
{
this.lblMsg.Text="<b>可能出现以下错误:</b><br>用户已经登录";
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
Session["userName"]="";
}
private void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(this.txtSearchWord.Text.Trim()!="")
{
Response.Redirect("search.aspx?keyword="+Server.UrlEncode(this.txtSearchWord.Text.Trim())+"&type="+this.listLimite.SelectedValue);
//Response.Write(Server.UrlEncode(this.txtSearchWord.Text));
}
else
{
this.txtSearchWord.Text="请输入查询关键字";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -