Пример #1
0
        // ** utilities

        // update filter (called after editing the filter row)
        private void UpdateFilter()
        {
            // make sure we have a filter row
            if (_row < 0)
            {
                return;
            }

            // make sure we have a data view
            DataView dv = _flex.DataSource as DataView;

            if (dv == null)
            {
                DataTable dt = _flex.DataSource as DataTable;
                if (dt != null)
                {
                    dv = dt.DefaultView;
                }
            }

            if (_flex.DataSource != null)
            {
                CurrencyManager cm = (CurrencyManager)_flex.BindingContext[_flex.DataSource, _flex.DataMember];
                cm.EndCurrentEdit();
            }

            // scan each cell in the filter row and build new filter
            StringBuilder sb = new StringBuilder();

            for (int col = _flex.Cols.Fixed; col < _flex.Cols.Count; col++)
            {
                // get column value
                string expr = string.Empty;
                if (_flex.Col == col && _flex.Editor != null)
                {
                    expr = _flex.Editor.Text.TrimEnd();
                }
                else
                {
                    expr = _flex.GetDataDisplay(_row, col).TrimEnd();
                }

                if (_flex.Cols[col].DataType == typeof(bool))
                {
                    switch (_flex.GetCellCheck(_row, col))
                    {
                    case CheckEnum.TSChecked:
                        expr = "true";
                        break;

                    case CheckEnum.TSUnchecked:
                        expr = "false";
                        break;
                    }
                }

                // ignore empty cells
                if (expr.Length == 0)
                {
                    continue;
                }

                IDictionary dataMap = _flex.Cols[col].DataMap;
                if (dataMap != null)
                {
                    foreach (object key in dataMap.Keys)
                    {
                        if (string.Compare(dataMap[key].ToString(), expr, true) == 0)
                        {
                            expr = key.ToString();
                            break;
                        }
                    }
                }

                // get filter expression
                expr = BuildFilterExpression(col, expr);
                if (expr.Length == 0)
                {
                    continue;
                }

                // concatenate new condition
                if (sb.Length > 0)
                {
                    sb.Append(" And ");
                }
                sb.AppendFormat("[{0}]{1}", _flex.Cols[col].Name, expr);
            }

            // apply filter to current view
            string strFilter = sb.ToString();

            if (dv == null)
            {
                Dictionary <string, ConditionFilter> filters = BuildConditionFilters(strFilter);
                for (int col = _flex.Cols.Fixed; col < _flex.Cols.Count; ++col)
                {
                    if (!filters.ContainsKey(_flex.Cols[col].Name))
                    {
                        _flex.Cols[col].Filter = null;
                    }
                    else
                    {
                        _flex.Cols[col].Filter = filters[_flex.Cols[col].Name];
                    }
                }
                _flex.ApplyFilters();
                return;
            }

            if (strFilter == dv.RowFilter)
            {
                return;
            }
            try
            {
                _flex[_row, 0] = null;
                dynamic editor = _flex.Editor;
                _editorSelectionStart  = editor.SelectionStart;
                _editorSelectionLength = editor.SelectionLength;

                dv.RowFilter = strFilter;
            }
            catch
            {
                _flex[_row, 0] = "Err";
            }

            // stay in filter row
            _flex.Row = _row;
        }