📄 admin_main.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>
/// admin_main 的摘要说明。
/// </summary>
public class admin_main : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label SysInfo;
protected System.Web.UI.WebControls.DataList myDL;
protected System.Web.UI.WebControls.Label CopyRight;
public object num;
public object num1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string username;
username=(string)Session["username"];
if(username.Trim()!="")
{
conn(); //填充DataList
getLabelText();
}
else Page.Visible=false;
}
// 在此处放置用户代码以初始化页面
}
private object selCkArticleNum() //选择发布新闻总数
{
try
{
string conn=ConfigurationSettings.AppSettings["dsn"]; //取得DSN字符
SqlConnection con = new SqlConnection(conn);//连接字符串
con.Open();
SqlCommand cmd=new SqlCommand("sp_selCkArticleNum",con); //建立命令
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();//执行命令
if(rd.Read())
{
num=rd["co"];
}
rd.Close();
con.Close();
return num;
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
return num;
}
}
private object selNckArticleNum() //选择待审新闻总数
{
try
{
string conn=ConfigurationSettings.AppSettings["dsn"]; //取得DSN字符
SqlConnection con = new SqlConnection(conn);//连接字符串
con.Open();
SqlCommand cmd=new SqlCommand("sp_selNckArticleNum",con); //建立命令
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader rd;
rd=cmd.ExecuteReader();//执行命令
if(rd.Read())
{
num1=rd["co"];
}
rd.Close();
con.Close();
return num1;
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
return num1;
}
}
public string show(object a)
{
string username=(string)Session["username"];
string b=(string)a;
string c;
if(username.Trim()==b.Trim() )
{
c="<font color=red bold=true>"+b+"</font>";
}
else c=b ;
return c;
}
#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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void conn() //填充DataList
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"]; //取得DSN字符
SqlConnection myConnection = new SqlConnection(con);//连接字符串
myConnection.Open();
SqlDataAdapter myCommand = new SqlDataAdapter(); //创建SqlDataAdapter 类
myCommand.SelectCommand=new SqlCommand("sp_selAdminAll",myConnection);
myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
DataSet ds = new DataSet(); //建立并填充数据集
myCommand.Fill(ds);
myDL.DataSource=ds; //绑定DataList
myDL.DataBind();
myConnection.Close();
}
catch(SqlException e)
{
Response.Write("Exception in Main: " + e.Message); //出错处理
}
}
private void getLabelText() //显示信息
{
SysInfo.Text=" <font color=0000FF size=3 face=·½ÕýÊæÌå><strong> "+"系统信息:"+"</strong></Font>";
SysInfo.Text=SysInfo.Text+"发布新闻总数 <font bold=true>"+selCkArticleNum()+"</font>"+" 待审新闻数 <font bold=true>" +selNckArticleNum()+"</font><br><br>";
string dr=(string)Session["userclass"];
string power="";
if((int)Session["addnews"]==1)
{
power="<font color=#FF0000 size=2><em>"+"添加新闻 "+"</em></font>";
}
if((int)Session["addnchk"]==1)
{
power=power+"<font color=#FF0000 size=2><em>"+"添加新闻无需审核 "+"</em></font>";
}
if((int)Session["chgnews"]==1)
{
power=power+"<font color=#FF0000 size=2><em>"+"修改新闻 "+"</em></font>";
}
if((int)Session["chknews"]==1)
{
power=power+"<font color=#FF0000 size=2><em>"+"审核新闻 "+"</em></font>";
}
if((int)Session["remark"]==1)
{
power=power+"<font color=#FF0000 size=2><em>"+"管理评论 "+"</em></font>";
}
//,Session["addnchk"],Session["chgnews"],Session["chknews"],Session["remark"]
//您是系统管理员,拥有所有权限
//添加新闻 添加新闻无需审核 修改新闻 管理评论 审核新闻
SysInfo.Text+=" <font color=0000FF size=3 face=·½ÕýÊæÌå><strong> "+"您的权限:"+"</strong></Font>";
dr=dr.Trim();
if(dr=="系统管理员")
{
SysInfo.Text+="您是系统管理员,拥有所有权限"+"<br><br>";
}
else
{
SysInfo.Text+="您是新闻管理员,拥有权限:";
SysInfo.Text+=power+"<br><br>";
}
SysInfo.Text+="使用说明:请先添加分类然后才能添加新闻"+"<br><br>";
SysInfo.Text+="<div align =right >程序制作:MS</div>";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -