private bool lookUp(T match, CompOpBase lookUpOperation) { PropertyInfo propertyInfo; foreach (GridColumn column in grvLookUp.Columns) { if (column.Visible && !String.IsNullOrEmpty(column.FieldName)) { propertyInfo = typeof(T).GetProperty(column.FieldName); if (propertyInfo != null) { object value = propertyInfo.GetValue(match, null); if (value != null) { if (lookUpOperation.isSatisfy(value.ToString().ToLower())) { return(true); } } } } } foreach (var lookUpPropertyName in LookUpPropertyNames()) { propertyInfo = typeof(T).GetProperty(lookUpPropertyName); if (propertyInfo == null) { throw new ArgumentException(String.Format("Không có thuộc tính {0}", lookUpPropertyName)); } object value = propertyInfo.GetValue(match, null); if (value != null) { if (lookUpOperation.isSatisfy(value.ToString().ToLower())) { return(true); } } } return(false); }
private void txtLookUp_TextChanged(object sender, EventArgs e) { memoryCache.Query = txtLookUp.Text; dgvLookUp.Refresh(); return; string searchTerm = GetSearchTerm().ToLower(); string sTemp = String.Empty; lstNewTerms = new SortedList <int, string>(); lookupTerms = searchTerm.Split('%'); int indexSearch = -1; if (listResult == null) { listResult = ListInitInfo; } for (int i = 0; i < lookupTerms.Length; i++) { if (!String.IsNullOrEmpty(lookupTerms[i])) { if (!lstNewTerms.ContainsValue(lookupTerms[i])) { lstNewTerms.Add(i, lookupTerms[i]); } } } if (lookupTerms.Length == 1) { if (!String.IsNullOrEmpty(lookupTerms[0])) { compareOperate = new EqualsOperation(lookupTerms[0]); sNewSearch = lookupTerms[0]; listResult = ListInitInfo.FindAll(Match); } else { listResult = ListInitInfo; } indexSearch = 0; } else { if (lstOldTerms != null) { if (lstOldTerms.Count > lstNewTerms.Count) { listResult = ReSearch(); indexSearch = -1; } else { foreach (var lstNewTerm in lstNewTerms) { if (!lstOldTerms.TryGetValue(lstNewTerm.Key, out sTemp) || sTemp != lstNewTerm.Value) { sOldSearch = sTemp ?? String.Empty; sNewSearch = lstNewTerm.Value; indexSearch = lstNewTerm.Key; break; } } } } else { listResult = ReSearch(); indexSearch = -1; } if (indexSearch == 0) { compareOperate = new StartsOperation(lstNewTerms[indexSearch]); listResult = StartsOptimizedList.FindAll(Match); } else if (indexSearch == lookupTerms.Length - 1) { compareOperate = new EndsOperation(lstNewTerms[indexSearch]); listResult = EndsOptimizedList.FindAll(Match); } else if (indexSearch > -1) { compareOperate = new ContainsOperation(lstNewTerms[indexSearch]); listResult = ContainsOptimizedList.FindAll(Match); } } dgvLookUp.DataBindings.Clear(); dgvLookUp.DataSource = listResult; dgvLookUp.ClearSelection(); sOldSearch = sNewSearch; lstOldTerms = lstNewTerms; oldIndexSearch = indexSearch; tsStatus.Text = String.Format("Có {0} kết quả được tìm thấy", listResult.Count); }
private void txtLookUp_TextChanged(object sender, EventArgs e) { string searchTerm = GetSearchTerm().ToLower(); string sTemp = String.Empty; lstNewTerms = new SortedList <int, string>(); lookupTerms = searchTerm.Split("%".ToCharArray()[0]); int indexSearch = -1; if (listResult == null) { listResult = ListInitInfo; } for (int i = 0; i < lookupTerms.Length; i++) { if (!String.IsNullOrEmpty(lookupTerms[i])) { if (!lstNewTerms.ContainsValue(lookupTerms[i])) { lstNewTerms.Add(i, lookupTerms[i]); } } } if (lookupTerms.Length == 1) { if (!String.IsNullOrEmpty(lookupTerms[0])) { compareOperate = new EqualsOperation(lookupTerms[0]); sNewSearch = lookupTerms[0]; listResult = ListInitInfo.FindAll(Match); } else { listResult = ListInitInfo; } indexSearch = 0; } else { if (lstOldTerms != null) { if (lstOldTerms.Count > lstNewTerms.Count) { listResult = ReSearch(); indexSearch = -1; } else { foreach (var lstNewTerm in lstNewTerms) { if (!lstOldTerms.TryGetValue(lstNewTerm.Key, out sTemp) || sTemp != lstNewTerm.Value) { sOldSearch = sTemp ?? String.Empty; sNewSearch = lstNewTerm.Value; indexSearch = lstNewTerm.Key; break; } } } } else { listResult = ReSearch(); indexSearch = -1; } if (indexSearch == 0) { compareOperate = new StartsOperation(lstNewTerms[indexSearch]); listResult = StartsOptimizedList.FindAll(Match); } else if (indexSearch == lookupTerms.Length - 1) { compareOperate = new EndsOperation(lstNewTerms[indexSearch]); listResult = EndsOptimizedList.FindAll(Match); } else if (indexSearch > -1) { compareOperate = new ContainsOperation(lstNewTerms[indexSearch]); listResult = ContainsOptimizedList.FindAll(Match); } } //T[] arrTemp = new T[pageSize]; //listResult.CopyTo(0, arrTemp, 0, pageSize); //listDisplay = new List<T>(); //listDisplay.AddRange(arrTemp); grcLookUp.DataSource = listResult; sOldSearch = sNewSearch; lstOldTerms = lstNewTerms; oldIndexSearch = indexSearch; tsStatus.Text = String.Format("Có {0} kết quả được tìm thấy", listResult.Count); }
private void Search(object expression) { if (searching) { return; } searching = true; //string searchTerm = GetSearchTerm().ToLower(); string searchTerm = Convert.ToString(expression).ToLower(); string sTemp = String.Empty; lstNewTerms = new SortedList <int, string>(); lookupTerms = searchTerm.Split("%".ToCharArray()[0]); int indexSearch = -1; if (listResult == null) { listResult = ListInitInfo; } for (int i = 0; i < lookupTerms.Length; i++) { if (!String.IsNullOrEmpty(lookupTerms[i])) { if (!lstNewTerms.ContainsValue(lookupTerms[i])) { lstNewTerms.Add(i, lookupTerms[i]); } } } if (lookupTerms.Length == 1) { if (!String.IsNullOrEmpty(lookupTerms[0])) { compareOperate = new EqualsOperation(lookupTerms[0]); sNewSearch = lookupTerms[0]; listResult = ListInitInfo.FindAll(Match); } else { listResult = ListInitInfo; } indexSearch = 0; } else { if (lstOldTerms != null) { if (lstOldTerms.Count > lstNewTerms.Count) { listResult = ReSearch(); indexSearch = -1; } else { foreach (var lstNewTerm in lstNewTerms) { if (!lstOldTerms.TryGetValue(lstNewTerm.Key, out sTemp) || sTemp != lstNewTerm.Value) { sOldSearch = sTemp ?? String.Empty; sNewSearch = lstNewTerm.Value; indexSearch = lstNewTerm.Key; break; } } } } else { listResult = ReSearch(); indexSearch = -1; } if (indexSearch == 0) { compareOperate = new StartsOperation(lstNewTerms[indexSearch]); listResult = StartsOptimizedList.FindAll(Match); } else if (indexSearch == lookupTerms.Length - 1) { compareOperate = new EndsOperation(lstNewTerms[indexSearch]); listResult = EndsOptimizedList.FindAll(Match); } else if (lstNewTerms.Count > 0) { if (indexSearch == -1) { indexSearch = lstNewTerms.Keys[lstNewTerms.Count - 1]; } compareOperate = new ContainsOperation(lstNewTerms[indexSearch]); listResult = ContainsOptimizedList.FindAll(Match); } } T[] arrTemp = new T[pageSize]; listResult.CopyTo(0, arrTemp, 0, listResult.Count < pageSize ? listResult.Count : pageSize); pageIndex = 0; pageTotal = listResult.Count / pageSize + (listResult.Count % pageSize > 0 ? 1 : 0); listDisplay.Clear(); foreach (var item in arrTemp) { if (item != null) { listDisplay.Add(item); } } Invoke((MethodInvoker) delegate() { grcLookUp.RefreshDataSource(); tsStatus.Text = String.Format("Có {0} kết quả được tìm thấy", listResult.Count); }); sOldSearch = sNewSearch; lstOldTerms = lstNewTerms; oldIndexSearch = indexSearch; searching = false; bool isRemain = false; Invoke((MethodInvoker) delegate() { if (searchTerm != txtLookUp.Text.ToLower()) { isRemain = true; searchTerm = txtLookUp.Text; } }); if (isRemain) { Search(searchTerm); } }