Purview_User_Initial.aspx:用户权限初始化,对用户数据表系统功能数据表进行求笛卡儿集,并存入权限分配数据库。
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 Microsoft.Web.UI.WebControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Purview_User_Initial 的摘要说明。
/// </summary>
public class Purview_User_Initial : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_Curnodeid;
protected Microsoft.Web.UI.WebControls.TreeView TreeViewAll;
protected System.Web.UI.WebControls.Button btn_Purview_Initial;
protected System.Web.UI.WebControls.Label lbl_mesg;
protected YljWeb.Classes.TreeControl tree=new YljWeb.Classes.TreeControl();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)//该页是否是为响应客户端而产生的或者是否是首次访问,系统自动生成
{
BindTreeViewAll();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_Purview_Initial.Click += new System.EventHandler(this.btn_Purview_Initial_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BindTreeViewAll()
{
string str_Sql="select * from Purview_All order by order_id";
if (YljWeb.Classes.SqlConn.IsExist(str_Sql)) // 遍历树
{
tree.BindTreeViewShow("nodeid","parentid","location","mytext",str_Sql,lbl_Curnodeid,TreeViewAll);
}
}
private void btn_Purview_Initial_Click(object sender, System.EventArgs e)
{
this.lbl_mesg.Text = "系统正在对用户权限进行初始化操作,请稍后!";
/////// 清空权限列表
string strSql_Clear = "Delete from Purview_User_Have ";
YljWeb.Classes.SqlConn.ExecuteSql(strSql_Clear);
////// 查出所有用户
string strSql_User = "Select * from AdminUser ";
DataSet ds_user= new DataSet();
ds_user = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(strSql_User);
if ( ds_user.Tables[0].Rows.Count > 0 )
{
for ( int i = 0 ; i < ds_user.Tables[0].Rows.Count ; i ++ )
{
string strSql_Purview = "Select * from Purview_All order by nodeid";
DataSet ds_purview= new DataSet();
ds_purview = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(strSql_Purview);
/////// 组合用户权限列表的项 /////////////////////
if ( ds_purview.Tables[0].Rows.Count > 0 )
{
for ( int j = 0 ; j < ds_purview.Tables[0].Rows.Count ; j ++ )
{
string username = ds_user.Tables[0].Rows[i]["username"].ToString().Trim();
string nodeid = ds_purview.Tables[0].Rows[j]["nodeid"].ToString().Trim();
string parentid = ds_purview.Tables[0].Rows[j]["parentid"].ToString().Trim();
string mytext = ds_purview.Tables[0].Rows[j]["mytext"].ToString().Trim();
string location = ds_purview.Tables[0].Rows[j]["location"].ToString().Trim();
string command_name = ds_purview.Tables[0].Rows[j]["command_name"].ToString().Trim();
string order_id = ds_purview.Tables[0].Rows[j]["order_id"].ToString().Trim();
try
{
//////// 写入用户权限数据库 ///////////////////////////
string strSql_Insert = "Insert into Purview_User_Have (username,nodeid,parentid,mytext,location,command_name,order_id,state) values('"+ username +"','"+ nodeid +"','"+ parentid +"','"+ mytext +"','"+ location +"','"+ command_name +"','"+ order_id +"',0)";
YljWeb.Classes.SqlConn.ExecuteSql(strSql_Insert);
}
catch(Exception er)
{
this.lbl_mesg.Text = "用户权限初始化失败!";
this.ShowErrMsg(" Sorry! 用户权限初始化失败!原因是:"+ er.Message);
}
}
}
else
{
this.ShowErrMsg("对不起,系统功能列表为空,请先设置功能列表!2秒自动转到功能设置页面");
Response.Write("<meta http-equiv=refresh content=2;url=Purview_All_Index.aspx>");
}
}
this.lbl_mesg.Text = "用户权限初始化成功!";
this.ShowErrMsg(" 提示:用户权限初始化成功!");
}
else
{
this.ShowErrMsg("对不起,暂时没有用户,请先填加用户!2秒自动转到填加用户页面");
Response.Write("<meta http-equiv=refresh content=2;url=Admin_List.aspx>");
}
}
/// <summary>
/// ////////////////////////////// 弹出消息框 ////////////////////////////////////////
/// </summary>
/// <param name="MsgStr"></param>
private void ShowErrMsg(string MsgStr)
{
this.Response.Write("<script language='javascript'>");
this.Response.Write("alert('" +MsgStr + "');");
this.Response.Write("</script>");
}
}
}