public LogicPhraseDTO GetQuickSearchLogicPhrase(string text, EntitySearchDTO entitySearch) { LogicPhraseDTO quickSearchLogic = new LogicPhraseDTO(); quickSearchLogic.AndOrType = AndOREqualType.Or; foreach (var item in entitySearch.EntitySearchAllColumns) { if (item.ColumnID != 0) { SearchProperty searchProperty = new SearchProperty(); searchProperty.SearchColumnID = item.ID; searchProperty.ColumnID = item.ColumnID; searchProperty.IsKey = item.Column.PrimaryKey; searchProperty.Value = text; LogicPhraseDTO logic = null; if (item.RelationshipTail == null) { logic = quickSearchLogic; } else { logic = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(quickSearchLogic, item.RelationshipTail, null); logic.AndOrType = AndOREqualType.Or; } int n; var isNumeric = int.TryParse(text, out n); DateTime a; var isDateTime = DateTime.TryParse(text, out a); if (item.Column.ColumnType == Enum_ColumnType.Numeric) { if (!isNumeric) { continue; } searchProperty.Operator = CommonOperator.Equals; } else if (item.Column.ColumnType == Enum_ColumnType.Date) { continue; } else if (item.Column.ColumnType == Enum_ColumnType.Boolean) { continue; } else if (item.Column.ColumnType == Enum_ColumnType.String) { searchProperty.Operator = CommonOperator.Contains; } else { continue; } logic.Phrases.Add(searchProperty); } } return(quickSearchLogic); }
//public List<PreDefinedSearchColumns> GetSearchColumns() //{ // List<PreDefinedSearchColumns> result = new List<PreDefinedSearchColumns>(); // foreach (var property in SimpleColumnControls) // { // var value = property.ControlManager.GetValue(); // if (PropertyHasValue(property, value)) // { // PreDefinedSearchColumns item = new PreDefinedSearchColumns(); // if (property.EntitySearchColumn != null) // item.EntitySearchColumnsID = property.EntitySearchColumn.ID; // else // item.ColumnID = property.Column.ID; // item.Value = value; // item.Operator = property.ControlManager.GetOperator(); // result.Add(item); // } // } // return result; //} public DP_SearchRepository GetSearchRepository() { if (firstRepository == null) { firstRepository = new DP_SearchRepository(SearchInitializer.EntityID); } else { firstRepository.Phrases.Clear(); } firstRepository.Title = SearchInitializer.Title; firstRepository.IsSimpleSearch = true; firstRepository.EntitySearchID = EntitySearch == null ? 0 : EntitySearch.ID; foreach (var property in SimpleColumnControls) { var value = property.ControlManager.GetValue(null); if (PropertyHasValue(property, value)) { LogicPhraseDTO logic = null; if (property.EntitySearchColumn.RelationshipTail == null) { logic = firstRepository; } else { logic = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(firstRepository, property.EntitySearchColumn.RelationshipTail, null); } SearchProperty searchProperty = new SearchProperty(); searchProperty.SearchColumnID = property.EntitySearchColumn != null ? property.EntitySearchColumn.ID : 0; searchProperty.ColumnID = property.Column.ID; searchProperty.IsKey = property.Column.PrimaryKey; searchProperty.Value = value; searchProperty.Operator = property.ControlManager.GetOperator(); logic.Phrases.Add(searchProperty); } } foreach (var relControl in RelationshipColumnControls) { if (relControl.EditNdTypeArea.GetDataList().Any()) { var data = relControl.EditNdTypeArea.GetDataList().First(); LogicPhraseDTO logic = AgentHelper.GetOrCreateSearchRepositoryFromRelationshipTail(firstRepository, relControl.EntitySearchColumn.RelationshipTail, data); //foreach (var property in data.KeyProperties) //{ // SearchProperty searchProperty = new SearchProperty(); // searchProperty.SearchColumnID = relControl.EntitySearchColumn != null ? relControl.EntitySearchColumn.ID : 0; // searchProperty.ColumnID = property.Column.ID; // searchProperty.IsKey = property.Column.PrimaryKey; // searchProperty.Value = property.Value; // searchProperty.Operator = CommonOperator.Equals; // logic.Phrases.Add(searchProperty); //} } else { var text = relControl.EditNdTypeArea.TemporaryDisplayView.GetSearchText(); if (!string.IsNullOrEmpty(text)) { var entitySearch = relControl.EditNdTypeArea.SearchViewEntityArea.SearchEntityArea.SimpleSearchEntityArea.EntitySearch; var quickSearchLogic = GetQuickSearchLogicPhrase(text, entitySearch); firstRepository.Phrases.Add(quickSearchLogic); } } } //foreach (var relControl in RelationshipColumnControls) //{ // else // { // var value = relControl.EditNdTypeArea.TemporaryDisplayView.GetSearchText(); // if (!string.IsNullOrEmpty(value)) // { // SearchProperty searchProperty = new SearchProperty(); // searchProperty.SearchColumnID = relControl.EntitySearchColumn != null ? relControl.EntitySearchColumn.ID : 0; // searchProperty.Value = value; // searchProperty.Operator = CommonOperator.Contains; // logic.Phrases.Add(searchProperty); // } // } //} return(firstRepository); }