Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace MidtermProj_Sim_134713
  7. {
  8. class Inventory
  9. {
  10. public Items[] inventoryitems;
  11. public int max;
  12. public int current;
  13. int inventorycode2;
  14. double inventoryprice2;
  15. bool validinventorycode;
  16. bool validinventoryprice;
  17. string inventorycode;
  18. string inventoryname;
  19. string inventoryprice;
  20.  
  21. public Inventory()
  22. {
  23. max = 25;
  24. inventoryitems = new Items[max];
  25. current = 0;
  26. }
  27.  
  28. public Items Find(string inventorycode)
  29. {
  30. Items target = null;
  31.  
  32. for (int i = 0; i < max; i++)
  33. {
  34. if (inventoryitems[i] != null)
  35. {
  36. if (inventorycode == inventoryitems[i].GetCode())
  37. {
  38. target = inventoryitems[i];
  39. break;
  40. }
  41. }
  42. }
  43. return target;
  44. }
  45.  
  46. public void AddItems()
  47. {
  48. Console.Clear();
  49. do
  50. {
  51.  
  52. Console.Write("Input Inventory Code: ");
  53. inventorycode = Console.ReadLine();
  54. validinventorycode = int.TryParse(inventorycode, out inventorycode2);
  55. if (inventorycode == "\\c")
  56. {
  57. Console.WriteLine("Transacation Cancelled!");
  58. validinventorycode = true;
  59. }
  60. else if ((validinventorycode == false) || (inventorycode.Length != 5))
  61. {
  62. Console.WriteLine("Inventory Code is Invalid!");
  63. validinventorycode = false;
  64. }
  65.  
  66. for (int i = 0; i < current; i++)
  67. {
  68. if (inventorycode == inventoryitems[i].GetCode())
  69. {
  70. Console.WriteLine("Inventory code already exists.");
  71. validinventorycode = false;
  72. }
  73. }
  74. }while ((validinventorycode == false));
  75. if (inventorycode != "\\c")
  76. {
  77. do
  78. {
  79. Console.Write("Input Inventory Name: ");
  80. inventoryname = Console.ReadLine();
  81.  
  82. if (inventoryname == "\\c")
  83. {
  84. Console.WriteLine("Transaction Cancelled!");
  85. validinventorycode = true;
  86. }
  87. }
  88. while (validinventorycode == false);
  89.  
  90. if (inventoryname != "\\c")
  91. {
  92. do
  93. {
  94. Console.Write("Input Inventory Price: ");
  95. inventoryprice = Console.ReadLine();
  96. validinventoryprice = double.TryParse(inventoryprice, out inventoryprice2);
  97. if (inventoryprice == "\\c")
  98. {
  99. Console.WriteLine("Transaction Cancelled!");
  100. validinventoryprice = true;
  101. }
  102. if (validinventoryprice == false)
  103. {
  104. Console.WriteLine("Inventory price is invalid!");
  105. }
  106. }
  107. while ((validinventoryprice == false));
  108.  
  109. if (current > max)
  110. {
  111. Console.WriteLine("Inventory is full.");
  112. }
  113.  
  114. if (inventoryprice != "\\c")
  115. {
  116. Console.WriteLine("Inventory is successfully added.");
  117. inventoryitems[current] = new Items(inventorycode, inventoryname, inventoryprice);
  118. current++;
  119. }
  120.  
  121. }
  122. }
  123. }
  124.  
  125. public void EditInventory()
  126. {
  127. int i = 0,x=0 ;
  128. Console.Clear();
  129. Items target = Find(inventorycode);
  130. do
  131. {
  132. Console.Write("Input Inventory Code: ");
  133. inventorycode = Console.ReadLine();
  134. validinventorycode = int.TryParse(inventorycode, out inventorycode2);
  135. if (inventorycode == "\\c")
  136. {
  137. Console.WriteLine("Transacation Cancelled.");
  138. validinventorycode = true;
  139. }
  140. else if ((validinventorycode == false) || (inventorycode.Length != 5))
  141. {
  142. Console.WriteLine("Inventory code is invalid!");
  143. }
  144.  
  145. for (i= 0; i < current; i++)
  146. {
  147.  
  148. if (inventorycode == inventoryitems[i].GetCode())
  149. {
  150. x = 1;
  151. target = inventoryitems[i];
  152.  
  153. Console.Write("Change Name [{0}]: ", target.GetName());
  154. inventoryname = Console.ReadLine();
  155. if (inventoryname == "")
  156. {
  157. inventoryname = target.GetName();
  158. }
  159. if (inventoryname == "\\c")
  160. {
  161. Console.WriteLine("Transaction cancelled!");
  162. }
  163. else
  164. {
  165. do
  166. {
  167. Console.Write("Change Price [{0}]: ", target.GetPrice());
  168. inventoryprice = Console.ReadLine();
  169. validinventoryprice = double.TryParse(inventoryprice, out inventoryprice2);
  170.  
  171. if (inventoryprice == "\\c")
  172. {
  173. Console.WriteLine("Transaction cancelled!");
  174. }
  175. else if (validinventoryprice == false)
  176. {
  177. Console.WriteLine("Invalid Inventory Price!");
  178. }
  179. else
  180. {
  181. target.code = inventorycode;
  182. target.name = inventoryname;
  183. target.price = inventoryprice;
  184. Console.WriteLine("Inventory Item " + target.GetCode() + " Successfully Edited!");
  185. validinventoryprice = true;
  186. }
  187. } while ((validinventoryprice == false));
  188. }
  189. i = current;
  190. validinventorycode = true;
  191. }
  192. }
  193. if (x == 0 && inventorycode.Length==5)
  194. {
  195. Console.WriteLine("Inventory Code Does Not Exists!");
  196. }
  197. }while (validinventorycode == false);
  198. }
  199.  
  200. public void DeleteInventory()
  201. {
  202. int y = 0;
  203. Console.Clear();
  204. do
  205. {
  206. Console.Write("Input Inventory Code: ");
  207. inventorycode = Console.ReadLine();
  208. validinventorycode = int.TryParse(inventorycode, out inventorycode2);
  209. if (inventorycode == "\\c")
  210. {
  211. Console.WriteLine("Transacation Cancelled.");
  212. }
  213. if ((validinventorycode == false) || (inventorycode.Length != 5))
  214. {
  215. Console.WriteLine("Inventory code is invalid!");
  216. }
  217. }
  218. while ((inventorycode.Length != 5) || (inventorycode == "\\c") || (validinventorycode == false));
  219.  
  220. if ((validinventorycode == true) && (inventorycode.Length == 5) && (inventorycode != "\\c"))
  221. {
  222. Items target = Find(inventorycode);
  223.  
  224. for (int i = 0; i < current; i++)
  225. {
  226. if (inventorycode == inventoryitems[i].GetCode())
  227. {
  228. y = 1;
  229. Console.WriteLine("=================");
  230. Console.WriteLine("{0}", target.GetName());
  231. Console.WriteLine("{0}", target.GetPrice());
  232. Console.WriteLine("=================");
  233. Console.Write("Are you sure you want to delete this entry? [y/n]: ");
  234. string answer = Console.ReadLine();
  235.  
  236. if (answer == "Y" || answer == "y")
  237. {
  238. if (inventoryitems[i] != null)
  239. {
  240. inventoryitems[i] = null;
  241. current--;
  242. Console.WriteLine("Entry Deleted!");
  243. }
  244. }
  245. else if (answer == "N" || answer == "n" || answer == "\\c")
  246. {
  247. Console.WriteLine("Transaction Cancelled!");
  248. }
  249. }
  250. }
  251. if (y == 0 && inventorycode.Length == 5)
  252. Console.WriteLine("Inventory code does not exist.");
  253.  
  254. }
  255. }
  256.  
  257. public void DisplayAllItems()
  258. {
  259. Console.Clear();
  260. Console.WriteLine("--------------------------------------------");
  261. Console.WriteLine("|Code Name Price|");
  262. Console.WriteLine("--------------------------------------------");
  263. for (int i = 0; i <= current; i++)
  264. {
  265. if (current == 0)
  266. {
  267. Console.WriteLine("Inventory is empty.");
  268. }
  269. else if (inventoryitems[i] != null)
  270. {
  271. Console.WriteLine("|{0}\t\t{1}\t\t{2}|", inventoryitems[i].GetCode(), inventoryitems[i].GetName(), inventoryitems[i].GetPrice());
  272.  
  273. }
  274. }
  275. Console.WriteLine("--------------------------------------------");
  276. }
  277.  
  278. public void ClearInventory()
  279. {
  280.  
  281. Console.Clear();
  282. if (current == 0)
  283. Console.WriteLine("Inventory is empty.");
  284. else
  285. {
  286. Console.Write("Are you sure you want to delete all entries? [y/n]:");
  287. string answer = Console.ReadLine();
  288. if (answer == "Y" || answer == "y")
  289. {
  290. for (int i = 0; i < current; i++)
  291. {
  292. if (inventoryitems[i].code != null)
  293. {
  294. inventoryitems[i].code = null;
  295. inventoryitems[i].price = null;
  296. inventoryitems[i].name = null;
  297. current--;
  298. }
  299.  
  300. }
  301. Console.WriteLine("All inventory items deleted");
  302. }
  303. else
  304. Console.WriteLine("Transaction Cancelled!");
  305. }
  306. }
  307. }
  308.  
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement