Exemplo n.º 1
0
 private bool NodeContainsField(TreeNode node, Njit.Common.IAccessPermission c)
 {
     foreach (TreeNode item in node.Nodes)
     {
         if ((item.Tag is Control) && (item.Tag as Control).Name == c.Name)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private void SaveNodes(TreeNodeCollection treeNodeCollection, Model.MainModelDataContext dc)
        {
            foreach (TreeNode item in treeNodeCollection)
            {
                //int code;
                //var codeQuery = dc.AccessPermissionTrees.Select(t => t.ID).ToArray();
                //if (codeQuery.Count() == 0)
                //    code = 1;
                //else
                //    code = codeQuery.Max() + 1;

                Njit.Common.IAccessPermission c      = item.Tag as Njit.Common.IAccessPermission;
                Model.AccessPermissionTree    entity = Model.AccessPermissionTree.GetNewInstance(c == null ? item.Text : c.GetPath(), item.Parent == null ? null : GetParentName(item), item.Text, item.Checked, false);
                int originalCode;
                if (int.TryParse(item.Name, out originalCode))
                {
                    var query = dc.AccessPermissionTrees.Where(t => t.ID == originalCode);
                    if (query.Count() == 1)
                    {
                        Model.AccessPermissionTree originalEntity = query.Single();
                        //Model.AccessPermissionTree.Copy(originalEntity, entity);
                        this.DataAccess.UpdateWithObject(entity, originalEntity);
                        //originalEntity.ID = originalCode;
                    }
                }
                else
                {
                    this.DataAccess.InsertObject(entity);
                    //dc.AccessPermissionTrees.InsertOnSubmit(entity);
                }
                dc.SubmitChanges();

                if (item.Nodes.Count > 0)
                {
                    SaveNodes(item.Nodes, dc);
                }
            }
        }