コード例 #1
0
        private void treeList1_DragDrop(object sender, DragEventArgs e)
        {
            FwkAuthorizationRule rule = null;
            CategoryTree         wCategoryTree_ToMove = null;
            TreeListHitInfo      wHitInfo             = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));

            if (wHitInfo.Node == null)
            {
                return;
            }

            rule = e.Data.GetData(typeof(FwkAuthorizationRule)) as FwkAuthorizationRule;

            if (rule == null)
            {
                wCategoryTree_ToMove = e.Data.GetData(typeof(CategoryTree)) as CategoryTree;
            }
            //List<FwkAuthorizationRule> wRuleList = e.Data.GetData(typeof(List<FwkAuthorizationRule>)) as List<FwkAuthorizationRule>;
            //FwkAuthorizationRule rule = e.Data.GetData(typeof(FwkAuthorizationRule)) as FwkAuthorizationRule;
            #region Move rule
            if (rule != null)
            {
                _CurrentCategory        = (CategoryTree)treeList1.GetDataRecordByNode(wHitInfo.Node);
                lblCurrentCategory.Text = _CurrentCategory.Name;
                if (_CurrentCategory.IsCategory == false)
                {
                    //Obtengo el padre
                    _ParentFwkCategory = _CategoryTreeList.Where(p => p.Id.Equals(_CurrentCategory.ParentId)).FirstOrDefault <CategoryTree>();
                    _CurrentCategory   = _ParentFwkCategory;
                }

                #region Add Rules to Category

                if (!_CurrentCategory.AnyRule(rule.Name))
                {
                    _CurrentCategory.AddRule(rule);
                    FwkMembership.CreateRuleInCategory(_CurrentCategory.FwkCategory, frmAdmin.Provider.Name);
                }

                #endregion

                PopulateAsync();
            }

            #endregion


            if (wCategoryTree_ToMove != null)
            {
                if (wCategoryTree_ToMove.Id == _CurrentCategory.Id)
                {
                    Cursor = Cursors.Default;
                    return;
                }

                #region Mueve una categoria
                if (wCategoryTree_ToMove.IsCategory)
                {
                    if (_CurrentCategory.IsCategory == false)
                    {
                        //Obtengo el padre de la categoria destino
                        _ParentFwkCategory = _CategoryTreeList.Where(p => p.Id.Equals(_CurrentCategory.ParentId)).FirstOrDefault <CategoryTree>();
                        _CurrentCategory   = _ParentFwkCategory;
                    }
                    if (wCategoryTree_ToMove.ParentId == _CurrentCategory.Id)
                    {
                        Cursor = Cursors.Default;
                        return;
                    }

                    FwkMembership.UpdateParentCategory(
                        wCategoryTree_ToMove.FwkCategory.CategoryId,
                        wCategoryTree_ToMove.FwkCategory.ParentId.Value,
                        _CurrentCategory.FwkCategory.CategoryId,
                        frmAdmin.Provider.Name);
                }
                #endregion

                #region Mueve una regla a otra categoria
                if (wCategoryTree_ToMove.IsCategory == false)
                {
                    if (_CurrentCategory.IsCategory == false)
                    {
                        //Obtengo el padre de la categoria destino
                        _CurrentCategory = _CategoryTreeList.Where(p => p.Id.Equals(_CurrentCategory.ParentId)).FirstOrDefault <CategoryTree>();
                    }
                    if (wCategoryTree_ToMove.ParentId == _CurrentCategory.Id)
                    {
                        Cursor = Cursors.Default;
                        return;
                    }

                    if (!_CurrentCategory.AnyRule(wCategoryTree_ToMove.Name))
                    {
                        _CurrentCategory.AddRule(wCategoryTree_ToMove.FwkAuthorizationRule);
                        FwkMembership.CreateRuleInCategory(_CurrentCategory.FwkCategory, frmAdmin.Provider.Name);

                        //Obtengo el padre de la regla a mover para eliminarle la regla
                        _ParentFwkCategory = _CategoryTreeList.Where(p => p.Id.Equals(wCategoryTree_ToMove.ParentId)).FirstOrDefault <CategoryTree>();
                        _ParentFwkCategory.RemoveRule(wCategoryTree_ToMove.Name);
                        FwkMembership.CreateRuleInCategory(_ParentFwkCategory.FwkCategory, frmAdmin.Provider.Name);
                    }
                }
                #endregion

                PopulateAsync();
            }
            Cursor = Cursors.Default;
        }