예제 #1
0
 public static void SetLookupFilter(LookupEdit targetEdit, List <LookupEdit> sourceEdits,
                                    Dictionary <string, string> bindings)
 {
     foreach (var source in sourceEdits)
     {
         source.AjaxEvents.Change.Event += (seneder, e) => {
             targetEdit.SuspendAjaxEvents();
             targetEdit.Clear();
             targetEdit.ResumeAjaxEvents();
         };
     }
     targetEdit.PrepareLookupFilter += (sender, e) => {
         e.Filters.Clear();
         foreach (var source in sourceEdits)
         {
             var value = source.Value;
             var id    = value != null ? (Guid)value : Guid.Empty;
             if (id == Guid.Empty)
             {
                 continue;
             }
             e.Filters.Add(new Dictionary <string, object> {
                 { "comparisonType", FilterComparisonType.Equal },
                 { "leftExpressionColumnPath", bindings[source.ClientID] },
                 { "useDisplayValue", false },
                 { "rightExpressionParameterValues", new object[] { id } }
             });
         }
     };
 }
예제 #2
0
        //Implements filtering and auto-select for AccountEdit and ContactEdit to act as multilookup
        public static void CustomerMultilookupEditEmulator(LookupEdit accountEdit,
                                                           LookupEdit contactEdit,
                                                           UserConnection userConnection)
        {
            contactEdit.PrepareLookupFilter += (sender, e) => {
                e.Filters.Clear();
                var selectedAccountObject = accountEdit.Value;
                var accountId             = selectedAccountObject != null
                                                        ? (Guid)selectedAccountObject
                                                        : Guid.Empty;
                if (accountId == Guid.Empty)
                {
                    return;
                }
                e.Filters.Add(new Dictionary <string, object> {
                    { "comparisonType", FilterComparisonType.Equal },
                    { "leftExpressionColumnPath", "Account" },
                    { "useDisplayValue", false },
                    { "rightExpressionParameterValues", new object[] { accountId } }
                });
            };

            contactEdit.AjaxEvents.Change.Event += (sender, e) => {
                var accountId                = Guid.Empty;
                var accountName              = string.Empty;
                var manager                  = userConnection.EntitySchemaManager;
                var query                    = new EntitySchemaQuery(manager, "Account");
                var primaryColumnName        = query.AddColumn("Id").Name;
                var primaryDisplayColumnName = query.AddColumn("Name").Name;
                query.Filters.Add(query.CreateFilterWithParameters(
                                      FilterComparisonType.Equal,
                                      "[Contact:Account:Id].Id",
                                      (Guid)contactEdit.Value));
                var entities = query.GetEntityCollection(userConnection);
                if (entities.Count > 0)
                {
                    accountId   = entities[0].GetTypedColumnValue <Guid>(primaryColumnName);
                    accountName =
                        entities[0].GetTypedColumnValue <string>(primaryDisplayColumnName);
                }
                else
                {
                    return;
                }
                accountEdit.SuspendAjaxEvents();
                accountEdit.SetValueAndText(accountId, accountName);
                accountEdit.ResumeAjaxEvents();
            };
        }