📄 admin_popedom.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient ;
using System.Configuration;
namespace WebNews.admin
{
/// <summary>
/// _1 的摘要说明。
/// </summary>
public class _1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection SqlConnection1;//添加数据库的操作对象
protected System.Data.SqlClient.SqlDataAdapter SqlDataAdapter1;
protected System.Data.DataSet DataSet1;
protected System.Data.SqlClient.SqlCommand SqlCommand1;
protected System.Data.SqlClient.SqlDataReader SqlDataReader1;
public string ClassName;
protected System.Web.UI.WebControls.CheckBox addNew;
protected System.Web.UI.WebControls.CheckBox addNchk;
protected System.Web.UI.WebControls.CheckBox chgnews;
protected System.Web.UI.WebControls.CheckBox chknews;
protected System.Web.UI.WebControls.CheckBox remark;
protected System.Web.UI.WebControls.Button Submit;
protected System.Web.UI.WebControls.Label myLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
string userclass = (string)Session["userclass"];
if(userclass.Trim()=="系统管理员")
{
validateCheckBox();
bindRadioButtonList();
}
else
{
Page.Visible=false;
}
}
}
private void validateCheckBox() //读取权限
{
myLabel.Text="用户"+Request["username"]+"的权限";
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectCommand=new SqlCommand("sp_selAdminbyUserName",SqlConnection1);
SqlDataAdapter1.SelectCommand.CommandType=CommandType.StoredProcedure ;
SqlDataAdapter1.SelectCommand.Parameters.Add("@username",SqlDbType.Char,40);
SqlDataAdapter1.SelectCommand.Parameters["@username"].Value=Request["username"];
DataSet1=new DataSet();
try
{
SqlDataAdapter1.Fill(DataSet1,"Admin");
}
catch (SqlException e1)
{
myLabel.Text ="数据库操作错误:"+e1.Message;
}
DataRow dr;
dr=DataSet1.Tables["Admin"].Rows[0] ; //取得popedom字段
ClassName=(string)dr["classname"];
if(dr["popedom"]!=null)
{
string popedom=(string)dr["popedom"]; //验证是否有增加新闻权限
int i=popedom.Length;
string df=popedom.Replace("addnews","1");
int j=df.Length ;
if(i!=j)
{
addNew.Checked=true;
}
i=popedom.Length; //验证是否有增加新闻不需审核功能的权限
df=popedom.Replace("addnchk","1");
j=df.Length ;
if(i!=j)
{
addNchk.Checked=true;
}
i=popedom.Length; //验证是否有修改新闻的权限
df=popedom.Replace("chgnews","1");
j=df.Length ;
if(i!=j)
{
chgnews.Checked=true;
}
i=popedom.Length; //验证是否有审核新闻的权限
df=popedom.Replace("chknews","1");
j=df.Length ;
if(i!=j)
{
chknews.Checked=true;
}
i=popedom.Length; //验证是否有管理评论的权限
df=popedom.Replace("remark","1");
j=df.Length ;
if(i!=j)
{
remark.Checked=true;
}
}
}
private void bindRadioButtonList() //读取管理的分类
{
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectCommand=new SqlCommand("sp_selFclassAll",SqlConnection1);
SqlDataAdapter1.SelectCommand.CommandType=CommandType.StoredProcedure ;
DataSet1=new DataSet();
try
{
SqlDataAdapter1.Fill(DataSet1);
}
catch (SqlException e1)
{
myLabel.Text ="数据库操作错误:"+e1.Message;
}
RadioButtonList1.DataSource=DataSet1; //绑定RadioButtonList
RadioButtonList1.DataTextField="className";
RadioButtonList1.DataValueField="className";
RadioButtonList1.DataBind();
foreach(ListItem li in RadioButtonList1.Items) //选中分类名
{
if(li.Text ==ClassName)
{
li.Selected = true;
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Submit.Click += new System.EventHandler(this.Submit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Submit_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
string popedom="";
if(addNew.Checked==true)
{
popedom="addnews,";
}
if(addNchk.Checked==true)
{
popedom+="addnchk,";
}
if(chgnews.Checked==true)
{
popedom+="chgnews,";
}
if(chknews.Checked==true)
{
popedom+="chknews,";
}
if(remark.Checked==true)
{
popedom+="remark,";
}
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand1=new SqlCommand("sp_updateAdminPower",SqlConnection1);
SqlCommand1.CommandType=CommandType.StoredProcedure;
SqlCommand1.Parameters.Add("@popedom",SqlDbType.NChar,200);
SqlCommand1.Parameters["@popedom"].Value = popedom;
SqlCommand1.Parameters.Add("@classname",SqlDbType.Char,100);
SqlCommand1.Parameters["@classname"].Value = RadioButtonList1.SelectedItem.Text;
SqlCommand1.Parameters.Add("@username",SqlDbType.Char,100);
SqlCommand1.Parameters["@username"].Value = Request["username"];
try
{
SqlConnection1.Open();
int i=SqlCommand1.ExecuteNonQuery();
if(i>0)
{
Response.Redirect("admin_user.aspx");
}
}
catch (SqlException e1)
{
myLabel.Text ="数据库操作错误:"+e1.Message;
}
finally
{
SqlConnection1.Close();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -