复制代码 代码如下:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[work_sysmenu]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[work_sysmenu]
GO
CREATE TABLE [dbo].[work_sysmenu] (
[flowid] [int] IDENTITY (1, 1) NOT NULL ,
[menu_title] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[menu_value] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[menu_url] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
[menu_parent] [int] NULL ,
[menu_role] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[menu_meno] [text] COLLATE Chinese_PRC_CI_AS NULL ,
[isvalid] [int] NULL ,
[menu_order] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
复制代码 代码如下:
/// <summary>
/// 根据用户权限获取系统菜单
/// </summary>
private void GetSysMenu()
{
string str = "select * from work_sysmenu where dbo.GetCharCount(menu_role,'" + this.roleid +"')=1 and isvalid=1 order by menu_order";
DataSet ds= sysSqlRunner.getDataset(str);
DataRow[] drRoot = ds.Tables[0].Select("menu_parent=0");
//循环生成父菜单
foreach (DataRow dr in drRoot)
{
MenuItem mi = new MenuItem();
mi.Text = dr["menu_title"].ToString();
mi.Value = dr["menu_value"].ToString();
//mi.NavigateUrl = dr["menu_url"].ToString();
mi.Selectable = false;
mainMenu.Items.Add(mi);
//递归算法生成所有级别的下级子菜单
CreateMenu(ds.Tables[0], dr["flowid"].ToString(), mi);
}
}
复制代码 代码如下:
Create function GetCharCount(@target varchar(100),@sear varchar(1))
returns int
as
begin
declare @charcount int
select @charcount=(len(@target)-len(replace(@target,@sear,'')))
return @charcount
end
复制代码 代码如下:
/// <summary>
/// 创建无级树菜单
/// </summary>
/// <param>获取菜单的数据源</param>
/// <param>菜单的父ID</param>
/// <param>创建菜单的Item</param>
private void CreateMenu(DataTable dt,string parentID,MenuItem parItem)
{
DataRow[] drs= dt.Select("menu_parent=" + parentID);
if (drs.Length > 0)
{
foreach (DataRow dr in drs)
{
MenuItem mi = new MenuItem();
mi.Text = dr["menu_title"].ToString();
mi.Value = dr["menu_value"].ToString();
mi.NavigateUrl = dr["menu_url"].ToString();
parItem.ChildItems.Add(mi);
CreateMenu(dt, dr["flowid"].ToString(), mi);
}
}
else
{
return ;
}
}
新闻热点
疑难解答
图片精选