Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. if (ProductNameArray.Any(usersearch.Contains))
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Linq;
  8.  
  9. namespace Prac_Test3
  10. {
  11.  
  12.  
  13. class Program
  14. {
  15. // Constants
  16. const int SIZE_OF_PRODUCT_CODE = 4;
  17. const float CATEGORY_A_MARKUP = 10.0F;
  18. const float CATEGORY_C_MARKUP = 33.3F;
  19. const float CATEGORY_P_MARKUP = 15.0F;
  20. const int ARRAY_SIZE = 100;
  21.  
  22.  
  23. static void DisplayMenu()
  24. {
  25. Console.Clear();
  26. Console.WriteLine("--------------> Menu <------------");
  27. Console.WriteLine("1. Add a product (a)");
  28. Console.WriteLine("2. Find a product (f)");
  29. Console.WriteLine("3. Enter the quantity in stock (q)");
  30. Console.WriteLine("4. Delete a product (d)");
  31. Console.WriteLine("5. Calculate and display values (v)");
  32. Console.WriteLine("6. Exit (x)");
  33. Console.Write("rnEnter your selection: ");
  34. }
  35. static void AddProduct( string[] ProductNameArray, string[] ProductCodeArray, float[] WholesalePriceArray, ref int NextAvaliablePosition)
  36. {
  37. string ProductName = "";
  38. string ProductCode = "";
  39. string ProductCategory = "";
  40.  
  41. float WholesalePricePerItem = 0.0F;
  42.  
  43. bool ParseResult = false;
  44. bool ErrorFlag = false;
  45.  
  46. string UserResponse = "";
  47.  
  48. do
  49. {
  50. ErrorFlag = false;
  51. Console.Write("Product Name : ");
  52. ProductName = Console.ReadLine();
  53. if (ProductName == "")
  54. {
  55. Console.ForegroundColor = ConsoleColor.Red;
  56. Console.WriteLine("Product Name must not be left blank.");
  57. Console.ForegroundColor = ConsoleColor.Gray;
  58. ErrorFlag = true;
  59. }
  60. } while (ErrorFlag);
  61.  
  62. do
  63. {
  64. ErrorFlag = false;
  65. Console.Write("Product Code : ");
  66. ProductCode = Console.ReadLine();
  67. if (ProductCode == "")
  68. {
  69. Console.ForegroundColor = ConsoleColor.Red;
  70. Console.WriteLine("Product Name must not be left blank.");
  71. Console.ForegroundColor = ConsoleColor.Gray;
  72. ErrorFlag = true;
  73. }
  74. else if (ProductCode.Length != SIZE_OF_PRODUCT_CODE)
  75. {
  76. Console.ForegroundColor = ConsoleColor.Red;
  77. Console.WriteLine("Product Code must be exactly four characters.");
  78. Console.ForegroundColor = ConsoleColor.Gray;
  79. ErrorFlag = true;
  80. }
  81. else
  82. {
  83. ProductCategory = ProductCode.Substring(0, 1);
  84. ProductCategory = ProductCategory.ToUpper();
  85. if (ProductCategory != "A" && ProductCategory != "C" && ProductCategory != "P")
  86. {
  87. Console.ForegroundColor = ConsoleColor.Red;
  88. Console.WriteLine("Product Code must start with A, C or P.");
  89. Console.ForegroundColor = ConsoleColor.Gray;
  90. ErrorFlag = true;
  91. }
  92. else if (!(Char.IsDigit(ProductCode[1])) && !(Char.IsDigit(ProductCode[2])) && !(Char.IsDigit(ProductCode[3])))
  93. {
  94. Console.ForegroundColor = ConsoleColor.Red;
  95. Console.WriteLine("Product Code must be A, C or P followed by three digits.");
  96. Console.ForegroundColor = ConsoleColor.Gray;
  97. ErrorFlag = true;
  98. }
  99. }
  100. } while (ErrorFlag);
  101.  
  102. do
  103. {
  104. ErrorFlag = false;
  105. Console.Write("Wholesale price per item ($): ");
  106. UserResponse = Console.ReadLine();
  107. ParseResult = float.TryParse(UserResponse, out WholesalePricePerItem);
  108. if (ParseResult == false)
  109. {
  110. Console.ForegroundColor = ConsoleColor.Red;
  111. Console.WriteLine("Not a valid number.");
  112. Console.ForegroundColor = ConsoleColor.Gray;
  113. ErrorFlag = true;
  114. }
  115. else if (WholesalePricePerItem <= 0)
  116. {
  117. Console.ForegroundColor = ConsoleColor.Red;
  118. Console.WriteLine("Wholesale price must be a number greater than 0.");
  119. Console.ForegroundColor = ConsoleColor.Gray;
  120. ErrorFlag = true;
  121. }
  122. } while (ErrorFlag);
  123. }
  124. static void FindProduct(Array ProductNameArray)
  125. {
  126.  
  127. int search = -1;
  128. string usersearch;
  129.  
  130. usersearch = Console.ReadLine();
  131. search = Array.IndexOf(ProductNameArray, usersearch);
  132.  
  133. if (search >=0)
  134. {
  135. if (ProductNameArray.Any(usersearch.Contains))
  136. {
  137. Console.WriteLine(" details blah blah");
  138. }
  139. }
  140. else if (search <0)
  141. {
  142. Console.WriteLine("No record exists.");
  143. }
  144.  
  145. if (ProductNameArray.Cast<string>().Any(usersearch.Contains))
  146.  
  147. static void FindProduct(Array ProductNameArray)
  148.  
  149. static void FindProduct(string[] ProductNameArray)
  150.  
  151. namespace Your.Namespace
  152. {
  153. using System;
  154. using ... // your other usings
  155. using System.Linq;
  156.  
  157. public sealed class YourClass
  158. {
  159. public void Test()
  160. {
  161. // ...
  162. yourArray.Any()
  163. }
  164. }
  165. }
  166.  
  167. using System.Linq;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement