<asp:TreeView ID="TreeView1" runat="server"
ShowCheckBoxes="All" ShowExpandCollapse="False" ShowLines="True">
<ParentNodeStyle BorderColor="#80FF80" Font-Overline="False" Font-Underline="True"
ForeColor="#80FF80" Height="20px" />
<RootNodeStyle Height="20px" />
</asp:TreeView>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
DataTextField="Rolename" DataValueField="Roleid">
</asp:DropDownList>
<br />
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" Text="Button" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllRoles"
TypeName="Maticsoft.BLL.RoleManager" ></asp:ObjectDataSource>
protected void btnUpdate_Click(object sender, EventArgs e)
{
int roleid = int.Parse(DropDownList1.SelectedValue.ToString());
int a = RolerightManager.delete_by_roleid(roleid);
int c = 0; for (int i = 0; i < TreeView1.CheckedNodes.Count; i++)
{
int funid = int.Parse(TreeView1.CheckedNodes[i].Value.ToString());
c = RolerightManager.add_roleRight(roleid, funid); }
if (c > 0)
{
Response.Write("<script>alert('权限分配成功! ')</script>");
}
}
public static int delete_by_roleid(int roleid)
{
return RolerightService.delete_by_roleid(roleid);
} public static int add_roleRight(int roleid, int funid)
{
Roleright ro = new Roleright();
ro.Roleid = roleid;
ro.Funid = funid;
return RolerightService.add_roleRight(ro);
}
public static int delete_by_roleid(int roleid)
{
string sql = "delete from Roleright where roleid=" + roleid;
return DBHelper.ExcuteCommand(sql);
} public static int add_roleRight(Roleright roleringht)
{
string sql = string.Format("insert into RoleRight (roleid,funid) values ({0},{1})", roleringht.Roleid, roleringht.Funid);
return DBHelper.ExcuteCommand(sql);
} public static IList<Role> GetAllRoles()
{
return RoleService.GetAllRole();
}
public static IList<Role> GetAllRole()
{ string sqlstr = "select * from Role where roleid !=3";
return GetRoleBySql(sqlstr, null); }
public static IList<Role> GetRoleBySql(string sqlstr, params SqlParameter[] values)
{
SqlDataReader dr;
if (values == null)
{
dr = DBHelper.GetReader(sqlstr);
}
else
{
dr = DBHelper.GetReader(sqlstr, values);
}
try
{ if (dr != null)
{
List<Role> list = new List<Role>();
while (dr.Read())
{
Role role = new Role();
role.Roleid = (int)dr["roleid"];
role.Rolename = (string)dr["rolename"];
list.Add(role);
}
dr.Close();
return list;
}
else
{
dr.Close();
return null;
} }
catch (Exception e)
{
throw e;
}
finally
{
dr.Close(); //及时关闭dr,回收资源
}
大侠们帮看看 是哪出了问题 在网上查了 有的说是程序存在死循环,有的说 内存不足,有的说 读取数据量太多,有的则说 没有及时释放内存,有的则说是递归造成的,不知道如何解决这个问题,请大家 帮看看这代码 哪些地方该如何改 才不会报这样的错误!如果把 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
DataTextField="Rolename" DataValueField="Roleid">
</asp:DropDownList>
<br />
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" Text="Button" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllRoles"
TypeName="Maticsoft.BLL.RoleManager" ></asp:ObjectDataSource> 和btnUpdate_Click点击事件注释掉后 就显示正常了 权限也显示正常了
不知道错在哪,请大侠们帮帮忙 看一下那代码如何改正
ShowCheckBoxes="All" ShowExpandCollapse="False" ShowLines="True">
<ParentNodeStyle BorderColor="#80FF80" Font-Overline="False" Font-Underline="True"
ForeColor="#80FF80" Height="20px" />
<RootNodeStyle Height="20px" />
</asp:TreeView>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
DataTextField="Rolename" DataValueField="Roleid">
</asp:DropDownList>
<br />
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" Text="Button" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllRoles"
TypeName="Maticsoft.BLL.RoleManager" ></asp:ObjectDataSource>
protected void btnUpdate_Click(object sender, EventArgs e)
{
int roleid = int.Parse(DropDownList1.SelectedValue.ToString());
int a = RolerightManager.delete_by_roleid(roleid);
int c = 0; for (int i = 0; i < TreeView1.CheckedNodes.Count; i++)
{
int funid = int.Parse(TreeView1.CheckedNodes[i].Value.ToString());
c = RolerightManager.add_roleRight(roleid, funid); }
if (c > 0)
{
Response.Write("<script>alert('权限分配成功! ')</script>");
}
}
public static int delete_by_roleid(int roleid)
{
return RolerightService.delete_by_roleid(roleid);
} public static int add_roleRight(int roleid, int funid)
{
Roleright ro = new Roleright();
ro.Roleid = roleid;
ro.Funid = funid;
return RolerightService.add_roleRight(ro);
}
public static int delete_by_roleid(int roleid)
{
string sql = "delete from Roleright where roleid=" + roleid;
return DBHelper.ExcuteCommand(sql);
} public static int add_roleRight(Roleright roleringht)
{
string sql = string.Format("insert into RoleRight (roleid,funid) values ({0},{1})", roleringht.Roleid, roleringht.Funid);
return DBHelper.ExcuteCommand(sql);
} public static IList<Role> GetAllRoles()
{
return RoleService.GetAllRole();
}
public static IList<Role> GetAllRole()
{ string sqlstr = "select * from Role where roleid !=3";
return GetRoleBySql(sqlstr, null); }
public static IList<Role> GetRoleBySql(string sqlstr, params SqlParameter[] values)
{
SqlDataReader dr;
if (values == null)
{
dr = DBHelper.GetReader(sqlstr);
}
else
{
dr = DBHelper.GetReader(sqlstr, values);
}
try
{ if (dr != null)
{
List<Role> list = new List<Role>();
while (dr.Read())
{
Role role = new Role();
role.Roleid = (int)dr["roleid"];
role.Rolename = (string)dr["rolename"];
list.Add(role);
}
dr.Close();
return list;
}
else
{
dr.Close();
return null;
} }
catch (Exception e)
{
throw e;
}
finally
{
dr.Close(); //及时关闭dr,回收资源
}
大侠们帮看看 是哪出了问题 在网上查了 有的说是程序存在死循环,有的说 内存不足,有的说 读取数据量太多,有的则说 没有及时释放内存,有的则说是递归造成的,不知道如何解决这个问题,请大家 帮看看这代码 哪些地方该如何改 才不会报这样的错误!如果把 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1"
DataTextField="Rolename" DataValueField="Roleid">
</asp:DropDownList>
<br />
<asp:Button ID="btnUpdate" runat="server" onclick="btnUpdate_Click" Text="Button" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllRoles"
TypeName="Maticsoft.BLL.RoleManager" ></asp:ObjectDataSource> 和btnUpdate_Click点击事件注释掉后 就显示正常了 权限也显示正常了
不知道错在哪,请大侠们帮帮忙 看一下那代码如何改正
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货