private static List<iSearch_Title_Result> DataReader_To_Simple_Result_List2(DbDataReader Reader, List<string> MetadataFieldNames) { // Create return list List<iSearch_Title_Result> returnValue = new List<iSearch_Title_Result>(); // Create some lists used during the construction Dictionary<int, Database_Title_Result> titleLookupByRowNumber = new Dictionary<int, Database_Title_Result>(); Dictionary<int, Database_Item_Result> itemLookupByItemID = new Dictionary<int, Database_Item_Result>(); Dictionary<int, int> rowNumberLookupByItemID = new Dictionary<int, int>(); // May have not values returned if (Reader.FieldCount < 5) return null; // Get all the main title values first int minimumRownumber = -1; while (Reader.Read()) { // Create new database title object for this Database_Title_Result result = new Database_Title_Result { RowNumber = Reader.GetInt32(0), BibID = Reader.GetString(1), GroupTitle = Reader.GetString(2), OPAC_Number = Reader.GetInt32(3), OCLC_Number = Reader.GetInt64(4), GroupThumbnail = Reader.GetString(5), MaterialType = Reader.GetString(6), Primary_Identifier_Type = Reader.GetString(7), Primary_Identifier = Reader.GetString(8) }; titleLookupByRowNumber.Add(result.RowNumber, result); if (minimumRownumber == -1) { minimumRownumber = result.RowNumber; } } // Move to the item system-required information table Reader.NextResult(); // If there were no titles, then there are no results if (titleLookupByRowNumber.Count == 0) return returnValue; // Step through all the item rows, build the item, and add to the title Database_Title_Result titleResult = titleLookupByRowNumber[minimumRownumber]; returnValue.Add(titleResult); int lastRownumber = titleResult.RowNumber; while (Reader.Read()) { // Ensure this is the right title for this item int thisRownumber = Reader.GetInt32(0); if (thisRownumber != lastRownumber) { titleResult = titleLookupByRowNumber[thisRownumber]; lastRownumber = thisRownumber; // Add this title to the list returnValue.Add(titleResult); } // Create new database item object for this Database_Item_Result result = new Database_Item_Result { ItemID = Reader.GetInt32(1), VID = Reader.GetString(2), Title = Reader.GetString(3), IP_Restriction_Mask = Reader.GetInt16(4), MainThumbnail = Reader.GetString(5), Level1_Index = (short)Reader.GetInt32(6), Level1_Text = Reader.GetString(7), Level2_Index = (short)Reader.GetInt32(8), Level2_Text = Reader.GetString(9), Level3_Index = (short)Reader.GetInt32(10), Level3_Text = Reader.GetString(11), PubDate = Reader.GetString(12), PageCount = Reader.GetInt32(13), Link = Reader.GetString(14), Spatial_KML = Reader.GetString(15), COinS_OpenURL = Reader.GetString(16) }; // Save to the hash lookup for adding display metadata itemLookupByItemID[result.ItemID] = result; rowNumberLookupByItemID[result.ItemID] = thisRownumber; // Add this to the title object titleResult.Add_Item_Result(result); } // Move to the item aggregation-configured display information table Reader.NextResult(); // Set some values for checking for uniformity of values const int ITEMS_TO_CHECK_IN_EACH_TITLE = 20; bool first_item_analyzed = true; List<bool> checking_fields = new List<bool>(); int display_fields_count = 0; int itemcount = 0; int lastRowNumber = -1; while (Reader.Read()) { // Get the item id and then work back to the local title id int itemId = Reader.GetInt32(0); int rowNumber = rowNumberLookupByItemID[itemId]; // If this is the very first item analyzed, need to do some work first if (first_item_analyzed) { // Save the number of display fields display_fields_count = Reader.FieldCount - 1; // Add a boolean for each display field for (int i = 0; i < display_fields_count; i++) { // Add the default boolean value here checking_fields.Add(true); // Save the metadata label MetadataFieldNames.Add(Reader.GetName(i + 1)); } // Done with the first row analysis, so ensure it does not repeat first_item_analyzed = false; } // Is this is the start of a new title row? if (lastRowNumber != rowNumber) { // Get this title object titleResult = titleLookupByRowNumber[rowNumber]; // Set items analyzed for this title to zero itemcount = 0; // Back to checking each metadata field since this is a new title for (int i = 0; i < display_fields_count; i++) checking_fields[i] = true; // Save this row numbe as the last row number analyzed lastRowNumber = rowNumber; } if (itemcount == 0) { // Set all the initial display values (at the title level) from // this item's display information titleResult.Metadata_Display_Values = new string[display_fields_count]; for (int i = 0; i < display_fields_count; i++) { titleResult.Metadata_Display_Values[i] = Reader.GetString(i + 1); } } else if (itemcount < ITEMS_TO_CHECK_IN_EACH_TITLE) { // Compare the values attached with each display piece of metadata // from the title with this additional, individual item. If the // values are the same, it should display at the title level, but // if they are different, we will not display the values at that level for (int i = 0; i < display_fields_count; i++) { // If we already found a mismatch for this metadata field, then // no need to continue checking if (checking_fields[i]) { if (String.Compare(titleResult.Metadata_Display_Values[i], Reader.GetString(i + 1), StringComparison.InvariantCultureIgnoreCase) != 0) { titleResult.Metadata_Display_Values[i] = "*"; checking_fields[i] = false; } } } } } return returnValue; }
/// <summary> Adds information about a child item under this title result </summary> /// <param name="Item_Result"> Display and identification information for a single item within this title </param> internal void Add_Item_Result(Database_Item_Result Item_Result) { itemList.Add(Item_Result); }
/// <summary> Adds information about a child item under this title result </summary> /// <param name="Item_Result"> Display and identification information for a single item within this title </param> internal void Add_Item_Result(Database_Item_Result Item_Result) { Items.Add(Item_Result); }