Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. /// <summary> Searches for InventoryItem records based on a keyword entered by
  2. /// the user. All inventory items, including parent items, with the
  3. /// keyword found in their name field will be returned.
  4. /// </summary>
  5. public virtual void searchInventoryItemByName()
  6. {
  7. _out.writeLn("Enter a keyword of the item name to be searched");
  8. System.String keyWordString = _out.readLn();
  9.  
  10. ItemSearch itemSearch = new ItemSearch();
  11.  
  12. SearchStringField name = new SearchStringField();
  13. name.@operator = SearchStringFieldOperator.contains;
  14. name.operatorSpecified = true;
  15. name.searchValue = keyWordString;
  16.  
  17. SearchEnumMultiSelectField type = new SearchEnumMultiSelectField();
  18. String[] inv = new String[1];
  19. inv[0] = ITEM_TYPE;
  20. type.@operator = SearchEnumMultiSelectFieldOperator.anyOf;
  21. type.operatorSpecified = true;
  22. type.searchValue = inv;
  23.  
  24. SearchBooleanField isLotItem = new SearchBooleanField();
  25. isLotItem.searchValue = false;
  26. isLotItem.searchValueSpecified = true;
  27.  
  28. SearchBooleanField isSerialItem = new SearchBooleanField();
  29. isSerialItem.searchValue = false;
  30. isSerialItem.searchValueSpecified = true;
  31.  
  32. ItemSearchBasic itemBasic = new ItemSearchBasic();
  33. itemBasic.type = type;
  34. itemBasic.itemId = name;
  35. itemBasic.isLotItem = isLotItem;
  36. itemBasic.isSerialItem = isSerialItem;
  37.  
  38. itemSearch.basic = itemBasic;
  39.  
  40. SearchResult res = _service.search(itemSearch);
  41. if (res.status.isSuccess)
  42. {
  43. Record[] recordList;
  44. _out.writeLn("\nNumber of items found with the keyword " + keyWordString + ": " + res.totalRecords);
  45. if (res.totalRecords > 0)
  46. {
  47. _out.writeLn("\nPage size: " + res.pageSize);
  48.  
  49. for (int i = 1; i <= res.totalPages; i++)
  50. {
  51. recordList = res.recordList;
  52. _out.writeLn("Page " + res.pageIndex);
  53. _out.writeLn("------");
  54.  
  55. for (int j = 0; j < recordList.Length; j++)
  56. {
  57. if (recordList[j] is InventoryItem)
  58. {
  59. InventoryItem item = (InventoryItem)(recordList[j]);
  60. displayInventoryItemFields(item);
  61. }
  62. }
  63. if (res.pageIndex < res.totalPages)
  64. {
  65. if (useTba)
  66. {
  67. setPreferences();
  68. }
  69. res = _service.searchMoreWithId(res.searchId, i + 1);
  70. }
  71. }
  72. }
  73. }
  74. else
  75. {
  76. _out.error(getStatusDetails(res.status));
  77. }
  78. }
  79.  
  80. /// <summary> A helper method that takes an InventoryItem and prints out
  81. /// its Display Name, Item ID and Cost fields.
  82. /// </summary>
  83. private void displayInventoryItemFields(InventoryItem item)
  84. {
  85. if (item != null)
  86. {
  87. if (item.displayName != null)
  88. {
  89. _out.writeLn(" Display Name: " + item.displayName);
  90. }
  91. else
  92. {
  93. _out.writeLn(" Display Name: none");
  94. }
  95.  
  96. if (item.itemId != null)
  97. {
  98. _out.writeLn(" Item ID: " + item.itemId);
  99. }
  100. else
  101. {
  102. _out.writeLn(" Item ID: none");
  103. }
  104.  
  105. if (item.purchaseDescription != null)
  106. {
  107. _out.writeLn(" Purchase Description: " + item.purchaseDescription);
  108. }
  109. else
  110. {
  111. _out.writeLn(" Purchase Description: none");
  112. }
  113.  
  114. if ((System.Object) item.cost != null)
  115. {
  116. _out.writeLn(" Cost: " + item.cost + "\n");
  117. }
  118. else
  119. {
  120. _out.writeLn(" Cost: none\n");
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement