Recorder.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using Lab18.Models;
  3. namespace Lab18
  4. {
  5. public class Recorder
  6. {
  7. Goods[] list_Goods; //ссылка на массив товаров
  8. Supplier[] list_Supplier; //ссылка на массив поставщиков
  9. GSRecords gsr_GSRecords; //ссылка на объект класса GSRecords
  10. int cur_sp; //текущее количество поставщиков
  11. int cur_gd; //текущее количество товаров
  12. int max_sp; //максимальное количество поставщиков
  13. int max_gd; //максимальное количество товаров
  14. /// <summary>
  15. /// Массив подсчёта количества поставщиков для товаров. Индексы этого
  16. /// массива совпадают с индексами в list_Goods
  17. /// </summary>
  18. private int[] goodsSupplierCount;
  19. //Описаниесвойств
  20. public Goods[] List_Goods
  21. {
  22. get { return list_Goods; }
  23. }
  24. public Supplier[] List_Supplier
  25. {
  26. get { return list_Supplier; }
  27. }
  28. public GSRecords Gsr_GSRecords
  29. {
  30. get { return gsr_GSRecords; }
  31. }
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="T:Lab18.Recorder"/> class.
  34. /// </summary>
  35. /// <param name="max_gd">Максимум товаров</param>
  36. /// <param name="max_sp">Максимум поставщиков</param>
  37. /// <param name="max_records">Максимум связей поставщиков с товарами</param>
  38. public Recorder(int max_gd, int max_sp, int max_records)
  39. {
  40. list_Goods = new Goods[max_gd];
  41. list_Supplier = new Supplier[max_sp];
  42. cur_sp = 0;
  43. this.max_sp = max_sp;
  44. cur_gd = 0;
  45. this.max_gd = max_gd;
  46. gsr_GSRecords = new GSRecords(max_records);
  47. goodsSupplierCount = new int[max_records];
  48. }
  49. //добавляем поставщика в массив поставщиков
  50. public bool AddSupplier(string name, int num_sp)
  51. {
  52. Supplier temp = new Supplier(name, num_sp); //проверяем, есть ли такой поставщика
  53. int i = 0;
  54. while ((i < cur_sp) && !temp.Equals(list_Supplier[i])) i++;
  55. if ((i != cur_sp) || (cur_sp == max_sp))
  56. {
  57. // Уже есть либо слишком много
  58. return false;
  59. }
  60. list_Supplier[cur_sp++] = temp;
  61. return true;
  62. }
  63. //выводспискапоставщиков
  64. public void St_Display()
  65. {
  66. for (int i = 0; i < cur_sp; i++)
  67. {
  68. Console.WriteLine(list_Supplier[i].S_name + " " + list_Supplier[i].S_id);
  69. }
  70. }
  71. //добавляемтоварвмассивтоваров
  72. public bool AddGoods(string name, int num_gd)
  73. {
  74. Goods temp = new Goods(name, num_gd); //проверяем, есть ли такой товар
  75. int i = 0;
  76. while ((i < cur_gd) && !temp.Equals(list_Goods[i])) i++;
  77. if ((i != cur_gd) /*нашли*/ || (cur_gd == max_gd) /*слишкоммноготоваров*/) return false;
  78. list_Goods[cur_gd] = temp;
  79. goodsSupplierCount[cur_gd] = 0;
  80. cur_gd++;
  81. return true;
  82. }
  83. //выводспискатоваров
  84. public void Cs_Display()
  85. {
  86. Console.WriteLine("Списоктоваров:");
  87. for (int i = 0; i < cur_gd; i++)
  88. {
  89. Console.WriteLine("Goods: " + list_Goods[i].G_name + " " + list_Goods[i].G_id);
  90. }
  91. }
  92. //регистрация поставщика
  93. public bool Recording(int SupplierID, int GoodsID)
  94. {
  95. int i = 0, j = 0;
  96. //естьлитакойпоставщик
  97. while ((i < cur_sp) && (SupplierID != list_Supplier[i].S_id)) i++;
  98. if (i == cur_sp) return false;
  99. //есть ли такой товар
  100. while ((j < cur_gd) && (GoodsID != list_Goods[j].G_id)) j++;
  101. if (j == cur_gd) return false;
  102. //нашли поставщика и товар в соотвествующих массивах, регистрируем поставщика товара
  103. goodsSupplierCount[j]++;
  104. return gsr_GSRecords.AddRecord(SupplierID, GoodsID);
  105. }
  106. public bool AddSupply(int goodID, int count, int supplierID)
  107. {
  108. return gsr_GSRecords.AddSupply(goodID, count, supplierID);
  109. }
  110. public void DisplayGoodsSuppliersCount()
  111. {
  112. Console.WriteLine("Количества поставщиков для товаров:");
  113. for (int i = 0; i < cur_gd; i++)
  114. {
  115. Console.WriteLine($"Для товара {list_Goods[i].G_name} количество поставщиков = {goodsSupplierCount[i]}");
  116. }
  117. }
  118. public void DisplayMaxGood()
  119. {
  120. int goodID;
  121. int goodCount;
  122. gsr_GSRecords.GetGoodCountsData(out goodID, out goodCount);
  123. Console.WriteLine($"Товар с максимумом количества - {goodID}. Количество - {goodCount}");
  124. }
  125. }
  126. }