/// <summary> /// Does Quick Find Search /// </summary> public async void DoSearch() { // Check Search Criteria if (string.IsNullOrEmpty(txtSearch.Text)) { return; } // Start progress ring until records loaded. progressRing.IsActive = true; // Set the cbLookFor, cbLookIn and searchbox disabled until views/records loaded. cbLookFor.IsEnabled = false; cbLookIn.IsEnabled = false; txtSearch.IsEnabled = false; // Clear data. this.lvList.ItemsSource = null; // Retrieve views by specifing search text, which should return 1 view (quick find view) // But do not set views to cbLookIn to let users select any views later on. views = await CRMHelper.RetrieveViews((int)CRMHelper.EntityMetadataExCollection. Where(x => x.EntityMetadata.LogicalName == (cbLookFor.SelectedItem as EntityMetadataEx).EntityMetadata.LogicalName). Select(x => x.EntityMetadata.ObjectTypeCode).FirstOrDefault(), false, false, txtSearch.Text + "%"); // Then retrieve record and assign to ListView if (views != null && views.Count != 0) { this.lvList.ItemsSource = await CRMHelper.RetrieveByFetchXmlForView(views[0], relatedData, primaryFieldName); } // Once record loaded, then enable comboboxes and search textbox. cbLookFor.IsEnabled = true; cbLookIn.IsEnabled = true; txtSearch.IsEnabled = true; // Hide btnSearch and show btnCancelSearch only after finish searching btnSearch.Visibility = Visibility.Collapsed; btnCancelSearch.Visibility = Visibility.Visible; progressRing.IsActive = false; }
/// <summary> /// Invoked when LookFor combobox selection item changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void cbLookFor_SelectionChanged(object sender, SelectionChangedEventArgs e) { progressRing.IsActive = true; // Clear search criteria txtSearch.Text = ""; // Clear data lvList.ItemsSource = null; // Show Search Button and Hide Cancel Button btnSearch.Visibility = Visibility.Visible; btnCancelSearch.Visibility = Visibility.Collapsed; // Set the cbLookFor and searchbox disabled until views/records loaded. cbLookFor.IsEnabled = false; cbLookIn.IsEnabled = false; txtSearch.IsEnabled = false; // Check if selected Entity is available for mobile, otherwise cannot retrieve data. EntityMetadataEx entityMetadata = CRMHelper.EntityMetadataExCollection.Where(x => x.EntityMetadata.LogicalName == ((sender as ComboBox).SelectedItem as EntityMetadataEx).EntityMetadata.LogicalName).FirstOrDefault(); if (entityMetadata == null) { MessageDialog dialog = new MessageDialog( String.Format(loader.GetString("NotValidForMobile"), ((sender as ComboBox).SelectedItem as EntityMetadata).DisplayName)); await dialog.ShowAsync(); // Reset the selection back to original (sender as ComboBox).SelectedItem = e.RemovedItems[0]; return; } // Retrieve available view definitions depending on conditions. cbLookIn.ItemsSource = await CRMHelper.RetrieveViews( (int)entityMetadata.EntityMetadata.ObjectTypeCode, isRegarding, isLookup, txtSearch.Text); // Assign display name cbLookIn.DisplayMemberPath = "Name"; cbLookIn.SelectedIndex = cbLookIn_SelectedIndex; }