csharp CriteriaController #xaf

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp CriteriaController #xaf相关的知识,希望对你有一定的参考价值。


using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;

using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Xpo;
using DevExpress.Persistent.Base;
using Fleetman.Module.BusinessObjects.Common;
using Fleetman.Module.BusinessObjects.CRM;
using System;
using System.ComponentModel;

namespace Fleetman.Module.Controllers
{
    public class CriteriaController : ObjectViewController
    {

        private SingleChoiceAction filteringCriterionAction;
        //     private PopupWindowShowAction saveGridFilterPopUpAction;

        private SimpleAction saveGridFilterAction;
        public CriteriaController()
        {




            filteringCriterionAction = new SingleChoiceAction(this, "FilteringCriterion", PredefinedCategory.Filters);
            filteringCriterionAction.Caption = "Filtruj";
            filteringCriterionAction.ToolTip = "Ustaw predefiniowany filtr na liscie";

            filteringCriterionAction.Execute += new SingleChoiceActionExecuteEventHandler(this.FilteringCriterionAction_Execute);
            TargetViewType = ViewType.ListView;

            saveGridFilterAction = new SimpleAction(this, "SaveGridFilter", PredefinedCategory.Filters);
            saveGridFilterAction.Caption = "Zapisz filtr";
            saveGridFilterAction.ToolTip = "Zapisz filtr zastosowany na liście w celu powtórnego wykorzystania";
            saveGridFilterAction.Execute += SaveGridFilterAction_Execute;



        }
        protected override void OnActivated()
        {
            RefreshActionItems();

            ObjectSpace.RollingBack += new EventHandler<CancelEventArgs>(ObjectSpace_RollingBack);
            ObjectSpace.Refreshing += new EventHandler<CancelEventArgs>(ObjectSpace_Refreshing);
            ObjectSpace.Reloaded += new EventHandler(ObjectSpace_Reloaded);
        }


        private string currentCriteria;
        private string criteriaCaption;
        private bool IsObjectCriteria()
        {
            if (string.IsNullOrEmpty(currentCriteria)) return false;
            return currentCriteria.Contains("#XpoObject#");
        }
        void ObjectSpace_RollingBack(object sender, CancelEventArgs e)
        {
            if (IsObjectCriteria())
            {
                UpdateCriteria(string.Empty, criteriaCaption);
            }
        }
        void ObjectSpace_Refreshing(object sender, CancelEventArgs e)
        {
            if (IsObjectCriteria())
            {
                UpdateCriteria(string.Empty, criteriaCaption);
            }
        }
        void ObjectSpace_Reloaded(object sender, EventArgs e)
        {
            if (IsObjectCriteria())
            {
                UpdateCriteria(currentCriteria, criteriaCaption);
            }
        }
        private void FilteringCriterionAction_Execute(
            object sender, SingleChoiceActionExecuteEventArgs e)
        {
            currentCriteria = e.SelectedChoiceActionItem.Data as string;
            criteriaCaption = e.SelectedChoiceActionItem.Caption;
            UpdateCriteria(currentCriteria, criteriaCaption);
        }
        private void UpdateCriteria(string criteria, string caption)
        {
            ((ListView)View).CollectionSource.BeginUpdateCriteria();
            // ((ListView)View).CollectionSource.Criteria.Clear();
            // ((ListView)View).CollectionSource.Criteria[caption] =
            ((ListView)View).CollectionSource.Criteria["FilteringCriterion"] =
              CriteriaEditorHelper.GetCriteriaOperator(criteria, View.ObjectTypeInfo.Type, ObjectSpace);
            ((ListView)View).CollectionSource.EndUpdateCriteria();
        }



        private void SaveGridFilterAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            var editor = ((ListView)View).Editor as ISupportFilter;
            if (editor != null && !string.IsNullOrEmpty(editor.Filter))
            {
                var objectSpace = Application.CreateObjectSpace(typeof(FilteringCriterion));
                FilteringCriterion filteringCriterion = objectSpace.CreateObject<FilteringCriterion>();

                filteringCriterion.ObjectType = View.ObjectTypeInfo.Type;
                filteringCriterion.Criterion = editor.Filter;
                filteringCriterion.Description = editor.Filter;
                filteringCriterion.CriteriaToCopy = editor.Filter;


                string FilteringDetailId = Application.FindDetailViewId(typeof(FilteringCriterion));
                DetailView view = Application.CreateDetailView(objectSpace, FilteringDetailId, true, filteringCriterion);
                e.ShowViewParameters.CreatedView = view;
                e.ShowViewParameters.Context = TemplateContext.View;
                e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;


                RefreshActionItems();
            }
        }

        protected void RefreshActionItems()
        {

            filteringCriterionAction.Items.Clear();
            foreach (FilteringCriterion criterion in ObjectSpace.GetObjects<FilteringCriterion>())
                if (criterion.ObjectType.IsAssignableFrom(View.ObjectTypeInfo.Type))
                {
                    if (criterion.EmployeeRoleCollection == null || criterion.EmployeeRoleCollection.Count == 0 || UserHasAccess(criterion))
                    {
                        filteringCriterionAction.Items.Add(
                        new ChoiceActionItem(criterion.Description, criterion.Criterion));
                    }
                }
            if (filteringCriterionAction.Items.Count > 0)
                filteringCriterionAction.Items.Add(new ChoiceActionItem("Wszystkie", null));
        }

        private bool UserHasAccess(FilteringCriterion criterion)
        {
            Pracownicy currentUser = ((XPObjectSpace)ObjectSpace).Session.GetObjectByKey<Pracownicy>(SecuritySystem.CurrentUserId);
            foreach (EmployeeRole role in criterion.EmployeeRoleCollection)
            {
                if (currentUser.IsInRole(role))
                {
                    return true;
                }

            }
            return false;
        }


    }
}

以上是关于csharp CriteriaController #xaf的主要内容,如果未能解决你的问题,请参考以下文章

csharp 例如-CSHARP-GroupDocs.Conversion.Examples.CSharp - 程序 - ConvertFilesToDifferentFormats.cs

csharp 例如-CSHARP-GroupDocs.Conversion.Examples.CSharp渲染,RenderPSDImageAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 例如-CSHARP-GroupDocs.Search.Examples.CSharp索引,AddDocumentToIndex.cs