网络讨论平台的设计与实现
throw ex; }
catch (Exception ex) {
throw ex; }
finally {
con.Close(); } return ds; } }
4、用户信息管理代码
public partial class Admin_UserList : System.Web.UI.Page {
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
Get_Info(); }
}
protected void gvInfo_RowDeleting(object sender, GridViewDeleteEventArgs e) {
SqlHelper mydata = new SqlHelper();
string ID = gvInfo.DataKeys[e.RowIndex].Values[0].ToString(); try
{
mydata.RunSql(\ from loginuser where use_id='\+ ID + \ Label4.Text = \删除成功!\ gvInfo.EditIndex = -1; Get_Info(); } catch {
Label4.Text = \删除失败!\ }
}
private void Get_Info() {
try {
36
四川理工学院本科毕业论文
gvInfo.DataSource = GetCodeBy(0); gvInfo.DataBind(); } catch { } }
protected void gvInfo_PageIndexChanging(object sender, GridViewPageEventArgs e) {
gvInfo.PageIndex = e.NewPageIndex; Get_Info(); }
protected void gvInfo_RowDataBound(object sender, GridViewRowEventArgs e) {//鼠标移动变色
if (e.Row.RowType == DataControlRowType.DataRow)
{//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add(\\ r;this.style.backgroundColor='#f6f6f6',this.style.fontWeight='';\
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add(\\ this.style.fontWeight='';\ }
//单击行改变行背景颜色
if (e.Row.RowType == DataControlRowType.DataRow) {
e.Row.Attributes.Add(\\this.sty le.color='buttontext';this.style.cursor='default';\ } }
public DataSet GetCodeBy(int iCount) {
SqlHelper date = new SqlHelper(); string strTop = \ if (iCount > 1) {
strTop = \\+ iCount.ToString(); }
string sql = \ \+ strTop + \ * from [loginuser] \ SqlConnection con = new SqlConnection(SqlHelper.connstring); SqlCommand cmd = new SqlCommand(sql, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = null; try {
37
网络讨论平台的设计与实现
con.Open(); ds = new DataSet(); da.Fill(ds); }
catch (SqlException ex) {
throw ex; }
catch (Exception ex) {
throw ex; } finally {
con.Close(); } return ds; } }
5、主题置顶操作代码
public partial class Admin_ZDTopic : System.Web.UI.Page {
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e) { }
protected void Button1_Click(object sender, EventArgs e) {
string dID = Request.QueryString[\
string sql = \Titlelist set IsTopName='置顶' where title_id=\+ dID; data.RunSql(sql);
Alert.AlertAndRedirect(\操作成功\\ }
protected void Button2_Click(object sender, EventArgs e) {
string dID = Request.QueryString[\
string sql = \Titlelist set IsTopName='' where title_id=\+ dID; data.RunSql(sql);
Alert.AlertAndRedirect(\操作成功\\ } }
6、主题转移操作代码
public partial class Admin_ZhuanTieManger : System.Web.UI.Page {
38
四川理工学院本科毕业论文
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e) {
if (!@IsPostBack) {
DropDownList1.DataSource = data.GetDataReader(\* from kind \ DropDownList1.DataTextField = \ DropDownList1.DataValueField = \ DropDownList1.DataBind(); } }
protected void Button1_Click(object sender, EventArgs e) {
string sql = \ Titlelist set kind_id='\+ DropDownList1.SelectedValue + \where title_id=\ data.RunSql(sql);
string sql1 = \ replylist set kind_id='\+ DropDownList1.SelectedValue + \where title_id=\+ Request.QueryString[\ data.RunSql(sql);
Alert.AlertAndRedirect(\转移成功!\\ } }
7、主题设为精华代码
public partial class Admin_JHTopic : System.Web.UI.Page {
SqlHelper data = new SqlHelper();
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
string dID = Request.QueryString[\
string sql = \Titlelist set IsNoun='精华' where title_id=\+ dID; data.RunSql(sql);
Alert.AlertAndRedirect(\操作成功\\ }
protected void Button2_Click(object sender, EventArgs e) {
string dID = Request.QueryString[\
string sql = \Titlelist set IsNoun='' where title_id=\+ dID; data.RunSql(sql);
Alert.AlertAndRedirect(\操作成功\\ }
39
网络讨论平台的设计与实现
}
8、管理员账号修改
public partial class Admin_AddAdmin : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (Session[\== null) {
Response.Write(\language='javascript'>alert('您还没有登陆');location.h ref='login.aspx'\ } else { } }
protected void btnAdd_Click(object sender, EventArgs e) { try {
SqlConnection con = new SqlConnection(SqlHelper.connstring); con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = (SqlConnection)con;//对象实例化
cmd.CommandText = \into Admin (Apwd,Aname)values(@Apwd,@A name)\
cmd.Parameters.Add(\SqlDbType.VarChar); cmd.Parameters.Add(\SqlDbType.VarChar); cmd.Parameters[\= this.txtpwd.Text; cmd.Parameters[\= this.txtname.Text; cmd.ExecuteNonQuery(); con.Close();
Response.Write(\language='javascript'>alert('添加成功');location.href=' AdminList.aspx'\ } catch {
Response.Write(\language='javascript'>alert('添加失败');location.href=' AdminList.aspx'\ } } }
40