private void AddNewFindCriteriaAtBestPosition(TFindCriteriaListItem ListItem) { TFindCriteriaColumn InsertCriteriaColumn; // TFindCriteriaColumn FoundInDefaultColumn; Int32 Counter; Int32 Counter2; Int32 Counter2Start = 0; Int32 DefaultPosition = -1; Int32 InsertPosition = -1; Int32 OtherItemFoundPosition; String ListItemName; ArrayList LookupCritieriaDefaultColumn = new ArrayList(); ArrayList CriteriaFieldsList = new ArrayList(); TSearchDirection SearchDirection; Boolean SearchInCurrentDirectionNecessary; Boolean ContinueSearch; ListItemName = ListItem.InternalName; // Find default position of the ListItem in one of the DefaultOrder lists if (FCriteriaFieldsLeftDefaultOrder.IndexOf(ListItemName) != -1) { DefaultPosition = FCriteriaFieldsLeftDefaultOrder.IndexOf(ListItemName); // FoundInDefaultColumn = TFindCriteriaColumn.fccLeft; LookupCritieriaDefaultColumn = FCriteriaFieldsLeftDefaultOrder; } if (FCriteriaFieldsRightDefaultOrder.IndexOf(ListItemName) != -1) { DefaultPosition = FCriteriaFieldsRightDefaultOrder.IndexOf(ListItemName); // FoundInDefaultColumn = TFindCriteriaColumn.fccRight; LookupCritieriaDefaultColumn = FCriteriaFieldsRightDefaultOrder; } // MessageBox.Show('Looking for other item to insert after in ' + FoundInDefaultColumn.ToString("G") + ' before position ' + DefaultPosition.ToString + '...'); OtherItemFoundPosition = -1; SearchDirection = TSearchDirection.sdBackward; ContinueSearch = true; SearchInCurrentDirectionNecessary = DefaultPosition > 0; // Determine which CriteriaFields list to search initially if (FCriteriaFieldsLeft != null) { CriteriaFieldsList = FCriteriaFieldsLeft; Counter2Start = 0; Counter2 = Counter2Start; } else if (FCriteriaFieldsRight != null) { CriteriaFieldsList = FCriteriaFieldsRight; Counter2Start = 1; Counter2 = Counter2Start; } else { // none of the two criteria field lists has any items (shouldn't happen!) } // Loop backwards/forwards in the LookupCritieriaDefaultColumn to check if any item // before/after the ListItemName is in one of the CriteriaFieldsLists. while (1 == 1) { if (SearchInCurrentDirectionNecessary) { Counter = DefaultPosition; ContinueSearch = true; while (ContinueSearch) { if (SearchDirection == TSearchDirection.sdBackward) { Counter = Counter - 1; // MessageBox.Show('Searching backwards. Checking position ' + Counter.ToString + '...'); // Lower end of LookupCritieriaDefaultColumn reached? if (Counter < 0) { // MessageBox.Show('Lower end of list reached!'); break; } } else { Counter = Counter + 1; // MessageBox.Show('Searching forward. Checking position ' + Counter.ToString + '...'); // Upper end of LookupCritieriaDefaultColumn reached? if (Counter == LookupCritieriaDefaultColumn.Count) { // MessageBox.Show('Upper end of list reached!'); ContinueSearch = false; break; } } if (ContinueSearch) { Counter2 = Counter2Start; CriteriaFieldsList = FCriteriaFieldsLeft; // Look in the left and right CriteriaFieldsLists for a predecessor/successor of ListItemName while (Counter2 <= 1) { // MessageBox.Show('Looking for ' + LookupCritieriaDefaultColumn[Counter].ToString); if (CriteriaFieldsList.IndexOf(LookupCritieriaDefaultColumn[Counter].ToString()) != -1) { OtherItemFoundPosition = CriteriaFieldsList.IndexOf(LookupCritieriaDefaultColumn[Counter]); if (SearchDirection == TSearchDirection.sdBackward) { // New item should be inserted after the found item InsertPosition = OtherItemFoundPosition + 1; } else { // New item should be inserted before the found item InsertPosition = OtherItemFoundPosition - 1; if (InsertPosition == -1) { InsertPosition = 0; } } // MessageBox.Show('Found other item at position ' + OtherItemFoundPosition.ToString + ', will insert new at position ' + InsertPosition.ToString); break; } // Other item not found in the first CriteriaFieldsList? if (OtherItemFoundPosition == -1) { Counter2 = Counter2 + 1; if (Counter2 == 1) { // MessageBox.Show('Other item not found in FCriteriaFieldsLeft, looking in FCriteriaFieldsRight...'); CriteriaFieldsList = FCriteriaFieldsRight; } } else { // New item found in the first CriteriaFieldsList break; } } // while (Counter2 <= 1) } // ContinueSearch = true if (OtherItemFoundPosition != -1) { // New item found break; } } // while 2 = 2 } // SearchInCurrentDirectionNecessary = true // Other item was found? if (OtherItemFoundPosition != -1) { break; } else if (ContinueSearch) { SearchDirection = TSearchDirection.sdForward; if (DefaultPosition < CriteriaFieldsList.Count) { SearchInCurrentDirectionNecessary = true; } else { break; } } else { break; } } // while 1 = 1 // Item found in the same LookupCritieriaDefaultColumn that is currently displayed if (OtherItemFoundPosition != -1) { // Found in left column if (CriteriaFieldsList == FCriteriaFieldsLeft) { // Add the checked item at the appropriate position FCriteriaFieldsLeft.Insert(InsertPosition, ListItemName); } else { // Add the checked item at the appropriate position FCriteriaFieldsRight.Insert(InsertPosition, ListItemName); } } else { InsertCriteriaColumn = ListItem.CriteriaColumn; if (InsertCriteriaColumn == TFindCriteriaColumn.fccLeft) { if (FCriteriaFieldsLeft == null) { // Make new list FCriteriaFieldsLeft = new ArrayList(); } // Add the item at the end FCriteriaFieldsLeft.Add(ListItemName); } else { if (FCriteriaFieldsRight == null) { // Make new list FCriteriaFieldsRight = new ArrayList(); } // Add the item at the end FCriteriaFieldsRight.Add(ListItemName); } } }
private void SetupFindCriteriaLists() { object[] CheckedListItemArray; CheckedListBox TheCheckedListBox; Int32 Counter1; Int32 Counter2; String LocalisedCountyLabel; String Dummy; FFindCriteriaListsSetupRunning = true; LocalisedStrings.GetLocStrCounty(out LocalisedCountyLabel, out Dummy); LocalisedCountyLabel = LocalisedCountyLabel.Replace(":", "").Replace("&", ""); CheckedListItemArray = new object[7]; CheckedListItemArray[0] = new TFindCriteriaListItem("Partner Name", "PartnerName", TFindCriteriaColumn.fccLeft); CheckedListItemArray[1] = new TFindCriteriaListItem("Personal (First) Name", "PersonalName", TFindCriteriaColumn.fccLeft); CheckedListItemArray[2] = new TFindCriteriaListItem("Previous Name", "PreviousName", TFindCriteriaColumn.fccLeft); CheckedListItemArray[3] = new TFindCriteriaListItem("Partner Key", "PartnerKey", TFindCriteriaColumn.fccRight); CheckedListItemArray[4] = new TFindCriteriaListItem("OMSS Key", "OMSSKey", TFindCriteriaColumn.fccRight); CheckedListItemArray[5] = new TFindCriteriaListItem("Partner Class", "PartnerClass", TFindCriteriaColumn.fccRight); CheckedListItemArray[6] = new TFindCriteriaListItem("Partner Status", "PartnerStatus", TFindCriteriaColumn.fccRight); clbPartnerFindCriteria.Items.AddRange(CheckedListItemArray); CheckedListItemArray = new object[11]; CheckedListItemArray[0] = new TFindCriteriaListItem("Address 1", "Address1", TFindCriteriaColumn.fccLeft); CheckedListItemArray[1] = new TFindCriteriaListItem("Address 2", "Address2", TFindCriteriaColumn.fccLeft); CheckedListItemArray[2] = new TFindCriteriaListItem("Address 3", "Address3", TFindCriteriaColumn.fccLeft); CheckedListItemArray[3] = new TFindCriteriaListItem("Post Code", "PostCode", TFindCriteriaColumn.fccLeft); CheckedListItemArray[4] = new TFindCriteriaListItem("City/Town", "City", TFindCriteriaColumn.fccLeft); CheckedListItemArray[5] = new TFindCriteriaListItem(LocalisedCountyLabel, "County", TFindCriteriaColumn.fccLeft); CheckedListItemArray[6] = new TFindCriteriaListItem("Country", "Country", TFindCriteriaColumn.fccLeft); CheckedListItemArray[7] = new TFindCriteriaListItem("Mailing Addresses Only", "MailingAddressOnly", TFindCriteriaColumn.fccLeft); CheckedListItemArray[8] = new TFindCriteriaListItem("Phone Number", "PhoneNumber", TFindCriteriaColumn.fccLeft); CheckedListItemArray[9] = new TFindCriteriaListItem("Email", "Email", TFindCriteriaColumn.fccLeft); CheckedListItemArray[10] = new TFindCriteriaListItem("Location Key", "LocationKey", TFindCriteriaColumn.fccRight); clbAddressFindCriteria.Items.AddRange(CheckedListItemArray); CheckedListItemArray = new object[1]; CheckedListItemArray[0] = new TFindCriteriaListItem("Personnel Criteria Section", "PersonnelCriteria", TFindCriteriaColumn.fccRight); clbOtherFindCriteria.Items.AddRange(CheckedListItemArray); Counter2 = 0; TheCheckedListBox = clbPartnerFindCriteria; while (Counter2 <= 2) { for (Counter1 = 0; Counter1 <= TheCheckedListBox.Items.Count - 1; Counter1 += 1) { TFindCriteriaListItem CurrentItem = (TFindCriteriaListItem)TheCheckedListBox.Items[Counter1]; if (FCriteriaFieldsLeft != null) { if (FCriteriaFieldsLeft.Contains(CurrentItem.InternalName)) { TheCheckedListBox.SetItemChecked(Counter1, true); } } if (FCriteriaFieldsRight != null) { if (FCriteriaFieldsRight.Contains(CurrentItem.InternalName)) { TheCheckedListBox.SetItemChecked(Counter1, true); } } } Counter2 = Counter2 + 1; if (Counter2 == 1) { TheCheckedListBox = clbAddressFindCriteria; } if (Counter2 == 2) { TheCheckedListBox = clbOtherFindCriteria; } } FFindCriteriaListsSetupRunning = false; // disable PartnerKeyBehavior checkbox Counter1 = 0; foreach (TFindCriteriaListItem CurrentItem in clbPartnerFindCriteria.Items) { if (CurrentItem.InternalName == "PartnerKey") { chkExactPartnerKeyMatchSearch.Enabled = clbPartnerFindCriteria.GetItemChecked(Counter1); return; } Counter1 = Counter1 + 1; } }