/// <summary> /// Handles the Click event of the btnSearch control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> void btnSearch_Click(object sender, RoutedEventArgs e) { Common.Network.Message msg; Dictionary <string, UIElement> .Enumerator en = _boundProperties.GetEnumerator(); Common.CouchDB.Lucene.QueryBuilder qb = new Common.CouchDB.Lucene.QueryBuilder(); string propertyName; DateTime from, to; // TODO : this needs cleaned up while (en.MoveNext()) { if (en.Current.Value.GetType() == typeof(TextBox)) { propertyName = (string)((TextBox)en.Current.Value).Tag; if (((TextBox)en.Current.Value).Text.Trim().Length > 0) { qb.AddText(propertyName, ((TextBox)en.Current.Value).Text.Trim()); } } else if (en.Current.Value.GetType() == typeof(DatePicker)) { propertyName = (string)((DatePicker)en.Current.Value).Tag; propertyName = propertyName.Replace("_from", ""); if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { from = ((DatePicker)en.Current.Value).SelectedDate.Value; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) { throw new InvalidOperationException("A UIElement of type DatePicker was expected."); } else { break; } } if (!((DatePicker)en.Current.Value).SelectedDate.HasValue) { to = DateTime.MaxValue; } else { to = ((DatePicker)en.Current.Value).SelectedDate.Value; } qb.AddDate(propertyName, from, to); } else { from = DateTime.MinValue; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) { throw new InvalidOperationException("A UIElement of type DatePicker was expected."); } else { break; } } // Does to have a selected value? if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { to = DateTime.MaxValue; qb.AddDate(propertyName, from, to); } } } else { throw new Exception("Unsupported UIElement"); } } Common.CouchDB.Lucene.Search search = new Common.CouchDB.Lucene.Search(_couchdb.Server, _couchdb, "search", "by_all", qb); Common.CouchDB.Result result = search.Get <Common.CouchDB.Lucene.SearchResultCollection>( 60000, 60000, Settings.Instance.NetworkBufferSize, Settings.Instance.NetworkBufferSize); List <Guid> versionGuids = new List <Guid>(); List <Common.Postgres.Version> versions = new List <Common.Postgres.Version>(); Common.CouchDB.Lucene.SearchResultCollection newSRC = new Common.CouchDB.Lucene.SearchResultCollection(); DisplayResultsDelegate actDisplayResults = DisplayResults; // Get list of all version guids returned for (int i = 0; i < search.SearchResultCollection.Count; i++) { versionGuids.Add(Guid.Parse(search.SearchResultCollection[i].Id)); } // Get all current versions for resources versions = Common.Postgres.Version.GetCurrentVersionsFromVersionGuids(versionGuids.ToArray()); for (int i = 0; i < versions.Count; i++) { newSRC.Add(search.SearchResultCollection.Get(versions[i].VersionGuid)); } Dispatcher.BeginInvoke(actDisplayResults, dgResults, newSRC); }
/// <summary> /// Handles the Click event of the btnSearch control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> void btnSearch_Click(object sender, RoutedEventArgs e) { Common.Network.Message msg; Dictionary<string, UIElement>.Enumerator en = _boundProperties.GetEnumerator(); Common.CouchDB.Lucene.QueryBuilder qb = new Common.CouchDB.Lucene.QueryBuilder(); string propertyName; DateTime from, to; // TODO : this needs cleaned up while (en.MoveNext()) { if (en.Current.Value.GetType() == typeof(TextBox)) { propertyName = (string)((TextBox)en.Current.Value).Tag; if(((TextBox)en.Current.Value).Text.Trim().Length > 0) qb.AddText(propertyName, ((TextBox)en.Current.Value).Text.Trim()); } else if (en.Current.Value.GetType() == typeof(DatePicker)) { propertyName = (string)((DatePicker)en.Current.Value).Tag; propertyName = propertyName.Replace("_from",""); if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { from = ((DatePicker)en.Current.Value).SelectedDate.Value; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) throw new InvalidOperationException("A UIElement of type DatePicker was expected."); else break; } if (!((DatePicker)en.Current.Value).SelectedDate.HasValue) to = DateTime.MaxValue; else to = ((DatePicker)en.Current.Value).SelectedDate.Value; qb.AddDate(propertyName, from, to); } else { from = DateTime.MinValue; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) throw new InvalidOperationException("A UIElement of type DatePicker was expected."); else break; } // Does to have a selected value? if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { to = DateTime.MaxValue; qb.AddDate(propertyName, from, to); } } } else throw new Exception("Unsupported UIElement"); } Common.CouchDB.Lucene.Search search = new Common.CouchDB.Lucene.Search(_couchdb.Server, _couchdb, "search", "by_all", qb); Common.CouchDB.Result result = search.Get<Common.CouchDB.Lucene.SearchResultCollection>( 60000, 60000, Settings.Instance.NetworkBufferSize, Settings.Instance.NetworkBufferSize); List<Guid> versionGuids = new List<Guid>(); List<Common.Postgres.Version> versions = new List<Common.Postgres.Version>(); Common.CouchDB.Lucene.SearchResultCollection newSRC = new Common.CouchDB.Lucene.SearchResultCollection(); DisplayResultsDelegate actDisplayResults = DisplayResults; // Get list of all version guids returned for (int i = 0; i < search.SearchResultCollection.Count; i++) versionGuids.Add(Guid.Parse(search.SearchResultCollection[i].Id)); // Get all current versions for resources versions = Common.Postgres.Version.GetCurrentVersionsFromVersionGuids(versionGuids.ToArray()); for (int i = 0; i < versions.Count; i++) { newSRC.Add(search.SearchResultCollection.Get(versions[i].VersionGuid)); } Dispatcher.BeginInvoke(actDisplayResults, dgResults, newSRC); }