/// <summary> /// 设置GridLookUpEdit多列过滤 /// </summary> /// <param name="repGLUEdit">GridLookUpEdit的知识库,eg:gridlookUpEdit.Properties</param> private void SetGridLookUpEditMoreColumnFilter(DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit repGLUEdit) { repGLUEdit.EditValueChanging += (sender, e) => { this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => { GridLookUpEdit edit = sender as GridLookUpEdit; DevExpress.XtraGrid.Views.Grid.GridView view = edit.Properties.View as DevExpress.XtraGrid.Views.Grid.GridView; //获取GriView私有变量 System.Reflection.FieldInfo extraFilter = view.GetType().GetField("extraFilter", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); List <DevExpress.Data.Filtering.CriteriaOperator> columnsOperators = new List <DevExpress.Data.Filtering.CriteriaOperator>(); foreach (GridColumn col in view.VisibleColumns) { if (col.Visible && col.ColumnType == typeof(string)) { columnsOperators.Add(new DevExpress.Data.Filtering.FunctionOperator(DevExpress.Data.Filtering.FunctionOperatorType.Contains, new DevExpress.Data.Filtering.OperandProperty(col.FieldName), new DevExpress.Data.Filtering.OperandValue(edit.Text))); } } string filterCondition = new DevExpress.Data.Filtering.GroupOperator(DevExpress.Data.Filtering.GroupOperatorType.Or, columnsOperators).ToString(); extraFilter.SetValue(view, filterCondition); //获取GriView中处理列过滤的私有方法 System.Reflection.MethodInfo ApplyColumnsFilterEx = view.GetType().GetMethod("ApplyColumnsFilterEx", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); ApplyColumnsFilterEx.Invoke(view, null); })); }; }
//构建数据库查询参数 private void builderQueryParams(List <MB.Util.Model.QueryParameterInfo> lstParams, CriteriaOperator op, bool isNot) { DevExpress.Data.Filtering.GroupOperator groupOp = op as DevExpress.Data.Filtering.GroupOperator; if (op is DevExpress.Data.Filtering.GroupOperator) { MB.Util.Model.QueryParameterInfo groupPar = null; if (groupOp.OperatorType == GroupOperatorType.And) { groupPar = new MB.Util.Model.QueryParameterInfo(isNot?MB.Util.Model.QueryGroupLinkType.AndNot : MB.Util.Model.QueryGroupLinkType.AND); } else { groupPar = new MB.Util.Model.QueryParameterInfo(isNot?MB.Util.Model.QueryGroupLinkType.OrNot : MB.Util.Model.QueryGroupLinkType.OR); } lstParams.Add(groupPar); foreach (CriteriaOperator childOp in groupOp.Operands) { builderQueryParams(groupPar.Childs, childOp, isNot); } } else if (op is DevExpress.Data.Filtering.UnaryOperator) { DevExpress.Data.Filtering.UnaryOperator uOp = op as DevExpress.Data.Filtering.UnaryOperator; if (uOp.OperatorType == UnaryOperatorType.IsNull) { MB.Util.Model.QueryParameterInfo nullPar = new MB.Util.Model.QueryParameterInfo(); nullPar.PropertyName = QueryParametersEditHelper.RemoveSpecName(uOp.Operand.ToString()); nullPar.Condition = isNot ? MB.Util.DataFilterConditions.IsNotNull : MB.Util.DataFilterConditions.IsNull; lstParams.Add(nullPar); } else if (uOp.OperatorType == UnaryOperatorType.Not) { builderQueryParams(lstParams, uOp.Operand, true); } } else if (op is DevExpress.Data.Filtering.BetweenOperator) { DevExpress.Data.Filtering.BetweenOperator btOp = op as DevExpress.Data.Filtering.BetweenOperator; MB.Util.Model.QueryParameterInfo btPar = new MB.Util.Model.QueryParameterInfo(); btPar.PropertyName = QueryParametersEditHelper.RemoveSpecName(btOp.Property.ToString()); btPar.Condition = isNot?MB.Util.DataFilterConditions.NotBetween:MB.Util.DataFilterConditions.Between; btPar.Value = (btOp.BeginExpression as DevExpress.Data.Filtering.OperandValue).Value; btPar.Value2 = (btOp.EndExpression as DevExpress.Data.Filtering.OperandValue).Value; if (_ColPropertys.ContainsKey(btPar.PropertyName)) { btPar.DataType = _ColPropertys[btPar.PropertyName].DataType; } lstParams.Add(btPar); } else if (op is DevExpress.Data.Filtering.BinaryOperator) { DevExpress.Data.Filtering.BinaryOperator binOp = op as DevExpress.Data.Filtering.BinaryOperator; MB.Util.Model.QueryParameterInfo binPar = new MB.Util.Model.QueryParameterInfo(); binPar.PropertyName = QueryParametersEditHelper.RemoveSpecName(binOp.LeftOperand.ToString()); binPar.Condition = QueryParametersEditHelper.ConvertToFilterCondition(binOp.OperatorType, isNot); binPar.Value = (binOp.RightOperand as DevExpress.Data.Filtering.OperandValue).Value; if (_ColPropertys.ContainsKey(binPar.PropertyName)) { binPar.DataType = _ColPropertys[binPar.PropertyName].DataType; } lstParams.Add(binPar); } else if (op is DevExpress.Data.Filtering.InOperator) { DevExpress.Data.Filtering.InOperator inOp = op as DevExpress.Data.Filtering.InOperator; if (inOp.Operands.Count == 0) { return; } MB.Util.Model.QueryParameterInfo inPar = new MB.Util.Model.QueryParameterInfo(); inPar.PropertyName = QueryParametersEditHelper.RemoveSpecName(inOp.LeftOperand.ToString()); inPar.Condition = isNot ? MB.Util.DataFilterConditions.NotIn : MB.Util.DataFilterConditions.In; //获取In 的查询值 List <string> vals = new List <string>(); foreach (DevExpress.Data.Filtering.OperandValue v in inOp.Operands) { if (v.Value == null) { continue; } vals.Add(v.Value.ToString()); } inPar.Value = string.Join(",", vals.ToArray()); if (_ColPropertys.ContainsKey(inPar.PropertyName)) { inPar.DataType = _ColPropertys[inPar.PropertyName].DataType; } lstParams.Add(inPar); } else { } }