Beispiel #1
0
        private void ReplaceWhereItem(string searchField, object searchValue, string template, bool isInput)
        {
            WhereSqlClauseBuilder whereSqlClause = WhereSqlClauses.Find(builder => builder.Exists(item => ((SqlClauseBuilderItemIUW)item).DataField == searchField));

            string searchText          = searchValue.ToString();
            string formattedSearchText = TSqlBuilder.Instance.FormatFullTextString(LogicOperatorDefine.And, searchText);

            //找到了已经存在的和searchField字段匹配的WhereSqlClauseBuilder
            if (whereSqlClause != null)
            {
                if (searchText == DeluxeSearch.ClearWhereCondition)
                {
                    WhereSqlClauses.Remove(whereSqlClause);
                }
                else
                {
                    if (searchText.IsNotEmpty())
                    {
                        if (searchField == SearchField)
                        {
                            whereSqlClause.Clear();
                        }
                        else
                        {
                            whereSqlClause.Remove(item =>
                            {
                                var curItem        = (SqlClauseBuilderItemIUW)item;
                                bool compareResult = false;

                                //如果是全文检索(有Template),则按照字段匹配删除,否则附加上值的匹配
                                if (this.SearchMethod == DeluxeSearchMethodType.FullText && template.IsNotEmpty())
                                {
                                    compareResult = curItem.DataField == searchField;
                                }
                                else
                                {
                                    compareResult = curItem.DataField == searchField && (curItem.Data.ToString() == searchText ||
                                                                                         curItem.Data.ToString() == formattedSearchText);
                                }
                                return(compareResult);
                            });
                        }

                        FillSearchFieldWhereSqlClauseBuilder(whereSqlClause, searchField, searchText, template, isInput);
                    }
                }
            }
            else if (searchText.IsNotEmpty() && searchText != DeluxeSearch.ClearWhereCondition)
            {
                whereSqlClause = new WhereSqlClauseBuilder();

                FillSearchFieldWhereSqlClauseBuilder(whereSqlClause, searchField, searchText, template, isInput);

                WhereSqlClauses.Add(whereSqlClause);
            }
        }