public IEnumerable <T> Select(QParam param, IEnumerable <T> list = null) { if (param.ValueLeft is QFunc func && func.Type == QFunctionType.distinct && func.Items.FirstOrDefault() is QItem item) { return(ListHelper.Distinct(list ?? items, item, param.Query?.GetComparer()));// } IEnumerable <T> buf = param.IsCompaund ? Select(param.Parameters, list) : null; if (buf == null) { if (param.ValueLeft is QColumn) { buf = Select(param.Column, param.Comparer, param.Value, list); } else if (param.ValueLeft is QReflection) { buf = Select(((QReflection)param.ValueLeft).Invoker, param.Comparer, param.Value, list); } else { buf = Search(param, list); } } return(buf); }
public QEnum(IList list, DBColumn column = null) : this() { foreach (var item in list) { if (item is QItem) { items.Add((QItem)item); } else { items.Add(QParam.Fabric(item, column)); } } }
public IEnumerable <T> Search(QParam param, IEnumerable <T> list = null) { list = list ?? this; foreach (T row in list) { if (param.ValueLeft == null || param.ValueRight == null) { } if (CheckItem(row, param.ValueLeft.GetValue(row), param.ValueRight.GetValue(row), param.Comparer)) { yield return(row); } } }
public DBTableView(DBTable <T> table, QParam defaultFilter, DBViewKeys mode = DBViewKeys.None, DBStatus statusFilter = DBStatus.Empty) { propertyHandler = null; this.table = table; FilterQuery = new Query <T>(); Query = new QQuery(); TypeFilter = typeof(T); DefaultParam = defaultFilter; StatusFilter = statusFilter; keys = mode; table.AddView(this); if ((keys & DBViewKeys.Empty) != DBViewKeys.Empty) { UpdateFilter(); } }
public IEnumerable <T> Select(QItemList <QParam> parameters, IEnumerable <T> list = null) { IEnumerable <T> buffer = null; for (int i = 0; i < parameters.Count; i++) { QParam param = parameters[i]; if (buffer != null && param.Logic.Type == LogicTypes.And) { if (!buffer.Any()) { break; } list = buffer; } var temp = Select(param, list); if (buffer == null) { buffer = temp; } else if (param.Logic.Type == LogicTypes.Undefined) { buffer = buffer.Concat(temp); } else if (param.Logic.Type == LogicTypes.Or) { buffer = param.Logic.Not ? buffer.Except(temp) : buffer.Union(temp); } else if (param.Logic.Type == LogicTypes.And) { buffer = param.Logic.Not ? buffer.Except(temp).Union(temp.Except(buffer)) : buffer.Intersect(temp); } } return(buffer); }
public IEnumerable <T> Select(QParam param, IEnumerable <T> list = null) { IEnumerable <T> buf = Select(param.Parameters, list); if (buf == null) { if (param.ValueLeft is QColumn) { buf = Select(param.Column, param.Comparer, param.Value, list); } else if (param.ValueLeft is QReflection) { buf = Select(((QReflection)param.ValueLeft).Invoker, param.Comparer, param.Value, list); } else { buf = Search(param, list); } } return(buf); }
public DBTableView(QParam defaultFilter, DBViewKeys mode = DBViewKeys.None, DBStatus statusFilter = DBStatus.Empty) : this(DBTable.GetTable <T>(null, false), defaultFilter, mode, statusFilter) { }
private void CheckFilterQuery() { ClearFilter(); foreach (var filter in FilterQuery.Parameters) { if (filter.Invoker == null || filter.Value == null || filter.Value == DBNull.Value || filter.Value.ToString().Length == 0) { if (filter.Comparer.Type != CompareTypes.Is) { continue; } } var pcolumn = filter.Invoker as DBColumn; if (filter.Invoker.Name == nameof(Object.ToString)) { Query.SimpleFilter(filter.Value as string); } else if (pcolumn != null) { string code = pcolumn.Name; QParam param = new QParam() { Column = pcolumn, Logic = filter.Logic, Comparer = filter.Comparer, Value = filter.Comparer.Type != CompareTypes.Is ? filter.Value : null }; if (param.Value is string && param.Comparer.Type == CompareTypes.Like) { string s = (string)param.Value; if (s.IndexOf('%') < 0) { param.Value = string.Format("%{0}%", s); } } int i = code.IndexOf('.'); if (i >= 0) { int s = 0; QQuery sexpression = Query; QQuery newQuery = null; while (i > 0) { string iname = code.Substring(s, i - s); if (s == 0) { var pc = table.Columns[iname]; if (pc != null) { iname = pc.Name; } } var c = sexpression.Table.Columns[iname]; if (c.IsReference) { newQuery = new QQuery(string.Empty, c.ReferenceTable); sexpression.BuildParam(c, CompareType.In, newQuery); sexpression = newQuery; } s = i + 1; i = code.IndexOf('.', s); } newQuery.Parameters.Add(param); } else { Query.Parameters.Add(param);//.BuildParam(col, column.Value, true); } } else { var param = new QParam() { ValueLeft = new QReflection(filter.Invoker), Logic = filter.Logic, Comparer = filter.Comparer, Value = filter.Comparer.Type != CompareTypes.Is ? filter.Value : null }; Query.Parameters.Add(param); } } }