|
板凳
楼主 |
发表于 2017-6-30 17:16:07
|
只看该作者
--------------------------PageHelper.cs-------------------------------------------
using System.Linq;
using System.Web;
using System.Data;
using FineUI;
using System.Web.UI;
public class PageHelper
{
public static bool Check_page(Page p)
{
//HttpSessionState Session = HttpContext.Current.Session;
target = HttpContext.Current.Request.Cookies["target"].Value;
string target1 = p.Request.CurrentExecutionFilePath;
bool isAuthed = false;
if ("/"+target == target1)
{
isAuthed = true;
}
return isAuthed;
}
//左侧树形权限菜单用
private static DataTable DtTree;
private static string uid;
private static string target;
private static void init_uid()
{
HttpRequest Request = HttpContext.Current.Request;
uid = Request.Cookies["uid"].Value;
}
public static void Init_Auth(Tree TV, string P_ID, bool isNav)
{
init_uid();
string connString = OraData.strConnection;
string SQL1 = "SELECT DISTINCT A.P_ID,A.ID,A.NAME,A.TARGET,A.AUTH,A.VISIBLE,A.ICON,A.SORT FROM WEB_LEFT_TREE A LEFT JOIN WEB_ROLE_MENU B ON A.ID = B.R_MENU LEFT JOIN WEB_USER_ROLE C ON B.R_ID = C.U_ROLE LEFT JOIN WEB_USER_MENU D ON A.ID = D.U_MENU ";
SQL1 = SQL1 + "WHERE(A.AUTH = 0 OR C.U_ID = '" + uid + "' OR D.U_ID = '" + uid + "') AND A.VISIBLE = 1 ORDER BY A.ID,A.SORT ";
DtTree = OraData.ExecuteDataTable(connString, CommandType.Text, SQL1, null);
DataRow[] dr;
if (P_ID == "")
{
dr = DtTree.Select("P_ID IS NULL");
}
else
{
dr = DtTree.Select("P_ID =" + P_ID + "");
}
if (dr.Count() > 0)
{
TV.Nodes.Clear();
for (int i = 0; i < dr.Count(); i++)
{
TreeNode TNT = new TreeNode();
TNT.Text = dr["NAME"].ToString();
TNT.NodeID = dr["ID"].ToString();
string IconPath = "~/extjs/res/icon/";
if (dr["ICON"].ToString() == "")
{
IconPath = IconPath + "folder" + ".png";
}
else
{
IconPath = IconPath + dr["ICON"].ToString() + ".png";
}
TNT.IconUrl = (IconPath);
if (isNav == true)
{
if (dr["TARGET"].ToString() != "")
{
TNT.NavigateUrl = dr["TARGET"].ToString() + ".aspx";
}
}
TNT.EnableClickEvent = true;
TV.Nodes.Add(TNT);
NodeRecursion(TNT, dr["ID"].ToString(), isNav);
TV.ExpandAllNodes();
}
}
}
private static void NodeRecursion(TreeNode TNP, string TND, bool isNav)
{
DataRow[] dr = DtTree.Select("P_ID ='" + TND + "' ");
if (dr.Count() > 0)
{
TNP.Nodes.Clear();
for (int i = 0; i < dr.Count(); i++)
{
TreeNode tn1 = new TreeNode();
tn1.Text = dr["NAME"].ToString();
tn1.NodeID = dr["ID"].ToString();
string IconPath = "~/extjs/res/icon/";
if (dr["ICON"].ToString() == "")
{
IconPath = IconPath + "folder" + ".png";
}
else
{
IconPath = IconPath + dr["ICON"].ToString() + ".png";
}
tn1.IconUrl = (IconPath);
if (isNav == true)
{
if (dr["TARGET"].ToString() != "")
{
tn1.NavigateUrl = dr["TARGET"].ToString() + ".aspx";
}
}
tn1.EnableClickEvent = true;
TNP.Nodes.Add(tn1);
NodeRecursion(tn1, dr["ID"].ToString(), isNav);
}
}
}
}
End--------------------------PageHelper.cs-------------------------------------------
-------------------------Default.aspx.cs-------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (DomainCheck("EXAS", "CQE") == true)
{
Init_left_tree();
get_name();
Alert.Show(u_name+" "+u_title+" 欢迎回来。","Computer Assisted Management System 3.0",MessageBoxIcon.Information);
}
else
{
Alert.Show("请使用有效的域账户登陆操作系统。", "", MessageBoxIcon.Warning);
}
}
}
protected void leftMenuTree_NodeCommand(object sender, TreeCommandEventArgs e)
{
//Session.Add("target", leftMenuTree.SelectedNode.NavigateUrl);
HttpCookie cookie = new HttpCookie("target");
cookie.Value = leftMenuTree.SelectedNode.NavigateUrl;
cookie.Expires = DateTime.Now.AddDays(1);
HttpContext.Current.Response.Cookies.Add(cookie);
}
End-------------------------Default.aspx.cs-------------------------------------------
-------------------------子页面-------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (PageHelper.Check_page(this.Page) == false)
{
Response.Redirect("~/NoAuth.aspx");
}
}
}
End-------------------------子页面------------------------------------------------------- |
|