private void BindManager()
{
string sqlText = "select * from Module";
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode moduleNode = new TreeNode();
moduleNode.Text = ds.Tables[0].Rows[i]["ModuleName"].ToString();
string funcText = "select * from Functions where ModuleNO="+ds.Tables[0].Rows[i]["ModuleID"];
DataSet funcDs = DBUtility.SqlHelper.GetDataSest(CommandType.Text,funcText,null);
for (int j = 0; j < funcDs.Tables[0].Rows.Count; j++)
{
TreeNode funcNode = new TreeNode();
funcNode.Text = funcDs.Tables[0].Rows[j]["FunctionName"].ToString();
funcNode.NavigateUrl = funcDs.Tables[0].Rows[j]["PagePath"].ToString();
funcNode.Target = "mainFrame";
moduleNode.ChildNodes.Add(funcNode);
}
this.TreeView1.Nodes.Add(moduleNode);
}
}
/// <summary>
/// 绑定普通用户
/// </summary>
private void BindUser()
{
int userID = GetIDByUser();
DataTable dt = GetRoleByUID(userID);
for (int i = 0; i < dt.Rows.Count; i++)
{
int RoleID = int.Parse(dt.Rows[i]["RolesID"].ToString());
DataTable dt2 = GetModuleID(RoleID);
DataTable dt3 = GetModAndFunc(RoleID);
for (int j = 0; j < dt2.Rows.Count; j++)
{
int ModuleID = Convert.ToInt32(dt2.Rows[j]["ModuleID"]);
string ModuleName = GetModuleName(ModuleID).ToString();
DataRow[] dtR = dt3.Select("ModuleID=" + ModuleID);
if (IsExistsNode(ModuleName))
{
continue;
}
else
{
TreeNode tn = new TreeNode();
tn.Text = ModuleName;
for (int k = 0; k < dtR.Length; k++)
{
DataRow dr = dtR[k];
int FunctionID = Convert.ToInt32(dr["FunctionID"]);
DataTable dtF = GetFunctionName(FunctionID);
string FunctionName =dtF.Rows[0]["FunctionName"].ToString();
string PagePath = dtF.Rows[0]["PagePath"].ToString();
TreeNode tn2 = new TreeNode();
tn2.Text = FunctionName;
tn2.NavigateUrl = PagePath;
tn2.Target = "mainFrame";
tn.ChildNodes.Add(tn2);
tn.Expand();
}
this.TreeView1.Nodes.Add(tn);
}
{
string sqlText = "select * from Module";
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode moduleNode = new TreeNode();
moduleNode.Text = ds.Tables[0].Rows[i]["ModuleName"].ToString();
string funcText = "select * from Functions where ModuleNO="+ds.Tables[0].Rows[i]["ModuleID"];
DataSet funcDs = DBUtility.SqlHelper.GetDataSest(CommandType.Text,funcText,null);
for (int j = 0; j < funcDs.Tables[0].Rows.Count; j++)
{
TreeNode funcNode = new TreeNode();
funcNode.Text = funcDs.Tables[0].Rows[j]["FunctionName"].ToString();
funcNode.NavigateUrl = funcDs.Tables[0].Rows[j]["PagePath"].ToString();
funcNode.Target = "mainFrame";
moduleNode.ChildNodes.Add(funcNode);
}
this.TreeView1.Nodes.Add(moduleNode);
}
}
/// <summary>
/// 绑定普通用户
/// </summary>
private void BindUser()
{
int userID = GetIDByUser();
DataTable dt = GetRoleByUID(userID);
for (int i = 0; i < dt.Rows.Count; i++)
{
int RoleID = int.Parse(dt.Rows[i]["RolesID"].ToString());
DataTable dt2 = GetModuleID(RoleID);
DataTable dt3 = GetModAndFunc(RoleID);
for (int j = 0; j < dt2.Rows.Count; j++)
{
int ModuleID = Convert.ToInt32(dt2.Rows[j]["ModuleID"]);
string ModuleName = GetModuleName(ModuleID).ToString();
DataRow[] dtR = dt3.Select("ModuleID=" + ModuleID);
if (IsExistsNode(ModuleName))
{
continue;
}
else
{
TreeNode tn = new TreeNode();
tn.Text = ModuleName;
for (int k = 0; k < dtR.Length; k++)
{
DataRow dr = dtR[k];
int FunctionID = Convert.ToInt32(dr["FunctionID"]);
DataTable dtF = GetFunctionName(FunctionID);
string FunctionName =dtF.Rows[0]["FunctionName"].ToString();
string PagePath = dtF.Rows[0]["PagePath"].ToString();
TreeNode tn2 = new TreeNode();
tn2.Text = FunctionName;
tn2.NavigateUrl = PagePath;
tn2.Target = "mainFrame";
tn.ChildNodes.Add(tn2);
tn.Expand();
}
this.TreeView1.Nodes.Add(tn);
}
}
}
}
}
public bool IsExistsNode(string noteText)
{
for (int i = 0; i < this.TreeView1.Nodes.Count; i++)
{
if (noteText == this.TreeView1.Nodes[i].Text)
{
return true;
}
}
return false;
}
/// <summary>
/// 获取用户ID
/// </summary>
/// <returns></returns>
public int GetIDByUser()
{
string sqlText = "select * from Users where UserName='" + Session["UserName"] + "'";
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]);
}
/// 获取用户ID
/// </summary>
/// <returns></returns>
public int GetIDByUser()
{
string sqlText = "select * from Users where UserName='" + Session["UserName"] + "'";
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]);
}
/// <summary>
/// 获取角色ID集合
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetRoleByUID(int id)
{
string sqlText = "select * from User_Role where UserID=" + id;
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return ds.Tables[0];
}
/// <summary>
/// 获取角色所有权限模块ID(消除重复ID)
/// </summary>
/// <param name="roleID"></param>
/// <returns></returns>
public DataTable GetModuleID(int roleID)
{
string sqlText = "select distinct ModuleID from RolePurview where RoleID=" + roleID;
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return ds.Tables[0];
}
/// 获取角色ID集合
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetRoleByUID(int id)
{
string sqlText = "select * from User_Role where UserID=" + id;
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return ds.Tables[0];
}
/// <summary>
/// 获取角色所有权限模块ID(消除重复ID)
/// </summary>
/// <param name="roleID"></param>
/// <returns></returns>
public DataTable GetModuleID(int roleID)
{
string sqlText = "select distinct ModuleID from RolePurview where RoleID=" + roleID;
DataSet ds = DBUtility.SqlHelper.GetDataSest(CommandType.Text, sqlText, null);
return ds.Tables[0];
}
/// <summary>
/// 获取模块名称
/// </summary>
/// <param name="moduleID"></param>
/// <returns></returns>
public string GetModuleName(int moduleID)
{
string strText = "select ModuleName from Module where ModuleID = " + moduleID;
string moduleName = DBUtility.SqlHelper.ExecuteScalar(CommandType.Text, strText, null).ToString();
return moduleName;
}
/// 获取模块名称
/// </summary>
/// <param name="moduleID"></param>
/// <returns></returns>
public string GetModuleName(int moduleID)
{
string strText = "select ModuleName from Module where ModuleID = " + moduleID;
string moduleName = DBUtility.SqlHelper.ExecuteScalar(CommandType.Text, strText, null).ToString();
return moduleName;
}
/// <summary>
/// 获取角色所对应的功能ID和模块ID
/// </summary>
/// <param name="roleID"></param>
/// <returns></returns>
public DataTable GetModAndFunc(int roleID)
{
string strText = "select FunctionID,ModuleID from RolePurview where RoleID=" + roleID;
DataTable dt = DBUtility.SqlHelper.GetDataSest(CommandType.Text, strText, null).Tables[0];
return dt;
}
/// 获取角色所对应的功能ID和模块ID
/// </summary>
/// <param name="roleID"></param>
/// <returns></returns>
public DataTable GetModAndFunc(int roleID)
{
string strText = "select FunctionID,ModuleID from RolePurview where RoleID=" + roleID;
DataTable dt = DBUtility.SqlHelper.GetDataSest(CommandType.Text, strText, null).Tables[0];
return dt;
}
public DataTable GetFunctionName(int functionID)
{
string strText = "select FunctionName,PagePath from Functions where FunctionID=" + functionID;
DataTable dt = DBUtility.SqlHelper.GetDataSest(CommandType.Text, strText, null).Tables[0];
return dt;
}
{
string strText = "select FunctionName,PagePath from Functions where FunctionID=" + functionID;
DataTable dt = DBUtility.SqlHelper.GetDataSest(CommandType.Text, strText, null).Tables[0];
return dt;
}