2

我正在尝试执行自定义 K2 智能对象的 Get List 方法,该方法查询 SQL 数据库对象(视图)。我在现有的 C# 项目中使用 API 来执行这些智能对象。我想将多个过滤器传递给这个 GetList 方法。

我正在使用下面的代码添加单个过滤器,但无法弄清楚传递多个过滤器的方法:

Dictionary<string, string>[] results = null;
if (!server.Connection.IsConnected) return results;

SmartObject smartObject = server.GetSmartObject(objectName);
SmartListMethod newList = smartObject.ListMethods["GetList"];
smartObject.MethodToExecute = methodName;

Contains myFilter = new Contains();
myFilter.Left = new PropertyExpression(filterPropertyName, PropertyType.Text);
myFilter.Right = new ValueExpression(filterValue, PropertyType.Text);

newList.Filter = myFilter;

SmartObjectList list = server.ExecuteList(smartObject);

results = new Dictionary<string, string>[list.SmartObjectsList.Count];
for (int i = 0; i < list.SmartObjectsList.Count; i++)
{
    results[i] = new Dictionary<string, string>();
    SmartObject smo = list.SmartObjectsList[i];
    foreach (SmartProperty property in smo.Properties)
    {
         results[i].Add(property.Name, property.Value);
    }
}
return results;

就像myFilter上面的代码一样,我想传递多个这样的过滤器。

4

1 回答 1

1
Dictionary<string, string>[] results = null;
if (!server.Connection.IsConnected) return results;

SmartObject smartObject = server.GetSmartObject(objectName);
SmartListMethod newList = smartObject.ListMethods["GetList"];
smartObject.MethodToExecute = methodName;

Contains myFilter = new Contains();
myFilter.Left = new PropertyExpression(filterPropertyName, PropertyType.Text);
myFilter.Right = new ValueExpression(filterValue, PropertyType.Text);

    Contains myFilter2 = new Contains();
    myFilter2.Left = new PropertyExpression(filterPropertyName2, PropertyType.Text);
    myFilter2.Right = new ValueExpression(filterValue2, PropertyType.Text);

    Not myFilter3 = new Not(myFilter2);

    // And can have the left and right filters set to pre-defined filteres to combined them!
    And myCombinedFilter = new And();
    myCombinedFilter.Left = myFilter;
    myCombinedFilter.Right = myFilter2;

    // Or also works!
    Or myCombinedFilterOr = new Or();
    myCombinedFilterOr.Left = myCombinedFilter;
    myCombinedFilterOr.Right = myFilter3;

// ((MyFilter && myFilter2) || Not MyFilter2)
newList.Filter = myCombinedFilterOr;

SmartObjectList list = server.ExecuteList(smartObject);

results = new Dictionary<string, string>[list.SmartObjectsList.Count];
for (int i = 0; i < list.SmartObjectsList.Count; i++)
{
    results[i] = new Dictionary<string, string>();
    SmartObject smo = list.SmartObjectsList[i];
    foreach (SmartProperty property in smo.Properties)
    {
         results[i].Add(property.Name, property.Value);
    }
}
return results;
于 2013-10-09T16:52:36.687 回答