权限设计中,怎样把树型目录映射为常量?

flyingdream123 2009-10-26 05:50:08
所有菜单功能


//把以上数据表在程序中映射成的静态类,感觉这样很麻烦,有什么办法可能代替
/// <summary>
/// 用户权限
/// </summary>
public static class Permissions
{
public static class 人事
{
static string m_value = "02";

public static string Value
{
get { return 人事.m_value; }
set { 人事.m_value = value; }
}
public static class 基本资料
{
static string m_value = "02";

public static string Value
{
get { return 基本资料.m_value; }
set { 基本资料.m_value = value; }
}
public static class 分店设置
{
static string m_value = "02";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
}


}
public static class 员工管理
{
static string m_value = "0202";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
public static class 查询
{
static string m_value = "020201";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
}
public static class 新添
{
static string m_value = "020202";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
}
public static class 修改
{
static string m_value = "020203";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
}
public static class 删除
{
static string m_value = "020204";

public static string Value
{
get { return m_value; }
set { m_value = value; }
}
}


}

}


}



EmployeeEditForm addNewForm;
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
//客户程序的调用,也就是最终要达到的目的啊

if (Permissions.HasPermission(Permissions.人事.员工管理.新添.Value))
{
MessageBox.Show("你无权限", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

if (addNewForm == null || addNewForm.IsDisposed)
{
addNewForm = new EmployeeEditForm(update, OperationCategory.New);
addNewForm.Show();
}
else
{
addNewForm.Activate();
}
}

...全文
66 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyingdream123 2009-10-29
  • 打赏
  • 举报
回复
up
viki117 2009-10-27
  • 打赏
  • 举报
回复
数据库吧,总需要有个对应关系,你要判断权限还,直接把对应写到程序中,可以考虑用XML文件。。添加修改都比较方便的
flyingdream123 2009-10-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 bejon 的回复:]
请使用"扩展方法",用法可查询MSDN
[/Quote]
为现有类扩展方法,对这我个问题好像没有什么关系?
flyingdream123 2009-10-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gisyellow 的回复:]
数据结构的嵌套,比较难搞的。。可以考虑用哈希表来存储对应的值,将“Permissions.人事.员工管理.新添”和“Permissions.人事.基本资料.分店设置”这样的嵌套层次作为Key,将对应的值作为Value。。
[/Quote]
这个是一值得考虑的方法,如果用哈希表的话,键值比较长,输入不是很方便。还有就是一担菜单位置改变,要从解决方案中找到那些地方用到了此键值也是不是很方便。

用户静态类,最不方便的地方就是菜单路径更改时麻烦。有自动完成,查找也很方便。
阿牛138588 2009-10-26
  • 打赏
  • 举报
回复
请使用"扩展方法",用法可查询MSDN
gisyellow 2009-10-26
  • 打赏
  • 举报
回复
数据结构的嵌套,比较难搞的。。可以考虑用哈希表来存储对应的值,将“Permissions.人事.员工管理.新添”和“Permissions.人事.基本资料.分店设置”这样的嵌套层次作为Key,将对应的值作为Value。。
liaoyukun111 2009-10-26
  • 打赏
  • 举报
回复
这个比较好了
aotian798 2009-10-26
  • 打赏
  • 举报
回复
顶了
bancxc 2009-10-26
  • 打赏
  • 举报
回复
全都是static 学习
taoistong 2009-10-26
  • 打赏
  • 举报
回复
什么意思。
tostring () ???

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧