我有一个System.Windows.Forms.Treeview
带有复选框的控件来构建权限树,节点是从数据库记录动态构建的,以及从后面的代码中添加的自Allow Add
定义Allow Delete
节点Allow Update
。
问题是当我尝试从树中检索检查节点时,我得到一个StackOverflowException
.
这是我的代码:
List<tbl_JobPermission> SaveCheckedPermissions(int _JobID, System.Windows.Forms.TreeNodeCollection theNodes)
{
using (WFMDBEntities _DBContext = new WFMDBEntities())
{
tbl_JobPermission _JopPermissionHelperVar;
if (theNodes.Count > 0)
{
foreach (System.Windows.Forms.TreeNode aNode in theNodes.OfType<System.Windows.Forms.TreeNode>().Where(x => x.Checked == true))
{
int _tempJobPermID = int.Parse(aNode.Parent.Name);
if (aNode.Name.Contains('_'))
{
_JopPermissionHelperVar =
new tbl_JobPermission()
{
TblPremition = _tempJobPermID,
Tbljob = _JobID
};
if (aNode.Name.ToLower().Contains("add"))
{
_JopPermissionHelperVar.AllowNew = true;
}
else if (aNode.Name.ToLower().Contains("update"))
{
_JopPermissionHelperVar.AllowUpdate = true;
}
else if (aNode.Name.ToLower().Contains("delete"))
{
_JopPermissionHelperVar.AllowDelete = true;
}
if (!_JobPermissions.Contains(_JopPermissionHelperVar))
{
_JobPermissions.Add(_JopPermissionHelperVar);
}
}
else
{
_JopPermissionHelperVar =
new tbl_JobPermission()
{
TblPremition = int.Parse(aNode.Name),
Tbljob = _JobID
};
if (!_JobPermissions.Contains(_JopPermissionHelperVar))
{
_JobPermissions.Add(_JopPermissionHelperVar);
}
}
if (aNode.Nodes.Count > 0)
{
_JobPermissions.AddRange(SaveCheckedPermissions(_JobID, aNode.Nodes));
}
}
}
}
return _JobPermissions;
}