Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary> Searches for InventoryItem records based on a keyword entered by
- /// the user. All inventory items, including parent items, with the
- /// keyword found in their name field will be returned.
- /// </summary>
- public virtual void searchInventoryItemByName()
- {
- _out.writeLn("Enter a keyword of the item name to be searched");
- System.String keyWordString = _out.readLn();
- ItemSearch itemSearch = new ItemSearch();
- SearchStringField name = new SearchStringField();
- name.@operator = SearchStringFieldOperator.contains;
- name.operatorSpecified = true;
- name.searchValue = keyWordString;
- SearchEnumMultiSelectField type = new SearchEnumMultiSelectField();
- String[] inv = new String[1];
- inv[0] = ITEM_TYPE;
- type.@operator = SearchEnumMultiSelectFieldOperator.anyOf;
- type.operatorSpecified = true;
- type.searchValue = inv;
- SearchBooleanField isLotItem = new SearchBooleanField();
- isLotItem.searchValue = false;
- isLotItem.searchValueSpecified = true;
- SearchBooleanField isSerialItem = new SearchBooleanField();
- isSerialItem.searchValue = false;
- isSerialItem.searchValueSpecified = true;
- ItemSearchBasic itemBasic = new ItemSearchBasic();
- itemBasic.type = type;
- itemBasic.itemId = name;
- itemBasic.isLotItem = isLotItem;
- itemBasic.isSerialItem = isSerialItem;
- itemSearch.basic = itemBasic;
- SearchResult res = _service.search(itemSearch);
- if (res.status.isSuccess)
- {
- Record[] recordList;
- _out.writeLn("\nNumber of items found with the keyword " + keyWordString + ": " + res.totalRecords);
- if (res.totalRecords > 0)
- {
- _out.writeLn("\nPage size: " + res.pageSize);
- for (int i = 1; i <= res.totalPages; i++)
- {
- recordList = res.recordList;
- _out.writeLn("Page " + res.pageIndex);
- _out.writeLn("------");
- for (int j = 0; j < recordList.Length; j++)
- {
- if (recordList[j] is InventoryItem)
- {
- InventoryItem item = (InventoryItem)(recordList[j]);
- displayInventoryItemFields(item);
- }
- }
- if (res.pageIndex < res.totalPages)
- {
- if (useTba)
- {
- setPreferences();
- }
- res = _service.searchMoreWithId(res.searchId, i + 1);
- }
- }
- }
- }
- else
- {
- _out.error(getStatusDetails(res.status));
- }
- }
- /// <summary> A helper method that takes an InventoryItem and prints out
- /// its Display Name, Item ID and Cost fields.
- /// </summary>
- private void displayInventoryItemFields(InventoryItem item)
- {
- if (item != null)
- {
- if (item.displayName != null)
- {
- _out.writeLn(" Display Name: " + item.displayName);
- }
- else
- {
- _out.writeLn(" Display Name: none");
- }
- if (item.itemId != null)
- {
- _out.writeLn(" Item ID: " + item.itemId);
- }
- else
- {
- _out.writeLn(" Item ID: none");
- }
- if (item.purchaseDescription != null)
- {
- _out.writeLn(" Purchase Description: " + item.purchaseDescription);
- }
- else
- {
- _out.writeLn(" Purchase Description: none");
- }
- if ((System.Object) item.cost != null)
- {
- _out.writeLn(" Cost: " + item.cost + "\n");
- }
- else
- {
- _out.writeLn(" Cost: none\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement